📄 endpointctrl.c
字号:
{
/* New endpoint, but the tree node is already existed, add into the tree */
pCurTreeNode->pEndpoint = pEndpnt;
lRet = OK;
}
/* Clear the local name */
ClearEndpointLocalName(&LocalName);
return lRet;
}
}
/* New endpoint whose local name has new hierarchical format, add into the
endpoint tree */
while (i < LocalName.wHierarchicalNum)
{
TSListNode* ptslist_node = NULL;
MGCP_ENDPOINT_TREE_NODE *pNewNode
= (MGCP_ENDPOINT_TREE_NODE*)calloc(1, sizeof(MGCP_ENDPOINT_TREE_NODE));
Assert(pNewNode);
// memset(pNewNode, 0, sizeof(MGCP_ENDPOINT_TREE_NODE));
/* Terminal node ? */
if (i == LocalName.wHierarchicalNum-1)
{
pNewNode->pEndpoint = pEndpnt;
}
StrClone(&pNewNode->TreeNodeName, LocalName.SubNames[i]);
ptslist_node = SListAppend(pCurNodeList, pNewNode);
if (ptslist_node == NULL)
{
free(ptslist_node);
free(pNewNode->TreeNodeName);
free(pNewNode);
return FAIL;
}
pCurNodeList = &pNewNode->SubNodeList;
i++;
}
ClearEndpointLocalName(&LocalName);
return OK;
}
/******************************************************************************
* Function : FindEndpointByName
*
* Description : Find the endpoints whose name are match the requested
* name. If the requested name use wildcard, the found
* endpoint number maybe more than one.
*
* Input parameters : pcName - Target endpoint name.
* pEndpntTree - Pointer to the endpoint tree in which the
* endpoints are checked.
*
* Output parameters : pFoundEndpointList - Store the endpoint handle whose
* name match the requested name.
*
* Return value : Return TRUE if endpoint is found; otherwise return FALSE.
*
* Comments :
*
* History :
* 2005/09/16 : Creation
*
* Date : Sep 16 2005, Frank Zhang
******************************************************************************/
BOOL FindEndpointByName(char *pcName, MGCP_ENDPOINT_TREE *pEndpntTree,
SLIST *pFoundEndpointList)
{
ENDPOINT_LOCAL_NAME LocalName;
BOOL bRet = FALSE;
Assert(pcName);
Assert(pEndpntTree);
Assert(pFoundEndpointList);
memset(&LocalName, 0, sizeof(LocalName));
if (pcName != NULL )
{
/* Parse local name */
if (ParseEndpointName(pcName, &LocalName) == OK)
{
if (FindEndpointNodeByName(&LocalName, 0, &pEndpntTree->Root,
pFoundEndpointList))
{
/* Endpoint node data is pointing to MGCP_ENDPOINT_TREE_NODE,
change it to pointer to H_MGCP_ENDPOING */
MGCP_ENDPOINT_TREE_NODE *pNode;
SListReset(pFoundEndpointList);
while((pNode = SListGetCurData(pFoundEndpointList)) != NULL)
{
/* If current Endpoint tree node contain no endpoint handle, remove it,
such as find "MG01" in endpoint tree "MG01/S1", endpoint tree
node is found, but no endpoint under this node */
if (pNode->pEndpoint != NULL)
{
bRet = TRUE;
pFoundEndpointList->cur->data = pNode->pEndpoint;
SListNextNode(pFoundEndpointList);
}
else
{
/* No endpoint handle under this found tree node, remove it */
SListDelCurNode(pFoundEndpointList);
}
}
}
}
ClearEndpointLocalName(&LocalName);
}
return bRet;
}
/******************************************************************************
* Function : RemoveEndpointFromEnpointTree
*
* Description : Remove the endpoint from the endpoint tree.
*
* Input parameters : pEndpoint - Endpoint handle to be removed.
* pEndpointTree - Pointer to endpoint tree.
*
* Output parameters :
*
* Return value : Return TRUE if endpoint is removed successfully;
* otherwise return FALSE.
*
* Comments :
*
* History :
* 2005/09/18 : Creation
*
* Date : Sep 18 2005, Frank Zhang
******************************************************************************/
BOOL RemoveEndpointFromEnpointTree(H_MGCP_ENDPOINT pEndpoint,
MGCP_ENDPOINT_TREE *pEndpointTree)
{
SLIST EndpointList;
ENDPOINT_LOCAL_NAME LocalName;
MGCP_ENDPOINT_TREE_NODE *pNode = NULL;
BOOL bRet = FALSE;
if (pEndpoint == NULL || pEndpointTree == NULL)
{
return FALSE;
}
/* Check endpoint name validity, no wildcard is permitted */
if (strchr(pEndpoint->pcEndpointName, '*') != NULL
|| strchr(pEndpoint->pcEndpointName, '&') != NULL)
return FALSE;
memset(&LocalName, 0, sizeof(ENDPOINT_LOCAL_NAME));
SListInit(&EndpointList);
if (ParseEndpointName(pEndpoint->pcEndpointName, &LocalName) == OK)
{
if (FindEndpointNodeByName(&LocalName, 0, &pEndpointTree->Root, &EndpointList))
{
Assert(EndpointList.count == 1);
SListReset(&EndpointList);
pNode = SListGetCurData(&EndpointList);
if (pNode == NULL)
{
bRet = FALSE;
}
else
{
/* Not actually remove the endpoint, only set the endpoint handle to be NULL */
pNode->pEndpoint = NULL;
bRet = TRUE;
}
}
}
ClearEndpointLocalName(&LocalName);
SListDel(&EndpointList);
return bRet;
}
/******************************************************************************
* Function : ClearEndpointTreeNode
*
* Description : Clear the endpoint tree node.
*
* Input parameters : pNode - Pointer to endpoint tree node to be cleared.
*
* Output parameters :
*
* Return value : None
*
* Comments :
*
* History :
* 2005/09/19 : Creation
*
* Date : Sep 19 2005, Frank Zhang
******************************************************************************/
void ClearEndpointTreeNode(MGCP_ENDPOINT_TREE_NODE *pNode)
{
MGCP_ENDPOINT_TREE_NODE *pTmpNode = NULL;
Assert(pNode);
if (pNode != NULL)
{
/* Free the node name */
free(pNode->TreeNodeName);
/* Clear the sub-nodes */
SListReset(&pNode->SubNodeList);
while ((pTmpNode = SListGetCurData(&pNode->SubNodeList)) != NULL)
{
ClearEndpointTreeNode(pTmpNode);
SListNextNode(&pNode->SubNodeList);
}
SListFreeAll(&pNode->SubNodeList);
}
}
/******************************************************************************
* Function : ClearEndpointTree
*
* Description : Clear the endpoint tree.
*
* Input parameters : pEndpointTree - Pointer to Endpoint tree to be cleared.
*
* Output parameters :
*
* Return value : None
*
* Comments :
*
* History :
* 2005/09/19 : Creation
*
* Date : Sep 19 2005, Frank Zhang
******************************************************************************/
void ClearEndpointTree(MGCP_ENDPOINT_TREE *pEndpointTree)
{
MGCP_ENDPOINT_TREE_NODE *pNode = NULL;
if (pEndpointTree != NULL)
{
SListReset(&pEndpointTree->Root);
while ((pNode = SListGetCurData(&pEndpointTree->Root)) != NULL)
{
ClearEndpointTreeNode(pNode);
SListNextNode(&pEndpointTree->Root);
}
SListFreeAll(&pEndpointTree->Root);
}
}
/******************************************************************************
* Function : MgcpEndpointSendRsipCmdOut
*
* Description : Construct a RSIP command message and send it to the
* TransacMng.
*
* Input parameters : pEndpoint - Endpoint handle.
* pRestartMethod - Pointer to the restart method.
* dwRestartDelay - Restart delay.
* wReasonCode - Reason code.
* pExperiParamList - Pointer to the experimental parameters.
*
* Output parameters :
*
* Return value : None
*
* Comments : NOTE: RSIP command is always the first message sent out,
* so it need not piggyback any other messages.
*
* History :
* 2005/09/19 : Creation
*
* Date : Sep 19 2005, Frank Zhang
******************************************************************************/
void MgcpEndpointSendRsipCmdOut(H_MGCP_ENDPOINT pEndpoint,
RESTART_METHOD *pRestartMethod,
DWORD dwRestartDelay,
WORD wReasonCode,
EXPERIMENTAL_PARAMS *pExperiParamList)
{
MGCP_STACK_MSG StackMsg;
MGCP_CMD_OUT *pCmdOut = (MGCP_CMD_OUT*)calloc(1, sizeof(MGCP_CMD_OUT));
DWORD *pdwNewCmdID = (DWORD*)calloc(1, sizeof(DWORD));
Assert(pEndpoint);
Assert(pRestartMethod);
Assert(pdwNewCmdID);
Assert(pCmdOut);
// memset(pCmdOut, 0, sizeof(MGCP_CMD_OUT));
memset(&StackMsg, 0, sizeof(MGCP_STACK_MSG));
*pdwNewCmdID = GetNewCommandID(pEndpoint);
/* Fill command data */
pCmdOut->dwCmdId = *pdwNewCmdID;
pCmdOut->hEndpointHandle = pEndpoint;
pCmdOut->dwInitRTO = CalculateRTOInitValue(pEndpoint);
CopyNotifiedEntity(&pCmdOut->NotifiedEntity, &pEndpoint->NotifiedEntity);
pCmdOut->eType = MGCP_CMD_RSIP;
pCmdOut->u.pRsipCmd = (MGCP_RSIP_CMD*)calloc(1, sizeof(MGCP_RSIP_CMD));
Assert(pCmdOut->u.pRsipCmd);
// memset(pCmdOut->u.pRsipCmd, 0, sizeof(MGCP_RSIP_CMD));
/* Save the last RSIP info */
pEndpoint->RestartMethod.eType = pRestartMethod->eType;
StrClone(&pEndpoint->RestartMethod.pcExtenPackageName,
pRestartMethod->pcExtenPackageName);
StrClone(&pEndpoint->RestartMethod.pcExtenMethodName,
pRestartMethod->pcExtenMethodName);
pEndpoint->dwRestartDelay = dwRestartDelay;
pEndpoint->wReasonCode = wReasonCode;
/* Fill restart method */
pCmdOut->u.pRsipCmd->RestartMethod.eType = pRestartMethod->eType;
StrClone(&pCmdOut->u.pRsipCmd->RestartMethod.pcExtenPackageName,
pRestartMethod->pcExtenPackageName);
StrClone(&pCmdOut->u.pRsipCmd->RestartMethod.pcExtenMethodName,
pRestartMethod->pcExtenMethodName);
/* Fill restart dealy */
if (pEndpoint->dwRestartDelay > 0
&& pEndpoint->RestartMethod.eType != RESTART_METHOD_FORCED
&& pEndpoint->RestartMethod.eType != RESTART_METHOD_CANCEL_GRACEFUL)
{
pCmdOut->u.pRsipCmd->pdwRestartDelay = (DWORD*)malloc(sizeof(DWORD));
Assert(pCmdOut->u.pRsipCmd->pdwRestartDelay);
*pCmdOut->u.pRsipCmd->pdwRestartDelay = pEndpoint->dwRestartDelay;
}
/* Fill reason code */
if (wReasonCode != 0)
{
pCmdOut->u.pRsipCmd->pReasonCode = (REASON_CODE*)calloc(1, sizeof(REASON_CODE));
Assert(pCmdOut->u.pRsipCmd->pReasonCode);
// memset(pCmdOut->u.pRsipCmd->pReasonCode, 0, sizeof(REASON_CODE));
pCmdOut->u.pRsipCmd->pReasonCode->wCode = wReasonCode;
}
/* Fill experimental parameters */
if (pExperiParamList != NULL)
CopyExperimentalParameters(&pCmdOut->u.pRsipCmd->ExperiParamList,
pExperiParamList);
StackMsg.eMsgCode = M_OUTGOING_CMD;
StackMsg.pMsgData = pCmdOut;
/* Add RSIP command ID into piggyback command list */
SListAppend(&pEndpoint->PendingCmdOutList, pdwNewCmdID);
SendMsgToTransationManager(TRANSAC_MANAGER_HANDLE(pEndpoint), &StackMsg);
}
/******************************************************************************
* Function : MgcpEndpointSendNtfyCmdOut
*
* Description : Construct a NTFY command message and send it to the
* TransacMng.
*
* Input parameters : pEndpoint - Endpoint handle
* pEventList - Pointer to the list of notified events.
*
* Output parameters :
*
* Return value : None
*
* Comments :
*
* History :
* 2005/09/20 : Creation
*
* Date : Sep 20 2005, Frank Zhang
******************************************************************************/
void MgcpEndpointSendNtfyCmdOut(H_MGCP_ENDPOINT pEndpoint, SLIST *pEventList)
{
WORD i = 0;
MGCP_CMD_OUT *pCmd = (MGCP_CMD_OUT*)calloc(1, sizeof(MGCP_CMD_OUT));
DWORD *pdwNewCmdID = (DWORD*)calloc(1, sizeof(DWORD));
Assert(pCmd);
Assert(pdwNewCmdID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -