示例#1
0
文件: perutil.c 项目: GGGO/asterisk
void set16BitCharSet 
(OOCTXT* pctxt, Asn116BitCharSet* pCharSet, Asn116BitCharSet* pAlphabet)
{
   /* Permitted alphabet range can either be specified as a range of    */
   /* characters or as a discrete set..                                 */

   if (pAlphabet->charSet.data) {
      int nocts = pAlphabet->charSet.nchars * 2;
      pCharSet->charSet.nchars = pAlphabet->charSet.nchars;

      pCharSet->charSet.data = 
         (ASN116BITCHAR*) ASN1MALLOC (pctxt, nocts);

      if (pCharSet->charSet.data != NULL)
         memcpy (pCharSet->charSet.data, pAlphabet->charSet.data, nocts);
   }
   else {
      pCharSet->firstChar = pAlphabet->firstChar;
      pCharSet->lastChar  = pAlphabet->lastChar;
      pCharSet->charSet.nchars = pCharSet->lastChar - pCharSet->firstChar;
   }

   pCharSet->unalignedBits = getUIntBitCount (pCharSet->charSet.nchars);

   pCharSet->alignedBits = 1;
   while (pCharSet->unalignedBits > pCharSet->alignedBits)
      pCharSet->alignedBits <<= 1;

}
示例#2
0
void xu_octmcpy_d (ASN1CTXT* ctxt_p, ASN1DynOctStr *octStr_p, void* data_p, 
   int datalen)
{
   octStr_p->numocts = datalen;
   octStr_p->data  = (ASN1OCTET*) ASN1MALLOC (ctxt_p, datalen);
   if (octStr_p->data == NULL) return;
   memcpy ((char*) octStr_p->data, (char*) data_p, datalen);
}
示例#3
0
void xu_octscpy_d (ASN1CTXT* ctxt_p, ASN1UINT* nocts_p, 
                   ASN1ConstOctetPtr* data_p2, char* cstring, char zterm)
{
   char* pstr;
   *nocts_p = (ASN1UINT)strlen (cstring);
   if (zterm) (*nocts_p)++;
   pstr = (char*) ASN1MALLOC (ctxt_p, *nocts_p);
   *data_p2 = (ASN1ConstOctetPtr) pstr;
   if (pstr == NULL) return;
   strncpy (pstr, cstring, *nocts_p);
}
示例#4
0
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");
}
示例#5
0
char* errGetText (OOCTXT* pctxt)
{
   char lbuf[500];
   char* pBuf = (char*) ASN1MALLOC (pctxt,
      (sizeof(lbuf) + 100 * (2 + pctxt->errInfo.stkx)) * sizeof(char));

   sprintf (pBuf, "ASN.1 ERROR: Status %d\n", pctxt->errInfo.status);
   sprintf (lbuf, "%s\nStack trace:", errFmtMsg (&pctxt->errInfo, lbuf));
   strcat(pBuf, lbuf);

   while (pctxt->errInfo.stkx > 0) {
      pctxt->errInfo.stkx--;
      sprintf (lbuf, "  Module: %s, Line %d\n",
               pctxt->errInfo.stack[pctxt->errInfo.stkx].module,
               pctxt->errInfo.stack[pctxt->errInfo.stkx].lineno);
      strcat(pBuf, lbuf);
   }

   errFreeParms (&pctxt->errInfo);

   return pBuf;
}
示例#6
0
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");
}
示例#7
0
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");	
}
示例#8
0
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");
}
示例#9
0
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消息则退出
	}
}