ooq931.c

来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 1,944 行 · 第 1/5 页

C
1,944
字号
         msgbuf[i++] = ieLen;      /* 2nd octet for length */         ieLen--;         msgbuf[i++] = 5; /* protocol discriminator */         memcpy((msgbuf + i), ie->data, ieLen);         i += ieLen;               }else      {         OOTRACEWARN1("Warning: Only UUIE is supported currently\n");         return OO_FAILED;      }   }   //   len = i+1-4; /* complete message length */      /* Tpkt length octets populated with total length of the message */   if(msgbuf[0] != OOFacility)   {      len = i-1;      msgbuf[3] = (len >> 8);       msgbuf[4] = len;        /* including tpkt header */   }else{      len = i-4;      msgbuf[6] = (len >> 8);      msgbuf[7] = len;   }  #ifndef _COMPACT   if(msgbuf[0] != OOFacility)      ooQ931PrintMessage (call, msgbuf+5, len-4);   else      ooQ931PrintMessage (call, msgbuf+8, len-4);#endif   return OO_OK;}/**/int ooSendCallProceeding(OOH323CallData *call){   int ret;       H225VendorIdentifier *vendor;   H225CallProceeding_UUIE *callProceeding;   Q931Message *q931msg=NULL;   OOCTXT *pctxt = &gH323ep.msgctxt;   OOTRACEDBGC3("Building CallProceeding (%s, %s)\n", call->callType,                  call->callToken);   ret = ooCreateQ931Message(&q931msg, Q931CallProceedingMsg);   if(ret != OO_OK)   {            OOTRACEERR1("Error: In allocating memory for - H225 Call "                           "Proceeding message\n");      return OO_FAILED;   }      q931msg->callReference = call->callReference;   q931msg->userInfo = (H225H323_UserInformation*)memAlloc(pctxt,                             sizeof(H225H323_UserInformation));   if(!q931msg->userInfo)   {      OOTRACEERR1("ERROR:Memory - ooSendCallProceeding - userInfo\n");      return OO_FAILED;   }   memset (q931msg->userInfo, 0, sizeof(H225H323_UserInformation));   q931msg->userInfo->h323_uu_pdu.m.h245TunnelingPresent=1;    q931msg->userInfo->h323_uu_pdu.h245Tunneling =                                    OO_TESTFLAG(gH323ep.flags, OO_M_TUNNELING);    q931msg->userInfo->h323_uu_pdu.h323_message_body.t =          T_H225H323_UU_PDU_h323_message_body_callProceeding;      callProceeding = (H225CallProceeding_UUIE*)memAlloc(pctxt,                                             sizeof(H225CallProceeding_UUIE));   if(!callProceeding)   {      OOTRACEERR1("ERROR:Memory - ooSendCallProceeding - callProceeding\n");      return OO_FAILED;   }   memset(callProceeding, 0, sizeof(H225CallProceeding_UUIE));   q931msg->userInfo->h323_uu_pdu.h323_message_body.u.callProceeding = callProceeding;   callProceeding->m.multipleCallsPresent = 1;   callProceeding->m.maintainConnectionPresent = 1;   callProceeding->multipleCalls = FALSE;   callProceeding->maintainConnection = FALSE;   callProceeding->m.callIdentifierPresent = 1;   callProceeding->callIdentifier.guid.numocts =                                    call->callIdentifier.guid.numocts;   memcpy(callProceeding->callIdentifier.guid.data,           call->callIdentifier.guid.data,           call->callIdentifier.guid.numocts);   callProceeding->protocolIdentifier = gProtocolID;     /* Pose as Terminal or Gateway */   if(gH323ep.isGateway)      callProceeding->destinationInfo.m.gatewayPresent = TRUE;   else      callProceeding->destinationInfo.m.terminalPresent = TRUE;   callProceeding->destinationInfo.m.vendorPresent = 1;   vendor = &callProceeding->destinationInfo.vendor;   if(gH323ep.productID)   {      vendor->m.productIdPresent = 1;      vendor->productId.numocts = ASN1MIN(strlen(gH323ep.productID),                                     sizeof(vendor->productId.data));      strncpy(vendor->productId.data, gH323ep.productID,               vendor->productId.numocts);   }   if(gH323ep.versionID)   {      vendor->m.versionIdPresent = 1;      vendor->versionId.numocts = ASN1MIN(strlen(gH323ep.versionID),                                      sizeof(vendor->versionId.data));      strncpy(vendor->versionId.data, gH323ep.versionID,               vendor->versionId.numocts);    }   vendor->vendor.t35CountryCode = gH323ep.t35CountryCode;   vendor->vendor.t35Extension = gH323ep.t35Extension;   vendor->vendor.manufacturerCode = gH323ep.manufacturerCode;         OOTRACEDBGA3("Built Call Proceeding(%s, %s)\n", call->callType,                  call->callToken);      ret = ooSendH225Msg(call, q931msg);   if(ret != OO_OK)   {      OOTRACEERR3("Error:Failed to enqueue CallProceeding message to outbound queue.(%s, %s)\n", call->callType, call->callToken);   }   memReset(&gH323ep.msgctxt);   return ret;}int ooSendAlerting(OOH323CallData *call){   int ret;       H225Alerting_UUIE *alerting;   H225VendorIdentifier *vendor;   Q931Message *q931msg=NULL;   OOCTXT *pctxt = &gH323ep.msgctxt;   ret = ooCreateQ931Message(&q931msg, Q931AlertingMsg);   if(ret != OO_OK)   {            OOTRACEERR1("Error: In allocating memory for - H225 "                  "Alerting message\n");      return OO_FAILED;   }   q931msg->callReference = call->callReference;   q931msg->userInfo = (H225H323_UserInformation*)memAlloc(pctxt,                             sizeof(H225H323_UserInformation));   if(!q931msg->userInfo)   {      OOTRACEERR1("ERROR:Memory -  ooSendAlerting - userInfo\n");      return OO_FAILED;   }   memset (q931msg->userInfo, 0, sizeof(H225H323_UserInformation));   q931msg->userInfo->h323_uu_pdu.m.h245TunnelingPresent=1;    q931msg->userInfo->h323_uu_pdu.h245Tunneling = OO_TESTFLAG(gH323ep.flags,                                                               OO_M_TUNNELING);    q931msg->userInfo->h323_uu_pdu.h323_message_body.t =          T_H225H323_UU_PDU_h323_message_body_alerting;      alerting = (H225Alerting_UUIE*)memAlloc(pctxt,                                              sizeof(H225Alerting_UUIE));   if(!alerting)   {      OOTRACEERR1("ERROR:Memory -  ooSendAlerting - alerting\n");      return OO_FAILED;   }   memset(alerting, 0, sizeof(H225Alerting_UUIE));   q931msg->userInfo->h323_uu_pdu.h323_message_body.u.alerting = alerting;   alerting->m.multipleCallsPresent = 1;   alerting->m.maintainConnectionPresent = 1;   alerting->multipleCalls = FALSE;   alerting->maintainConnection = FALSE;   /*Populate aliases */   alerting->m.alertingAddressPresent = TRUE;   if(call->ourAliases)      ret = ooPopulateAliasList(pctxt, call->ourAliases,                                        &alerting->alertingAddress);   else      ret = ooPopulateAliasList(pctxt, gH323ep.aliases,                                       &alerting->alertingAddress);   if(OO_OK != ret)   {      OOTRACEERR1("Error:Failed to populate alias list in Alert message\n");      memReset(pctxt);      return OO_FAILED;   }   alerting->m.presentationIndicatorPresent = TRUE;   alerting->presentationIndicator.t =                              T_H225PresentationIndicator_presentationAllowed;   alerting->m.screeningIndicatorPresent = TRUE;   alerting->screeningIndicator = userProvidedNotScreened;   alerting->m.callIdentifierPresent = 1;   alerting->callIdentifier.guid.numocts =                                    call->callIdentifier.guid.numocts;   memcpy(alerting->callIdentifier.guid.data,           call->callIdentifier.guid.data,           call->callIdentifier.guid.numocts);   alerting->protocolIdentifier = gProtocolID;     /* Pose as Terminal or Gateway */   if(gH323ep.isGateway)      alerting->destinationInfo.m.gatewayPresent = TRUE;   else      alerting->destinationInfo.m.terminalPresent = TRUE;   alerting->destinationInfo.m.vendorPresent = 1;   vendor = &alerting->destinationInfo.vendor;   if(gH323ep.productID)   {      vendor->m.productIdPresent = 1;      vendor->productId.numocts = ASN1MIN(strlen(gH323ep.productID),                                         sizeof(vendor->productId.data));      strncpy(vendor->productId.data, gH323ep.productID,                                         vendor->productId.numocts);   }   if(gH323ep.versionID)   {      vendor->m.versionIdPresent = 1;      vendor->versionId.numocts = ASN1MIN(strlen(gH323ep.versionID),                                         sizeof(vendor->versionId.data));      strncpy(vendor->versionId.data, gH323ep.versionID,               vendor->versionId.numocts);    }         vendor->vendor.t35CountryCode = gH323ep.t35CountryCode;   vendor->vendor.t35Extension = gH323ep.t35Extension;   vendor->vendor.manufacturerCode = gH323ep.manufacturerCode;      OOTRACEDBGA3("Built Alerting (%s, %s)\n", call->callType, call->callToken);      ret = ooSendH225Msg(call, q931msg);   if(ret != OO_OK)   {      OOTRACEERR3("Error: Failed to enqueue Alerting message to outbound queue. (%s, %s)\n", call->callType, call->callToken);   }   memReset(&gH323ep.msgctxt);   return ret;}int ooSendFacility(OOH323CallData *call){   int ret=0;   Q931Message *pQ931Msg = NULL;   H225Facility_UUIE *facility=NULL;   OOCTXT *pctxt = &gH323ep.msgctxt;   OOTRACEDBGA3("Building Facility message (%s, %s)\n", call->callType,                 call->callToken);   ret = ooCreateQ931Message(&pQ931Msg, Q931FacilityMsg);   if(ret != OO_OK)   {      OOTRACEERR3	 ("ERROR: In allocating memory for facility message (%s, %s)\n",	  call->callType, call->callToken);      return OO_FAILED;   }   pQ931Msg->callReference = call->callReference;   pQ931Msg->userInfo = (H225H323_UserInformation*)memAlloc(pctxt,                             sizeof(H225H323_UserInformation));   if(!pQ931Msg->userInfo)   {      OOTRACEERR3("ERROR:Memory - ooSendFacility - userInfo(%s, %s)\n",                    call->callType, call->callToken);      return OO_FAILED;   }   memset (pQ931Msg->userInfo, 0, sizeof(H225H323_UserInformation));   pQ931Msg->userInfo->h323_uu_pdu.m.h245TunnelingPresent=1;    pQ931Msg->userInfo->h323_uu_pdu.h245Tunneling =       OO_TESTFLAG (call->flags, OO_M_TUNNELING);    pQ931Msg->userInfo->h323_uu_pdu.h323_message_body.t =       T_H225H323_UU_PDU_h323_message_body_facility;      facility = (H225Facility_UUIE*)       memAllocZ (pctxt, sizeof(H225Facility_UUIE));   if(!facility)   {      OOTRACEERR3("ERROR:Memory - ooSendFacility - facility (%s, %s)"                  "\n", call->callType, call->callToken);      return OO_FAILED;   }   pQ931Msg->userInfo->h323_uu_pdu.h323_message_body.u.facility = facility;   /* Populate Facility UUIE */   facility->protocolIdentifier = gProtocolID;     facility->m.callIdentifierPresent = 1;   facility->callIdentifier.guid.numocts =                                    call->callIdentifier.guid.numocts;   memcpy(facility->callIdentifier.guid.data,           call->callIdentifier.guid.data,           call->callIdentifier.guid.numocts);   facility->reason.t = T_H225FacilityReason_transportedInformation;   OOTRACEDBGA3("Built Facility message to send (%s, %s)\n", call->callType,                 call->callToken);   ret = ooSendH225Msg(call, pQ931Msg);   if(ret != OO_OK)   {      OOTRACEERR3	 ("Error:Failed to enqueue Facility message to outbound "	  "queue.(%s, %s)\n", call->callType, call->callToken);   }   memReset (&gH323ep.msgctxt);   return ret;}int ooSendReleaseComplete(OOH323CallData *call){   int ret;      Q931Message *q931msg=NULL;   H225ReleaseComplete_UUIE *releaseComplete;   enum Q931CauseValues cause = Q931ErrorInCauseIE;   unsigned h225ReasonCode = T_H225ReleaseCompleteReason_undefinedReason;   OOCTXT *pctxt = &gH323ep.msgctxt;      OOTRACEDBGA3("Building Release Complete message to send(%s, %s)\n",                call->callType, call->callToken);   ret = ooCreateQ931Message(&q931msg, Q931ReleaseCompleteMsg);   if(ret != OO_OK)   {            OOTRACEERR3("Error: In ooCreateQ931Message - H225 Release Complete "                  "message(%s, %s)\n", call->callType, call->callToken);      if(call->callState < OO_CALL_CLEAR)      {         call->callEndReason = OO_REASON_LOCAL_CLEARED;         call->callState = OO_CALL_CLEAR;      }      return OO_FAILED;   }   q931msg->callReference = call->callReference;   q931msg->userInfo = (H225H323_UserInformation*)memAlloc(pctxt,                             sizeof(H225H323_UserInformation));   if(!q931msg->userInfo)   {      OOTRACEERR1("ERROR:Memory - ooSendReleaseComplete - userInfo\n");      return OO_FAILED;   }   memset (q931msg->userInfo, 0, sizeof(H225H323_UserInformation));   releaseComplete = (H225ReleaseComplete_UUIE*)memAlloc(pctxt,                                             sizeof(H225ReleaseComplete_UUIE));   if(!releaseComplete)   {      OOTRACEERR3("Error:Memory - ooSendReleaseComplete - releaseComplete"                  "(%s, %s)\n", call->callType, call->callToken);      return OO_FAILED;   }   memset(releaseComplete, 0, sizeof(H225ReleaseComplete_UUIE));   q931msg->userInfo->h323_uu_pdu.m.h245TunnelingPresent=1;    q931msg->userInfo->h323_uu_pdu.h245Tunneling = OO_TESTFLAG(gH323ep.flags,                                                               OO_M_TUNNELING);    q931msg->userInfo->h323_uu_pdu.h323_message_body.t =          T_H225H323_UU_PDU_h323_message_body_releaseComplete;      /* Get cause value and h225 reason code corresponding to OOCallClearReason*/   ooQ931GetCauseAndReasonCodeFromCallClearReason(call->callEndReason,                                                      &cause, &h225ReasonCode);   /* Set Cause IE */   ooQ931SetCauseIE(q931msg, cause, 0, 0);      /* Set H225 releaseComplete reasonCode */   releaseComplete->m.reasonPresent = TRUE;

⌨️ 快捷键说明

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