ooh245.c

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

C
1,743
字号
/* * Copyright (C) 2004-2005 by Objective Systems, Inc. * * This software is furnished under an open source license and may be  * used and copied only in accordance with the terms of this license.  * The text of the license may generally be found in the root  * directory of this installation in the COPYING file.  It  * can also be viewed online at the following URL: * *   http://www.obj-sys.com/open/license.html * * Any redistributions of this file including modified versions must  * maintain this copyright notice. * *****************************************************************************/#include "ooh245.h"#include "ooCalls.h"#include "printHandler.h"#include "ooh323ep.h"#include "ooCapability.h"#include "ooTimer.h"#ifdef _WIN32#include <stdlib.h>#include <process.h>#define getpid _getpid#endif#include <time.h>/** Global endpoint structure */extern ooEndPoint gH323ep;static ASN1OBJID gh245ProtocolID = {  6, { 0, 0, 8, 245, 0, 8 }};int ooCreateH245Message(H245Message **pph245msg, int type){   OOCTXT* pctxt = &gH323ep.msgctxt;   *pph245msg = (H245Message*) memAlloc (pctxt, sizeof(H245Message));   if(!(*pph245msg))   {      OOTRACEERR1("ERROR:Failed to allocate memory for h245 message\n");      return OO_FAILED;   }   else   {      (*pph245msg)->h245Msg.t = type;      (*pph245msg)->logicalChannelNo = 0;      switch(type)      {         case  T_H245MultimediaSystemControlMessage_request:            (*pph245msg)->h245Msg.u.request = (H245RequestMessage*) 	       memAllocZ (pctxt, sizeof(H245RequestMessage));            /*Check for successful mem allocation, and if successful initialize              mem to zero*/            if(!(*pph245msg)->h245Msg.u.request)            {               OOTRACEERR1("ERROR:Memory allocation for H.245 request"                                     " message failed\n");               return OO_FAILED;            }            break;         case T_H245MultimediaSystemControlMessage_response:            (*pph245msg)->h245Msg.u.response = (H245ResponseMessage*)	       memAllocZ (pctxt, sizeof(H245ResponseMessage));            /*Check for successful mem allocation, and if successful initialize              mem to zero*/            if(!(*pph245msg)->h245Msg.u.response)            {               OOTRACEERR1("ERROR:Memory allocation for H.245 response"                                     " message failed\n");               return OO_FAILED;            }            break;         case T_H245MultimediaSystemControlMessage_command:            (*pph245msg)->h245Msg.u.command = (H245CommandMessage*)	       memAllocZ (pctxt, sizeof(H245CommandMessage));            /*Check for successful mem allocation, and if successful initialize              mem to zero*/            if(!(*pph245msg)->h245Msg.u.command)            {               OOTRACEERR1("ERROR:Memory allocation for H.245 command"                                     " message failed\n");               return OO_FAILED;            }            break;         case T_H245MultimediaSystemControlMessage_indication:            (*pph245msg)->h245Msg.u.indication = (H245IndicationMessage*)	       memAllocZ (pctxt, sizeof(H245IndicationMessage));            /*Check for successful mem allocation, and if successful initialize              mem to zero*/            if(!(*pph245msg)->h245Msg.u.indication)            {               OOTRACEERR1("ERROR:Memory allocation for H.245 indication"                                     " message failed\n");               return OO_FAILED;            }            break;         default:            OOTRACEERR1("ERROR: H245 message type not supported\n");      }      return OO_OK;   }}int ooFreeH245Message(OOH323CallData *call, H245Message *pmsg){  /* In case of tunneling, memory is freed when corresponding Q931 message is freed.*/   OOTRACEDBGC1("msgCtxt Reset?");   if (0 != pmsg) {     if(!OO_TESTFLAG (call->flags, OO_M_TUNNELING)){         memReset (&gH323ep.msgctxt);         OOTRACEDBGC3(" Done (%s, %s)\n", call->callType, call->callToken);         return OO_OK;     }   }   OOTRACEDBGC3("Not Done (%s, %s)\n", call->callType, call->callToken);   return OO_OK;}#ifndef _COMPACTstatic void ooPrintH245Message    (OOH323CallData* call, ASN1OCTET* msgbuf, ASN1UINT msglen){   OOCTXT ctxt;   H245MultimediaSystemControlMessage mmMsg;   int ret;   initContext (&ctxt);   setPERBuffer (&ctxt, msgbuf, msglen, TRUE);   initializePrintHandler(&printHandler, "Sending H.245 Message");   /* Set event handler */   setEventHandler (&ctxt, &printHandler);   ret = asn1PD_H245MultimediaSystemControlMessage(&ctxt, &mmMsg);   if(ret != ASN_OK)   {      OOTRACEERR3("Error decoding H245 message (%s, %s)\n",                   call->callType, call->callToken);      OOTRACEERR1 (errGetText (&ctxt));   }   finishPrint();   freeContext(&ctxt);   }#endifint ooEncodeH245Message   (OOH323CallData *call, H245Message *ph245Msg, char *msgbuf, int size){   int len=0, encodeLen=0, i=0;   int stat=0;   ASN1OCTET* encodePtr=NULL;   H245MultimediaSystemControlMessage *multimediaMsg;   OOCTXT *pctxt = &gH323ep.msgctxt;   multimediaMsg = &(ph245Msg->h245Msg);   if(!msgbuf || size<200)   {      OOTRACEERR3("Error: Invalid message buffer/size for "                  "ooEncodeH245Message. (%s, %s)\n",                    call->callType, call->callToken);      return OO_FAILED;   }   msgbuf[i++] = ph245Msg->msgType;   msgbuf[i++] = (ph245Msg->logicalChannelNo>>8);   msgbuf[i++] = ph245Msg->logicalChannelNo;   /* This will contain the total length of the encoded message */   msgbuf[i++] = 0;   msgbuf[i++] = 0;      if(!OO_TESTFLAG (call->flags, OO_M_TUNNELING))   {      /* Populate message buffer to be returned */      len =  4;      msgbuf[i++] = 3; /* TPKT version */      msgbuf[i++] = 0; /* TPKT resevred */      /* 1st octet of length, will be populated once len is determined */      msgbuf[i++] = 0;       /* 2nd octet of length, will be populated once len is determined */      msgbuf[i++] = 0;   }      setPERBuffer (pctxt, msgbuf+i, (size-i), TRUE);   stat = asn1PE_H245MultimediaSystemControlMessage (&gH323ep.msgctxt,                                                             multimediaMsg);   if (stat != ASN_OK) {      OOTRACEERR3 ("ERROR: H245 Message encoding failed (%s, %s)\n",                    call->callType, call->callToken);      OOTRACEERR1 (errGetText (&gH323ep.msgctxt));      return OO_FAILED;   }      encodePtr = encodeGetMsgPtr(pctxt, &encodeLen);   len +=encodeLen;   msgbuf[3] = (len>>8);   msgbuf[4] = len;   if(!OO_TESTFLAG (call->flags, OO_M_TUNNELING))   {      msgbuf[7] = len>>8;      msgbuf[8] = len;   }#ifndef _COMPACT   ooPrintH245Message (call, encodePtr, encodeLen);#endif   return OO_OK;}int ooSendH245Msg(OOH323CallData *call, H245Message *msg){   int iRet=0,  len=0, msgType=0, logicalChannelNo = 0;   ASN1OCTET * encodebuf;   if(!call)      return OO_FAILED;   encodebuf = (ASN1OCTET*) memAlloc (call->pctxt, MAXMSGLEN);   if(!encodebuf)   {      OOTRACEERR3("Error:Failed to allocate memory for encoding H245 "                  "message(%s, %s)\n", call->callType, call->callToken);      return OO_FAILED;   }   iRet = ooEncodeH245Message(call, msg, encodebuf, MAXMSGLEN);   if(iRet != OO_OK)   {      OOTRACEERR3("Error:Failed to encode H245 message. (%s, %s)\n",                                              call->callType, call->callToken);      memFreePtr (call->pctxt, encodebuf);      return OO_FAILED;   }   if(!call->pH245Channel)   {      call->pH245Channel =                (OOH323Channel*) memAllocZ (call->pctxt, sizeof(OOH323Channel));      if(!call->pH245Channel)      {         OOTRACEERR3("Error:Failed to allocate memory for H245Channel "                     "structure. (%s, %s)\n", call->callType, call->callToken);         memFreePtr (call->pctxt, encodebuf);         return OO_FAILED;      }   }   /* We need to send EndSessionCommand immediately.*/	      if(!OO_TESTFLAG(call->flags, OO_M_TUNNELING)){      if(encodebuf[0]== OOEndSessionCommand) /* High priority message */      {         dListFreeAll(call->pctxt, &call->pH245Channel->outQueue);         dListAppend (call->pctxt, &call->pH245Channel->outQueue, encodebuf);         ooSendMsg(call, OOH245MSG);      }else{         dListAppend (call->pctxt, &call->pH245Channel->outQueue, encodebuf);         OOTRACEDBGC4("Queued H245 messages %d. (%s, %s)\n", 		   call->pH245Channel->outQueue.count, 		   call->callType, call->callToken);         }   }   else{      msgType = encodebuf[0];      logicalChannelNo = encodebuf[1];      logicalChannelNo = logicalChannelNo << 8;      logicalChannelNo = (logicalChannelNo | encodebuf[2]);      len = encodebuf[3];      len = len<<8;      len = (len | encodebuf[4]);      iRet = ooSendAsTunneledMessage	    (call, encodebuf+5,len,msgType, logicalChannelNo);      if(iRet != OO_OK)      {         memFreePtr (call->pctxt, encodebuf);         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, encodebuf);      return OO_OK;   }   return OO_OK;}int ooSendTermCapMsg(OOH323CallData *call){   int ret;   H245RequestMessage *request=NULL;   OOCTXT *pctxt=NULL;   ooH323EpCapability *epCap=NULL;   H245TerminalCapabilitySet *termCap=NULL;   H245AudioCapability *audioCap=NULL;   H245AudioTelephonyEventCapability *ateCap=NULL;   H245UserInputCapability *userInputCap = NULL;   H245CapabilityTableEntry *entry=NULL;   H245AlternativeCapabilitySet *altSet=NULL;   H245CapabilityDescriptor *capDesc=NULL;   H245Message *ph245msg=NULL;   H245VideoCapability *videoCap=NULL;   int i=0, j=0, k=0;   if(call->localTermCapState == OO_LocalTermCapSetSent)   {      OOTRACEINFO3("TerminalCapabilitySet exchange procedure already in "                   "progress. (%s, %s)\n", call->callType, call->callToken);      return OO_OK;   }    ret = ooCreateH245Message(&ph245msg,                               T_H245MultimediaSystemControlMessage_request);    if(ret == OO_FAILED)   {      OOTRACEERR3("Error:Failed to create H245 message for Terminal "                  "CapabilitySet (%s, %s)\n", call->callType,call->callToken);      return OO_FAILED;   }  /* Set request type as TerminalCapabilitySet */   request = ph245msg->h245Msg.u.request;   pctxt = &gH323ep.msgctxt;   ph245msg->msgType = OOTerminalCapabilitySet;

⌨️ 快捷键说明

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