⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rvmegacoobjects.c

📁 h.248协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	x->type = RV_MEGACOENTITYADDRESSTYPE_IP;
	rvStringConstruct(&x->deviceIp, "", alloc);

	/* distinguish IP addresses from domain names */
	if(strchr(dnsOrIp, ':') == NULL) /* rule out IPv6 */
	{
		while(*dnsOrIp)
		{
			if(isalpha(*dnsOrIp))
			{
				x->type = RV_MEGACOENTITYADDRESSTYPE_DNS;
				break;
			}
			++dnsOrIp;
		}
	}

	return x;
}


/*$
{function:
	{name: rvMegacoEntityAddressConstructDevice}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs an entity address object from a device name.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressConstructDevice(RvMegacoEntityAddress *x, const char *deviceName);}
	{params:
		{param: {n:x} {d:The entity address object.}}
		{param: {n:deviceName} {d:The device name.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressConstructDevice(RvMegacoEntityAddress *x, const char *deviceName)
{
	return rvMegacoEntityAddressConstructDeviceA(x, deviceName, &rvDefaultAlloc);
}


/*$
{function:
	{name: rvMegacoEntityAddressConstructDeviceA}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs an entity address object from a device name.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressConstructDeviceA(RvMegacoEntityAddress *x, const char *deviceName, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The entity address object.}}
		{param: {n:deviceName} {d:The device name.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressConstructDeviceA(RvMegacoEntityAddress *x, const char *deviceName, RvAlloc *alloc)
{
	rvStringConstruct(&x->address, deviceName, alloc);
	x->port = 0;
	x->type = RV_MEGACOENTITYADDRESSTYPE_DEVICE;
	rvStringConstruct(&x->deviceIp, "", alloc);
	return x;
}


/*$
{function:
	{name: rvMegacoEntityAddressConstructMtp}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs an entity address object from an mtp address.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressConstructMtp(RvMegacoEntityAddress *x, const char *mtpAddress);}
	{params:
		{param: {n:x} {d:The entity address object.}}
		{param: {n:mtpAddress} {d:The mtp address.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressConstructMtp(RvMegacoEntityAddress *x, const char *mtpAddress)
{
	return rvMegacoEntityAddressConstructMtpA(x, mtpAddress, &rvDefaultAlloc);
}


/*$
{function:
	{name: rvMegacoEntityAddressConstructMtpA}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs an entity address object from an mtp address.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressConstructMtpA(RvMegacoEntityAddress *x, const char *mtpAddress, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The entity address object.}}
		{param: {n:mtpAddress} {d:The mtp address.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressConstructMtpA(RvMegacoEntityAddress *x, const char *mtpAddress, RvAlloc *alloc)
{
	rvStringConstruct(&x->address, mtpAddress, alloc);
	x->port = 0;
	x->type = RV_MEGACOENTITYADDRESSTYPE_MTP;
	rvStringConstruct(&x->deviceIp, "", alloc);
	return x;
}

RvMegacoEntityAddress *rvMegacoEntityAddressConstructAny(RvMegacoEntityAddress *x, const char *mid)
{
	return rvMegacoEntityAddressConstructAnyA(x, mid, &rvDefaultAlloc);
}

typedef struct
{
	RvMegacoEntityAddress *address;
	RvAlloc *alloc;
	RvBool success;
} RvMegacoEntityAddressParseInfo;

static RvBool rvMegacoEntityAddressProcessMessageHeader(const RvMegacoEntityAddress *sender, unsigned int version, void *data)
{
	RvMegacoEntityAddressParseInfo *info  = (RvMegacoEntityAddressParseInfo *)data;
	rvMegacoEntityAddressConstructCopy(info->address, sender, info->alloc);
	info->success = rvTrue;
	return rvTrue;
}

RvMegacoEntityAddress *rvMegacoEntityAddressConstructAnyA(RvMegacoEntityAddress *x, const char *mid, RvAlloc *alloc)
{
	/* use parser to construct and validate */
	static const RvMegacoParserHandlers rvMegacoEntityAddressParserHandlers = 
		{ NULL, rvMegacoEntityAddressProcessMessageHeader, NULL, NULL, NULL, NULL, NULL	};
	
	RvMegacoEntityAddressParseInfo info;
	RvString msgtext;

	info.address = x;
	info.alloc = alloc;
	info.success = rvFalse;

	rvStringConstruct(&msgtext, "!/1 ", &rvDefaultAlloc);
	rvStringConcatenate(&msgtext, mid);
	rvStringConcatenate(&msgtext, "\nK{1}\n");

	rvMegacoParse(rvStringGetData(&msgtext), &rvMegacoEntityAddressParserHandlers, &info, &rvDefaultAlloc);
	return info.success ? x : NULL;
}


