ooh323ep.c
来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 781 行 · 第 1/2 页
C
781 行
/* * 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 "ooh323ep.h"#include "ootrace.h"#include "ooCalls.h"#include "ooCapability.h"#include "ooGkClient.h"#include "ooStackCmds.h"#include "ooCmdChannel.h"/** Global endpoint structure */ooEndPoint gH323ep;extern int gCmdPort;extern char gCmdIP[20];extern DList g_TimerList;int ooH323EpInitialize (enum OOCallMode callMode, const char* tracefile){ memset(&gH323ep, 0, sizeof(ooEndPoint)); initContext(&(gH323ep.ctxt)); initContext(&(gH323ep.msgctxt)); if(tracefile) { if(strlen(tracefile)>= MAXFILENAME) { printf("Error:File name longer than allowed maximum %d\n", MAXFILENAME-1); return OO_FAILED; } strcpy(gH323ep.traceFile, tracefile); }else{ strcpy(gH323ep.traceFile, DEFAULT_TRACEFILE); } gH323ep.fptraceFile = fopen(gH323ep.traceFile, "w"); if(gH323ep.fptraceFile == NULL) { printf("Error:Failed to open trace file %s for write.\n", gH323ep.traceFile); return OO_FAILED; } /* Initialize default port ranges that will be used by stack. Apps can override these by explicitely setting port ranges */ gH323ep.tcpPorts.start = TCPPORTSSTART; gH323ep.tcpPorts.max = TCPPORTSEND; gH323ep.tcpPorts.current=TCPPORTSSTART; gH323ep.udpPorts.start = UDPPORTSSTART; gH323ep.udpPorts.max = UDPPORTSEND; gH323ep.udpPorts.current = UDPPORTSSTART; gH323ep.rtpPorts.start = RTPPORTSSTART; gH323ep.rtpPorts.max = RTPPORTSEND; gH323ep.rtpPorts.current = RTPPORTSSTART; OO_SETFLAG(gH323ep.flags, OO_M_FASTSTART); OO_SETFLAG(gH323ep.flags, OO_M_TUNNELING); OO_SETFLAG(gH323ep.flags, OO_M_AUTOANSWER); OO_CLRFLAG(gH323ep.flags, OO_M_GKROUTED); gH323ep.aliases = NULL; gH323ep.termType = DEFAULT_TERMTYPE; gH323ep.t35CountryCode = DEFAULT_T35COUNTRYCODE; gH323ep.t35Extension = DEFAULT_T35EXTENSION; gH323ep.manufacturerCode = DEFAULT_MANUFACTURERCODE; gH323ep.productID = DEFAULT_PRODUCTID; gH323ep.versionID = OOH323C_VERSION; gH323ep.callType = T_H225CallType_pointToPoint; ooGetLocalIPAddress(gH323ep.signallingIP); gH323ep.listenPort = DEFAULT_H323PORT; gH323ep.listener = NULL; ooH323EpSetCallerID(DEFAULT_CALLERID); gH323ep.myCaps = NULL; gH323ep.noOfCaps = 0; gH323ep.callList = NULL; gH323ep.dtmfmode = 0; gH323ep.callingPartyNumber[0]='\0'; gH323ep.callMode = callMode; gH323ep.isGateway = FALSE; dListInit(&g_TimerList);/* This is for test application chansetup only*/ gH323ep.callEstablishmentTimeout = DEFAULT_CALLESTB_TIMEOUT; gH323ep.msdTimeout = DEFAULT_MSD_TIMEOUT; gH323ep.tcsTimeout = DEFAULT_TCS_TIMEOUT; gH323ep.logicalChannelTimeout = DEFAULT_LOGICALCHAN_TIMEOUT; gH323ep.sessionTimeout = DEFAULT_ENDSESSION_TIMEOUT; gH323ep.ifList = NULL; ooSetTraceThreshold(OOTRCLVLINFO); OO_SETFLAG(gH323ep.flags, OO_M_ENDPOINTCREATED); gH323ep.cmdListener = 0; gH323ep.cmdSock = 0; gH323ep.cmdPort = OO_DEFAULT_CMDLISTENER_PORT; return OO_OK;}EXTERN int ooH323EpSetAsGateway(){ gH323ep.isGateway = TRUE; return OO_OK;}int ooH323EpSetLocalAddress(const char* localip, int listenport){ if(localip) { strcpy(gH323ep.signallingIP, localip); strcpy(gCmdIP, localip); OOTRACEINFO2("Signalling IP address is set to %s\n", localip); } if(listenport) { gH323ep.listenPort = listenport; OOTRACEINFO2("Listen port number is set to %d\n", listenport); } return OO_OK;}int ooH323EpCreateCmdListener(int cmdPort){ if(cmdPort != 0) { gH323ep.cmdPort = cmdPort; gCmdPort = cmdPort; } if(ooCreateCmdListener() != OO_OK) return OO_FAILED; return OO_OK;}int ooH323EpAddAliasH323ID(const char *h323id){ ooAliases * psNewAlias=NULL; psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases)); if(!psNewAlias) { OOTRACEERR1("Error: Failed to allocate memory for new H323-ID alias\n"); return OO_FAILED; } psNewAlias->type = T_H225AliasAddress_h323_ID; psNewAlias->registered = FALSE; psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(h323id)+1); if(!psNewAlias->value) { OOTRACEERR1("Error: Failed to allocate memory for the new H323-ID alias " "value\n"); memFreePtr(&gH323ep.ctxt, psNewAlias); return OO_FAILED; } strcpy(psNewAlias->value, h323id); psNewAlias->next = gH323ep.aliases; gH323ep.aliases = psNewAlias; OOTRACEDBGA2("Added alias: H323ID - %s\n", h323id); return OO_OK;}int ooH323EpAddAliasDialedDigits(const char* dialedDigits){ ooAliases * psNewAlias=NULL; psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases)); if(!psNewAlias) { OOTRACEERR1("Error: Failed to allocate memory for new DialedDigits " "alias\n"); return OO_FAILED; } psNewAlias->type = T_H225AliasAddress_dialedDigits; psNewAlias->registered = FALSE; psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(dialedDigits)+1); if(!psNewAlias->value) { OOTRACEERR1("Error: Failed to allocate memory for the new DialedDigits" " alias value\n"); memFreePtr(&gH323ep.ctxt, psNewAlias); return OO_FAILED; } strcpy(psNewAlias->value, dialedDigits); psNewAlias->next = gH323ep.aliases; gH323ep.aliases = psNewAlias; OOTRACEDBGA2("Added alias: DialedDigits - %s\n", dialedDigits); return OO_OK;}int ooH323EpAddAliasURLID(const char * url){ ooAliases * psNewAlias=NULL; psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases)); if(!psNewAlias) { OOTRACEERR1("Error: Failed to allocate memory for new URL-ID alias\n"); return OO_FAILED; } psNewAlias->type = T_H225AliasAddress_url_ID; psNewAlias->registered = FALSE; psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(url)+1); if(!psNewAlias->value) { OOTRACEERR1("Error: Failed to allocate memory for the new URL-ID alias" " value\n"); memFreePtr(&gH323ep.ctxt, psNewAlias); return OO_FAILED; } strcpy(psNewAlias->value, url); psNewAlias->next = gH323ep.aliases; gH323ep.aliases = psNewAlias; OOTRACEDBGA2("Added alias: URL-ID - %s\n", url); return OO_OK;}int ooH323EpAddAliasEmailID(const char * email){ ooAliases * psNewAlias=NULL; psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases)); if(!psNewAlias) { OOTRACEERR1("Error: Failed to allocate memory for new Email-ID alias\n"); return OO_FAILED; } psNewAlias->type = T_H225AliasAddress_email_ID; psNewAlias->registered = FALSE; psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(email)+1); if(!psNewAlias->value) { OOTRACEERR1("Error: Failed to allocate memory for the new Email-ID alias" " value\n"); memFreePtr(&gH323ep.ctxt, psNewAlias); return OO_FAILED; } strcpy(psNewAlias->value, email); psNewAlias->next = gH323ep.aliases; gH323ep.aliases = psNewAlias; OOTRACEDBGA2("Added alias: Email-ID - %s\n", email); return OO_OK;}int ooH323EpAddAliasTransportID(const char * ipaddress){ ooAliases * psNewAlias=NULL; psNewAlias = (ooAliases*)memAlloc(&gH323ep.ctxt, sizeof(ooAliases)); if(!psNewAlias) { OOTRACEERR1("Error: Failed to allocate memory for new Transport-ID " "alias\n"); return OO_FAILED; } psNewAlias->type = T_H225AliasAddress_transportID; psNewAlias->registered = FALSE; psNewAlias->value = (char*) memAlloc(&gH323ep.ctxt, strlen(ipaddress)+1); if(!psNewAlias->value) { OOTRACEERR1("Error: Failed to allocate memory for the new Transport-ID " "alias value\n"); memFreePtr(&gH323ep.ctxt, psNewAlias); return OO_FAILED; } strcpy(psNewAlias->value, ipaddress); psNewAlias->next = gH323ep.aliases; gH323ep.aliases = psNewAlias; OOTRACEDBGA2("Added alias: Transport-ID - %s\n", ipaddress); return OO_OK;}int ooH323EpClearAllAliases(void){ ooAliases *pAlias = NULL, *pTemp; if(gH323ep.aliases) { pAlias = gH323ep.aliases; while(pAlias) { pTemp = pAlias; pAlias = pAlias->next; memFreePtr(&gH323ep.ctxt, pTemp); } gH323ep.aliases = NULL; } return OO_OK;}int ooH323EpSetH225MsgCallbacks(OOH225MsgCallbacks h225Callbacks){ gH323ep.h225Callbacks.onReceivedSetup = h225Callbacks.onReceivedSetup; gH323ep.h225Callbacks.onReceivedConnect = h225Callbacks.onReceivedConnect; gH323ep.h225Callbacks.onBuiltSetup = h225Callbacks.onBuiltSetup; gH323ep.h225Callbacks.onBuiltConnect = h225Callbacks.onBuiltConnect; return OO_OK;} int ooH323EpSetH323Callbacks(OOH323CALLBACKS h323Callbacks){ gH323ep.h323Callbacks.onNewCallCreated = h323Callbacks.onNewCallCreated; gH323ep.h323Callbacks.onAlerting = h323Callbacks.onAlerting; gH323ep.h323Callbacks.onIncomingCall = h323Callbacks.onIncomingCall; gH323ep.h323Callbacks.onOutgoingCall = h323Callbacks.onOutgoingCall; gH323ep.h323Callbacks.onCallEstablished = h323Callbacks.onCallEstablished; gH323ep.h323Callbacks.onCallForwarded = h323Callbacks.onCallForwarded; gH323ep.h323Callbacks.onCallCleared = h323Callbacks.onCallCleared; gH323ep.h323Callbacks.openLogicalChannels = h323Callbacks.openLogicalChannels; gH323ep.h323Callbacks.onReceivedDTMF = h323Callbacks.onReceivedDTMF; return OO_OK;}int ooH323EpDestroy(void){ /* free any internal memory allocated close trace file free context structure */ OOH323CallData * cur, *temp; if(OO_TESTFLAG(gH323ep.flags, OO_M_ENDPOINTCREATED)) { OOTRACEINFO1("Destroying H323 Endpoint\n"); if(gH323ep.callList) { cur = gH323ep.callList; while(cur) { temp = cur; cur = cur->next; temp->callEndReason = OO_REASON_LOCAL_CLEARED; ooCleanCall(temp); } gH323ep.callList = NULL; } if(gH323ep.listener) { ooSocketClose(*(gH323ep.listener)); gH323ep.listener = NULL; } if(gH323ep.cmdListener != 0) { ooSocketClose(gH323ep.cmdListener); gH323ep.cmdListener = 0; } ooGkClientDestroy(); if(gH323ep.fptraceFile) { fclose(gH323ep.fptraceFile); gH323ep.fptraceFile = NULL; } freeContext(&(gH323ep.ctxt)); OO_CLRFLAG(gH323ep.flags, OO_M_ENDPOINTCREATED);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?