callTransfer.cpp
资源名称:h323.zip [点击查看]
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:12k
源码类别:
IP电话/视频会议
开发平台:
WINDOWS
- /*
- * $Revision: 1.2 $
- * $Date: 1998/11/03 18:32:02 $
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "exchange.h"
- #include "h450msgs.h"
- /////////////////////////////////////////////////////////////
- //
- // ctInitiateInvoke()
- //
- // Inputs:
- // invokeID - must be zero until OSS updated
- // to fix bug.
- // callid - string upto 4 chars + NULL
- // ip - string with transfer-to ip address
- // e164 (opt) - will add if not NULL
- //
- // Output:
- // A pointer to a single H4501SuppService
- // object for which memory is allocated.
- //
- // CALLING FUNCTION MUST DELETE RETURD OBJECT.
- //
- /////////////////////////////////////////////////////////////
- H4501SuppService *
- ctInitiateInvoke(int invokeID, char *callid, unsigned int ip, char *e164)
- {
- ProtReturnCode ret;
- int len;
- int local;
- H4501SuppService *ss;
- H450AliasAddress *firstAA;
- H450AliasAddress *secondAA;
- H4501EndpointAddr *ep;
- H4502CTInitiateArg *initarg;
- H4501Invoke *inv;
- H4501Code *code;
- ss = new H4501SuppService;
- firstAA = new H450AliasAddress;
- secondAA = new H450AliasAddress;
- ep = new H4501EndpointAddr;
- initarg = new H4502CTInitiateArg;
- inv = new H4501Invoke;
- code = new H4501Code;
- LOG("nctInitiateInvoke()n");
- if(ip != 0) {
- sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(1720);
- addr.sin_addr.s_addr = ip;
- LOG(" firstAA->SetTransportID() to set address to: ip=0x%xn", ip);
- ret = firstAA->SetTransportID((sockaddr *)&addr);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" ep->AddDestAddr(*firstAA) to add first AliasAddress to EndpointAddressn");
- ret = ep->AddDestAddr(*firstAA);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- }
- if(e164 != NULL) {
- len = strlen(e164);
- LOG(" secondAA->SetE164() to set address to: %s len=%dn", e164,len);
- ret = secondAA->SetE164(e164, len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" ep->AddDestAddr(*secondAA) to add second AliasAddressn");
- ret = ep->AddDestAddr(*secondAA);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- }
- // callIdentity is mandatory
- len = strlen(callid);
- LOG(" initarg->SetCallID() to set callIdentity of InitiateArg, callid = %s len=%dn", callid, len);
- ret = initarg->SetCallID(callid,len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" initarg->SetNumber(*ep) to set reroutingNumber of InitiateArg n");
- ret = initarg->SetNumber(*ep);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- local = CTOT_INITIATE;
- LOG(" code->SetLocalCode() to set code to local:%d n",local);
- ret = code->SetLocalCode(local);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- invokeID = 0;
- LOG(" inv->SetInvokeId(%d) to set InvokeId of Invoke n",invokeID);
- ret = inv->SetInvokeId(invokeID);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" inv->SetCode(*code) to set opcode of Invoke n");
- ret = inv->SetCode(*code);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" inv->SetArgument(*initarg) to set argument of Invoke n");
- ret = inv->SetArgument(*initarg);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" SuppService->AddROS(*inv) to add the Invoken");
- ret = ss->AddROS(*inv);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- delete firstAA;
- delete secondAA;
- delete ep;
- delete initarg;
- delete inv;
- delete code;
- return (ss);
- }
- /////////////////////////////////////////////////////////////
- //
- // ctSetupInvoke()
- //
- // Inputs:
- // invokeID - must be zero until OSS updated
- // to fix bug.
- // callid - string upto 4 chars + NULL
- //
- // Output:
- // A pointer to a single H4501SuppService
- // object for which memory is allocated.
- //
- // CALLING FUNCTION MUST DELETE RETURD OBJECT.
- //
- /////////////////////////////////////////////////////////////
- H4501SuppService *
- ctSetupInvoke(int invokeID, char *callid)
- {
- ProtReturnCode ret;
- int len;
- int local;
- H4501SuppService *ss;
- H4502CTSetupArg *setuparg;
- H4501Invoke *inv;
- H4501Code *code;
- LOG("nctSetupInvoke(): enteredn");
- ss = new H4501SuppService;
- inv = new H4501Invoke;
- code = new H4501Code;
- setuparg = new H4502CTSetupArg;
- LOG("inv->SetInvokeId(%d)n",invokeID); // ???? ONLY ACCEPTS 0 FOR NOW
- ret = inv->SetInvokeId(invokeID);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- local = CTOT_SETUP;
- LOG("code->SetLocalCode(%d) n",local);
- ret = code->SetLocalCode(local);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG("inv->SetCode(*code) n");
- ret = inv->SetCode(*code);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- len = strlen(callid);
- LOG("setuparg->SetCallID("%s",%d)n",callid,len);
- ret = setuparg->SetCallID(callid,len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG("inv->SetArgument(*setuparg) n");
- ret = inv->SetArgument(*setuparg);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG("ss->AddROS(*inv)n");
- ret = ss->AddROS(*inv);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- delete inv;
- delete code;
- delete setuparg;
- return(ss);
- }
- /////////////////////////////////////////////////////////////
- //
- // ctSetupReturnResult()
- //
- // Inputs:
- // invokeID - invokeID from received message
- //
- // Output:
- // A pointer to a single H4501SuppService
- // object for which memory is allocated.
- //
- // CALLING FUNCTION MUST DELETE RETURD OBJECT.
- //
- /////////////////////////////////////////////////////////////
- H4501SuppService *
- ctSetupReturnResult(int invokeID)
- {
- ProtReturnCode ret;
- int len;
- int local;
- H4501SuppService *ss;
- H4501ReturnResult *res;
- H450NonStdParam *param;
- H4502DummyRes *dum;
- H4501Code *code;
- ss = new H4501SuppService;
- res = new H4501ReturnResult;
- param = new H450NonStdParam;
- dum = new H4502DummyRes;
- code = new H4501Code;
- LOG("ctSetupReturnResult: enteredn");
- LOG(" res->SetInvokeId(%d) on ReturnResult n",invokeID);
- ret = res->SetInvokeId(invokeID);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- local = CTOT_SETUP;
- LOG(" code->SetLocalCode() to set to local:%d n",local);
- ret = code->SetLocalCode(local);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- // This seems weird but in order to set the code in the result we
- // need to have either and Extension or NonStdData in DummyRes
- // so let's put NonStdData since it is easier to use for some junk
- unsigned short cc = 12;
- unsigned short ext = 34;
- unsigned short mc = 56;
- LOG(" param->SetH221NonStd(%d,%d,%d) to set NonStandardIdentifier n",cc,ext,mc);
- ret = param->SetH221NonStd(cc,ext,mc);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- unsigned char data[7] = {0x61,0x62,0x63,0x64,0x65,0x66,0x67};
- len = 7;
- LOG(" param->SetNonStdData() to set Data field of NonStandardParameter data=%s len=%dn",(char *)data,len);
- ret = param->SetNonStdData(data,len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" dum->SetNonStdData(*param) to load DummyRes with NonStandardDatan");
- ret = dum->SetNonStdData(*param);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" res->SetResult(*code, *dum) to set Emresult field n");
- ret = res->SetResult(*code, *dum);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" ss->AddROS(*res) to add the ReturnResultn");
- ret = ss->AddROS(*res);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- delete res;
- delete param;
- delete dum;
- delete code;
- return(ss);
- }
- /////////////////////////////////////////////////////////////
- //
- // ctInitiateReturnResult()
- //
- // Inputs:
- // invokeID - invokeID from received message
- //
- // Output:
- // A pointer to a single H4501SuppService
- // object for which memory is allocated.
- //
- // CALLING FUNCTION MUST DELETE RETURD OBJECT.
- //
- /////////////////////////////////////////////////////////////
- H4501SuppService *
- ctInitiateReturnResult(int invokeID)
- {
- ProtReturnCode ret;
- int len;
- int local;
- H4501SuppService *ss;
- H4501ReturnResult *res;
- H450NonStdParam *param;
- H4502DummyRes *dum;
- H4501Code *code;
- ss = new H4501SuppService;
- res = new H4501ReturnResult;
- param = new H450NonStdParam;
- dum = new H4502DummyRes;
- code = new H4501Code;
- LOG("ctInitiateReturnResult: enteredn");
- LOG(" res->SetInvokeId(%d) on ReturnResult n",invokeID);
- ret = res->SetInvokeId(invokeID);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- local = CTOT_INITIATE;
- LOG(" code->SetLocalCode() to set to local:%d n",local);
- ret = code->SetLocalCode(local);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- // This seems weird but in order to set the code in the result we
- // need to have either and Extension or NonStdData in DummyRes
- // so let's put NonStdData since it is easier to use for some junk
- unsigned short cc = 88;
- unsigned short ext = 77;
- unsigned short mc = 66;
- LOG(" param->SetH221NonStd(%d,%d,%d) to set NonStandardIdentifier n",cc,ext,mc);
- ret = param->SetH221NonStd(cc,ext,mc);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- unsigned char data[7] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37};
- len = 7;
- LOG(" param->SetNonStdData() to set Data field of NonStandardParameter data=%s len=%dn",(char *)data,len);
- ret = param->SetNonStdData(data,len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" dum->SetNonStdData(*param) to load DummyRes with NonStandardDatan");
- ret = dum->SetNonStdData(*param);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" res->SetResult(*code, *dum) to set Emresult field n");
- ret = res->SetResult(*code, *dum);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- LOG(" ss->AddROS(*res) to add the ReturnResultn");
- ret = ss->AddROS(*res);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- delete res;
- delete param;
- delete dum;
- delete code;
- return(ss);
- }
- int
- isInitiateInvoke(H4501SuppService *ss, int &invokeID, char *call_id,
- unsigned int &ip_addr, char *phone)
- {
- ProtReturnCode ret;
- extractedSS extSS;
- extSS.tH4501SuppService(ss);
- if (extSS.ssNumROSs > 0)
- {
- LOG("ssNumROSs=%d type=%d code=%dn",extSS.ssNumROSs,extSS.ssROS[0].type,extSS.ssROS[0].code);
- if (extSS.ssROS[0].type == ROS_INVOKE)
- {
- if (extSS.ssROS[0].code == CTOT_INITIATE)
- {
- LOG("initiate.invoke receivedn");
- invokeID = extSS.ssROS[0].InvokeId;
- strncpy(call_id, extSS.ssROS[0].Arg.CallID, 5);
- H4501EndpointAddr *ep = extSS.ssROS[0].Arg.EndpointAddr;
- H450AliasAddress *pAA;
- int count;
- int len;
- int type;
- ret = ep->GetNumDestAddrs(count);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- if(count == 0) {
- LOG("ERROR: No Dst addrs in initiate.invn");
- return(-1);
- }
- pAA = new H450AliasAddress[count];
- ret = ep->GetDestAddrs(pAA, count);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- }
- for(int ia = 0; ia < count; ia++) {
- type = pAA[ia].GetType();
- switch(type) {
- case AAT_INVALID:
- LOG("test_extractedSS: AliasAddress type is AAT_INVALIDn");
- break;
- case AAT_E164:
- {
- char *e164;
- ret = pAA[ia].GetE164(e164, len);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- } else {
- char retstr[MAXOUTSTR];
- LOG(" GetE164() e164 = %sn",
- sprint_string((unsigned char *)e164,
- MAXSTRLEN(len), retstr));
- LOG(" len = %dn",len);
- strncpy (phone, e164, len);
- phone[len] = ' ';
- }
- break;
- }
- case AAT_TRANSPORT_ID:
- {
- struct sockaddr_in addr;
- ret = pAA[ia].GetTransportID((sockaddr *)&addr);
- if (!PROT_IS_SUCCESS(ret)) {
- doError(ret,EXIT_ON_ERROR);
- } else {
- char sockstr[25];
- LOG("%sGetTransportID() transportID = %sn",
- sprint_sockaddr((sockaddr *)&addr,sockstr));
- ip_addr = addr.sin_addr.s_addr;
- }
- break;
- }
- default:
- LOG("AliasAddr type being ignored %dn",type);
- break;
- }
- }
- delete [] pAA;
- // LOG("Placing a call to transferredTon");
- // exchange->PlaceTransferedToCall(myindex, ip_addr,
- // phone, transfer_invoke_id, transfer_call_id);
- }
- else
- {
- return(0);
- }
- }
- else
- {
- return(0);
- }
- }
- else
- {
- return(0);
- }
- return(1);
- }