int ooReleaseSndRTPPlugin(struct ooAppContext* context) { #ifdef _WIN32 if(!FreeLibrary(media)) { OOTRACEWARN2(context, "Warn: Failed to release the plugin"); return OO_FAILED; } else OOTRACEINFO2(context, "INFO: Plugin released from memory"); #else if(dlclose(media) != 0) { OOTRACEWARN2(context, "Warn: Failed to release the plugin"); return OO_FAILED; } else OOTRACEINFO2(context, "INFO: Plugin released from memory"); #endif media = 0; FuncPtr_InitializePlugin = 0; FuncPtr_CreateTxRTPChan = 0; FuncPtr_CloseTxRTPChan = 0; FuncPtr_CreateRecvRTPChan = 0; FuncPtr_CloseRecvRTPChan = 0; FuncPtr_StartTxWaveFile = 0; FuncPtr_StopTxWaveFile = 0; FuncPtr_StartTxMic = 0; FuncPtr_StopTxMic = 0; FuncPtr_StartRecvAndPlayback = 0; FuncPtr_StopRecvAndPlayback = 0; return OO_OK; }
int ooH323EpSetLocalAddress(const char* localip, int listenport) { if(localip) { strcpy(gH323ep.signallingIP, 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 ooEndCall(OOH323CallData *call) { OOTRACEDBGA4("In ooEndCall call state is - %s (%s, %s)\n", ooGetCallStateText(call->callState), call->callType, call->callToken); if(call->callState == OO_CALL_REMOVED) { OOTRACEINFO2("Call already removed %s\n", call->callToken); return OO_OK; } if (call->callIdentifier.guid.numocts == 0) call->callState = OO_CALL_CLEARED; if(!call->pH225Channel || call->pH225Channel->sock ==0) { call->callState = OO_CALL_CLEARED; } if(call->callState == OO_CALL_CLEARED || call->callState == OO_CALL_CLEAR_RELEASESENT) { ooCleanCall(call); call->callState = OO_CALL_REMOVED; return OO_OK; } if(call->logicalChans) { OOTRACEINFO3("Clearing all logical channels. (%s, %s)\n", call->callType, call->callToken); ooClearAllLogicalChannels(call); } if(!OO_TESTFLAG(call->flags, OO_M_ENDSESSION_BUILT)) { if(call->h245SessionState == OO_H245SESSION_ACTIVE || call->h245SessionState == OO_H245SESSION_ENDRECVD) { ooSendEndSessionCommand(call); OO_SETFLAG(call->flags, OO_M_ENDSESSION_BUILT); } } if(!OO_TESTFLAG(call->flags, OO_M_RELEASE_BUILT)) { if(call->callState == OO_CALL_CLEAR || call->callState == OO_CALL_CLEAR_RELEASERECVD) { ooSendReleaseComplete(call); OO_SETFLAG(call->flags, OO_M_RELEASE_BUILT); } } return OO_OK; }
void CDlg_H323::DisengageRequest() { int iCharNum; int ret; H225DisengageRequest *DisengageRequest; OOCTXT *pctxt; //build and send RAS disengageRequest message ret = ooCreateRasMessage(myContext,T_H225RasMessage_disengageRequest); if(ret == OO_FAILED) { OOTRACEERR2(myContext,"Error:Failed to create Ras message"); return; } myContext->outgoingRas->msgType = OODisengageRequest; pctxt = myContext->outgoingRas->pctxt; DisengageRequest = myContext->outgoingRas->RasMsg.u.disengageRequest; DisengageRequest->requestSeqNum = (myContext->seqNumber++) % 65536; //endpointIdentifier iCharNum = DisengageRequest->endpointIdentifier.nchars = myContext->epIdentifier.nchars; DisengageRequest->endpointIdentifier.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,iCharNum * sizeof(ASN116BITCHAR)); memcpy(DisengageRequest->endpointIdentifier.data,myContext->epIdentifier.data,iCharNum * sizeof(ASN116BITCHAR)); //ConferenceID DisengageRequest->conferenceID.numocts = myContext->conferenceId.numocts; memcpy(DisengageRequest->conferenceID.data,myContext->conferenceId.data,myContext->conferenceId.numocts); //CallReferenceValue DisengageRequest->callReferenceValue = myContext->callReference; DisengageRequest->disengageReason.t = T_H225DisengageReason_normalDrop; //CallIdentifier DisengageRequest->m.callIdentifierPresent = TRUE; DisengageRequest->callIdentifier.guid.numocts = myContext->callIdentifier.guid.numocts; memcpy(DisengageRequest->callIdentifier.guid.data,myContext->callIdentifier.guid.data, myContext->callIdentifier.guid.numocts); ooSendRasMsg(myContext); OOTRACEINFO2(myContext, "Sending disengage request message"); }
int ooCreateCallCmdConnection(OOH323CallData* call) { int ret = 0; int thePipe[2]; OOTRACEINFO2("INFO: create cmd connect for call: %lx\n", call); call->CmdChanLock = malloc(sizeof(ast_mutex_t)); ast_mutex_init(call->CmdChanLock); if ((ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, thePipe)) == -1) { ast_mutex_destroy(call->CmdChanLock); free(call->CmdChanLock); call->CmdChanLock = NULL; return OO_FAILED; } ast_mutex_lock(call->CmdChanLock); call->cmdSock = thePipe[0]; call->CmdChan = thePipe[1]; ast_mutex_unlock(call->CmdChanLock); return OO_OK; }
void CDlg_H323::AdmissionRequest() { H225AdmissionRequest *admRequest; OOCTXT *pctxt; H225TransportAddress_ipAddress *IpAddr; int addr_seg1,addr_seg2,addr_seg3,addr_seg4; char hexIp[20]; H225AliasAddress *alias,*Alias1,*Alias2; int ret; int nCharNum; //build and send RAS registration message ret = ooCreateRasMessage(myContext,T_H225RasMessage_admissionRequest); if(ret == OO_FAILED) { OOTRACEERR2(myContext,"Error:Failed to create Ras message"); return; } myContext->outgoingRas->msgType = OOAdmissionRequest; pctxt = myContext->outgoingRas->pctxt; admRequest = myContext->outgoingRas->RasMsg.u.admissionRequest; admRequest->requestSeqNum = (myContext->seqNumber++) % 65536; admRequest->callType.t = T_H225CallType_pointToPoint; //endpoint identifier nCharNum = admRequest->endpointIdentifier.nchars = myContext->epIdentifier.nchars; admRequest->endpointIdentifier.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,nCharNum * sizeof(ASN116BITCHAR)); memcpy(admRequest->endpointIdentifier.data,myContext->epIdentifier.data,nCharNum * sizeof(ASN116BITCHAR)); //followed is destinationInfo or destCallSignalAddress if(m_bAsCaller) //作为主叫方 { //dest info admRequest->m.destinationInfoPresent = 1; dListInit(&(admRequest->destinationInfo)); alias = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias,0,sizeof(H225AliasAddress)); if(m_nDestStrType == 1) //目标字串是号码 { alias->t = T_H225AliasAddress_dialedDigits; alias->u.dialedDigits = LPCTSTR(m_strCalled); } else //目标字串是账户名称 { alias->t = T_H225AliasAddress_h323_ID; int nCount = m_strCalled.GetLength(); alias->u.h323_ID.nchars = nCount; alias->u.h323_ID.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); memset(alias->u.h323_ID.data,0,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) //这里需要进一步转换成16进制吗? alias->u.h323_ID.data[i] = (ASN116BITCHAR)m_strCalled.GetAt(i); } dListAppend(pctxt,&(admRequest->destinationInfo),alias); //srcInfo dListInit(&(admRequest->srcInfo)); if(m_bNumber) { Alias1 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(Alias1,0,sizeof(H225AliasAddress)); Alias1->t = T_H225AliasAddress_dialedDigits; Alias1->u.dialedDigits = LPCTSTR(m_strNumber); dListAppend(pctxt,&(admRequest->srcInfo),Alias1); } if(m_bName) { Alias2 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(Alias2,0,sizeof(H225AliasAddress)); Alias2->t = T_H225AliasAddress_h323_ID; int nCount = m_strName.GetLength(); Alias2->u.h323_ID.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) Alias2->u.h323_ID.data[i] = (ASN116BITCHAR)m_strName.GetAt(i); Alias2->u.h323_ID.nchars = nCount; dListAppend(pctxt,&(admRequest->srcInfo),Alias2); } //call reference myContext->callReference = ooGenerateCallReference(); //conference ID ooGenerateGUID(myContext->conferenceId.data); myContext->conferenceId.numocts = 16; //callIdentifier ooGenerateGUID(myContext->callIdentifier.guid.data); myContext->callIdentifier.guid.numocts = 16; } else //作为被叫方 { //destination alias admRequest->m.destinationInfoPresent = 1; dListInit(&(admRequest->destinationInfo)); if(m_bNumber) { Alias1 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(Alias1,0,sizeof(H225AliasAddress)); Alias1->t = T_H225AliasAddress_dialedDigits; Alias1->u.dialedDigits = LPCTSTR(m_strNumber); dListAppend(pctxt,&(admRequest->destinationInfo),Alias1); } if(m_bName) { Alias2 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(Alias2,0,sizeof(H225AliasAddress)); Alias2->t = T_H225AliasAddress_h323_ID; int nCount = m_strName.GetLength(); Alias2->u.h323_ID.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) Alias2->u.h323_ID.data[i] = (ASN116BITCHAR)m_strName.GetAt(i); Alias2->u.h323_ID.nchars = nCount; dListAppend(pctxt,&(admRequest->destinationInfo),Alias2); } //destination signaling address admRequest->m.destCallSignalAddressPresent = 1; admRequest->destCallSignalAddress.t = T_H225TransportAddress_ipAddress; IpAddr = (H225TransportAddress_ipAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress_ipAddress)); memset(IpAddr,0,sizeof(H225TransportAddress_ipAddress)); sscanf(myContext->localIP,"%d.%d.%d.%d",&addr_seg1,&addr_seg2,&addr_seg3,&addr_seg4); sprintf(hexIp,"%x %x %x %x",addr_seg1,addr_seg2,addr_seg3,addr_seg4); sscanf(hexIp,"%x %x %x %x",&IpAddr->ip.data[0],&IpAddr->ip.data[1], &IpAddr->ip.data[2], &IpAddr->ip.data[3]); IpAddr->ip.numocts = 4; IpAddr->port = 1720; admRequest->destCallSignalAddress.u.ipAddress = IpAddr; } admRequest->callReferenceValue = myContext->callReference; admRequest->bandWidth = 1; myContext->callReference = ooGenerateCallReference(); admRequest->callReferenceValue = myContext->callReference; admRequest->conferenceID.numocts = myContext->conferenceId.numocts; memcpy(admRequest->conferenceID.data,myContext->conferenceId.data,myContext->conferenceId.numocts); admRequest->activeMC = FALSE; admRequest->answerCall = FALSE; admRequest->canMapAlias = FALSE; admRequest->m.canMapAliasPresent = TRUE; admRequest->m.callIdentifierPresent = TRUE; admRequest->callIdentifier.guid.numocts = myContext->callIdentifier.guid.numocts; memcpy(admRequest->callIdentifier.guid.data,myContext->callIdentifier.guid.data, myContext->callIdentifier.guid.numocts); admRequest->willSupplyUUIEs = FALSE; admRequest->m.willSupplyUUIEsPresent = TRUE; ooSendRasMsg(myContext); OOTRACEINFO2(myContext, "Sending admission request message"); }
void CDlg_H323::UnregistrationRequest() { H225UnregistrationRequest *UnregRequest; OOCTXT *pctxt; H225TransportAddress *CallSignalAddress; H225TransportAddress_ipAddress *IpAddr1; int addr_seg1,addr_seg2,addr_seg3,addr_seg4; char hexIp[20]; H225AliasAddress *alias1,*alias2; int ret; int iCharNum; ret = ooCreateRasMessage(myContext,T_H225RasMessage_unregistrationRequest); if(ret == OO_FAILED) { OOTRACEERR2(myContext,"Error:Failed to create Ras message"); return; } myContext->outgoingRas->msgType = OOUnregistrationRequest; UnregRequest = myContext->outgoingRas->RasMsg.u.unregistrationRequest; pctxt = myContext->outgoingRas->pctxt; //requestSeqNum UnregRequest->requestSeqNum = (myContext->seqNumber++) % 65536; //CallSignalAddress CallSignalAddress = (H225TransportAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress)); memset(CallSignalAddress,0,sizeof(H225TransportAddress)); CallSignalAddress->t = T_H225TransportAddress_ipAddress; IpAddr1 = (H225TransportAddress_ipAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress_ipAddress)); memset(IpAddr1,0,sizeof(H225TransportAddress_ipAddress)); sscanf(myContext->localIP,"%d.%d.%d.%d",&addr_seg1,&addr_seg2,&addr_seg3,&addr_seg4); sprintf(hexIp,"%x %x %x %x",addr_seg1,addr_seg2,addr_seg3,addr_seg4); sscanf(hexIp,"%x %x %x %x",&IpAddr1->ip.data[0],&IpAddr1->ip.data[1], &IpAddr1->ip.data[2],&IpAddr1->ip.data[3]); IpAddr1->ip.numocts = 4; IpAddr1->port = 1720; CallSignalAddress->u.ipAddress = IpAddr1; dListInit(&(UnregRequest->callSignalAddress)); dListAppend(pctxt,&(UnregRequest->callSignalAddress),CallSignalAddress); //endpointAlias if(m_bName || m_bNumber) { UnregRequest->m.endpointAliasPresent = 1; dListInit(&(UnregRequest->endpointAlias)); } else UnregRequest->m.endpointAliasPresent = 0; if(m_bName) { alias1 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias1,0,sizeof(H225AliasAddress)); alias1->t = T_H225AliasAddress_h323_ID; Asn116BitCharString *str = &(alias1->u.h323_ID); int nCount = m_strName.GetLength(); str->nchars = nCount; str->data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); memset(str->data,0,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) str->data[i] = (ASN116BITCHAR)m_strName.GetAt(i); dListAppend(pctxt,&(UnregRequest->endpointAlias),alias1); } if(m_bNumber) { alias2 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias2,0,sizeof(H225AliasAddress)); alias2->t = T_H225AliasAddress_dialedDigits; alias2->u.dialedDigits = LPCTSTR(m_strNumber); dListAppend(pctxt,&(UnregRequest->endpointAlias),alias2); } //endpointIdentifier UnregRequest->m.endpointIdentifierPresent = TRUE; iCharNum = UnregRequest->endpointIdentifier.nchars = myContext->epIdentifier.nchars; UnregRequest->endpointIdentifier.data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,iCharNum * sizeof(ASN116BITCHAR)); memcpy(UnregRequest->endpointIdentifier.data,myContext->epIdentifier.data,iCharNum * sizeof(ASN116BITCHAR)); ooSendRasMsg(myContext); OOTRACEINFO2(myContext, "Sending registration request message"); }
void CDlg_H323::RegistrationRequest() { int ret; H225RegistrationRequest *regRequest; OOCTXT *pctxt; H225TransportAddress *CallSignalAddress,*RasAddress; H225TransportAddress_ipAddress *IpAddr1,*IpAddr2; int addr_seg1,addr_seg2,addr_seg3,addr_seg4; char hexIp[20]; H225AliasAddress *alias1,*alias2; int bindPort; ret = ooSocketCreateUDP(&myContext->RASChannel); if(ret != ASN_OK) { OOTRACEERR2(myContext, "ERROR: Creating RAS channel failed..."); return; } bindPort = ooBindPort(myContext,OOUDP,myContext->RASChannel); if(bindPort == OO_FAILED) { OOTRACEERR2(myContext, "ERROR: Bind port failed..."); return; } myContext->RASCallback = &CH323MsgHandler::OnReceivedRasMsg; strncpy(myContext->GkIp,LPCTSTR(m_strGatekeeper),20); myContext->RasChanPort = 1719; //build and send RAS registration message ret = ooCreateRasMessage(myContext,T_H225RasMessage_registrationRequest); if(ret == OO_FAILED) { OOTRACEERR2(myContext,"Error:Failed to create Ras message"); return; } myContext->outgoingRas->msgType = OORegistrationRequest; regRequest = myContext->outgoingRas->RasMsg.u.registrationRequest; pctxt = myContext->outgoingRas->pctxt; regRequest->requestSeqNum = (myContext->seqNumber++) % 65536; regRequest->protocolIdentifier = gRasProtocolID; regRequest->discoveryComplete = FALSE; CallSignalAddress = (H225TransportAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress)); memset(CallSignalAddress,0,sizeof(H225TransportAddress)); CallSignalAddress->t = T_H225TransportAddress_ipAddress; IpAddr1 = (H225TransportAddress_ipAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress_ipAddress)); memset(IpAddr1,0,sizeof(H225TransportAddress_ipAddress)); ooGetLocalIPAddress(myContext->localIP); sscanf(myContext->localIP,"%d.%d.%d.%d",&addr_seg1,&addr_seg2,&addr_seg3,&addr_seg4); sprintf(hexIp,"%x %x %x %x",addr_seg1,addr_seg2,addr_seg3,addr_seg4); sscanf(hexIp,"%x %x %x %x",&IpAddr1->ip.data[0],&IpAddr1->ip.data[1], &IpAddr1->ip.data[2],&IpAddr1->ip.data[3]); IpAddr1->ip.numocts = 4; IpAddr1->port = 1720; CallSignalAddress->u.ipAddress = IpAddr1; dListInit(&(regRequest->callSignalAddress)); dListAppend(pctxt,&(regRequest->callSignalAddress),CallSignalAddress); RasAddress = (H225TransportAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress)); memset(RasAddress,0,sizeof(H225TransportAddress)); RasAddress->t = T_H225TransportAddress_ipAddress; IpAddr2 = (H225TransportAddress_ipAddress*)ASN1MALLOC(pctxt,sizeof(H225TransportAddress_ipAddress)); memset(IpAddr2,0,sizeof(H225TransportAddress_ipAddress)); sscanf(/*myContext->GkIp*/myContext->localIP,"%d.%d.%d.%d",&addr_seg1,&addr_seg2,&addr_seg3,&addr_seg4); sprintf(hexIp,"%x %x %x %x",addr_seg1,addr_seg2,addr_seg3,addr_seg4); sscanf(hexIp,"%x %x %x %x",&IpAddr2->ip.data[0],&IpAddr2->ip.data[1], &IpAddr2->ip.data[2],&IpAddr2->ip.data[3]); IpAddr2->ip.numocts = 4; IpAddr2->port = bindPort; RasAddress->u.ipAddress = IpAddr2; dListInit(&(regRequest->rasAddress)); dListAppend(pctxt,&(regRequest->rasAddress),RasAddress); //terminal type regRequest->terminalType.mc = FALSE; regRequest->terminalType.undefinedNode = FALSE; regRequest->terminalType.terminal.m.nonStandardDataPresent = FALSE; regRequest->terminalType.m.terminalPresent = TRUE; //terminal alias if(m_bName || m_bNumber) { regRequest->m.terminalAliasPresent = 1; dListInit(&(regRequest->terminalAlias)); } else regRequest->m.terminalAliasPresent = 0; if(m_bName) { alias1 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias1,0,sizeof(H225AliasAddress)); alias1->t = T_H225AliasAddress_h323_ID; Asn116BitCharString *str = &(alias1->u.h323_ID); int nCount = m_strName.GetLength(); str->nchars = nCount; str->data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); memset(str->data,0,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) //这里需要进一步转换成16进制吗? str->data[i] = (ASN116BITCHAR)m_strName.GetAt(i); dListAppend(pctxt,&(regRequest->terminalAlias),alias1); } if(m_bNumber) { alias2 = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias2,0,sizeof(H225AliasAddress)); alias2->t = T_H225AliasAddress_dialedDigits; alias2->u.dialedDigits = LPCTSTR(m_strNumber); dListAppend(pctxt,&(regRequest->terminalAlias),alias2); } //endpoint Vendor regRequest->endpointVendor.vendor.t35CountryCode = 9; regRequest->endpointVendor.vendor.t35Extension = 0; regRequest->endpointVendor.vendor.manufacturerCode= 61; regRequest->endpointVendor.productId.numocts = ASN1MIN(strlen("GiantVoip"), sizeof(regRequest->endpointVendor.productId.data)); strncpy((char*)regRequest->endpointVendor.productId.data, "GiantVoip", regRequest->endpointVendor.productId.numocts); regRequest->endpointVendor.versionId.numocts = ASN1MIN(strlen("Version 1.0"), sizeof(regRequest->endpointVendor.versionId.data)); strncpy((char*)regRequest->endpointVendor.versionId.data, "Version 1.0", regRequest->endpointVendor.versionId.numocts); regRequest->endpointVendor.m.productIdPresent=TRUE; regRequest->endpointVendor.m.versionIdPresent=TRUE; regRequest->keepAlive = FALSE; regRequest->willSupplyUUIEs = FALSE; regRequest->maintainConnection = FALSE; ooSendRasMsg(myContext); OOTRACEINFO2(myContext, "Sending registration request message"); }
void CDlg_H323::CallSetup() { struct ooConnectionEP connectionEP; H225Setup_UUIE setup; H225TransportAddress_ipAddress destCallSignalIpAddress; int addr_part1, addr_part2, addr_part3, addr_part4; char hexip[20]; H225TransportAddress_ipAddress srcCallSignalIpAddress; char localip[40]; int i =0, ret; H225H323_UserInformation userInfo; H225AliasAddress *alias; OOCTXT *pctxt; char destip[20]; if(m_bViaGK) //通过网守呼叫 { strcpy(destip,myContext->remoteIP); strcpy(connectionEP.ipaddress,myContext->remoteIP); connectionEP.port = 1720; } else //直接呼叫 { if(m_nDestStrType != 0) { AfxMessageBox("无效的呼叫地址,请重新输入"); return; } UpdateData(TRUE); strcpy(destip,LPCTSTR(m_strCalled)); strcpy(connectionEP.ipaddress,LPCTSTR(m_strCalled)); connectionEP.port = 1720; } /* This function will create a local socket and make a connect request to the destination IP at port 1720 */ ret = ooCreateH2250Channel(myContext, &CH323MsgHandler::OnReceivedH2250Msg, connectionEP, OOTRANSMITTER); if(ret !=OO_OK) { CloseCallingDlg(); AfxMessageBox("您呼叫的用户无法接受呼叫"); return; } /*Create outgoing Q931 message. An outgoing Q931 setup message will be created for the context. */ ret = ooCreateQ931Message(myContext, Q931SetupMsg); if(ret != OO_OK) { OOTRACEERR2(myContext, "ERROR: Creating Q931 setup message..."); CloseCallingDlg(); return; } /*Populate the setup UUIE to be passed into the outgoing setup message*/ memset (&setup, 0, sizeof(setup)); setup.protocolIdentifier = gProtocolID; setup.sourceInfo.m.vendorPresent=TRUE; /* Populate the vendor information */ setup.sourceInfo.vendor.vendor.t35CountryCode = 9; setup.sourceInfo.vendor.vendor.t35Extension = 0; setup.sourceInfo.vendor.vendor.manufacturerCode=61; setup.sourceInfo.vendor.productId.numocts = ASN1MIN(strlen("GiantVoip"), sizeof(setup.sourceInfo.vendor.productId.data)); strncpy((char*)setup.sourceInfo.vendor.productId.data, "GiantVoip", setup.sourceInfo.vendor.productId.numocts); setup.sourceInfo.vendor.versionId.numocts = ASN1MIN(strlen("Version 1.0"), sizeof(setup.sourceInfo.vendor.versionId.data)); strncpy((char*)setup.sourceInfo.vendor.versionId.data, "Version 1.0", setup.sourceInfo.vendor.versionId.numocts); setup.sourceInfo.vendor.m.productIdPresent=TRUE; setup.sourceInfo.vendor.m.versionIdPresent=TRUE; setup.sourceInfo.mc = FALSE; setup.sourceInfo.m.terminalPresent = TRUE; setup.sourceInfo.terminal.m.nonStandardDataPresent = FALSE; setup.sourceInfo.undefinedNode = FALSE; setup.activeMC=FALSE; pctxt = myContext->outgoing->pctxt; if(m_bViaGK) { //destination address(alias) dListInit(&(setup.destinationAddress)); if(m_nDestStrType == 1) //号码 { alias = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias,0,sizeof(H225AliasAddress)); alias->t = T_H225AliasAddress_dialedDigits; alias->u.dialedDigits = LPCTSTR(m_strCalled); dListAppend(pctxt,&(setup.destinationAddress),alias); } else/* if(m_nDestStrType == 2)*/ //账号 { alias = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias,0,sizeof(H225AliasAddress)); alias->t = T_H225AliasAddress_h323_ID; Asn116BitCharString *str = &(alias->u.h323_ID); int nCount = m_strCalled.GetLength(); str->nchars = nCount; str->data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); memset(str->data,0,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) //这里需要进一步转换成16进制吗? str->data[i] = (ASN116BITCHAR)m_strCalled.GetAt(i); dListAppend(pctxt,&(setup.destinationAddress),alias); } setup.m.destinationAddressPresent = TRUE; //source address (alias) dListInit(&(setup.sourceAddress)); if(m_bNumber) //号码 { alias = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias,0,sizeof(H225AliasAddress)); alias->t = T_H225AliasAddress_dialedDigits; alias->u.dialedDigits = LPCTSTR(m_strNumber); dListAppend(pctxt,&(setup.sourceAddress),alias); } if(m_bName) //账号 { alias = (H225AliasAddress*)ASN1MALLOC(pctxt,sizeof(H225AliasAddress)); memset(alias,0,sizeof(H225AliasAddress)); alias->t = T_H225AliasAddress_h323_ID; Asn116BitCharString *str = &(alias->u.h323_ID); int nCount = m_strName.GetLength(); str->nchars = nCount; str->data = (ASN116BITCHAR*)ASN1MALLOC(pctxt,sizeof(ASN116BITCHAR) * nCount); memset(str->data,0,sizeof(ASN116BITCHAR) * nCount); for(int i = 0; i < nCount; i++) //这里需要进一步转换成16进制吗? str->data[i] = (ASN116BITCHAR)m_strName.GetAt(i); dListAppend(pctxt,&(setup.sourceAddress),alias); } setup.m.sourceAddressPresent = TRUE; } else { /* Populate the destination Call Signal Address */ setup.destCallSignalAddress.t=T_H225TransportAddress_ipAddress; sscanf(destip, "%d.%d.%d.%d", &addr_part1, &addr_part2, &addr_part3, &addr_part4); sprintf(hexip, "%x %x %x %x", addr_part1, addr_part2, addr_part3, addr_part4); sscanf(hexip, "%x %x %x %x", &destCallSignalIpAddress.ip.data[0], &destCallSignalIpAddress.ip.data[1], &destCallSignalIpAddress.ip.data[2], &destCallSignalIpAddress.ip.data[3]); destCallSignalIpAddress.ip.numocts=4; destCallSignalIpAddress.port=1720; setup.destCallSignalAddress.u.ipAddress = &destCallSignalIpAddress; setup.m.destCallSignalAddressPresent=TRUE; /* Populate the source Call Signal Address */ setup.sourceCallSignalAddress.t=T_H225TransportAddress_ipAddress; ooGetLocalIPAddress(localip); sscanf(localip, "%d.%d.%d.%d", &addr_part1, &addr_part2, &addr_part3, &addr_part4); sprintf(hexip, "%x %x %x %x", addr_part1, addr_part2, addr_part3, addr_part4); sscanf(hexip, "%x %x %x %x", &srcCallSignalIpAddress.ip.data[0], &srcCallSignalIpAddress.ip.data[1], &srcCallSignalIpAddress.ip.data[2], &srcCallSignalIpAddress.ip.data[3]); srcCallSignalIpAddress.ip.numocts=4; srcCallSignalIpAddress.port=ooGetH225ChannelPort(myContext); setup.sourceCallSignalAddress.u.ipAddress = &srcCallSignalIpAddress; setup.m.sourceCallSignalAddressPresent=TRUE; } /* No fast start */ setup.m.fastStartPresent = FALSE; //modified by tony below 2004.12.13 /*setup.conferenceID.numocts = 16; for (i = 0; i < 16; i++) setup.conferenceID.data[i] = i + 1;*/ if(myContext->conferenceId.numocts != 16 ) { ooGenerateGUID(myContext->conferenceId.data); myContext->conferenceId.numocts = 16; } setup.conferenceID.numocts = myContext->conferenceId.numocts; memcpy(setup.conferenceID.data,myContext->conferenceId.data,myContext->conferenceId.numocts); //modified by tony above 2004.12.13 setup.conferenceGoal.t = T_H225Setup_UUIE_conferenceGoal_create; /* H.225 point to point call */ setup.callType.t = T_H225CallType_pointToPoint; /* Populate optional fields */ setup.m.callIdentifierPresent = TRUE; setup.m.mediaWaitForConnectPresent = TRUE; setup.m.canOverlapSendPresent = TRUE; //modified by tony below 2004.12.13 /* Dummy call identifier. Need to add a function in stack to generate unique call id */ /*setup.callIdentifier.guid.numocts = 16; for (i = 0; i < 16; i++) setup.callIdentifier.guid.data[i] = i + 1;*/ if(myContext->callIdentifier.guid.numocts != 16) { ooGenerateGUID(myContext->callIdentifier.guid.data); myContext->callIdentifier.guid.numocts = 16; } setup.callIdentifier.guid.numocts = myContext->callIdentifier.guid.numocts; memcpy(setup.callIdentifier.guid.data,myContext->callIdentifier.guid.data,myContext->callIdentifier.guid.numocts); /*Since currently call ID is generated outside stack, application needs to store it in the context field for stack to use.*/ //memcpy(myContext->callIdentifier.guid.data, setup.callIdentifier.guid.data,16); //myContext->callIdentifier.guid.numocts = setup.callIdentifier.guid.numocts; //modified by tony above 2004.12.13 setup.mediaWaitForConnect = FALSE; setup.canOverlapSend = FALSE; /* Populate the userInfo structure with the setup UUIE */ memset (&userInfo, 0, sizeof(userInfo)); userInfo.h323_uu_pdu.h323_message_body.t = T_H225H323_UU_PDU_h323_message_body_setup; userInfo.h323_uu_pdu.h323_message_body.u.setup = &setup; /* Add userinfo to the outgoing q931 setup message */ if(ooAddUserUserIE(myContext, &userInfo) != OO_OK) { OOTRACEERR2(myContext, "Error: Failed to add UUIE to Q931 message"); return; } else { /* This queues the outgoing message into the outgoing message queue. The message will be sent whenever the corresponing channel is ready for send, in other words corresponing socket is available for write. */ OOTRACEINFO2(myContext, "Sending H.225 setup message"); ooSendH225Msg(myContext); SetTimer(2006,30000,NULL); //启动10秒钟定时器,若在此期间无法收到Connect消息则退出 } }
void ooH323EpPrintConfig(void) { OOTRACEINFO1("H.323 Endpoint Configuration is as follows:\n"); OOTRACEINFO2("\tTrace File: %s\n", gH323ep.traceFile); if(!OO_TESTFLAG(gH323ep.flags, OO_M_FASTSTART)) { OOTRACEINFO1("\tFastStart - disabled\n"); } else{ OOTRACEINFO1("\tFastStart - enabled\n"); } if(!OO_TESTFLAG(gH323ep.flags, OO_M_TUNNELING)) { OOTRACEINFO1("\tH245 Tunneling - disabled\n"); } else{ OOTRACEINFO1("\tH245 Tunneling - enabled\n"); } if(!OO_TESTFLAG(gH323ep.flags, OO_M_MEDIAWAITFORCONN)) { OOTRACEINFO1("\tMediaWaitForConnect - disabled\n"); } else{ OOTRACEINFO1("\tMediaWaitForConnect - enabled\n"); } if(OO_TESTFLAG(gH323ep.flags, OO_M_AUTOANSWER)) OOTRACEINFO1("\tAutoAnswer - enabled\n"); else OOTRACEINFO1("\tAutoAnswer - disabled\n"); OOTRACEINFO2("\tTerminal Type - %d\n", gH323ep.termType); OOTRACEINFO2("\tT35 CountryCode - %d\n", gH323ep.t35CountryCode); OOTRACEINFO2("\tT35 Extension - %d\n", gH323ep.t35Extension); OOTRACEINFO2("\tManufacturer Code - %d\n", gH323ep.manufacturerCode); OOTRACEINFO2("\tProductID - %s\n", gH323ep.productID); OOTRACEINFO2("\tVersionID - %s\n", gH323ep.versionID); OOTRACEINFO2("\tLocal signalling IP address - %s\n", gH323ep.signallingIP); OOTRACEINFO2("\tH225 ListenPort - %d\n", gH323ep.listenPort); OOTRACEINFO2("\tCallerID - %s\n", gH323ep.callerid); OOTRACEINFO2("\tCall Establishment Timeout - %d seconds\n", gH323ep.callEstablishmentTimeout); OOTRACEINFO2("\tMasterSlaveDetermination Timeout - %d seconds\n", gH323ep.msdTimeout); OOTRACEINFO2("\tTerminalCapabilityExchange Timeout - %d seconds\n", gH323ep.tcsTimeout); OOTRACEINFO2("\tLogicalChannel Timeout - %d seconds\n", gH323ep.logicalChannelTimeout); OOTRACEINFO2("\tSession Timeout - %d seconds\n", gH323ep.sessionTimeout); return; }
int ooReadAndProcessCallStackCommand(OOH323CallData* call) { unsigned char buffer[MAXMSGLEN]; unsigned char *bPoint; int recvLen = 0; OOStackCommand cmd; memset(&cmd, 0, sizeof(OOStackCommand)); if (call->CmdChanLock) { ast_mutex_lock(call->CmdChanLock); recvLen = read(call->cmdSock, buffer, MAXMSGLEN); ast_mutex_unlock(call->CmdChanLock); } else { recvLen = read(call->cmdSock, buffer, MAXMSGLEN); } if(recvLen <= 0) { OOTRACEERR1("Error:Failed to read CMD message\n"); return OO_FAILED; } bPoint = buffer; while (bPoint < buffer + recvLen - sizeof(OOStackCommand)) { memcpy(&cmd, bPoint, sizeof(OOStackCommand)); bPoint += sizeof(OOStackCommand); if (cmd.plen1 > 0) { cmd.param1 = malloc(cmd.plen1 + 1); if (!cmd.param1) return OO_FAILED; memset(cmd.param1, 0, cmd.plen1 + 1); memcpy(cmd.param1, bPoint, cmd.plen1); bPoint += cmd.plen1; } if (cmd.plen2 > 0) { cmd.param2 = malloc(cmd.plen2 + 1); if (!cmd.param2) return OO_FAILED; memset(cmd.param2, 0, cmd.plen2 + 1); memcpy(cmd.param2, bPoint, cmd.plen2); bPoint += cmd.plen2; } if (cmd.plen3 > 0) { cmd.param3 = malloc(cmd.plen3 + 1); if (!cmd.param3) return OO_FAILED; memset(cmd.param3, 0, cmd.plen3 + 1); memcpy(cmd.param3, bPoint, cmd.plen3); bPoint += cmd.plen3; } if(cmd.type == OO_CMD_NOOP) continue; if(gH323ep.gkClient && gH323ep.gkClient->state != GkClientRegistered) { OOTRACEINFO1("Ignoring stack command as Gk Client is not registered" " yet\n"); } else { switch(cmd.type) { case OO_CMD_MAKECALL: OOTRACEINFO2("Processing MakeCall command %s\n", (char*)cmd.param2); ooH323MakeCall ((char*)cmd.param1, (char*)cmd.param2, (ooCallOptions*)cmd.param3); break; case OO_CMD_MANUALPROGRESS: ooSendProgress(call); break; case OO_CMD_MANUALRINGBACK: if(OO_TESTFLAG(gH323ep.flags, OO_M_MANUALRINGBACK)) { ooSendAlerting(call); if(OO_TESTFLAG(gH323ep.flags, OO_M_AUTOANSWER)) { ooSendConnect(call); } } break; case OO_CMD_ANSCALL: ooSendConnect(call); break; case OO_CMD_FWDCALL: OOTRACEINFO3("Forwarding call %s to %s\n", (char*)cmd.param1, (char*)cmd.param2); ooH323ForwardCall((char*)cmd.param1, (char*)cmd.param2); break; case OO_CMD_HANGCALL: OOTRACEINFO2("Processing Hang call command %s with q931 cause %d\n", (char*)cmd.param1); ooH323HangCall((char*)cmd.param1, *(OOCallClearReason*)cmd.param2, *(int *) cmd.param3); break; case OO_CMD_SENDDIGIT: if(call->jointDtmfMode & OO_CAP_DTMF_H245_alphanumeric) { ooSendH245UserInputIndication_alphanumeric( call, (const char*)cmd.param2); } else if(call->jointDtmfMode & OO_CAP_DTMF_H245_signal) { ooSendH245UserInputIndication_signal( call, (const char*)cmd.param2); } else { ooQ931SendDTMFAsKeyPadIE(call, (const char*)cmd.param2); } break; case OO_CMD_REQMODE: OOTRACEINFO3("Processing RequestMode command %s, requested mode is %d\n", (char *)cmd.param1, *(int *)cmd.param2); ooSendRequestMode(call, *(int *)cmd.param2); break; case OO_CMD_SETANI: OOTRACEINFO3("Processing SetANI command %s, ani is %s\n", (char *)cmd.param1, (char *)cmd.param2); if(cmd.param2) { strncpy(call->ourCallerId, cmd.param2, sizeof(call->ourCallerId)-1); call->ourCallerId[sizeof(call->ourCallerId)-1] = '\0'; } break; default: OOTRACEERR1("ERROR:Unknown command\n"); } } if(cmd.param1) free(cmd.param1); if(cmd.param2) free(cmd.param2); if(cmd.param3) free(cmd.param3); } return OO_OK; }
int ooReadAndProcessStackCommand() { OOH323CallData *pCall = NULL; unsigned char buffer[MAXMSGLEN]; int i, recvLen = 0; OOStackCommand cmd; memset(&cmd, 0, sizeof(OOStackCommand)); ast_mutex_lock(&gCmdChanLock); recvLen = read(gH323ep.cmdSock, buffer, MAXMSGLEN); ast_mutex_unlock(&gCmdChanLock); if(recvLen <= 0) { OOTRACEERR1("Error:Failed to read CMD message\n"); return OO_FAILED; } for(i=0; (int)(i+sizeof(OOStackCommand)) <= recvLen; i += sizeof(OOStackCommand)) { memcpy(&cmd, buffer+i, sizeof(OOStackCommand)); if(cmd.type == OO_CMD_NOOP) continue; if(gH323ep.gkClient && gH323ep.gkClient->state != GkClientRegistered && cmd.type != OO_CMD_STOPMONITOR) { OOTRACEINFO1("Ignoring stack command as Gk Client is not registered" " yet\n"); } else { switch(cmd.type) { case OO_CMD_MAKECALL: OOTRACEINFO2("Processing MakeCall command %s\n", (char*)cmd.param2); ooH323NewCall ((char*)cmd.param2); break; case OO_CMD_MANUALPROGRESS: pCall = ooFindCallByToken((char*)cmd.param1); if(!pCall) { OOTRACEINFO2("Call \"%s\" does not exist\n", (char*)cmd.param1); OOTRACEINFO1("Call migth be cleared/closed\n"); } else { ooSendProgress(ooFindCallByToken((char*)cmd.param1)); } break; case OO_CMD_MANUALRINGBACK: if(OO_TESTFLAG(gH323ep.flags, OO_M_MANUALRINGBACK)) { pCall = ooFindCallByToken((char*)cmd.param1); if(!pCall) { OOTRACEINFO2("Call \"%s\" does not exist\n", (char*)cmd.param1); OOTRACEINFO1("Call migth be cleared/closed\n"); } else { ooSendAlerting(ooFindCallByToken((char*)cmd.param1)); if(OO_TESTFLAG(gH323ep.flags, OO_M_AUTOANSWER)) { ooSendConnect(ooFindCallByToken((char*)cmd.param1)); } } } break; case OO_CMD_ANSCALL: pCall = ooFindCallByToken((char*)cmd.param1); if(!pCall) { OOTRACEINFO2("Call \"%s\" does not exist\n", (char*)cmd.param1); OOTRACEINFO1("Call might be cleared/closed\n"); } else { OOTRACEINFO2("Processing Answer Call command for %s\n", (char*)cmd.param1); ooSendConnect(pCall); } break; case OO_CMD_FWDCALL: OOTRACEINFO3("Forwarding call %s to %s\n", (char*)cmd.param1, (char*)cmd.param2); ooH323ForwardCall((char*)cmd.param1, (char*)cmd.param2); break; case OO_CMD_HANGCALL: OOTRACEINFO3("Processing Hang call command %s with q931 cause %d\n", (char*)cmd.param1, *(int *) cmd.param3); ooH323HangCall((char*)cmd.param1, *(OOCallClearReason*)cmd.param2, *(int *) cmd.param3); break; case OO_CMD_SENDDIGIT: pCall = ooFindCallByToken((char*)cmd.param1); if(!pCall) { OOTRACEERR2("ERROR:Invalid calltoken %s\n", (char*)cmd.param1); break; } if(pCall->jointDtmfMode & OO_CAP_DTMF_H245_alphanumeric) { ooSendH245UserInputIndication_alphanumeric( pCall, (const char*)cmd.param2); } else if(pCall->jointDtmfMode & OO_CAP_DTMF_H245_signal) { ooSendH245UserInputIndication_signal( pCall, (const char*)cmd.param2); } else { ooQ931SendDTMFAsKeyPadIE(pCall, (const char*)cmd.param2); } break; case OO_CMD_STOPMONITOR: OOTRACEINFO1("Processing StopMonitor command\n"); ooStopMonitorCalls(); break; default: OOTRACEERR1("ERROR:Unknown command\n"); } } if(cmd.param1) free(cmd.param1); if(cmd.param2) free(cmd.param2); if(cmd.param3) free(cmd.param3); } return OO_OK; }