oochannels.c
来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 1,774 行 · 第 1/4 页
C
1,774 行
NULL, &timeout); if(ret == -1) { OOTRACEERR3("Error in select while receiving H.2250 message - " "clearing call (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } /* If remaining part of the message is not received in 3 seconds exit */ if(!FD_ISSET(call->pH225Channel->sock, &readfds)) { OOTRACEERR3("Error: Incomplete H.2250 message received - clearing " "call (%s, %s)\n", call->callType, call->callToken); ooFreeQ931Message(pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_INVALIDMESSAGE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } } OOTRACEDBGC3("Received Q.931 message: (%s, %s)\n", call->callType, call->callToken); initializePrintHandler(&printHandler, "Received H.2250 Message"); /* Set event handler */ setEventHandler (pctxt, &printHandler); ret = ooQ931Decode (call, pmsg, len, message); if(ret != OO_OK) { OOTRACEERR3("Error:Failed to decode received H.2250 message. (%s, %s)\n", call->callType, call->callToken); } OOTRACEDBGC3("Decoded Q931 message (%s, %s)\n", call->callType, call->callToken); finishPrint(); removeEventHandler(pctxt); if(ret == OO_OK) ooHandleH2250Message(call, pmsg); return ret;}int ooH245Receive(OOH323CallData *call){ int recvLen, ret, len, total=0; ASN1OCTET message[MAXMSGLEN], message1[MAXMSGLEN]; ASN1BOOL aligned = TRUE; H245Message *pmsg; OOCTXT *pctxt = &gH323ep.msgctxt; struct timeval timeout; fd_set readfds; pmsg = (H245Message*)memAlloc(pctxt, sizeof(H245Message)); /* First read just TPKT header which is four bytes */ recvLen = ooSocketRecv (call->pH245Channel->sock, message, 4); /* Since we are working with TCP, need to determine the message boundary. Has to be done at channel level, as channels know the message formats and can determine boundaries */ if(recvLen<=0) { if(recvLen == 0) OOTRACEINFO3("Closing H.245 channels as remote end point closed H.245" " connection (%s, %s)\n", call->callType, call->callToken); else OOTRACEERR3("Error: Transport failure while trying to receive H245" " message (%s, %s)\n", call->callType, call->callToken); ooCloseH245Connection(call); ooFreeH245Message(call, pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } OOTRACEDBGC1("Receiving H245 message\n"); if(recvLen != 4) { OOTRACEERR3("Error: Reading TPKT header for H245 message (%s, %s)\n", call->callType, call->callToken); ooFreeH245Message(call, pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_INVALIDMESSAGE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } len = message[2]; len = len<<8; len = (len | message[3]); /* Remaining message length is length - tpkt length */ len = len - 4; /* Now read actual H245 message body. We should make sure that we receive complete message as indicated by len. If we don't then there is something wrong. The loop below receives message, then checks whether complete message is received. If not received, then uses select to peek for remaining bytes of the message. If message is not received in 3 seconds, then we have a problem. Report an error and exit. */ while(total < len) { recvLen = ooSocketRecv (call->pH245Channel->sock, message1, len-total); memcpy(message+total, message1, recvLen); total = total + recvLen; if(total == len) break; /* Complete message is received */ FD_ZERO(&readfds); FD_SET(call->pH245Channel->sock, &readfds); timeout.tv_sec = 3; timeout.tv_usec = 0; ret = ooSocketSelect(call->pH245Channel->sock+1, &readfds, NULL, NULL, &timeout); if(ret == -1) { OOTRACEERR3("Error in select...H245 Receive-Clearing call (%s, %s)\n", call->callType, call->callToken); ooFreeH245Message(call, pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } /* If remaining part of the message is not received in 3 seconds exit */ if(!FD_ISSET(call->pH245Channel->sock, &readfds)) { OOTRACEERR3("Error: Incomplete h245 message received (%s, %s)\n", call->callType, call->callToken); ooFreeH245Message(call, pmsg); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } } OOTRACEDBGC3("Complete H245 message received (%s, %s)\n", call->callType, call->callToken); setPERBuffer(pctxt, message, recvLen, aligned); initializePrintHandler(&printHandler, "Received H.245 Message"); /* Set event handler */ setEventHandler (pctxt, &printHandler); ret = asn1PD_H245MultimediaSystemControlMessage(pctxt, &(pmsg->h245Msg)); if(ret != ASN_OK) { OOTRACEERR3("Error decoding H245 message (%s, %s)\n", call->callType, call->callToken); ooFreeH245Message(call, pmsg); return OO_FAILED; } finishPrint(); removeEventHandler(pctxt); ooHandleH245Message(call, pmsg); return OO_OK;}/* Generic Send Message functionality. Based on type of message to be sent, it calls the corresponding function to retrieve the message buffer and then transmits on the associated channel Interpreting msgptr: Q931 messages except facility 1st octet - msgType, next 4 octets - tpkt header, followed by encoded msg Q931 message facility 1st octect - OOFacility, 2nd octet - tunneled msg type(in case no tunneled msg - OOFacility), 3rd and 4th octet - associated logical channel of the tunneled msg(0 when no channel is associated. ex. in case of MSD, TCS), next 4 octets - tpkt header, followed by encoded message. H.245 messages no tunneling 1st octet - msg type, next two octets - logical channel number(0, when no channel is associated), next two octets - total length of the message (including tpkt header) H.245 messages - tunneling. 1st octet - msg type, next two octets - logical channel number(0, when no channel is associated), next two octets - total length of the message. Note, no tpkt header is present in this case. */int ooSendMsg(OOH323CallData *call, int type){ int len=0, ret=0, msgType=0, tunneledMsgType=0, logicalChannelNo = 0; DListNode * p_msgNode=NULL; ASN1OCTET *msgptr, *msgToSend=NULL; if(call->callState == OO_CALL_CLEARED) { OOTRACEDBGA3("Warning:Call marked for cleanup. Can not send message." "(%s, %s)\n", call->callType, call->callToken); return OO_OK; } if(type == OOQ931MSG) { if(call->pH225Channel->outQueue.count == 0) { OOTRACEWARN3("WARN:No H.2250 message to send. (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } OOTRACEDBGA3("Sending Q931 message (%s, %s)\n", call->callType, call->callToken); p_msgNode = call->pH225Channel->outQueue.head; msgptr = (ASN1OCTET*) p_msgNode->data; msgType = msgptr[0]; if(msgType == OOFacility) { tunneledMsgType = msgptr[1]; logicalChannelNo = msgptr[2]; logicalChannelNo = logicalChannelNo << 8; logicalChannelNo = (logicalChannelNo | msgptr[3]); len = msgptr[6]; len = len<<8; len = (len | msgptr[7]); msgToSend = msgptr+4; }else { len = msgptr[3]; len = len<<8; len = (len | msgptr[4]); msgToSend = msgptr+1; } /* Remove the message from rtdlist pH225Channel->outQueue */ dListRemove(&(call->pH225Channel->outQueue), p_msgNode); if(p_msgNode) memFreePtr(call->pctxt, p_msgNode); /*TODO: This is not required ideally. We will see for some time and if we don't face any problems we will delete this code */#if 0 /* Check whether connection with remote is alright */ if(!ooChannelsIsConnectionOK(call, call->pH225Channel->sock)) { OOTRACEERR3("Error:Transport failure for signalling channel. " "Abandoning message send and marking call for cleanup.(%s" "'%s)\n", call->callType, call->callToken); if(call->callState < OO_CALL_CLEAR) call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEARED; return OO_OK; }#endif /* Send message out via TCP */ ret = ooSocketSend(call->pH225Channel->sock, msgToSend, len); if(ret == ASN_OK) { memFreePtr (call->pctxt, msgptr); OOTRACEDBGC3("H2250/Q931 Message sent successfully (%s, %s)\n", call->callType, call->callToken); ooOnSendMsg(call, msgType, tunneledMsgType, logicalChannelNo); return OO_OK; } else{ OOTRACEERR3("H2250Q931 Message send failed (%s, %s)\n", call->callType, call->callToken); memFreePtr (call->pctxt, msgptr); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } }/* end of type==OOQ931MSG */ if(type == OOH245MSG) { if(call->pH245Channel->outQueue.count == 0) { OOTRACEWARN3("WARN:No H.245 message to send. (%s, %s)\n", call->callType, call->callToken); return OO_FAILED; } OOTRACEDBGA3("Sending H245 message (%s, %s)\n", call->callType, call->callToken); p_msgNode = call->pH245Channel->outQueue.head; msgptr = (ASN1OCTET*) p_msgNode->data; msgType = msgptr[0]; logicalChannelNo = msgptr[1]; logicalChannelNo = logicalChannelNo << 8; logicalChannelNo = (logicalChannelNo | msgptr[2]); len = msgptr[3]; len = len<<8; len = (len | msgptr[4]); /* Remove the message from queue */ dListRemove(&(call->pH245Channel->outQueue), p_msgNode); if(p_msgNode) memFreePtr(call->pctxt, p_msgNode); /* Send message out */ if (0 == call->pH245Channel && !OO_TESTFLAG(call->flags, OO_M_TUNNELING)) { OOTRACEWARN3("Neither H.245 channel nor tunneling active " "(%s, %s)\n", call->callType, call->callToken); memFreePtr (call->pctxt, msgptr); /*ooCloseH245Session(call);*/ if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_OK; } if (0 != call->pH245Channel && 0 != call->pH245Channel->sock) { OOTRACEDBGC4("Sending %s H245 message over H.245 channel. " "(%s, %s)\n", ooGetMsgTypeText(msgType), call->callType, call->callToken); ret = ooSocketSend(call->pH245Channel->sock, msgptr+5, len); if(ret == ASN_OK) { memFreePtr (call->pctxt, msgptr); OOTRACEDBGA3("H245 Message sent successfully (%s, %s)\n", call->callType, call->callToken); ooOnSendMsg(call, msgType, tunneledMsgType, logicalChannelNo); return OO_OK; } else{ memFreePtr (call->pctxt, msgptr); OOTRACEERR3("ERROR:H245 Message send failed (%s, %s)\n", call->callType, call->callToken); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_TRANSPORTFAILURE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } }else if(OO_TESTFLAG (call->flags, OO_M_TUNNELING)){ OOTRACEDBGC4("Sending %s H245 message as a tunneled message." "(%s, %s)\n", ooGetMsgTypeText(msgType), call->callType, call->callToken); ret = ooSendAsTunneledMessage (call, msgptr+5,len,msgType, logicalChannelNo); if(ret != OO_OK) { memFreePtr (call->pctxt, msgptr); OOTRACEERR3("ERROR:Failed to tunnel H.245 message (%s, %s)\n", call->callType, call->callToken); if(call->callState < OO_CALL_CLEAR) { call->callEndReason = OO_REASON_INVALIDMESSAGE; call->callState = OO_CALL_CLEAR; } return OO_FAILED; } memFreePtr (call->pctxt, msgptr); return OO_OK; } } /* Need to add support for other messages such as T38 etc */ OOTRACEWARN3("ERROR:Unknown message type - message not Sent (%s, %s)\n", call->callType, call->callToken); return OO_FAILED;} int ooCloseH245Connection(OOH323CallData *call){ OOTRACEINFO3("Closing H.245 connection (%s, %s)\n", call->callType, call->callToken); if (0 != call->pH245Channel) { if(0 != call->pH245Channel->sock) ooSocketClose (call->pH245Channel->sock); if (call->pH245Channel->outQueue.count > 0) dListFreeAll(call->pctxt, &(call->pH245Channel->outQueue)); memFreePtr (call->pctxt, call->pH245Channel); call->pH245Channel = NULL; OOTRACEDBGC3("Closed H245 connection. (%s, %s)\n", call->callType, call->callToken); } call->h245SessionState = OO_H245SESSION_CLOSED; return OO_OK;}int ooCloseH245Listener(OOH323CallData *call){ OOTRACEINFO3("Closing H.245 Listener (%s, %s)\n", call->callType, call->callToken); if(call->h245listener) { ooSocketClose(*(call->h245listener)); memFreePtr(call->pctxt, call->h245listener); call->h245listener = NULL; } return OO_OK;}int ooOnSendMsg (OOH323CallData *call, int msgType, int tunneledMsgType, int associatedChan){ ooTimerCallback *cbData=NULL; switch(msgType) { case OOSetup: OOTRACEINFO3("Sent Message - Setup (%s, %s)\n", call->callType, call->callToken); /* Start call establishment timer */ cbData = (ooTimerCallback*) memAlloc(call->pctxt, sizeof(ooTimerCallback)); if(!cbData) { OOTRACEERR3("Error:Unable to allocate memory for timer callback."
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?