protocalapi.c

来自「mgcp协议源代码和测试程序,还有一个编译器」· C语言 代码 · 共 1,971 行 · 第 1/5 页

C
1,971
字号
	else
	{
		/* Only domain name */
		StrClone(&pEndpnt->NotifiedEntity.pcDomainName, pcCaName);
	}

	/* Call Agent port */
	pEndpnt->NotifiedEntity.wPort = wPort;

	Assert(pEndpnt->NotifiedEntity.pcDomainName);  

	/* Resolve the domain name to get IP addresses */
	if (IsDotDecimalAddress(pEndpnt->NotifiedEntity.pcDomainName))
	{
		/* Dot decimal format IP address */
		ConvertIpAddress(pEndpnt->NotifiedEntity.pIPAddrList,
						 pEndpnt->NotifiedEntity.pcDomainName);

		pEndpnt->NotifiedEntity.wCurAddrIndex = 0;
		pEndpnt->NotifiedEntity.wAddrNum = 1;

		return OK;
	}
	else
	{
	    /* Domain Name format address */
	    WORD i = 0;
	    struct hostent *pHostList;

	    if ((pHostList = gethostbyname(pEndpnt->NotifiedEntity.pcDomainName)) != NULL)
	    {
			/* Copy the new resolved address into the NE address list */
			while ((pHostList->h_addr_list[i]) != NULL)
			{
				pEndpnt->NotifiedEntity.pIPAddrList[i]
					= ntohl(*((DWORD*)pHostList->h_addr_list[i]));
				i++;
			}

			pEndpnt->NotifiedEntity.wAddrNum = i;
			pEndpnt->NotifiedEntity.wCurAddrIndex = 0;

			return OK;
	    }
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpEndpointAddSupportedPackage
 *
 * Description       : Set the supported MGCP packages of the endpoint, if the
 *                     package has set, ignore it, otherwise add it into the
 *                     package list.
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     ePackage - MGCP package tytpe
 *
 * Output parameters : 
 *
 * Return value      : Return FAIL if the packaeg has been in the package list,
 *                     otherwise return OK.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointAddSupportedPackage(H_ENDPOINT pEndpoint, E_MGCP_PACKAGE ePackage)
{
	E_MGCP_PACKAGE *pPkg;
	H_MGCP_ENDPOINT pEndpnt = (H_MGCP_ENDPOINT)pEndpoint;

	Assert(pEndpnt);

	SListReset(&pEndpnt->CapabilityList.SupportedPackages);

	/* Check if the package has been in the package list */
	while((pPkg = SListGetCurData(&pEndpnt->CapabilityList.SupportedPackages)) != NULL)
	{
		if (ePackage == *pPkg)
		{
			return OK;
		}
		SListNextNode(&pEndpnt->CapabilityList.SupportedPackages);
	}

	pPkg = (E_MGCP_PACKAGE*)calloc(1, sizeof(E_MGCP_PACKAGE));
	Assert(pPkg);
	*pPkg = ePackage;
	SListAppend(&pEndpnt->CapabilityList.SupportedPackages, pPkg);

	return OK;
}
/******************************************************************************
 * Function          : MgcpEndpointRemoveSupportedPackage
 *
 * Description       : Remove the supported MGCP packages of the endpoint, if
 *                     package is not in the package list, ignore it, otherwise
 *                     remove it from the package list.
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     ePackage - MGCP package tytpe
 *
 * Output parameters : 
 *
 * Return value      : Return FAIL if the packaeg is not in the package list,
 *                     otherwise remove it from the list and return OK.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointRemoveSupportedPackage(H_ENDPOINT pEndpoint, E_MGCP_PACKAGE ePackage)
{
	E_MGCP_PACKAGE *pPkg;
	H_MGCP_ENDPOINT pEndpnt = (H_MGCP_ENDPOINT)pEndpoint;

	Assert(pEndpnt);

	SListReset(&pEndpnt->CapabilityList.SupportedPackages);
	while((pPkg = SListGetCurData(&pEndpnt->CapabilityList.SupportedPackages))!= NULL)
	{
		if (ePackage == *pPkg)
		{
			free(pPkg);
			SListDelCurNode(&pEndpnt->CapabilityList.SupportedPackages);
			return OK;
		}
		SListNextNode(&pEndpnt->CapabilityList.SupportedPackages);
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpEndpointClearSupportedPackages
 *
 * Description       : Remove all the supported MGCP packages of the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
void MgcpEndpointClearSupportedPackages(H_ENDPOINT pEndpoint)
{
	Assert(pEndpoint);
	SListFreeAll(&((H_MGCP_ENDPOINT)pEndpoint)->CapabilityList.SupportedPackages);
}
/******************************************************************************
 * Function          : MgcpEndpointSetDefaultPackage
 *
 * Description       : Set the default MGCP packages of the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     ePackage - MGCP package tytpe
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the default packaeg is set successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointSetDefaultPackage(H_ENDPOINT pEndpoint, E_MGCP_PACKAGE ePackage)
{
	E_MGCP_PACKAGE *pPkg = NULL;
	H_MGCP_ENDPOINT pEndpnt = (H_MGCP_ENDPOINT)pEndpoint;

	Assert(pEndpnt);

	/* Ccheck if the default package has been in the supported package
	 list, if yes, free it firstly*/
	SListReset(&pEndpnt->CapabilityList.SupportedPackages);
	while((pPkg = SListGetCurData(&pEndpnt->CapabilityList.SupportedPackages))!= NULL)
	{
		if (ePackage == *pPkg)
		{
			SListDelCurNode(&pEndpnt->CapabilityList.SupportedPackages);
		}
		SListNextNode(&pEndpnt->CapabilityList.SupportedPackages);
	}

	/* Default package is not in the pakcage list, allocate a new */
	if (pPkg == NULL)
	{
		pPkg = (E_MGCP_PACKAGE*)calloc(1, sizeof(E_MGCP_PACKAGE));
		Assert(pPkg);
		*pPkg = ePackage;
	}
  
	/* Add the default package into the head of the package list */
	SListAdd(&pEndpnt->CapabilityList.SupportedPackages, pPkg);
	return OK;
}
/******************************************************************************
 * Function          : MgcpEndpointAddCodecCapability
 *
 * Description       : Set the supported compression algorithms of the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     wCapNum - Algorithms number in the list
 *                     pCababilities - Algorithms list
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the compression algorithms are set
 *                     successfully, otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/15       : Creation
 *
 * Date              : Dec 15 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointAddCodecCapability(H_ENDPOINT pEndpoint, MGCP_CODEC *pCabability)
{
	MGCP_CODEC *pCodec;
	H_MGCP_ENDPOINT pEndpnt = (H_MGCP_ENDPOINT)pEndpoint;

	Assert(pEndpnt);

	if (pCabability != NULL)
	{
		SListReset(&pEndpnt->CapabilityList.CompressAlgo);
		while((pCodec = SListGetCurData(&pEndpnt->CapabilityList.CompressAlgo)) != NULL)
		{
			if (StrCaseCmp(pCodec->CodecName, pCabability->CodecName) == 0)
			{
				return FAIL;
			}
			SListNextNode(&pEndpnt->CapabilityList.CompressAlgo);
		}
		pCodec = (MGCP_CODEC*)calloc(1, sizeof(MGCP_CODEC));
		Assert(pCodec);
		memcpy(pCodec, pCabability, sizeof(MGCP_CODEC));
		SListAppend(&pEndpnt->CapabilityList.CompressAlgo, pCodec);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpEndpointClearCodecCapability
 *
 * Description       : Remove all the supported MGCP compression algorithms of
 *                     the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/15       : Creation
 *
 * Date              : Dec 15 2005, Frank Zhang
 ******************************************************************************/
