mgcpmsgtran.c
来自「mgcp协议源代码和测试程序,还有一个编译器」· C语言 代码 · 共 1,868 行 · 第 1/5 页
C
1,868 行
/****************************************************************************** Copyright(C) 2005,2006 Frank ZHANG All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ******************************************************************************* Authors : Frank ZHANG (openmgcp@gmail.com)* Description : MGCP message and MGCP Abnf message* translation functions*** Date of creation : 08/15/2005*** History :* 2005/08/15 Frank ZHANG : - Creation******************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "typedef.h"#include "misc.h"#include "debg.h"#include "list.h"#include "mgcpdef.h"#include "abnf.h"#include "mgcpmsgtran.h"/******************************************************************************* * Function : FillParameterLines * * Description : Fill the internal mgcp parameter lines from the decoded * abnf parameter lines. * * Input parameters : pSrcData - Pointer to the decoded MGCP abnf parameter * lines * * Output parameters : pDesData - Pointer to The internal filled MGCP parameter * lines * * Return value : None * * Comments : * * History : * 2005/08/16 : Creation * * Date : Aug 16 2005, Frank Zhang ******************************************************************************/void FillParameterLines(MGCP_PARAMETERS *pDesData, TList *pSrcData){ int i = 0; TMGCPParameter *pSrcParam = NULL; Assert(pDesData); Assert(pSrcData); /* Fill every parameter */ for(i = 0; i < pSrcData->iNum; i++) { pSrcParam = (TMGCPParameter*)pSrcData->pNode + i; switch (pSrcParam->iType) { case MGCPParameter_ParamResponseAck: pDesData->pResponseAck = (RESPONSE_ACK*)calloc(1, sizeof(RESPONSE_ACK)); Assert(pDesData->pResponseAck); // memset(pDesData->pResponseAck, 0, sizeof(RESPONSE_ACK)); if (pSrcParam->u.ParamResponseAck.ResponseAck.flag) FillResponseAck(pDesData->pResponseAck, (TResponseAck*)pSrcParam->u.ParamResponseAck.ResponseAck.pRuleData); break; case MGCPParameter_ParamBearerInformation: pDesData->pBearerInformation= (BEARER_INFO*)calloc(1, sizeof(BEARER_INFO)); Assert(pDesData->pBearerInformation); // memset(pDesData->pBearerInformation, 0, sizeof(BEARER_INFO)); if (pSrcParam->u.ParamBearerInformation.BearerInformation.flag) FillBearerInfo(pDesData->pBearerInformation, (TBearerInformation*)pSrcParam->u.ParamBearerInformation.BearerInformation.pRuleData); break; case MGCPParameter_ParamCallId: StrClone(&pDesData->pcCallId, pSrcParam->u.ParamCallId.CallId); break; case MGCPParameter_ParamConnectionId: pDesData->pConnectionIds = (CONNECTION_IDS*)calloc(1, sizeof(CONNECTION_IDS)); Assert(pDesData->pConnectionIds); // memset(pDesData->pConnectionIds, 0, sizeof(CONNECTION_IDS)); if (pSrcParam->u.ParamConnectionId.ConnectionId.flag) FillConnectionIDS(pDesData->pConnectionIds, (TConnectionId*)pSrcParam->u.ParamConnectionId.ConnectionId.pRuleData); break; case MGCPParameter_ParamNotifiedEntity: pDesData->pNotifiedEntity = (NOTIFIED_ENTITY*)calloc(1, sizeof(NOTIFIED_ENTITY)); Assert(pDesData->pNotifiedEntity); // memset(pDesData->pNotifiedEntity, 0, sizeof(NOTIFIED_ENTITY)); if (pSrcParam->u.ParamNotifiedEntity.NotifiedEntity.flag) FillNotifiedEntity(pDesData->pNotifiedEntity, (TNotifiedEntity*)pSrcParam->u.ParamNotifiedEntity.NotifiedEntity.pRuleData); break; case MGCPParameter_ParamRequestIdentifier: if (pSrcParam->u.ParamRequestIdentifier.RequestIdentifier.flag) StrClone(&pDesData->pcRequestIdentifier, (char*)pSrcParam->u.ParamRequestIdentifier.RequestIdentifier.pRuleData); break; case MGCPParameter_ParamLocalConnectionOptions: pDesData->pLocalConnectionOptions = (LOCAL_CONNEC_OPTS*)calloc(1, sizeof(LOCAL_CONNEC_OPTS)); Assert(pDesData->pLocalConnectionOptions); // memset(pDesData->pLocalConnectionOptions, 0, sizeof(LOCAL_CONNEC_OPTS)); if (pSrcParam->u.ParamLocalConnectionOptions.LocalConnectionOptions.flag) FillLocalConnectionOpts(pDesData->pLocalConnectionOptions, (TLocalConnectionOptions*)pSrcParam->u.ParamLocalConnectionOptions.LocalConnectionOptions.pRuleData); break; case MGCPParameter_ParamConnectionMode: pDesData->pConnectionMode= (CONNECTION_MODE*)calloc(1, sizeof(CONNECTION_MODE)); Assert(pDesData->pConnectionMode); // memset(pDesData->pConnectionMode, 0, sizeof(CONNECTION_MODE)); FillConnectionMode(pDesData->pConnectionMode, &pSrcParam->u.ParamConnectionMode.ConnectionMode); break; case MGCPParameter_ParamRequestedEvents: pDesData->pRequestedEvents = (REQUESTED_EVENTS*)calloc(1, sizeof(REQUESTED_EVENTS)); Assert(pDesData->pRequestedEvents); // memset(pDesData->pRequestedEvents, 0, sizeof(REQUESTED_EVENTS)); if (pSrcParam->u.ParamRequestedEvents.RequestedEvents.flag) FillRequestEvents(pDesData->pRequestedEvents, (TRequestedEvents*)pSrcParam->u.ParamRequestedEvents.RequestedEvents.pRuleData); break; case MGCPParameter_ParamSignalRequests: pDesData->pSignalRequests = (SIGNAL_REQUESTS*)calloc(1, sizeof(SIGNAL_REQUESTS)); Assert(pDesData->pSignalRequests); // memset(pDesData->pSignalRequests, 0, sizeof(SIGNAL_REQUESTS)); if (pSrcParam->u.ParamSignalRequests.SignalRequests.flag) FillSignalRequests(pDesData->pSignalRequests, (TSignalRequests*)pSrcParam->u.ParamSignalRequests.SignalRequests.pRuleData); break; case MGCPParameter_ParamDigitMap: pDesData->pDigitMap= (DIGIT_MAP*)calloc(1, sizeof(DIGIT_MAP)); Assert(pDesData->pDigitMap); // memset(pDesData->pDigitMap, 0, sizeof(DIGIT_MAP)); if (pSrcParam->u.ParamDigitMap.DigitMap.flag) FillDigitMap(pDesData->pDigitMap, (TDigitMap*)pSrcParam->u.ParamDigitMap.DigitMap.pRuleData); break; case MGCPParameter_ParamConnectionParameters: pDesData->pConnectionParameters= (CONNECTION_PARAMETERS*)calloc(1, sizeof(CONNECTION_PARAMETERS)); Assert(pDesData->pConnectionParameters); // memset(pDesData->pConnectionParameters, 0, sizeof(CONNECTION_PARAMETERS)); if (pSrcParam->u.ParamConnectionParameters.ConnectionParameters.flag) FillConnectionParameters(pDesData->pConnectionParameters, (TConnectionParameters*)pSrcParam->u.ParamConnectionParameters.ConnectionParameters.pRuleData); break; case MGCPParameter_ParamReasonCode: pDesData->pReasonCode = (REASON_CODE*)calloc(1, sizeof(REASON_CODE)); Assert(pDesData->pReasonCode); // memset(pDesData->pReasonCode, 0, sizeof(REASON_CODE)); FillReasonCode(pDesData->pReasonCode, &pSrcParam->u.ParamReasonCode.ReasonCode); break; case MGCPParameter_ParamSpecificEndpointID: if (pSrcParam->u.ParamSpecificEndpointID.SpecificEndpointID.flag) { pDesData->pSpecificEndpointID = (ENDPOINT_NAME*)calloc(1, sizeof(ENDPOINT_NAME)); Assert(pDesData->pSpecificEndpointID); // memset(pDesData->pSpecificEndpointID, 0, sizeof(ENDPOINT_NAME)); FillEndpointName(pDesData->pSpecificEndpointID, (TEndpointName*)pSrcParam->u.ParamSpecificEndpointID.SpecificEndpointID.pRuleData); } break; case MGCPParameter_ParamSecondEndpointID: pDesData->pSecondEndpointID = (ENDPOINT_NAME*)calloc(1, sizeof(ENDPOINT_NAME)); Assert(pDesData->pSecondEndpointID); // memset(pDesData->pSecondEndpointID, 0, sizeof(ENDPOINT_NAME)); FillEndpointName(pDesData->pSecondEndpointID, &pSrcParam->u.ParamSecondEndpointID.SecondEndpointID); break; case MGCPParameter_ParamSecondConnectionID: if (pSrcParam->u.ParamSecondConnectionID.SecondConnectionID.ConnectionIdValue.iNum) StrClone(&pDesData->pcSecondConnectionID, (char*)pSrcParam->u.ParamSecondConnectionID.SecondConnectionID.ConnectionIdValue.pNode); break; case MGCPParameter_ParamRequestedInfo: pDesData->pRequestedInfo= (REQUESTED_INFO*)calloc(1, sizeof(REQUESTED_INFO)); Assert(pDesData->pRequestedInfo); // memset(pDesData->pRequestedInfo, 0, sizeof(REQUESTED_INFO)); if (pSrcParam->u.ParamRequestedInfo.RequestedInfo.flag) FillReqestedInfo(pDesData->pRequestedInfo, (TRequestedInfo*)pSrcParam->u.ParamRequestedInfo.RequestedInfo.pRuleData); break; case MGCPParameter_ParamQuarantineHandling: pDesData->pQuarantineHandling = (QUARANTINE_HANDLING*)calloc(1, sizeof(QUARANTINE_HANDLING)); Assert(pDesData->pQuarantineHandling); // memset(pDesData->pQuarantineHandling, 0, sizeof(QUARANTINE_HANDLING)); FillQuarantineHandling(pDesData->pQuarantineHandling, &pSrcParam->u.ParamQuarantineHandling.QuarantineHandling); break; case MGCPParameter_ParamDetectEvents: pDesData->pDetectEvents = (DETECT_EVENTS*)calloc(1, sizeof(DETECT_EVENTS)); Assert(pDesData->pDetectEvents); // memset(pDesData->pDetectEvents, 0, sizeof(DETECT_EVENTS)); if (pSrcParam->u.ParamDetectEvents.DetectEvents.flag) FillDetectEvents(pDesData->pDetectEvents, (TSignalRequests*)pSrcParam->u.ParamDetectEvents.DetectEvents.pRuleData); break; case MGCPParameter_ParamRestartMethod: pDesData->pRestartMethod = (RESTART_METHOD*)calloc(1, sizeof(RESTART_METHOD)); Assert(pDesData->pRestartMethod); // memset(pDesData->pRestartMethod, 0, sizeof(RESTART_METHOD)); FillRestartMethod(pDesData->pRestartMethod, &pSrcParam->u.ParamRestartMethod.RestartMethod); break; case MGCPParameter_ParamRestartDelay: pDesData->pRestartDelay = (DWORD*)calloc(1, sizeof(DWORD)); Assert(pDesData->pRestartDelay); // memset(pDesData->pRestartDelay, 0, sizeof(DWORD)); *pDesData->pRestartDelay = (DWORD)atoi(pSrcParam->u.ParamRestartDelay.RestartDelay); break; case MGCPParameter_ParamCapabilities: pDesData->pCapabilities = (CAPABILITIES*)calloc(1, sizeof(CAPABILITIES)); Assert(pDesData->pCapabilities); // memset(pDesData->pCapabilities, 0, sizeof(CAPABILITIES)); if (pSrcParam->u.ParamCapabilities.Capabilities.flag) FillCapabilities(pDesData->pCapabilities, (TCapabilities*)pSrcParam->u.ParamCapabilities.Capabilities.pRuleData); break; case MGCPParameter_ParamEventStates: pDesData->pEventStates= (EVENT_STATES*)calloc(1, sizeof(EVENT_STATES)); Assert(pDesData->pEventStates); // memset(pDesData->pEventStates, 0, sizeof(EVENT_STATES)); if (pSrcParam->u.ParamEventStates.EventStates.flag) FillEventStates(pDesData->pEventStates, (TSignalRequests*)pSrcParam->u.ParamEventStates.EventStates.pRuleData); break; case MGCPParameter_ParamPackageList: pDesData->pPackageList= (PACKAGE_LIST*)calloc(1, sizeof(PACKAGE_LIST)); Assert(pDesData->pPackageList); // memset(pDesData->pPackageList, 0, sizeof(PACKAGE_LIST)); if (pSrcParam->u.ParamPackageList.PackageList.flag) FillPackageList(pDesData->pPackageList, (TPackageList*)pSrcParam->u.ParamPackageList.PackageList.pRuleData); break; case MGCPParameter_ParamMaxMGCPDatagram: pDesData->pMaxMGCPDatagram = (DWORD*)calloc(1, sizeof(DWORD)); Assert(pDesData->pMaxMGCPDatagram); // memset(pDesData->pMaxMGCPDatagram, 0, sizeof(DWORD)); *pDesData->pMaxMGCPDatagram = (DWORD)atoi(pSrcParam->u.ParamMaxMGCPDatagram.MaxMGCPDatagram); break; case MGCPParameter_ExtendedParameter: FillExperimentalParameters(&pDesData->ExperiParamList, &pSrcParam->u.ExtendedParameter); break; default: Assert(0); } }}/******************************************************************************* * Function : AppendNewParameter * * Description : Append a new MGCP parameter into the parameter lines. * * Input parameters : pData - Pointer to the original MGCP parameter lines * wNum - The current number of the parameters in the * parameter line * * Output parameters : pData - The new MGCP parameter lines with a new * parameters appended * * Return value : Return the Pointer of the new MGCP parameter lines * * Comments : * * History : * 2005/08/16 : Creation * * Date : Aug 16 2005, Frank Zhang ******************************************************************************/TMGCPParameter* AppendNewParameter(TMGCPParameter *pData, WORD wNum){ pData = (TMGCPParameter*)realloc(pData, (wNum+1)*sizeof(TMGCPParameter)); Assert(pData); if (pData != NULL) memset(pData+wNum, 0, sizeof(TMGCPParameter)); return pData;}/******************************************************************************* * Function : FillAbnfParameterLines * * Description : Fill the abnf mgcp parameter lines from the internal * MGCP parameters * * Input parameters : pSrcData - Pointer to the internal MGCP parameter lines * * Output parameters : pDesData - Pointer to the filled abnf MGCP parameter * lines * * Return value : None * * Comments : * * History : * 2005/08/16 : Creation * * Date : Aug 16 2005, Frank Zhang ******************************************************************************/void FillAbnfParameterLines(TList *pDesData, MGCP_PARAMETERS*pSrcData){ TMGCPParameter *pDesParam = NULL; WORD wNum = 0; Assert(pSrcData); Assert(pSrcData); /* Response ack */ if (pSrcData->pResponseAck != NULL) { pDesParam = AppendNewParameter(pDesParam, wNum); Assert(pDesParam); if (pDesParam != NULL) { FillAbnfParamResponseAck(pDesParam+wNum, pSrcData->pResponseAck);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?