⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transacmng.c

📁 内容正如其名
💻 C
📖 第 1 页 / 共 5 页
字号:
                             pAbnfMsgList,                             &pTransacMng->MsgList,                             pTranMgcpCmdOut->pCmdOut->wPiggyCmdNum,                             pTranMgcpCmdOut->pCmdOut->PiggybackCmdIDTable);  }  /* Fill the current outgoing mgcp command */  pAbnfMsgList->MGCPMessage.pNode = realloc(pAbnfMsgList->MGCPMessage.pNode,            ((WORD)pAbnfMsgList->MGCPMessage.iNum+1)*sizeof(TMGCPMessage));  Assert(pAbnfMsgList->MGCPMessage.pNode);  pAbnfMgcpMsg = ((TMGCPMessage*)pAbnfMsgList->MGCPMessage.pNode)                  + pAbnfMsgList->MGCPMessage.iNum;  memset(pAbnfMgcpMsg, 0, sizeof(TMGCPMessage));  pAbnfMsgList->MGCPMessage.iNum++;  /* Command type */  pAbnfMgcpMsg->iType = MGCPMessage_MGCPCommand;  /* Fill the command data */  FillAbnfMgcpCommand(&pAbnfMgcpMsg->u.MGCPCommand,                      pTranMgcpCmdOut->pCmdOut->eType,                      pTranMgcpCmdOut->pCmdOut->u.pRsipCmd,                      pTranMgcpCmdOut->dwTransacId,                      pTranMgcpCmdOut->pCmdOut->hEndpointHandle->pcEndpointName,                      pTransacMng->pcDomainName,                      pTransacMng->pStack->pcMgcpVersion,                      pTransacMng->pStack->pcProfileName);}/****************************************************************************** * Function          : FillAbnfMgcpRspOut * * Description       : Fill the Abnf mgcp response *                      * Input parameters  : pTransacMng - Handle of the TransacMng  *                     pMgcpRspOut - Pointer to Mgcp outgoing response data *                     bNeedAck - Flag of whether this response need ack * * Output parameters : pAbnfMsgList * * Return value      : None * * Comments          :  * * History           : *  2005/09/04       : Creation * * Date              : Sep 04 2005, Frank ZHANG ******************************************************************************/void FillAbnfMgcpRspOut(H_MGCP_TRANSAC_MANAGER pTransacMng,                        TMGCPMsgList *pAbnfMsgList,                        MGCP_RSP_OUT *pMgcpRspOut,                        BOOL bNeedAck){  TMGCPMessage *pAbnfMgcpMsg = NULL;      /* First check if need piggyback other commands */  if (pMgcpRspOut->wPiggyCmdNum > 0)  {    BuildPiggybackedCommands(pTransacMng, pAbnfMsgList,                             &pTransacMng->MsgList, pMgcpRspOut->wPiggyCmdNum,                             pMgcpRspOut->PiggybackCmdIDTable);  }  /* Fill the current outgoing mgcp command */  pAbnfMsgList->MGCPMessage.pNode = realloc(pAbnfMsgList->MGCPMessage.pNode,            ((WORD)pAbnfMsgList->MGCPMessage.iNum+1)*sizeof(TMGCPMessage));  Assert(pAbnfMsgList->MGCPMessage.pNode);  pAbnfMgcpMsg = ((TMGCPMessage*)pAbnfMsgList->MGCPMessage.pNode)                  + pAbnfMsgList->MGCPMessage.iNum;  memset(pAbnfMgcpMsg, 0, sizeof(TMGCPMessage));  pAbnfMsgList->MGCPMessage.iNum++;    /* Command type */  pAbnfMgcpMsg->iType = MGCPMessage_MGCPResponse;  /* Fill the command data */  FillAbnfMgcpResponse(&pAbnfMgcpMsg->u.MGCPResponse, pMgcpRspOut->wRspCode,                       pMgcpRspOut->pcRspString, pMgcpRspOut->dwTransacId,                       pMgcpRspOut->eType, pMgcpRspOut->u.pEpcfRsp, bNeedAck);}/****************************************************************************** * Function          : SendMgcpCmdOut * * Description       : Encode the mgcp commands and sent out to the socket *                      * Input parameters  : pTransacMng - Handle of the TransacMng  *                     pTranMgcpCmdOut - Pointer to Mgcp transaction outgoing *                                       command data * * Output parameters :  * * Return value      : None * * Comments          :  * * History           : *  2005/09/03       : Creation * * Date              : Sep 03 2005, Frank ZHANG ******************************************************************************/void SendMgcpCmdOut(H_MGCP_TRANSAC_MANAGER pTransacMng,                    TRANSAC_CMD_OUT *pTranMgcpCmdOut){  TMGCPMsgList AbnfMsgList;  TCtx ctx;  char EnBuffer[ABNF_ENCODE_BUF_LEN];  Assert(pTransacMng);  Assert(pTranMgcpCmdOut);  Assert(pTranMgcpCmdOut->pCmdOut);    memset(&AbnfMsgList, 0, sizeof(TMGCPMsgList));  CtxInitial(&ctx, EnBuffer, ABNF_ENCODE_BUF_LEN);  memset(EnBuffer, 0, sizeof(EnBuffer));  FillAbnfMgcpCmdOut(pTransacMng, &AbnfMsgList, pTranMgcpCmdOut);  if (EN_MGCPMsgList(&ctx, &AbnfMsgList) == OK)  {    struct sockaddr_in DesAddress;    socklen_t SocketLen = sizeof(struct sockaddr_in);    WORD wIndex = pTranMgcpCmdOut->pCmdOut->NotifiedEntity.wCurAddrIndex;        DesAddress.sin_family = AF_INET;    DesAddress.sin_port = htons(pTranMgcpCmdOut->pCmdOut->NotifiedEntity.wPort);    DesAddress.sin_addr.s_addr      = htonl(pTranMgcpCmdOut->pCmdOut->NotifiedEntity.pIPAddrList[wIndex]);    /* If Log message is on, print the transmit abnf message */    DEBUG({  int i = 0;             LogMSG(LOG_ABNF_MSG, "\n<TX----------------------------------------:\n");                    for (i = 0; i < ctx.pCur-ctx.pHead; i++)               LogMSG(LOG_ABNF_MSG, "%c", ctx.pHead[i]);           });        if (sendto(pTransacMng->iSocket_fd, ctx.pHead, ctx.pCur-ctx.pHead, 0,               (struct sockaddr*)&DesAddress, SocketLen) < 0)    {      DEBUG(LogMSG(LOG_ERROR, "\n@@TransacMng: Fail to send socket data! IP: %d, Port: %d",                   pTranMgcpCmdOut->pCmdOut->NotifiedEntity.pIPAddrList[wIndex],                   pTranMgcpCmdOut->pCmdOut->NotifiedEntity.wPort););    }  }  else  {    DEBUG(LogMSG(LOG_ERROR, "\nFail to encode MGCP outgoing command!"););  }  Free_MGCPMsgList(&AbnfMsgList);}/****************************************************************************** * Function          : SendMgcpRspAckOut * * Description       : Fill the Abnf mgcp Response Ack and sent to the socket *                      * Input parameters  : pTransacMng - Handle of the TransacMng  *                     dwTranID - Transaction ID of the ACK response * * Output parameters :  * * Return value      : None * * Comments          :  * * History           : *  2005/09/03       : Creation * * Date              : Sep 03 2005, Frank ZHANG ******************************************************************************/void SendMgcpRspAckOut(H_MGCP_TRANSAC_MANAGER pTransacMng, DWORD dwTranID){  MGCP_RSP_OUT *pMgcpRspOut = (MGCP_RSP_OUT*)calloc(1, sizeof(MGCP_RSP_OUT));  Assert(pMgcpRspOut);  Assert(pTransacMng);    /* Send response ack out */  pMgcpRspOut->wRspCode = 0;  pMgcpRspOut->dwTransacId = dwTranID;    SendMgcpRspOut(pTransacMng, pMgcpRspOut, FALSE);  ClearMgcpRspOut(pMgcpRspOut);  free(pMgcpRspOut);}/****************************************************************************** * Function          : SendMgcpRspOut * * Description       : Fill the Abnf mgcp Response and sent to the socket, if  *                     the response need ack, add the ACK parameter into the *                     Abnf response data. *                      * Input parameters  : pTransacMng - Handle of the TransacMng  *                     pMgcpRspOut - Pointer to Mgcp outgoing response data *                     bNeedAck - Flag if the response need ack * * Output parameters :  * * Return value      : None * * Comments          :  * * History           : *  2005/09/03       : Creation * * Date              : Sep 03 2005, Frank ZHANG ******************************************************************************/void SendMgcpRspOut(H_MGCP_TRANSAC_MANAGER pTransacMng,                    MGCP_RSP_OUT *pMgcpRspOut , BOOL bNeedAck){  TMGCPMsgList AbnfMsgList;  TCtx ctx;  char EnBuffer[ABNF_ENCODE_BUF_LEN];    memset(&AbnfMsgList, 0, sizeof(TMGCPMsgList));   CtxInitial(&ctx, EnBuffer, ABNF_ENCODE_BUF_LEN);  memset(EnBuffer, 0, sizeof(EnBuffer));  FillAbnfMgcpRspOut(pTransacMng, &AbnfMsgList, pMgcpRspOut, bNeedAck);  if (EN_MGCPMsgList(&ctx, &AbnfMsgList) == OK)  {    struct sockaddr_in DesAddress;      socklen_t SocketLen = sizeof(struct sockaddr);        DesAddress.sin_family = AF_INET;    DesAddress.sin_port = htons(pMgcpRspOut->wDesPort);    DesAddress.sin_addr.s_addr = htonl(pMgcpRspOut->dwDesIpAddr);    /* If Log message is on, print the transmit abnf message */    DEBUG({  int i = 0;             LogMSG(LOG_ABNF_MSG, "\n<TX----------------------------------------:\n");                   for (i = 0; i < ctx.pCur-ctx.pHead; i++)               LogMSG(LOG_ABNF_MSG, "%c", ctx.pHead[i]);           });        if (sendto(pTransacMng->iSocket_fd, ctx.pHead, ctx.pCur-ctx.pHead, 0,           (struct sockaddr*)&DesAddress, SocketLen) <0)    {      DEBUG(LogMSG(LOG_ERROR, "\nTransacMng: Fail to send socket data! IP: %d, Port: %d",                   pMgcpRspOut->dwDesIpAddr,                   pMgcpRspOut->wDesPort););    }  }  else  {    DEBUG(LogMSG(LOG_ERROR, "\nFail to encode MGCP outgoing response!"););  }  Free_MGCPMsgList(&AbnfMsgList);}/****************************************************************************** * Function          : RemovePiggyBackingCmdID * * Description       : Find the commands/responses piggybacking the target *                     command id, if found, remove the command id from the  *                     piggybacking command ID table, if the tabke is empty,  *                     move this command/response from piggybacking list to none *                     piggybacking list *                      * Input parameters  : dwCommandID - Command ID to be find and removed  *                     pMsgList - pointer to Mgcp outgoing message list * * Output parameters :  * * Return value      : None * * Comments          :  * * History           : *  2005/09/03       : Creation * * Date              : Sep 03 2005, Frank ZHANG ******************************************************************************/void RemovePiggyBackingCmdID(DWORD dwCommandID, MGCP_MSG_LIST *pMsgList){  WORD i;  TRANSAC_CMD_OUT *pCmdPiggy;  TRANSAC_RSP_OUT *pRspPiggy;  TRANSAC_RSP_WAIT_ACK *pRspPiggyWaitAck;  Assert(pMsgList);  SListReset(&pMsgList->CmdSentPiggybackList);  while((pCmdPiggy = SListGetCurData(&pMsgList->CmdSentPiggybackList))!= NULL)  {    Assert(pCmdPiggy->pCmdOut->wPiggyCmdNum > 0);    for (i = 0; i < pCmdPiggy->pCmdOut->wPiggyCmdNum; i++)    {      if (pCmdPiggy->pCmdOut->PiggybackCmdIDTable[i] == dwCommandID)      {        WORD j;                /* Advance the following command IDs after the found Command ID */        for (j = i+1; j < pCmdPiggy->pCmdOut->wPiggyCmdNum; j++)        {                    pCmdPiggy->pCmdOut->PiggybackCmdIDTable[i] =                                   pCmdPiggy->pCmdOut->PiggybackCmdIDTable[j];        }        pCmdPiggy->pCmdOut->wPiggyCmdNum--;        break;      }    }        /* If piggybacked command number is 0, move this transaction command into       none piggybacking command list */    if (pCmdPiggy->pCmdOut->wPiggyCmdNum == 0)    {      SListAppend(&pMsgList->CmdSentList, pCmdPiggy);      SListDelCurNode(&pMsgList->CmdSentPiggybackList);    }    else      SListNextNode(&pMsgList->CmdSentPiggybackList);  }  SListReset(&pMsgList->RspSentPiggybackList);  while((pRspPiggy = SListGetCurData(&pMsgList->RspSentPiggybackList))!= NULL)  {    Assert(pRspPiggy->pRspOut->wPiggyCmdNum > 0);    for (i = 0; i < pRspPiggy->pRspOut->wPiggyCmdNum; i++)    {      if (pRspPiggy->pRspOut->PiggybackCmdIDTable[i] == dwCommandID)      {        WORD j;        /* Advance the following command IDs after the found Command ID */        for (j = i+1; j < pRspPiggy->pRspOut->wPiggyCmdNum; j++)        {                    pRspPiggy->pRspOut->PiggybackCmdIDTable[i] =                                   pRspPiggy->pRspOut->PiggybackCmdIDTable[j];        }        pRspPiggy->pRspOut->wPiggyCmdNum--;        break;      }    }        /* If piggybacked command number is 0, move this transaction response into       none piggybacking response list */    if (pRspPiggy->pRspOut->wPiggyCmdNum == 0)    {      SListAppend(&pMsgList->RspSentList, pRspPiggy);      SListDelCurNode(&pMsgList->RspSentPiggybackList);    }    else      SListNextNode(&pMsgList->RspSentPiggybackList);  }  SListReset(&pMsgList->RspSentPiggyWaitAckList);  while((pRspPiggyWaitAck = SListGetCurData(&pMsgList->RspSentPiggyWaitAckList))!= NULL)  {    Assert(pRspPiggyWaitAck->pRspOut->wPiggyCmdNum > 0);    for (i = 0; i < pRspPiggyWaitAck->pRspOut->wPiggyCmdNum; i++)    {      if (pRspPiggyWaitAck->pRspOut->PiggybackCmdIDTable[i] == dwCommandID)      {        WORD j;                /* Advance the following command IDs after the found Command ID */

⌨️ 快捷键说明

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