void MgcpEndpointClearCodecCapability(H_ENDPOINT pEndpoint)
{
	Assert(pEndpoint);
	SListFreeAll(&((H_MGCP_ENDPOINT)pEndpoint)->CapabilityList.CompressAlgo);
}
/******************************************************************************
 * Function          : MgcpEndpointSetRestartDealy
 *
 * Description       : Set the restart delay of the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     dwRestartDelay - Restart delay
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the restart delay is set successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointSetRestartDealy(H_ENDPOINT pEndpoint, DWORD dwRestartDelay)
{
	Assert(pEndpoint);

	((H_MGCP_ENDPOINT)pEndpoint)->dwRestartDelay = dwRestartDelay;
	return OK;
}
/******************************************************************************
 * Function          : MgcpEndpointAddPersistentEvent
 *
 * Description       : Add a persitent event into list of the endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     ePkgID - MGCP package type of the persistent event
 *                     eEventID - MGCP event type of the persistent event
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the persistent event is added successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/13       : Creation
 *
 * Date              : Dec 13 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointAddPersistentEvent(H_ENDPOINT pEndpoint, E_MGCP_PACKAGE ePkgID,
                                    E_MGCP_EVENT eEventID)
{
	MGCP_PERSIS_EVENT *pEvent;

	pEvent = (MGCP_PERSIS_EVENT*)calloc(1, sizeof(MGCP_PERSIS_EVENT));
	Assert(pEvent);
	pEvent->ePkgID = ePkgID;
	pEvent->EventID = eEventID;
	SListAppend(&((H_MGCP_ENDPOINT)pEndpoint)->PerSistentEvents, pEvent);
	return OK;
}
/******************************************************************************
 * Function          : MgcpEndpointClearPersistentEvents
 *
 * Description       : Remove all the supported persistent events of the 
 *                     endpoint
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/15       : Creation
 *
 * Date              : Dec 15 2005, Frank Zhang
 ******************************************************************************/
void MgcpEndpointClearPersistentEvents(H_ENDPOINT pEndpoint)
{
	Assert(pEndpoint);
	SListFreeAll(&((H_MGCP_ENDPOINT)pEndpoint)->PerSistentEvents);
}
/******************************************************************************
 * Function          : MgcpEndpointNotifyEvent
 *
 * Description       : Notify an observed event to the protocal stack. Construct
 *                     a internal message and send it to the message queue.
 *                     
 * Input parameters  : pEndpoint - Handle of the Endpoint
 *                     pEvent - Pointer to the observed event
 *                     pExperiParamList - Experimental parameters of the
 *                                        observed event
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the message is sent into the queue
 *                     successfylly, otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/11/20       : Creation
 *
 * Date              : Nov 20 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpEndpointNotifyEvent(H_ENDPOINT pEndpoint, MGCP_OBSERVED_EVENT *pEvent,
                             EXPERIMENTAL_PARAMS *pExperiParamList)
{

⌨️ 快捷键说明

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