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

📄 rvwpconfig.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:

#include "string.h"
#include <stdio.h>
#include "ci.h"
#include "rvtypes.h"
#include "rvmemory.h"
#include "cibuf.h"
#include "rvwpconfig.h"
#include "cm.h"
#include "cmintr.h"


char * bufConfig = NULL;
int bufCfSize = 0;
int bufCfNode = 0;
int bufCfStrSize = 0;
int bufCfOffset = 0;



typedef struct
{
  RvInt32   level;
  RvInt8    isString;
  RvInt32   value;
  RvUint32  nameLen;
} BufInfoBlock;

int prePareConfig()
{
	if (bufConfig != NULL)
		return ERROR;
	bufCfSize = CONFIG_COMMON_LEN;
	if(RvMemoryAlloc(NULL, (void**)&bufConfig, (RvSize_t)bufCfSize) != RV_OK)
		return ERR_CI_ALLOCERROR;

	memset(bufConfig, 0, bufCfSize);
	bufCfOffset = 8 + 4 + 4 + 4;
	return ciPrepareTargetBuffer((void*)bufConfig, bufCfSize);
}

void String2Bmp(char* string, char* bmp, int size)
{
    int count;

    for (count = 0; count < size; count++)
    {
        bmp[count*2] = '\0';
        bmp[count*2+1] = string[count];
    }
}

void Bmp2String(char* bmp, char* string, int size)
{
    int count;

    for (count = 0; count < size/2; count++)
        string[count] = bmp[count*2+1];
    string[size/2] = '\0';
}


void endConfig()
{
	if (bufConfig != NULL)
		RvMemoryFree(bufConfig);

	bufConfig = NULL;
	bufCfSize = 0;
	bufCfNode = 0;
	bufCfStrSize = 0;
	bufCfOffset = 0;
}
extern FILE* fp;
extern RvSemaphore* fileSem;
int addBufSize()
{
	char* temp = bufConfig;
	bufCfSize += CONFIG_COMMON_LEN;
	if(RvMemoryAlloc(NULL, (void**)&bufConfig, (RvSize_t)bufCfSize) != RV_OK)
		return ERR_CI_ALLOCERROR;

	memset(bufConfig, 0, bufCfSize);
	memcpy(bufConfig, temp, bufCfOffset);
	RvMemoryFree(temp);
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
	{
		fprintf(fp,"current buf size is %d!\n", bufCfSize);
		ReleaseSemaphore(fileSem,1,NULL);
	}*/
	return 0;
}

int addItem(RvInt32 level, RvInt8 isString, RvInt32 value, RvUint32 strLen, char* name)
{
	int temp;
	int size = 4 + 1 + 4 + 4 + strlen(name);/*level(4) + isString(1) + value(4) + strLen(4) + strlen(name)*/
	if (isString)
		size += strLen;

	if (bufCfOffset + size >= bufCfSize)
		if (addBufSize() < 0)
		{
	/*		if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
			{
				fprintf(fp,"addItem :addBufSize return error!\n");
				ReleaseSemaphore(fileSem,1,NULL);
			}
			if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
			{
				fprintf(fp,"name:%s\n", name);
				ReleaseSemaphore(fileSem,1,NULL);
			}
		*/	return ERR_CI_ALLOCERROR;
		}

	/*level(4)*/
	temp = level;
	temp = RvConvertHostToNetwork32(temp);
	memcpy((void *)(bufConfig + bufCfOffset), (void*)&temp, (RvSize_t)sizeof(int));
	bufCfOffset += 4;

	/*isString(1)*/
	memcpy((bufConfig + bufCfOffset), (char*)&isString, sizeof(char));
	bufCfOffset += 1;

	/*stringlen(4)*/
	if (isString)
		temp = strLen;
	else
		temp = *(int*)value;
	temp = RvConvertHostToNetwork32(temp);
	memcpy((bufConfig + bufCfOffset), (char*)&temp, sizeof(int));
	bufCfOffset += 4;

	/*namelen(4)*/
	temp = strlen(name);
	temp = RvConvertHostToNetwork32(temp);
	memcpy((bufConfig + bufCfOffset), (char*)&temp, sizeof(int));
	bufCfOffset += 4;

	/*name*/
	memcpy((void*)(bufConfig + bufCfOffset), (void*)name, strlen(name));
	bufCfOffset += strlen(name);

	/*string*/
	if (isString)
	{
		memcpy((void *)(bufConfig + bufCfOffset), (void*)value, strLen);
		bufCfOffset += strLen;
	}

	bufCfNode++;

	return 0;
}

