transacmng.c

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

C
1,780 行
字号
 *  2005/09/10       : Creation
 *
 * Date              : Sep 10 2005, Frank Zhang
 ******************************************************************************/
void ProcessUpdataNotifiedEntityMsg(H_MGCP_TRANSAC_MANAGER pTransacMng,
                                    MSG_DATA_UPDATE_NE *pMsgData)
{
  TRANSAC_CMD_OUT *pTranCmdOut;

  Assert(pTransacMng);
  Assert(pMsgData);

  /* Find the outgoing commands and resend to the new NE address */
  SListReset(&pTransacMng->MsgList.CmdSentList);
  while ((pTranCmdOut = SListGetCurData(&pTransacMng->MsgList.CmdSentList)) != NULL)
  {
    /* If the time duration no more than the T-MAX ? */
    if (pTranCmdOut->pCmdOut->hEndpointHandle == pMsgData->hEndpoint
        && pTranCmdOut->dwTimeDuration <= pTransacMng->dwTimerMax)
    {
      /* Change the NE to be the new */
      ClearNotifiedEntity(&pTranCmdOut->pCmdOut->NotifiedEntity);
      CopyNotifiedEntity(&pTranCmdOut->pCmdOut->NotifiedEntity,
                         &pMsgData->NewNotifiedEntity);

      /* Resend the command to the new NE */
      SendMgcpCmdOut(pTransacMng, pTranCmdOut);

      /* Reset the retransmissiont couter */
      pTranCmdOut->wRetranCounter = 0;
    }

    SListNextNode(&pTransacMng->MsgList.CmdSentList);
  }
  
  /* Find the outgoing piggybacking commands and resend to the new NE address */
  SListReset(&pTransacMng->MsgList.CmdSentPiggybackList);
  while ((pTranCmdOut = SListGetCurData(&pTransacMng->MsgList.CmdSentPiggybackList)) != NULL)
  {
    /* If the time duration no more than the T-MAX ? */
    if (pTranCmdOut->pCmdOut->hEndpointHandle == pMsgData->hEndpoint
        && pTranCmdOut->dwTimeDuration <= pTransacMng->dwTimerMax)
    {
      /* Change the NE to be the new */
      ClearNotifiedEntity(&pTranCmdOut->pCmdOut->NotifiedEntity);
      CopyNotifiedEntity(&pTranCmdOut->pCmdOut->NotifiedEntity,
                         &pMsgData->NewNotifiedEntity);
      
      /* Resend the command to the new NE */
      SendMgcpCmdOut(pTransacMng, pTranCmdOut);

      /* Reset the retransmissiont couter */
      pTranCmdOut->wRetranCounter = 0;
    }

    SListNextNode(&pTransacMng->MsgList.CmdSentPiggybackList);
  }

  /* Free the message data */
  ClearNotifiedEntity(&pMsgData->NewNotifiedEntity);
  free(pMsgData);
}
/******************************************************************************
 * Function          : ProcessResponseOutTimeOut
 *
 * Description       : Check if every Mgcp outgoing transaction response in the
 *                     response list is expired, if yes, remove it from the
 *                     response list, otherwise update the elapse time.
 *                     
 * Input parameters  : pTransacMng - TransactionManager handle 
 *                     pRspOutList - Pointer to outgoing Mgcp response list
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/10       : Creation
 *
 * Date              : Sep 10 2005, Frank Zhang
 ******************************************************************************/
void ProcessResponseOutTimeOut(H_MGCP_TRANSAC_MANAGER pTransacMng, SLIST *pRspOutList)
{
  TRANSAC_RSP_OUT *pRspOut;
  
  Assert(pTransacMng);
  Assert(pRspOutList);
 
  /* Check if outgoing response in rspsend list is expired */
  SListReset(pRspOutList);
  while ((pRspOut = SListGetCurData(pRspOutList)) != NULL)
  {
    /* Increase the elapse time of this response */
    pRspOut->dwTimeDuration += pTransacMng->TickTimer.wTimerInterval;
    
    if (pRspOut->dwTimeDuration >= pTransacMng->dwTimerHIST)
    {
      /* Response expired, remove it from the list */
      SListDelCurNode(pRspOutList);

      /* Free the response */
      ClearTranRspOut(pRspOut);
      free(pRspOut);
    }
    else
      SListNextNode(pRspOutList);
  }
}
/******************************************************************************
 * Function          : ProcessResponseWaitAckTimeOut
 *
 * Description       : Check if every Mgcp outgoing transaction response waiting
 *                     ACK is expired, if yes, remove it from the response list,
 *                     otherwise update the elapse time.
 *                     
 * Input parameters  : pTransacMng - TransactionManager handle
 *                     pRspWaitingAckList - Point to the list of the response
 *                                          waiting ACK.
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/10       : Creation
 *
 * Date              : Sep 10 2005, Frank Zhang
 ******************************************************************************/
void ProcessResponseWaitAckTimeOut(H_MGCP_TRANSAC_MANAGER pTransacMng,
                                   SLIST *pRspWaitingAckList)
{
  TRANSAC_RSP_WAIT_ACK *pRspWaitAck;

  Assert(pTransacMng);
  Assert(pRspWaitingAckList);
  
  SListReset(pRspWaitingAckList);
  while ((pRspWaitAck = SListGetCurData(pRspWaitingAckList)) != NULL)
  {
    /* Increase the elapse time of this response */
    pRspWaitAck->dwTimeDuration += pTransacMng->TickTimer.wTimerInterval;

    /* Check if this outgoing response is expired */   
    if (pRspWaitAck->dwTimeDuration >= pTransacMng->dwTimerHIST)
    {
      /* Response expired, remove it from the list */
      SListDelCurNode(pRspWaitingAckList);

      /* Free the response */
      ClearTranRspOutWaitAck(pRspWaitAck);
      free(pRspWaitAck);
    }
    else
    {
      /* Check if need re-send this response */
      if (pRspWaitAck->dwTimeDuration <= pTransacMng->dwTimerMax
          && pRspWaitAck->wRetranCounter < pTransacMng->wCounterMax2)
      {
        /* If RTO timeout ? */
        if (pRspWaitAck->dwRTO < pTransacMng->TickTimer.wTimerInterval)
        {
          /*Re-send the response */
          SendMgcpRspOut(pTransacMng, pRspWaitAck->pRspOut, TRUE);
  
          /* Increment the retransmission counter and recalculate the RTO */
          pRspWaitAck->wRetranCounter++; 
          pRspWaitAck->dwRTO = RTO_DEFAULT*pRspWaitAck->wRetranCounter;
        }
        else
        {
          /* Decrease the RTO */
          pRspWaitAck->dwRTO -= pTransacMng->TickTimer.wTimerInterval;
        }
      }
  
      SListNextNode(pRspWaitingAckList);
    }
  }
}
/******************************************************************************
 * Function          : ProcessAckedResponseTimeOut
 *
 * Description       : Check if every Mgcp outgoing transaction AckResponse is
 *                     expired, if yes, remove it from the response list,
 *                     otherwise updata the elapse time.
 *                     
 * Input parameters  : pTransacMng - TransactionManager handle 
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/10       : Creation
 *
 * Date              : Sep 10 2005, Frank Zhang
 ******************************************************************************/
void ProcessAckedResponseTimeOut(H_MGCP_TRANSAC_MANAGER pTransacMng)
{
  TRANSAC_RSP_WAIT_ACK *pRspAcked;
 
  Assert(pTransacMng);
 
  SListReset(&pTransacMng->MsgList.RspAckReceivedList);
  while ((pRspAcked = SListGetCurData(&pTransacMng->MsgList.RspAckReceivedList)) != NULL)
  {
    /* Updata elapse time of this outgoing response */
    pRspAcked->dwTimeDuration += pTransacMng->TickTimer.wTimerInterval;

    /* Check if this outgoing response is expired */   
    if (pRspAcked->dwTimeDuration > pTransacMng->dwTimerHIST)
    {
      /* Response expired, remove it from the list */
      SListDelCurNode(&pTransacMng->MsgList.RspAckReceivedList);

      /* Free the response */
      ClearTranRspOutWaitAck(pRspAcked);
      free(pRspAcked);
    }
    else
      SListNextNode(&pTransacMng->MsgList.RspAckReceivedList);
  }
}
/******************************************************************************
 * Function          : ProcessResponsetAckTimeOut
 *
 * Description       : Check if every Mgcp outgoing transaction Response ACK is
 *                     expired, if yes, remove it from the response list,
 *                     otherwise updata the elapse time.
 *                     
 * Input parameters  : pTransacMng - TransactionManager handle 
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/10       : Creation
 *
 * Date              : Sep 10 2005, Frank Zhang
 ******************************************************************************/
void ProcessResponsetAckTimeOut(H_MGCP_TRANSAC_MANAGER pTransacMng)
{
  TRANSAC_RSPACK_OUT *pRspAck;
 
  Assert(pTransacMng);
 
  SListReset(&pTransacMng->MsgList.AckRspSentList);
  while ((pRspAck = SListGetCurData(&pTransacMng->MsgList.AckRspSentList)) != NULL)
  {
    /* Updata elapse time of this outgoing response */
    pRspAck->dwTimeDuration += pTransacMng->TickTimer.wTimerInterval;

    /* Check if this outgoing response is expired */   
    if (pRspAck->dwTimeDuration > pTransacMng->dwTimerHIST)
    {
      /* Response expired, remove it from the list */
      SListDelCurNode(&pTransacMng->MsgList.AckRspSentList);

      /* Free the response */
      free(pRspAck);
    }
    else
      SListNextNode(&pTransacMng->MsgList.AckRspSentList);
  }
}
/******************************************************************************
 * Function          : CheckDNSToGetMoreCA
 *
 * Description       : Use DNS service to get more IP address of the Notified
 *                     Entity:
 *                     1) If DNS checking is the first time, only check if there
 *                        have new resolved IP addresses different to the first
 *                        IP address of the NotifiedEnity, if have, update the
 *                        NotifiedEntity IP list and return TRUE; otherwise 
 *                        remain the NotifiedEntity IP list unchanged and return
 *                        FALSE;
 *                     2) If DNS checking is not the first time, If get new
 *                        resolved IP addresses, copy them into the IP address
 *                        list and return TRUE; otherwise, remain the
 *                        NotifiedEntity IP list unchanged and return FALSE.

 *                     NOTE: If the current address index is the first on, the
 *                     DNS resolution is the first time, else if the index is
 *                     the last one, the DNS resolution is the last time.
 *                     
 * Input parameters  : pNotifiedEntity - Pointer to NofifiedEntity. 
 *
 * Output parameters : 
 *
 * Return value      : TRUE If new IP address is got, otherwise return FALSE.
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/11       : Creation
 *
 * Date              : Sep 11 2005, Frank Zhang
 ******************************************************************************/
BOOL CheckDNSToGetMoreCA(NOTIFIED_ENTITY *pNotifiedEntity)
{
  int i = 0;
  int j = 0;
  struct hostent *pHostList;
  BOOL bFound = FALSE;
  DWORD dwTmpIp = 0;
  DWORD dwHostIp;
  DWORD TmpAddressList[MAX_IP_ADDRESS];
  WORD wTmpIndex = 0;

  Assert(pNotifiedEntity);
  memset(TmpAddressList, 0, sizeof(TmpAddressList));
  
  if (pNotifiedEntity->pcDomainName == NULL)
    return FALSE;

  /* Check whether the host name is dot decimal format */
  if (IsDotDecimalAddress(pNotifiedEntity->pcDomainName))
  {
    return FALSE;
  }

  /* Resolve the DNS, if fail to resolve, return false*/
  if ((pHostList = gethostbyname(pNotifiedEntity->pcDomainName)) == NULL)
    return FALSE;

  /* If this is the first DNS check ? */
  if (pNotifiedEntity->wCurAddrIndex == 0)
  {
    /* The address index must start from 1 because the first
       address still occupy the index 0 */
    WORD wIndex = 1;
    DWORD dwFirstAddr = pNotifiedEntity->pIPAddrList[0];
    
    /* Copy the new resolved address into the NE address list, if the 
       original fist addree is in the new address list, exclude it */
    while (pHostList->h_addr_list[i] != NULL)
    {
      dwHostIp = ntohl(*((DWORD*)pHostList->h_addr_list[i]));
      if (dwHostIp != dwFirstAddr)
      {
        bFound = TRUE;
        pNotifiedEntity->pIPAddrList[wIndex] = dwHostIp;
        wIndex++;

        if (wIndex >= MAX_IP_ADDRESS)
          break;
      }

⌨️ 快捷键说明

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