ooh323.c
来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 1,721 行 · 第 1/5 页
C
1,721 行
OOTRACEINFO3("Received SETUP message (%s, %s)\n", call->callType, call->callToken); ooOnReceivedSetup(call, q931Msg); /* H225 message callback */ if(gH323ep.h225Callbacks.onReceivedSetup) gH323ep.h225Callbacks.onReceivedSetup(call, q931Msg); /* Free up the mem used by the received message, as it's processing is done. */ ooFreeQ931Message(q931Msg); ooSendCallProceeding(call);/* Send call proceeding message*/ /* DISABLEGK is used to selectively disable gatekeeper use. For incoming calls DISABLEGK can be set in onReceivedSetup callback by application. Very useful in pbx applications where gk is used only when call is to or from outside pbx domian */ if(gH323ep.gkClient && !OO_TESTFLAG(call->flags, OO_M_DISABLEGK)) { if(gH323ep.gkClient->state == GkClientRegistered) { ret = ooGkClientSendAdmissionRequest(gH323ep.gkClient, call, FALSE); call->callState = OO_CALL_WAITING_ADMISSION; }else{ /* TODO: Should send Release complete with reject reason */ OOTRACEERR1("Error:Ignoring incoming call as not yet" "registered with Gk\n"); } } else ret = ooH323CallAdmitted (call); break; case Q931CallProceedingMsg:/* Call proceeding message is received */ OOTRACEINFO3("H.225 Call Proceeding message received (%s, %s)\n", call->callType, call->callToken); ooOnReceivedCallProceeding(call, q931Msg); ooFreeQ931Message(q931Msg); break; case Q931AlertingMsg:/* Alerting message received */ OOTRACEINFO3("H.225 Alerting message received (%s, %s)\n", call->callType, call->callToken); ooOnReceivedAlerting(call, q931Msg); if(gH323ep.h323Callbacks.onAlerting && call->callState<OO_CALL_CLEAR) gH323ep.h323Callbacks.onAlerting(call); ooFreeQ931Message(q931Msg); break; case Q931ConnectMsg:/* Connect message received */ OOTRACEINFO3("H.225 Connect message received (%s, %s)\n", call->callType, call->callToken); /* Disable call establishment timer */ for(i = 0; i<call->timerList.count; i++) { pNode = dListFindByIndex(&call->timerList, i); pTimer = (OOTimer*)pNode->data; if(((ooTimerCallback*)pTimer->cbData)->timerType & OO_CALLESTB_TIMER) { memFreePtr(call->pctxt, pTimer->cbData); ooTimerDelete(call->pctxt, &call->timerList, pTimer); OOTRACEDBGC3("Deleted CallESTB timer. (%s, %s)\n", call->callType, call->callToken); break; } } ret = ooOnReceivedSignalConnect(call, q931Msg); if(ret != OO_OK) OOTRACEERR3("Error:Invalid Connect message received. (%s, %s)\n", call->callType, call->callToken); else{ /* H225 message callback */ if(gH323ep.h225Callbacks.onReceivedConnect) gH323ep.h225Callbacks.onReceivedConnect(call, q931Msg); if(gH323ep.h323Callbacks.onCallEstablished) gH323ep.h323Callbacks.onCallEstablished(call); } ooFreeQ931Message(q931Msg); break; case Q931InformationMsg: OOTRACEINFO3("H.225 Information msg received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; case Q931ReleaseCompleteMsg:/* Release complete message received */ OOTRACEINFO3("H.225 Release Complete message received (%s, %s)\n", call->callType, call->callToken); ooOnReceivedReleaseComplete(call, q931Msg); ooFreeQ931Message(q931Msg); break; case Q931FacilityMsg: OOTRACEINFO3("H.225 Facility message Received (%s, %s)\n", call->callType, call->callToken); ooOnReceivedFacility(call, q931Msg); ooFreeQ931Message(q931Msg); break; case Q931ProgressMsg: OOTRACEINFO3("H.225 Progress message received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; case Q931StatusMsg: OOTRACEINFO3("H.225 Status message received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; case Q931StatusEnquiryMsg: OOTRACEINFO3("H.225 Status Inquiry message Received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; case Q931SetupAckMsg: OOTRACEINFO3("H.225 Setup Ack message received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; case Q931NotifyMsg: OOTRACEINFO3("H.225 Notify message Received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); break; default: OOTRACEWARN3("Invalid H.225 message type received (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(q931Msg); } return ret;}int ooOnReceivedFacility(OOH323CallData *call, Q931Message * pQ931Msg){ H225H323_UU_PDU * pH323UUPdu = NULL; H225Facility_UUIE * facility = NULL; int ret; H225TransportAddress_ipAddress_ip *ip = NULL; OOTRACEDBGC3("Received Facility Message.(%s, %s)\n", call->callType, call->callToken); /* Get Reference to H323_UU_PDU */ if(!pQ931Msg->userInfo) { OOTRACEERR3("Error: UserInfo not found in received H.225 Facility " "message (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } pH323UUPdu = &pQ931Msg->userInfo->h323_uu_pdu; if(!pH323UUPdu) { OOTRACEERR1("ERROR: H225H323_UU_PDU absent in incoming facility " "message\n"); return OO_FAILED; } facility = pH323UUPdu->h323_message_body.u.facility; if(facility) { /* Depending on the reason of facility message handle the message */ if(facility->reason.t == T_H225FacilityReason_transportedInformation) { if(OO_TESTFLAG (call->flags, OO_M_TUNNELING)) { OOTRACEDBGB3("Handling tunneled messages in Facility. (%s, %s)\n", call->callType, call->callToken); ooHandleTunneledH245Messages(call, pH323UUPdu); OOTRACEDBGB3("Finished handling tunneled messages in Facility." "(%s, %s)\n",call->callType, call->callToken); } else { OOTRACEERR3("ERROR:Tunneled H.245 message received in facility. " "Tunneling is disabled at local for this call (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } } else if(facility->reason.t == T_H225FacilityReason_startH245) { OOTRACEINFO3("Remote wants to start a separate H.245 Channel " "(%s, %s)\n", call->callType, call->callToken); /*start H.245 channel*/ ret = ooHandleStartH245FacilityMessage(call, facility); if(ret != OO_OK) { OOTRACEERR3("ERROR: Handling startH245 facility message " "(%s, %s)\n", call->callType, call->callToken); return ret; } } else if(facility->reason.t == T_H225FacilityReason_callForwarded) { OOTRACEINFO3("Call Forward Facility message received. (%s, %s)\n", call->callType, call->callToken); if(!facility->m.alternativeAddressPresent && !facility->m.alternativeAliasAddressPresent) { OOTRACEERR3("Error:No alternative address provided in call forward" "facility message.(%s, %s)\n", call->callType, call->callToken); if(call->callState < OO_CALL_CLEAR) { call->callState = OO_CALL_CLEAR; call->callEndReason = OO_REASON_INVALIDMESSAGE; } return OO_OK; } call->pCallFwdData = (OOCallFwdData *) memAlloc(call->pctxt, sizeof(OOCallFwdData)); if(!call->pCallFwdData) { OOTRACEERR3("Error:Memory - ooOnReceivedFacility - pCallFwdData " "(%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } call->pCallFwdData->fwdedByRemote = TRUE; call->pCallFwdData->ip[0]='\0'; call->pCallFwdData->aliases = NULL; if(facility->m.alternativeAddressPresent) { if(facility->alternativeAddress.t != T_H225TransportAddress_ipAddress) { OOTRACEERR3("ERROR: Source call signalling address type not ip " "(%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } ip = &facility->alternativeAddress.u.ipAddress->ip; sprintf(call->pCallFwdData->ip, "%d.%d.%d.%d", ip->data[0], ip->data[1], ip->data[2], ip->data[3]); call->pCallFwdData->port = facility->alternativeAddress.u.ipAddress->port; } if(facility->m.alternativeAliasAddressPresent) { ooH323RetrieveAliases(call, &facility->alternativeAliasAddress, &call->pCallFwdData->aliases); } /* Now we have to clear the current call and make a new call to fwded location*/ if(call->callState < OO_CALL_CLEAR) { call->callState = OO_CALL_CLEAR; call->callEndReason = OO_REASON_REMOTE_FWDED; }else{ OOTRACEERR3("Error:Can't forward call as it is being cleared." " (%s, %s)\n", call->callType, call->callToken); return OO_OK; } } else{ OOTRACEINFO3("Unhandled Facility reason type received (%s, %s)\n", call->callType, call->callToken); } } else{ /* Empty facility message Check for tunneling */ OOTRACEDBGB3("Handling tunneled messages in empty Facility message." " (%s, %s)\n", call->callType, call->callToken); ooHandleTunneledH245Messages(call, pH323UUPdu); OOTRACEDBGB3("Finished handling tunneled messages in empty Facility " "message. (%s, %s)\n", call->callType, call->callToken); } return OO_OK;}int ooHandleStartH245FacilityMessage (OOH323CallData *call, H225Facility_UUIE *facility){ H225TransportAddress_ipAddress *ipAddress = NULL; int ret; /* Extract H245 address */ if(!facility->m.h245AddressPresent) { OOTRACEERR3("ERROR: startH245 facility message received with no h245 " "address (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } if(facility->h245Address.t != T_H225TransportAddress_ipAddress) { OOTRACEERR3("ERROR:Unknown H245 address type in received startH245 " "facility message (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } ipAddress = facility->h245Address.u.ipAddress; if(!ipAddress) { OOTRACEERR3("ERROR:Invalid startH245 facility message. No H245 ip " "address found. (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } sprintf(call->remoteIP, "%d.%d.%d.%d", ipAddress->ip.data[0], ipAddress->ip.data[1], ipAddress->ip.data[2], ipAddress->ip.data[3]); call->remoteH245Port = ipAddress->port; /* disable tunneling for this call */ OO_CLRFLAG (call->flags, OO_M_TUNNELING); /*Establish an H.245 connection */ ret = ooCreateH245Connection(call); if(ret != OO_OK) { OOTRACEERR3("ERROR: Failed to establish an H.245 connection with remote" " endpoint (%s, %s)\n", call->callType, call->callToken); return ret; } return OO_OK;}int ooHandleTunneledH245Messages (OOH323CallData *call, H225H323_UU_PDU * pH323UUPdu){ H245Message *pmsg; OOCTXT *pctxt = &gH323ep.msgctxt; int ret=0,i=0; OOTRACEDBGC3("Checking for tunneled H.245 messages (%s, %s)\n", call->callType, call->callToken); /* Check whether there are tunneled messages */ if(pH323UUPdu->m.h245TunnelingPresent) { if(pH323UUPdu->h245Tunneling) { OOTRACEDBGB4("Total number of tunneled H245 messages are %d.(%s, %s)" "\n", (int)pH323UUPdu->h245Control.n, call->callType, call->callToken); for(i=0; i< (int)pH323UUPdu->h245Control.n; i++) { OOTRACEDBGC5("Retrieving %d of %d tunneled H.245 messages." "(%s, %s)\n",i+1, pH323UUPdu->h245Control.n, call->callType, call->callToken);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?