#define ADDITEM(para1, para2, level, isString)								\
{																		\
if (para1##->para2 != NULL)												\
	if (addItem(level, isString, (RvInt32)para1##->para2, isString?strlen((char*)para1##->para2):0, #para2)<0)		\
		return ERR_CI_ALLOCERROR;										\
}

int buildSysCof(IN SystemConfiguration* sys)
{
	int sysLevel = 1;

	addItem(sysLevel, 0, 0, 0, "system");

	ADDITEM(sys, manualStart, sysLevel+1, 0);
	ADDITEM(sys, pdlName, sysLevel+1, 1);
	ADDITEM(sys, cidAssociate, sysLevel+1, 0);
	ADDITEM(sys, delimiter, sysLevel+1, 1);
	ADDITEM(sys, maxCalls, sysLevel+1, 0);
	ADDITEM(sys, maxChannels, sysLevel+1, 0);
	ADDITEM(sys, maxRasOutTransaction, sysLevel+1, 0);
	ADDITEM(sys, maxRasInTransaction, sysLevel+1, 0);
	if (sys->localIpAddress != NULL)
	{
		addItem(sysLevel+1, 1, (RvInt32)sys->localIpAddress, 4, "localIPAddress");
	}
	ADDITEM(sys, portFrom, sysLevel+1, 0);
	ADDITEM(sys, portTo, sysLevel+1, 0);

	if (sys->allocations != NULL)
	{
		addItem(sysLevel+1, 0, 0, 0, "allocations");

		ADDITEM(sys->allocations, vtPoolSize, sysLevel+2, 0);
		ADDITEM(sys->allocations, vtNodeCount, sysLevel+2, 0);
		ADDITEM(sys->allocations, channels, sysLevel+2, 0);
		ADDITEM(sys->allocations, chanDescs, sysLevel+2, 0);
		ADDITEM(sys->allocations, messages, sysLevel+2, 0);
		ADDITEM(sys->allocations, nameChans, sysLevel+2, 0);
		ADDITEM(sys->allocations, tpktChans, sysLevel+2, 0);
		ADDITEM(sys->allocations, tpktNoBuffers, sysLevel+2, 0);
		ADDITEM(sys->allocations, udpChans, sysLevel+2, 0);
		ADDITEM(sys->allocations, protocols, sysLevel+2, 0);
		ADDITEM(sys->allocations, maxProcs, sysLevel+2, 0);
		ADDITEM(sys->allocations, maxBuffSize, sysLevel+2, 0);
		ADDITEM(sys->allocations, maxPoolSizeInKB, sysLevel+2, 0);
	}

	if (sys->callProperty != NULL)
	{
		addItem(sysLevel+1, 0, 0, 0, "callProperty");

		ADDITEM(sys->callProperty, fullProperty, sysLevel+2, 0);
		ADDITEM(sys->callProperty, copySingleMessage, sysLevel+2, 0);
		ADDITEM(sys->callProperty, deleteSingleMessage, sysLevel+2, 0);
		ADDITEM(sys->callProperty, doNotUseProperty, sysLevel+2, 0);
	}

	if (sys->watchdog != NULL)
	{
		addItem(sysLevel+1, 0, 0, 0, "watchdog");
		ADDITEM(sys->watchdog, interval, sysLevel+2, 0);
	}

	return 0;
}

int buildRasCof(IN RasConfigration* ras)
{
	int rasLevel = 1;
	int i;
	char tmpbuf[10];
	int tmpval = 0;
	addItem(rasLevel, 0, 0, 0, "RAS");

	ADDITEM(ras, responseTimeOut, rasLevel+1, 0);
	ADDITEM(ras, gatekeeper, rasLevel+1, 0);
	ADDITEM(ras, manualRAS, rasLevel+1, 0);
	ADDITEM(ras, maxFail, rasLevel+1, 0);
	ADDITEM(ras, allowCallsWhenNonReg, rasLevel+1, 0);
	ADDITEM(ras, manualRegistration, rasLevel+1, 0);
	ADDITEM(ras, rasPort, rasLevel+1, 0);
	ADDITEM(ras, compare15bitRasCrv, rasLevel+1, 0);
	ADDITEM(ras, maxRetries, rasLevel+1, 0);
	ADDITEM(ras, maxMulticastTTL, rasLevel+1, 0);
	ADDITEM(ras, overlappedSending, rasLevel+1, 0);
	if (ras->preGrantedArqUse != NULL)
	{
		addItem(rasLevel+1, 0, (RvInt32)&tmpval, 0, "preGrantedArqUse");

		ADDITEM(ras->preGrantedArqUse, direct, rasLevel+2, 0);
		ADDITEM(ras->preGrantedArqUse, routed, rasLevel+2, 0);
	}
	ADDITEM(ras, dontRegisterOnTimeOut, rasLevel+1, 0);
	ADDITEM(ras, supportAltGK, rasLevel+1, 0);
	ADDITEM(ras, preTimeToLiveRegistration, rasLevel+1, 0);

	if (ras->manualDiscovery != NULL)
	{
		addItem(rasLevel+1, 0, (RvInt32)&tmpval, 0, "manualDiscovery");
		if (ras->manualDiscovery->defaultGatekeeper != NULL)
		{
			addItem(rasLevel+2, 0, (RvInt32)&tmpval, 0, "defaultGatekeeper");
			addItem(rasLevel+3, 0, (RvInt32)&tmpval, 0, "ipAddress");

			addItem(rasLevel+4, 0, (RvInt32)&(ras->manualDiscovery->defaultGatekeeper->ipAddress.port), 0, "port");
			addItem(rasLevel+4, 1, (RvInt32)&(ras->manualDiscovery->defaultGatekeeper->ipAddress.ip), 4, "ip");

		}
	}

	if (ras->registrationInfo != NULL)
	{
		addItem(rasLevel+1, 0, (RvInt32)&tmpval, 0, "registrationInfo");

		ADDITEM(ras->registrationInfo, timeToLive, rasLevel+2, 0);
		if (ras->registrationInfo->terminalType != NULL)
		{
			addItem(rasLevel+2, 0, (RvInt32)&tmpval, 0, "terminalType");
			if (ras->registrationInfo->terminalType->terminal != NULL)
			{
				TerminalInfo* terminal = ras->registrationInfo->terminalType->terminal;
				addItem(rasLevel+3, 0, (RvInt32)&tmpval, 0, "terminal");
				if (terminal->nonStandardData != NULL)
				{
					addItem(rasLevel+4, 0, (RvInt32)&tmpval, 0, "nonStandardData");
					if (terminal->nonStandardData->nonStandardIdentifier != NULL)
					{
						addItem(rasLevel+5, 0, (RvInt32)&tmpval, 0, "nonStandardIdentifier");
						if (terminal->nonStandardData->nonStandardIdentifier->h221NonStandard != NULL)
						{
							addItem(rasLevel+6, 0, (RvInt32)&tmpval, 0, "h221NonStandard");
							ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, t35CountryCode, rasLevel+7, 0);
							ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, t35Extension, rasLevel+7, 0);
							ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, manufacturerCode, rasLevel+7, 0);
						}
						ADDITEM(terminal->nonStandardData->nonStandardIdentifier, object, rasLevel+6, 1);
					}
					ADDITEM(terminal->nonStandardData, data, rasLevel+5, 1);
					
				}
			}
			ADDITEM(ras->registrationInfo->terminalType, mc, rasLevel+3, 0);
			ADDITEM(ras->registrationInfo->terminalType, undefinedNode, rasLevel+3, 0);
			if (ras->registrationInfo->terminalType->vendor != NULL)
			{
				addItem(rasLevel+3, 0, (RvInt32)&tmpval, 0, "vendor");

				if (ras->registrationInfo->terminalType->vendor->vendor != NULL)
				{
					addItem(rasLevel+4, 0, (RvInt32)&tmpval, 0, "vendor");
					ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, t35CountryCode, rasLevel+5, 0);
					ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, t35Extension, rasLevel+5, 0);
					ADDITEM(ras->registrationInfo->terminalType->vendor->vendor, manufacturerCode, rasLevel+5, 0);
				}

				ADDITEM(ras->registrationInfo->terminalType->vendor, productId, rasLevel+4, 1);
				ADDITEM(ras->registrationInfo->terminalType->vendor, versionId, rasLevel+4, 1);
			}
		}
		if (ras->registrationInfo->terminalAlias != NULL)
		{
			char aliasname[128];
			char* aliasTemp;
			addItem(rasLevel+2, 0, (RvInt32)&tmpval, 0, "terminalAlias");
			for (i = 0; i < *(ras->registrationInfo->aliasSize); i++)
			{
				sprintf(tmpbuf, "%d", i+1);
				addItem(rasLevel+3, 0, (RvInt32)&tmpval, strlen(tmpbuf), tmpbuf);

				if (strcmp(ras->registrationInfo->terminalAlias[i].aliasType, "h323-ID") == 0)
				{
					aliasTemp = ras->registrationInfo->terminalAlias[i].aliasVal;
					String2Bmp(aliasTemp, aliasname, strlen(aliasTemp));
					addItem(rasLevel+4, 1, (int)aliasname, 2 * strlen(aliasTemp), "h323-ID");
				}
				else if (strcmp(ras->registrationInfo->terminalAlias[i].aliasType, "e164") == 0)
				{
					aliasTemp = ras->registrationInfo->terminalAlias[i].aliasVal;
					addItem(rasLevel+4, 1, (int)aliasTemp, strlen(aliasTemp), "e164");
				}
			}
		}

		ADDITEM(ras->registrationInfo, gatekeeperIdentifier, rasLevel+2, 0);

		if (ras->registrationInfo->endpointVendor != NULL)
		{
			addItem(rasLevel+2, 0, (RvInt32)&tmpval, 0, "endpointVendor");

			if (ras->registrationInfo->endpointVendor->vendor != NULL)
			{
				addItem(rasLevel+3, 0, (RvInt32)&tmpval, 0, "vendor");

				ADDITEM(ras->registrationInfo->endpointVendor->vendor, t35CountryCode, rasLevel+4, 0);
				ADDITEM(ras->registrationInfo->endpointVendor->vendor, t35Extension, rasLevel+4, 0);
				ADDITEM(ras->registrationInfo->endpointVendor->vendor, manufacturerCode, rasLevel+4, 0);

⌨️ 快捷键说明

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