/*$
{function:
	{name: rvMegacoEntityAddressConstructCopy}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs a copy of an entity address object.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressConstructCopy(RvMegacoEntityAddress *d, const RvMegacoEntityAddress *s, RvAlloc *alloc);}
	{params:
		{param: {n:d} {d:The destination entity address object.}}
		{param: {n:s} {d:The entity address object to copy.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressConstructCopy(RvMegacoEntityAddress *d, const RvMegacoEntityAddress *s, RvAlloc *alloc)
{
	rvStringConstructCopy(&d->address, &s->address, alloc);
	d->port = s->port;
	d->type = s->type;
	rvStringConstructCopy(&d->deviceIp, &s->deviceIp, alloc); 
	return d;
}


/*$
{function:
	{name: rvMegacoEntityAddressDestruct}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Destroys an entity address object.}
	}
	{proto: void rvMegacoEntityAddressDestruct(RvMegacoEntityAddress *x);}
	{params:
		{param: {n:x} {d:The entity address object.}}
	}
}
$*/
void rvMegacoEntityAddressDestruct(RvMegacoEntityAddress *x)
{
	rvStringDestruct(&x->address);
	rvStringDestruct(&x->deviceIp); 
}


/*$
{function:
	{name: rvMegacoEntityAddressCopy}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Copies the value of one entity address object to another.}
	}
	{proto: RvMegacoEntityAddress *rvMegacoEntityAddressCopy(RvMegacoEntityAddress *d, const RvMegacoEntityAddress *s);}
	{params:
		{param: {n:d} {d:The destination entity address object.}}
		{param: {n:s} {d:The entity address object to copy.}}
	}
	{returns: A pointer to the destination object, or NULL if the copy failed.}
}
$*/
RvMegacoEntityAddress *rvMegacoEntityAddressCopy(RvMegacoEntityAddress *d, const RvMegacoEntityAddress *s)
{
	rvStringCopy(&d->address, &s->address);
	d->port = s->port;
	d->type = s->type;
	rvStringCopy(&d->deviceIp, &s->deviceIp); 
	return d;
}


/*$
{function:
	{name: rvMegacoEntityAddressEqual}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Compares two entity address objects for equality.}
	}
	{proto: RvBool rvMegacoEntityAddressEqual(const RvMegacoEntityAddress *a, const RvMegacoEntityAddress *b);}
	{params:
		{param: {n:a} {d:The first entity address object.}}
		{param: {n:b} {d:The second entity address object.}}
	}
	{returns: rvTrue if the objects are equal, rvFalse if not.}
}
$*/
RvBool rvMegacoEntityAddressEqual(const RvMegacoEntityAddress *a, const RvMegacoEntityAddress *b)
{
	return rvStringEqualIgnoreCase(&a->address, &b->address) &&
		a->port == b->port && a->type == b->type &&
		rvStringEqualIgnoreCase(&a->deviceIp, &b->deviceIp); 
}


/*$
{function:
	{name: rvMegacoEntityAddressGetType}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Gets the type of the entity address object.}
	}
	{proto: RvMegacoEntityAddressType rvMegacoEntityAddressGetType(const RvMegacoEntityAddress *x);}
	{params:
		{param: {n:x} {d:The entity address object.}}
	}
	{returns: The type.}
}
$*/
RvMegacoEntityAddressType rvMegacoEntityAddressGetType(const RvMegacoEntityAddress *x)
{
	return x->type;
}


/*$
{function:
	{name: rvMegacoEntityAddressGetAddress}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Gets the address of the entity address object.}
	}
	{proto: const char *rvMegacoEntityAddressGetAddress(const RvMegacoEntityAddress *x);}
	{params:
		{param: {n:x} {d:The entity address object.}}
	}
	{returns: The address.}
}
$*/
const char *rvMegacoEntityAddressGetAddress(const RvMegacoEntityAddress *x)
{
	return rvStringGetData(&x->address);
}


/*$
{function:
	{name: rvMegacoEntityAddressGetPort}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Gets the port number of the entity address object.}
	}
	{proto: RvInetPort rvMegacoEntityAddressGetPort(const RvMegacoEntityAddress *x);}
	{params:
		{param: {n:x} {d:The entity address object.}}
	}
	{returns: The port number.}
}
$*/
RvInetPort rvMegacoEntityAddressGetPort(const RvMegacoEntityAddress *x)
{
	return x->port;
}


const char *rvMegacoEntityAddressGetDeviceIp(const RvMegacoEntityAddress *x)
{
	assert(x->type == RV_MEGACOENTITYADDRESSTYPE_DEVICE);
	return rvStringGetData(&x->deviceIp);
}

/*$
{function:
	{name: rvMegacoEntityAddressIsSet}
	{class: RvMegacoEntityAddress}
	{include: rvmegacoobjects.h}
	{description:
		{p: Checks whether the entity address object is set.}
	}
	{proto: RvBool rvMegacoEntityAddressIsSet(const RvMegacoEntityAddress *x);}
	{params:
		{param: {n:x} {d:The entity address object.}}
	}
	{returns: rvTrue if the object is set, rvFalse if not.}
}
$*/
RvBool rvMegacoEntityAddressIsSet(const RvMegacoEntityAddress *x)
{
	return *rvMegacoEntityAddressGetAddress(x) != 0;
}


/*$
{function:
	{name: rvMegacoTerminationIdConstruct}
	{class: RvMegacoTerminationId}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs a termination id object.}
	}
	{proto: RvMegacoTerminationId *rvMegacoTerminationIdConstruct(RvMegacoTerminationId *x, const char *name);}
	{params:
		{param: {n:x} {d:The termination id object.}}
		{param: {n:name} {d:The name of the termination. The name may contain the wildcard
		character '*' or the choose character '\$'.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
	{notes:
		{note: Use rvMegacoTerminationIdConstructRoot to construct ROOT.}
	}
}
$*/
RvMegacoTerminationId *rvMegacoTerminationIdConstruct(RvMegacoTerminationId *x, const char *name)
{
	return rvMegacoTerminationIdConstructA(x, name, &rvDefaultAlloc);
}


/*$
{function:
	{name: rvMegacoTerminationIdConstructA}
	{class: RvMegacoTerminationId}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs a termination id object.}
	}
	{proto: RvMegacoTerminationId *rvMegacoTerminationIdConstructA(RvMegacoTerminationId *x, const char *name, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The termination id object.}}
		{param: {n:name} {d:The name of the termination. The name may contain the wildcard
		character '*' or the choose character '\$'.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
	{notes:
		{note: Use rvMegacoTerminationIdConstructRootA to construct ROOT.}
	}
}
$*/
RvMegacoTerminationId *rvMegacoTerminationIdConstructA(RvMegacoTerminationId *x, const char *name, RvAlloc *alloc)
{
	rvStringConstruct(&x->name, name, alloc);
	return x;
}


/*$
{function:
	{name: rvMegacoTerminationIdConstructRoot}
	{class: RvMegacoTerminationId}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs a termination id object representing the root termination.}
	}
	{proto: RvMegacoTerminationId *rvMegacoTerminationIdConstructRoot(RvMegacoTerminationId *x);}
	{params:
		{param: {n:x} {d:The termination id object.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
$*/
RvMegacoTerminationId *rvMegacoTerminationIdConstructRoot(RvMegacoTerminationId *x)
{
	return rvMegacoTerminationIdConstructRootA(x, &rvDefaultAlloc);
}


/*$
{function:
	{name: rvMegacoTerminationIdConstructRootA}
	{class: RvMegacoTerminationId}
	{include: rvmegacoobjects.h}
	{description:
		{p: Constructs a termination id object representing the root termination.}
	}
	{proto: RvMegacoTerminationId *rvMegacoTerminationIdConstructRootA(RvMegacoTerminationId *x, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The termination id object.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -