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

📄 endpointctrl.c

📁 mgcp协议源代码和测试程序,还有一个编译器
💻 C
📖 第 1 页 / 共 5 页
字号:
        Assert(pRsp->u.pEpcfRsp);
//		memset(pRsp->u.pEpcfRsp, 0, sizeof(MGCP_EPCF_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pEpcfRsp->pPackageList);
      break;

      case MGCP_RSP_RQNT:
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pRqntRsp = (MGCP_RQNT_RSP*)calloc(1, sizeof(MGCP_RQNT_RSP));
        Assert(pRsp->u.pRqntRsp);
//		memset(pRsp->u.pRqntRsp, 0, sizeof(MGCP_RQNT_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pRqntRsp->pPackageList);
      break;

      case MGCP_RSP_CRCX:
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pCrcxRsp = (MGCP_CRCX_RSP*)calloc(1, sizeof(MGCP_CRCX_RSP));
        
        Assert(pRsp->u.pCrcxRsp);
//		memset(pRsp->u.pCrcxRsp, 0, sizeof(MGCP_CRCX_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pCrcxRsp->pPackageList);
      break;

      case MGCP_RSP_MDCX:
	  
		printf("\r\n    %s : L%d", __FILE__, __LINE__);
		printf("\r\n    MgcpEndpointSendRspOut( ... )");
	
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pMdcxRsp = (MGCP_MDCX_RSP*)calloc(1, sizeof(MGCP_MDCX_RSP));

        Assert(pRsp->u.pMdcxRsp);
//		memset(pRsp->u.pMdcxRsp, 0, sizeof(MGCP_MDCX_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pMdcxRsp->pPackageList);
      break;

      case MGCP_RSP_DLCX:
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pDlcxRsp = (MGCP_DLCX_RSP*)calloc(1, sizeof(MGCP_DLCX_RSP));

        Assert(pRsp->u.pDlcxRsp);
//		memset(pRsp->u.pDlcxRsp, 0, sizeof(MGCP_DLCX_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pDlcxRsp->pPackageList);
      break;

      case MGCP_RSP_AUEP:
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pAuepRsp = (MGCP_AUEP_RSP*)calloc(1, sizeof(MGCP_AUEP_RSP));

        Assert(pRsp->u.pAuepRsp);
//		memset(pRsp->u.pAuepRsp, 0, sizeof(MGCP_AUEP_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pAuepRsp->pPackageList);
      break;

      case MGCP_RSP_AUCX:
        if (pRsp->u.pEpcfRsp == NULL)
          pRsp->u.pAucxRsp = (MGCP_AUCX_RSP*)calloc(1, sizeof(MGCP_AUCX_RSP));

        Assert(pRsp->u.pAucxRsp);
//		memset(pRsp->u.pAucxRsp, 0, sizeof(MGCP_AUCX_RSP));
        EndpointReturnSupportedPackages(pEndpoint, &pRsp->u.pAucxRsp->pPackageList);
      break;

      case MGCP_RSP_COMM:
        /* Common Response, need no process! */
      break;

      default:
        Assert(0);
    }
  }

  Msg.eMsgCode = M_OUTGOING_RSP;
  Msg.pMsgData = pRsp;

	printf("\r\n    %s : L%d", __FILE__, __LINE__);
	printf("\r\n    MgcpEndpointSendRspOut( ... )");

  SendMsgToTransationManager(TRANSAC_MANAGER_HANDLE(pEndpoint), &Msg);
}
/******************************************************************************
 * Function          : EndpointCheckExperimentalParams
 *
 * Description       : Using callback function to Notify the application
 *                     to check the experimental parameters in an incoming
 *                     MGCP message. If the experimental parameters are optional
 *                     or are supported by the application, the function should
 *                     return OK, if the experimental parameters are mandatory
 *                     and are not supported by the application, a FAIL should
 *                     return.
 *                     
 * Input parameters  : pEndpoint - Endpoint handle.
 *                     pExperiParams - Pointer to experimental parameters.
 *
 * Output parameters : pRspCode - Pointer to the check result code returned
 *                                from application.
 *
 * Return value      : OK - If application support the experimental parameters
 *                          or they are optional.
 *                     FAIL - If application cannot support the experimental
 *                            parameters which are mandatory.
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/22       : Creation
 *
 * Date              : Sep 22 2005, Frank Zhang
 ******************************************************************************/
LONG EndpointCheckExperimentalParams(H_MGCP_ENDPOINT pEndpoint,
                              EXPERIMENTAL_PARAMS *pExperiParams,
                              WORD *pRspCode)
{
  MGCP_CBK_MSG CbkMsg;

  Assert(pExperiParams);
  Assert(pEndpoint);
  Assert(STACK_HANDLE(pEndpoint)->pCbkNotfyApp);
  
  if (pExperiParams == NULL && STACK_HANDLE(pEndpoint)->pCbkNotfyApp == NULL)
    return FAIL;

	memset(&CbkMsg, 0, sizeof(MGCP_CBK_MSG));
	
  CbkMsg.eType = MGCP_CBK_MSG_EXPERIMENTAL_PARM;
  CbkMsg.u.CbkExperiParam.pExperiParamList = pExperiParams;

  return STACK_HANDLE(pEndpoint)->pCbkNotfyApp((H_ENDPOINT)pEndpoint, &CbkMsg, pRspCode);
}
/******************************************************************************
 * Function          : EndpointProcessEncapEpcf
 *
 * Description       : Process the encapsulated EPCF parameters.
 *                     
 * Input parameters  : pEndpoint - Endpoint handle 
 *                     pEncapEpcf - Pointer to EPCF parameters
 *
 * Output parameters : pRspCode - Pointer to result code returned
 *
 * Return value      : Return OK if the encapsulate EPCF command is process
 *                     successfully, otherwise return FAIL.
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/25       : Creation
 *
 * Date              : Sep 25 2005, Frank Zhang
 ******************************************************************************/
LONG EndpointProcessEncapEpcf(H_MGCP_ENDPOINT pEndpoint,
                              ENCAPSULATED_EPCF *pEncapEpcf, WORD *pRspCode)
{
  Assert(pEndpoint);
  Assert(pEncapEpcf);
  
  if (pEncapEpcf->pBearerInfo != NULL)
  {
    MGCP_CBK_MSG CbkMsg;
	memset(&CbkMsg, 0, sizeof(MGCP_CBK_MSG));
    CbkMsg.eType = MGCP_CBK_MSG_CONFIG_ENDPOINT;
    CbkMsg.u.CbkConfigEndpoint.pBearerInfo = pEncapEpcf->pBearerInfo;
    
    Assert(STACK_HANDLE(pEndpoint)->pCbkNotfyApp);
  
    if (STACK_HANDLE(pEndpoint)->pCbkNotfyApp != NULL)
      return STACK_HANDLE(pEndpoint)->pCbkNotfyApp((H_ENDPOINT)pEndpoint, &CbkMsg, pRspCode);
    else
      return FAIL;
  }

  return OK;
}
/******************************************************************************
 * Function          : MgcpEndpointProcessEpcfCmd
 *
 * Description       : Process incoming MGCP EPCF command.
 *                     
 * Input parameters  : pEndpoint - Endpoint handle 
 *                     pCmdIn - Pointer to incoming EPCF command
 *
 * Output parameters : 
 *
 * Return value      : None
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/25       : Creation
 *
 * Date              : Sep 25 2005, Frank Zhang
 ******************************************************************************/
void MgcpEndpointProcessEpcfCmd(H_MGCP_ENDPOINT pEndpoint, MGCP_CMD_IN *pCmdIn)
{
  WORD wRspCode = 0;
  LONG iRet = OK;
  MGCP_CBK_MSG CbkMsg;

  Assert(pEndpoint);
  Assert(pCmdIn);
  Assert(pCmdIn->u.pEpcfCmd);
  Assert(pCmdIn->eType == MGCP_CMD_EPCF);

  memset(&CbkMsg, 0, sizeof(MGCP_CBK_MSG)); 
  
  switch (pEndpoint->eState)
  {
    case SM_NOTIFY:
    case SM_NOTIFY_PIGGYBACK:
    case SM_STEP_LOCK:
    case SM_DISCONNECTED:
    case SM_NORMAL:
    {
      /* Check if the BearerInfo parameter is missing, according to RFC3435,
         if Extension Parameters (vendor, package or other) are not used,
         the BearerInformation parameter is REQUIRED */
      if (pCmdIn->u.pEpcfCmd->pBearerInfo == NULL)
      {
        iRet = FAIL;
        wRspCode =  RSP_PROTOCOL_ERROR;
      }
      else
      {   
        CbkMsg.eType = MGCP_CBK_MSG_CONFIG_ENDPOINT;
        CbkMsg.u.CbkConfigEndpoint.pBearerInfo = pCmdIn->u.pEpcfCmd->pBearerInfo;
        CbkMsg.u.CbkConfigEndpoint.pExperiParamList = &pCmdIn->u.pEpcfCmd->ExperiParamList;

        Assert(STACK_HANDLE(pEndpoint)->pCbkNotfyApp);      
        if (STACK_HANDLE(pEndpoint)->pCbkNotfyApp != NULL)
          iRet = STACK_HANDLE(pEndpoint)->pCbkNotfyApp((H_ENDPOINT)pEndpoint, &CbkMsg, &wRspCode);
      }

      if (iRet != OK)
      {
        MgcpEndpointSendRspOut(pEndpoint, wRspCode, NULL, pCmdIn->dwTransacId,
                               pCmdIn->dwSrcIpAddr, pCmdIn->wSrcPort,
                               MGCP_RSP_COMM, NULL);
      }
      else
      {
        MgcpEndpointSendRspOut(pEndpoint, RSP_TRANSACTION_SUCCEED, NULL,
                               pCmdIn->dwTransacId, pCmdIn->dwSrcIpAddr,
                               pCmdIn->wSrcPort, MGCP_RSP_COMM, NULL);
        
        /* Save the BearerInfo of this endpoint */
        ClearBearerInfo(&pEndpoint->BearerInfo);
        CopyBearerInfo(&pEndpoint->BearerInfo, pCmdIn->u.pEpcfCmd->pBearerInfo);
      }
    }
    break;
    
    /* Below states must be impossible */
    case SM_INIT:
    case SM_RESTART_WAIT_CMD:
    case SM_RESTART:
    case SM_RESTART_NOTIFY:
    case SM_WAIT_DISCONNECTED:
    case SM_DISCONNECTED_WAIT_CMD:
      Assert(0);
    break;
  }  
}
/******************************************************************************
 * Function          : EndpointParseMgcpEventName
 *
 * Description       : Check the validity of the event name and translate it
 *                     to be the MGCP Event format. The checking includes:
 *                     1) If the package type is supported by endpoint.
 *                     2) If event type is supported by the stack.
 *                     3) If the connection ID is valid to endpoint.
 *                     
 * Input parameters  : pEndpoint - Endpoint handle 
 *                     pEventName - Pointer to EventName to be parsed
 *
 * Output parameters : pMgcpEventName - Store the parsed MGCP EventName. If fail
 *                                      to parse, the content in this struct is
 *                                      cleared.
 *                     pwErrorCode - Error code.
 *
 * Return value      : OK - If event name is parsed successfully.
 *                     FAIL - If fail to parse the event name.
 *
 * Comments          : 
 *
 * History           :
 *  2005/09/26       : Creation
 *
 * Date              : Sep 26 2005, Frank Zhang
 ******************************************************************************/
LONG EndpointParseMgcpEventName(H_MGCP_ENDPOINT pEndpoint, EVENT_NAME *pEventName,
                                MGCP_EVENT_NAME *pMgcpEventName, WORD *pwErrorCode)
{  
  MGCP_PACKAGE Package;
  MGCP_PKG_EVENT Event;

  Assert(pEndpoint);
  Assert(pEventName);
  Assert(pMgcpEventName);
  
  memset(&Package, 0, sizeof(MGCP_PACKAGE));
  memset(&Event, 0, sizeof(MGCP_PKG_EVENT));
  
  /* If package name is NULL, use the default package; else if fail to find
     the package ID in the package table, terminate check  */
  if (pEventName->pcPackageName == NULL)
  {
    E_MGCP_PACKAGE* pDefaultPackage;

    /* Get default package of this endpoint */
    SListReset(&pEndpoint->CapabilityList.SupportedPackages);
    pDefaultPackage = SListGetCurData(&pEndpoint->CapabilityList.SupportedPackages);
	if (pDefaultPackage == NULL)
	{
		return FAIL;
	}
    Package.ePackageType = *pDefaultPackage;
  }
  else if (FindMgcpPackageByName(&Package, pEventName->pcPackageName) != OK)
  {
    *pwErrorCode = RSP_UNSUPPORTED_PACKAGE;
	printf("\r\n\r\n    %s : L%d \r\n", __FILE__, __LINE__);
	printf("    EndpointParseMgcpEventName( ... ) \r\n");
    return FAIL;
  }
  
  /* Check whether the package is supported by this endpoint */
  if (!EndpointCheckPackageIsSupported(pEndpoint, Package.ePackageType))
  {
    *pwErrorCode = RSP_UNSUPPORTED_PACKAGE;
	printf("\r\n\r\n    %s : L%d \r\n", __FILE__, __LINE__);
	printf("    EndpointParseMgcpEventName( ... ) \r\n");
    return FAIL;
  }
  
  // 只有当请求中的出现这种情况时 pEventName->pcConnectionId 才不为空 : 
  // eventName = [eventName-packageName "/"] eventName-eventId "@" eventName-ConnectionId
  /* Parse the connection ID */
  if (pEventName->pcConnectionId != NULL
      && ParseMgcpConnectionID(pEventName->pcConnectionId, &pEndpoint->CallList,
                               &pMgcpEventName->ConnectionId) != OK)
  {
    *pwErrorCode = RSP_INCORRECT_CONNECTION_ID;
    return FAIL;
  }

  /* Save the package ID */
  pMgcpEventName->ePkgID = Package.ePackageType;

  /* Parser the Event_ID */
  switch (pEventName->eType)
  {
    case EVENT_ID:
      if (FindMgcpPkgEventByName(&Event, pEventName->pcEventIDName,
                                 Package.ePackageType) != OK)
      {
        *pwErrorCode = RSP_NO_SUCH_EVENT_SIGNAL;
        return FAIL;
      }
	  printf("\r\n    %s : L%d", __FILE__, __LINE__);
	  printf("\r\n    EVENT_ID");
      pMgcpEventName->EventID.eEventIdType = MGCP_EVENT_ID_SPECI;
      pMgcpEventName->EventID.u.eEventID = Event.eEventID;
    break;

    case EVENT_ALL:
	  printf("\r\n    %s : L%d", __FILE__, __LINE__);
	  printf("\r\n    EVENT_ALL");
      pMgcpEventName->EventID.eEventIdType = MGCP_EVENT_ID_SPECI;
      pMgcpEventName->EventID.u.eEventID = MGCP_EVT_ALL;
    break;

    case EVENT_DTMF_ASTERISK:
	  printf("\r\n    %s : L%d", __FILE__, __LINE__);
	  printf("\r\n    EVENT_DTMF_ASTERISK");
      /* Package of "*" Event must be DTMF Package */
      if (Package.ePackageType != MGCP_PKG_DTMF)
      {
        *pwErrorCode = RSP_NO_SUCH_EVENT_SIGNAL;
        return FAIL;
      }

      pMgcpEventName->EventID.eEventIdType = MGCP_EVENT_ID_SPECI;
      pMgcpEventName->EventID.u.eEventID = D_DTMF_ASTERISK;
    break;
    
    case EVENT_DTMF_POUND:
	  printf("\r\n    %s : L%d", __FILE__, __LINE__);
	  printf("\r\n    EVENT_DTMF_POUND

⌨️ 快捷键说明

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