📄 endpointctrl.c
字号:
* * 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; BOOL bRet = 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); /* 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; 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; 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); *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); /* 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); 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); Assert(pEndpoint); Assert(pEventList); /* Get new command ID */ pCmd->dwCmdId = GetNewCommandID(pEndpoint); *pdwNewCmdID = pCmd->dwCmdId; /* Piggyback commands */ FillPiggybackCmdIDS(&pCmd->wPiggyCmdNum, pCmd->PiggybackCmdIDTable, &pEndpoint->PendingCmdOutList); /* Endpoint handle */ pCmd->hEndpointHandle = pEndpoint; /* Notified entity */ CopyNotifiedEntity(&pCmd->NotifiedEntity, &pEndpoint->NotifiedEntity); /* RTO initial value */ pCmd->dwInitRTO = CalculateRTOInitValue(pEndpoint); /* Command type and data */ pCmd->eType = MGCP_CMD_NTFY; pCmd->u.pNtfyCmd = (MGCP_NTFY_CMD*)calloc(1, sizeof(MGCP_NTFY_CMD)); Assert(pCmd->u.pNtfyCmd); /* Fill Notified Entity, only if the CA has provided */ if (pEndpoint->bNotifiedEntityProvided) { pCmd->u.pNtfyCmd->pNotifiedEntity = (NOTIFIED_ENTITY*)calloc(1, sizeof(NOTIFIED_ENTITY)); Assert(pCmd->u.pNtfyCmd->pNotifiedEntity); CopyNotifiedEntity(pCmd->u.pNtfyCmd->pNotifiedEntity, &pEndpoint->NotifiedEntity); } /* Requested ID */ Assert(pEndpoint->pcRequestedID); StrClone(&pCmd->u.pNtfyCmd->pcRequestIdentifier, pEndpoint->pcRequestedID); /* Fill observed events */ if (pEventList->count > 0) { MGCP_OBSERVED_EVENT *pObservedEvent; pCmd->u.pNtfyCmd->pObservedEvents = (OBSERVED_EVENTS*)calloc(1, sizeof(OBSERVED_EVENTS)); Assert(pCmd->u.pNtfyCmd->pObservedEvents); pCmd->u.pNtfyCmd->pObservedEvents->wNum = (WORD)pEventList->count; pCmd->u.pNtfyCmd->pObservedEvents->pSigReqList = (SIGNAL_REQUEST*)calloc((WORD)pEventList->count, sizeof(SIGNAL_REQUEST)); Assert(pCmd->u.pNtfyCmd->pObservedEvents->pSigReqList); /* Fill every observed event */ SListReset(pEventList); while((pObservedEvent = SListGetCurData(pEventList)) != NULL) { MGCP_EVENT_ID EventID; MGCP_CONNEC_ID ConnectionID; EventID.eEventIdType = MGCP_EVENT_ID_SPECI; EventID.u.eEventID = pObservedEvent->eEventID; /* If connection ID of the observed event is 0, ignore it ! */ if (pObservedEvent->dwConnecID != 0) { ConnectionID.eConnecType = CONNEC_SPECIFIC; ConnectionID.dwConnecID = pObservedEvent->dwConnecID; } else { ConnectionID.eConnecType = CONNEC_UNDEFINE; } /* Fill event name */ TranslateMgcpEventName(&pCmd->u.pNtfyCmd->pObservedEvents->pSigReqList[i].SignalName, pObservedEvent->ePkgID, &EventID, &ConnectionID); /* Fill event parameters (Such as OC/OF event parameters) */ CopyEventParameters(&pCmd->u.pNtfyCmd->pObservedEvents->pSigReqList[i].SigParamList, &pObservedEvent->EventParams); i++; SListNextNode(pEventList); } } /* Add the NTFY command ID into pending command out list */ SListAppend(&pEndpoint->PendingCmdOutList, pdwNewCmdID); /* Check if the endpoint state is DISCONNECTED, if yes, buffer the NTFY command */ if (pEndpoint->eState == SM_DISCONNECTED) { MGCP_BUF_CMD *pBufCmd = (MGCP_BUF_CMD*)calloc(1, sizeof(MGCP_BUF_CMD)); Assert(pBufCmd); pBufCmd->dwTimwDuration = TRANSAC_MANAGER_HANDLE(pEndpoint)->dwTimerMax; pBufCmd->pCmdOut = pCmd; SListAppend(&pEndpoint->BuffedCmdInDisconected, pBufCmd); } else { MGCP_STACK_MSG Msg; /* Fill stack message */ Msg.eMsgCode = M_OUTGOING_CMD; Msg.pMsgData = pCmd; SendMsgToTransationManager(TRANSAC_MANAGER_HANDLE(pEndpoint), &Msg); }}/****************************************************************************** * Function : FillPiggybackCmdIDS * * Description : Fill the piggybacking command ID table according to the * PendingOutCmdID list. * * Input parameters : pSrc - Pointer to the PendingOutCmdID list. * * Output parameters : pwCmdNum - Piggybacking command ID number. * pdwCmdIdTable - Piggybacking command ID table. * * Return value : None *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -