⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultdialoghandler.cxx

📁 MiniSip Client with DomainKeys Authentication, Sip, Audio communications, Echo Cancel
💻 CXX
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) 2004-2006 the Minisip Team  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA *//* Copyright (C) 2004  * * Authors: Erik Eliasson <eliasson@it.kth.se> *          Johan Bilien <jobi@via.ecp.fr>*/#include<config.h>#include<libminisip/sip/DefaultDialogHandler.h>#include<libmnetutil/IP4Address.h>#include<libmnetutil/NetworkException.h>#include<libmsip/SipDialogRegister.h>//#include<libmsip/SipDialogContainer.h>#include<libmsip/SipHeaderFrom.h>#include<libmsip/SipHeaderTo.h>#include<libmsip/SipHeaderAcceptContact.h>#include<libmsip/SipMessage.h>#include<libmsip/SipMessageContentIM.h>#include<libmsip/SipCommandString.h>#include<libmsip/SipTransactionInviteServer.h>#include<libmsip/SipTransactionInviteServerUA.h>#include<libmsip/SipTransactionNonInviteServer.h>#include<libmsip/SipTransactionNonInviteClient.h>#include<libmutil/massert.h>#include<libminisip/sip/SipDialogVoipServer.h>#include<libminisip/sip/SipDialogVoipServer100rel.h>#include<libminisip/sip/SipDialogConfVoip.h>#include<libminisip/sip/SipDialogPresenceClient.h>#include<libminisip/sip/SipDialogPresenceServer.h>#include<libminisip/conference/ConfMessageRouter.h>#ifdef _WIN32_WCE#	include"../include/minisip_wce_extra_includes.h"#endif#ifdef P2T_SUPPORT#	include<libminisip/p2t/P2T.h>#	include<libminisip/p2t/SipDialogP2Tuser.h>#endif#include<libminisip/mediahandler/MediaHandler.h>#ifdef IPSEC_SUPPORT#	include<../ipsec/MsipIpsecAPI.h>#endif#include<libmutil/dbg.h>using namespace std;DefaultDialogHandler::DefaultDialogHandler(MRef<SipStack*> stack,             //SipDialogConfig &conf,	    //MRef<SipDialogConfig *> conf,	    MRef<SipSoftPhoneConfiguration*> pconf,	    MRef<MediaHandler *>mediaHandler): 		sipStack(stack),                //SipDialog(stack, conf),		phoneconf(pconf),		mediaHandler(mediaHandler){	outsideDialogSeqNo=1;//	dialogState.callId = string("DCH_")+itoa(rand())+"@"+getDialogConfig()->inherited->externalContactIP;#ifdef P2T_SUPPORT	//Initialize GroupListServer	grpListServer=NULL;#endif}DefaultDialogHandler::~DefaultDialogHandler(){// 	cerr << "~DefaultDialogHandler" << endl;}string DefaultDialogHandler::getName(){	return "DefaultDialogHandler";}bool DefaultDialogHandler::handleCommandPacket( MRef<SipMessage*> pkt){#if 0	/* First, check if this is a packet that could not be handled by	 * any transaction and send 481 response if that is the case */	if (source==SipSMCommand::transaction_layer && dispatchCount>=2){ // this is the packets second run of handling.		mdbg << "DefaultCallHandler::handleCommand: Detected dispatched already - sending 481"<< end;		//FIXME: Check what branch parameter to send.		MRef<SipResponse*> no_call= new SipResponse("nobranch", 481,"Call Leg/Transaction Does Not Exist", MRef<SipMessage*>(*pkt));		MRef<SipMessage*> pref(*no_call);		sipStack->getDispatcher()->getLayerTransport()->sendMessage(pref,				string(""), //branch				false				);		return true;	}#ifdef DEBUG_OUTPUT	if (source==SipSMCommand::transaction_layer&& dispatchCount>=2){ // this is the packets second run of handling.		cerr << "WARNING: INTERNAL ERROR: command was not handled (dispatched flag indication)"<<endl;		return true;	}#endif	#endif	if (pkt->getType()=="INVITE"){		//type casting		//MRef<SipRequest*> inv = MRef<SipRequest*>((SipRequest*)*pkt);		MRef<SipRequest*> inv = dynamic_cast<SipRequest*>(*pkt);		//inv->checkAcceptContact();		//check if it's a regular INVITE or a P2T INVITE#ifdef P2T_SUPPORT		if(inv->is_P2T()) {			inviteP2Treceived(SipSMCommand(pkt,source,destination));			}#endif		bool isConfJoin=false;		bool isP2T=false;		bool isConfConnect=false;		MRef<SipHeaderValueAcceptContact*> acp;		int i=0;		MRef<SipHeaderValue*> hdr=inv->getHeaderValueNo(SIP_HEADER_TYPE_ACCEPTCONTACT, i);		do{			if (hdr){				MRef<SipHeaderValueAcceptContact*> acp = (SipHeaderValueAcceptContact*)*hdr;				if(acp && acp->getFeaturetag()=="+sip.p2t=\"TRUE\"")					isP2T=true;				else if(acp && acp->getFeaturetag()=="+sip.confjoin=\"TRUE\"") {					//cout << "SIPINVITE: Setting conjoin to true" << endl;					isConfJoin=true;				}				else if(acp && acp->getFeaturetag()=="+sip.confconnect=\"TRUE\""){					isConfConnect=true;				}			}			i++;			hdr = inv->getHeaderValueNo(SIP_HEADER_TYPE_ACCEPTCONTACT, i);		}while(hdr);		if(isConfJoin) {			MRef<SipHeaderValueTo*> to = pkt->getHeaderValueTo();			string uri;			MRef<SipIdentity *> id = NULL;			if( to ){				id = phoneconf->getIdentity( to->getUri() );			}#ifdef DEBUG_OUTPUT						mdbg << "DefaultDialogHandler:: creating new SipDialogConfVoip" << end;#endif						//MRef<SipMessage*> pack = command.getCommandPacket();			//MRef<SipInvite*> inv = MRef<SipInvite*>((SipInvite*)*pack);			//get the GroupList from the remote GroupListServer			//MRef<GroupList*>grpList;			massert(dynamic_cast<SdpPacket*>(*inv->getContent())!=NULL);			MRef<SdpPacket*> sdp = (SdpPacket*)*inv->getContent();			string confid = sdp->getSessionLevelAttribute("confId");			string numToConnect = sdp->getSessionLevelAttribute("conf_#participants");			//this is a join packet and contains an advice list. The list is created from the			// packet here in order to send it to the GUI for display.			int num = 0;			//--- Convert each digit char and add into result.			int t=0;			while (numToConnect[t] >= '0' && numToConnect[t] <='9') {				num = (num * 10) + (numToConnect[t] - '0');				t++;			}			for(t=0;t<num;t++)				//connectList[t]=  sdp->getSessionLevelAttribute("participant_"+itoa(t+1));				connectList.push_back((ConfMember(sdp->getSessionLevelAttribute("participant_"+itoa(t+1)),"")));			//cerr << "DDH: "+numToConnect[0]<< endl;			//cerr << "DDH: "+numToConnect[1]<< endl;			cerr << "DDH: "+itoa(num)<< endl;			//int num=atoi(numToConnect);			//string gID = sdp->getSessionLevelAttribute("p2tGroupIdentity");			//string prot = sdp->getSessionLevelAttribute("p2tGroupListProt");			// get a session from the mediaHandler			MRef<Session *> mediaSession = 				mediaHandler->createSession(phoneconf->securityConfig, *(*phoneconf->inherited), pkt->getCallId() );			MRef<SipDialogConfig*> callConf = new SipDialogConfig(phoneconf->inherited);			if( id ){				cerr << "Got a call from Id " << id->getSipUri() << endl;				callConf->useIdentity( id, false );			}#ifdef IPSEC_SUPPORT			MRef<MsipIpsecAPI *> ipsecSession = new MsipIpsecAPI(mediaHandler->getExtIP(), phoneconf->securityConfig);			//MRef<SipDialogVoip*> voipCall = new SipDialogVoip(getDialogContainer(), callConf, 			//					phoneconf, mediaSession, pkt->getCallId(), ipsecSession ); 			//BM is it safe to pass the list like this?			MRef<SipDialog*> voipConfCall( new SipDialogConfVoip(sipStack->getConfCallback(),sipStack, callConf, 						phoneconf, mediaSession, &connectList,confid, pkt->getCallId(), ipsecSession )); #else				MRef<SipDialog*> voipConfCall( new SipDialogConfVoip(dynamic_cast<ConfMessageRouter*>(*sipStack->getConfCallback()), sipStack, callConf, 						phoneconf, mediaSession, &connectList,confid, pkt->getCallId()));#endif			sipStack->addDialog(voipConfCall);						SipSMCommand cmd(pkt, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);			bool handled = voipConfCall->handleCommand(cmd);			if (!handled){				cerr<<"Error: DefaultDialogHandler: VoIP dialog refused to handle the incoming INVITE"<<endl;			}			//			cmd.setDispatchCount(dispatchCount);//			getDialogContainer()->enqueueCommand(cmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);//			mdbg << cmd << end;		}		else if(isConfConnect) {			MRef<SipHeaderValueTo*> to = pkt->getHeaderValueTo();			string uri;			MRef<SipIdentity *> id = NULL;			if( to ){				id = phoneconf->getIdentity( to->getUri() );			}#ifdef DEBUG_OUTPUT						mdbg << "DefaultDialogHandler:: creating new SipDialogConfVoip" << end;#endif						massert(dynamic_cast<SdpPacket*>(*inv->getContent())!=NULL);			MRef<SdpPacket*> sdp = (SdpPacket*)*inv->getContent();			string confid = sdp->getSessionLevelAttribute("confId");			MRef<Session *> mediaSession = 				mediaHandler->createSession(phoneconf->securityConfig, *(*phoneconf->inherited), pkt->getCallId() );			MRef<SipDialogConfig*> callConf = new SipDialogConfig(phoneconf->inherited);			if( id ){				cerr << "Got a call from Id " << id->getSipUri() << endl;				callConf->useIdentity( id, false );			}#ifdef IPSEC_SUPPORT			MRef<MsipIpsecAPI *> ipsecSession = new MsipIpsecAPI(mediaHandler->getExtIP(), phoneconf->securityConfig);			//MRef<SipDialogVoip*> voipCall = new SipDialogVoip(getDialogContainer(), callConf, 			//					phoneconf, mediaSession, pkt->getCallId(), ipsecSession ); 			//BM is it safe to pass the list like this?			MRef<SipDialog*> voipConfCall( new SipDialogConfVoip(sipStack, callConf, 						phoneconf, mediaSession, confid, pkt->getCallId(), ipsecSession )); #else				MRef<SipDialog*> voipConfCall( new SipDialogConfVoip(dynamic_cast<ConfMessageRouter*>(*sipStack->getConfCallback()),sipStack, callConf, 						phoneconf, mediaSession, confid, pkt->getCallId()));#endif			sipStack->addDialog(voipConfCall);			SipSMCommand cmd(pkt, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);			//cmd.setDispatchCount(dispatchCount);			sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);			mdbg << cmd << end;		}		//start SipDialogVoIP		else{			MRef<SipHeaderValueTo*> to = pkt->getHeaderValueTo();			string uri;			MRef<SipIdentity *> id = NULL;			if( to ){				id = phoneconf->getIdentity( to->getUri() );			}			// get a session from the mediaHandler			MRef<Session *> mediaSession = 				mediaHandler->createSession(phoneconf->securityConfig, *(*phoneconf->inherited), pkt->getCallId() );			MRef<SipDialogConfig*> callConf = new SipDialogConfig(phoneconf->inherited);			if( id ){				cerr << "Got a call from Id " << id->getSipUri() << endl;				callConf->useIdentity( id, false );			}#ifdef IPSEC_SUPPORT			MRef<MsipIpsecAPI *> ipsecSession = new MsipIpsecAPI(mediaHandler->getExtIP(), phoneconf->securityConfig);			MRef<SipDialog*> voipCall( new SipDialogVoipServer(sipStack, callConf, 						phoneconf, mediaSession, pkt->getCallId(), ipsecSession )); #else				MRef<SipDialog*> voipCall;//			if (pkt->supported("100rel")){//				voipCall = new SipDialogVoipServer100rel(sipStack,//						callConf,//						phoneconf,//						mediaSession,//						pkt->getCallId());//			}else{

⌨️ 快捷键说明

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