protocalapi.c

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

C
1,971
字号
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetNetwork(H_STACK pStack, DWORD dwLocalIPAddr, WORD wPort)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);
  
	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->dwLocalIpAddr = dwLocalIPAddr;
		pTransacMng->wLocalPort = wPort;    
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}
	
	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetDomainName
 *
 * Description       : Set the domain name of the stack.
 *
 * Input parameters  : pStack - Handle of the stack
 *                     pcDomainName - Domain name
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetDomainName(H_STACK pStack, char *pcDomainName)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		StrClone(&pTransacMng->pcDomainName, pcDomainName);
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackRegisterEndpoint
 *
 * Description       : Creat a endpoint, initialize it and add it into the stack
 *
 * Input parameters  : pStack - Handle of the stack
 *                     pcEndpointName - Endpoint name
 *                     pCbkSigCheck - Signal chekc callback function of the
 *                                    endpoint
 *
 * Output parameters : ppEndpoint - Handle of the endpoint
 *
 * Return value      : Return OK if the endpoint is registered successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
#define DEF_AVER_ACK_DELAY 200 /* 200ms */
#define DEF_AVER_DEVIATION 50  /* 50ms */
LONG MgcpStackRegisterEndpoint(H_STACK pStack, H_ENDPOINT *ppEndpoint,
                               char *pcEndpointName, CBK_SIG_CHECK pCbkSigCheck)
{
	MGCP_ENDPOINT *pEndpnt;
	MGCP_STACK *pTmpStack = (MGCP_STACK*)pStack;

	Assert(pStack);
	Assert(ppEndpoint);
	Assert(pcEndpointName);
	Assert(pCbkSigCheck);

	/* The endpoint can not be registered when stack is running */
	if (pTmpStack->eStackState != STACK_STATE_CREATED)
	{
		return FAIL;
	}

	pEndpnt = (MGCP_ENDPOINT*)calloc(1, sizeof(MGCP_ENDPOINT));
	Assert(pEndpnt);
//	memset(pEndpnt, 0, sizeof(MGCP_ENDPOINT));
	/* Signal check CBK */
	pEndpnt->pCbkSigCheck = pCbkSigCheck;

	/* Endpoint name */
	StrClone(&pEndpnt->pcEndpointName, pcEndpointName);

	/* Service state */
	pEndpnt->bInService = TRUE;

	/* RTT to the CA */
	pEndpnt->lAverAckDelay = DEF_AVER_ACK_DELAY;
	pEndpnt->lAverDeviation = DEF_AVER_DEVIATION;

	pEndpnt->bNotifiedEntityProvided = FALSE;
	pEndpnt->bOnHookState = TRUE;

	/* Default is process and step */
	pEndpnt->bQuarantineProcess = TRUE;
	pEndpnt->bQuarantineLoop = FALSE;

	StrClone(&pEndpnt->pcRequestedID, "0");

	/* Initial connection ID (1-30000) */
	pEndpnt->dwCurConnecID = ((DWORD)rand() % 30000) + 1;

	/* Register the new endpoint */
	Assert(pTmpStack->pEndpointCtl);
	if (EndpointControlRegisterEndpoint((H_MGCP_ENDPOINT_CONTROL)
		(pTmpStack->pEndpointCtl), pEndpnt) == FAIL)
	{
		free(pEndpnt);
		free(pEndpnt->pcEndpointName);
		free(pEndpnt->pcRequestedID);
		return FAIL;
	}

	/* Initial restart wait delay */
	pEndpnt->dwRestartWaitDelay = InitRestartWaitDelay(pEndpnt);

	/* Initial restart method */
	pEndpnt->RestartMethod.eType = RESTART_METHOD_RESTART;

	/* Updata SM */
	pEndpnt->eState = SM_INIT;

	*ppEndpoint = (H_ENDPOINT)pEndpnt;

	return OK;
}
/******************************************************************************
 * Function          : MgcpStackSetDoaminNameValidatione
 *
 * Description       : Set the flag of whether need check the incoming mgcp
 *                     commands's domain name.
 *
 * Input parameters  : pStack - Handle of the stack
 *                     bOnOff - Whether use validition check
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetDoaminNameValidatione(H_STACK pStack, BOOL bOnOff)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->bCheckDomainName = bOnOff;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetMax1Retries
 *
 * Description       : Set the max1 retries in retransmission procedure
 *
 * Input parameters  : pStack - Handle of the stack
 *                     wRetryValue - Retry value
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
// 设置呼叫代理不可达的极限值		// Threshold of current CA is unreachable, default is 5
LONG MgcpStackSetMax1Retries(H_STACK pStack, WORD wRetryValue)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->wCounterMax1 = wRetryValue;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetMax2Retries
 *
 * Description       : Set the max2 retries in retransmission procedure
 *
 * Input parameters  : pStack - Handle of the stack
 *                     wRetryValue - Retry value
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
// 设置所有呼叫代理不可用的极限值		// Threshold of all CA are unavailable, default is 7
LONG MgcpStackSetMax2Retries(H_STACK pStack, WORD wRetryValue)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->wCounterMax2 = wRetryValue;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetMaxRTO
 *
 * Description       : Set the max RTO value of the stack.
 *
 * Input parameters  : pStack - Handle of the stack
 *                     wRTOValue - Max RTO value
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetMaxRTO(H_STACK pStack, WORD wRTOValue)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);


	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->dwTimerMaxRTO = wRTOValue;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetMaxInitRTO
 *
 * Description       : Set the max initial RTO of the stack.
 *
 * Input parameters  : pStack - Handle of the stack
 *                     wValue - Max initial RTO value
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetMaxInitRTO(H_STACK pStack, WORD wValue)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->dwTimerInitRTO = wValue;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpStackSetTimerMax
 *
 * Description       : Set the MaxTimer value of the stack.
 *
 * Input parameters  : pStack - Handle of the stack
 *                     wValue - Max timer value
 *
 * Output parameters : 
 *
 * Return value      : Return OK if the stack is configured successfylly,
 *                     otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/12/16       : Creation
 *
 * Date              : Dec 16 2005, Frank Zhang
 ******************************************************************************/
LONG MgcpStackSetTimerMax(H_STACK pStack, WORD wValue)
{
	H_MGCP_TRANSAC_MANAGER pTransacMng;

	Assert(pStack);

	pTransacMng = (H_MGCP_TRANSAC_MANAGER)(((MGCP_STACK*)pStack)->pTransacMng);
	Assert(pTransacMng);

	if (pTransacMng)
	{
		pthread_mutex_lock(&pTransacMng->pTranMngMutex);    
		pTransacMng->dwTimerMax = wValue;
		pthread_mutex_unlock(&pTransacMng->pTranMngMutex);
		return OK;
	}

	return FAIL;
}
/******************************************************************************
 * Function          : MgcpSackSetTimerHIST

⌨️ 快捷键说明

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