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

📄 defaultdialoghandler.cxx

📁 MiniSip Client with DomainKeys Authentication, Sip, Audio communications, Echo Cancel
💻 CXX
📖 第 1 页 / 共 3 页
字号:
					SipSMCommand cmd(command);			cmd.setSource(SipSMCommand::transaction_layer);			cmd.setDestination(SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(cmd, LOW_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);					//inform GUI. 			CommandString cmds(p2tDialogUser->getCallId(), "p2tAddUser", inv_user);			getDialogContainer()->getCallback()->handleCommand("gui", cmds );		}		//if user is not in GroupList deny it		else {			CommandString rej(/*p2tDialogUser->getDialogConfig().callId*/ p2tDialogUser->getCallId(), SipCommandString::reject_invite);			SipSMCommand cmd(rej, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(cmd, LOW_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);			 		}				}	else{		//there is already a call started for this user		if(grpList->getUser(inv_user)->getCallId()!=""){						//we have a collision			if(grpList->getUser(inv_user)->getLocalStarted()==true){						 //not implemented						}						SipSMCommand cmd(command);			cmd.setSource(SipSMCommand::transaction_layer);			cmd.setDestination(SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(cmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);						//reject this call			CommandString cmds(p2tDialogUser->getCallId(), SipCommandString::reject_invite);			SipSMCommand scmd(cmds, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(scmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);		}				//there is no call started for this user		else{						//set CallId in Group Member List			grpList->getUser(inv_user)->setCallId(p2tDialogUser->getCallId());			grpList->getUser(inv_user)->setStatus(P2T::STATUS_WAITACCEPT);						SipSMCommand cmd(command);			cmd.setSource(SipSMCommand::transaction_layer);			cmd.setDestination(SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(cmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);						//user has to accept it			CommandString cmds(p2tDialogUser->getCallId(), "p2tAddUser");			getDialogContainer()->getCallback()->handleCommand("gui", cmds );		}			}			}void DefaultDialogHandler::inviteP2Taccepted(const SipSMCommand &command){		//get P2TDialog	MRef<SipDialogP2T*> p2tDialog;	if(getP2TDialog(command.getCommandString().getParam(), p2tDialog)==false){			mdbg<<"DefaultDialogHandler::Couldn't find SipDialogP2T!"<<end;		return;	}	//start the Group List Server and add GroupList	MRef<GroupList*> grpList = p2tDialog->getGroupList();	grpListServer = new GroupListServer(phoneconf, 0);	grpListServer->start();	grpListServer->addGroupList(grpList);		//send accept_invite to all waiting SipDialogP2Tuser dialogs for this session	for(uint32_t l=0; l<grpList->getAllUser().size(); l++){		if(grpList->getAllUser()[l]->getStatus()==P2T::STATUS_WAITACCEPT){			CommandString cmds(grpList->getAllUser()[l]->getCallId(), SipCommandString::accept_invite);			SipSMCommand scmd(cmds, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer);			getDialogContainer()->enqueueCommand(scmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE);		}	}				//Start SipDialogP2Tuser for all remaining participants in the Group Member List	MRef<SipDialogConfig*> callConf;	string user="";	for(uint32_t k=0; k<grpList->getAllUser().size(); k++){		user=grpList->getAllUser()[k]->getUri();				//filter out own username//		if(user==getDialogConfig().inherited.userUri)		if(user==getDialogConfig()->inherited->sipIdentity->getSipUri())			continue;					// filter out users that have already started		// a dialog resp. has a callId in the grpList.		if(grpList->getAllUser()[k]->getCallId()!="")			continue;				//create callConfig		callConf = MRef<SipDialogConfig*>(new SipDialogConfig(phoneconf->inherited) );					//check user uri and modify DialogConfig		if(modifyDialogConfig(user, callConf)==false){			p2tDialog->removeUser(user, "uri malformed", "");			continue;		}											MRef<SipDialogP2Tuser*> p2tUserDialog = new SipDialogP2Tuser(sipStack, callConf, phoneconf, p2tDialog);		sipStack->addDialog(*p2tUserDialog);				//set CallId and localStarted in GroupMemberList		grpList->getAllUser()[k]->setCallId(p2tUserDialog->getCallId());		grpList->getAllUser()[k]->setLocalStarted(true);				CommandString inv(p2tUserDialog->getCallId(), SipCommandString::invite, user);        	SipSMCommand cmd(SipSMCommand(inv, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer));		getDialogContainer()->enqueueCommand( cmd, LOW_PRIO_QUEUE, PRIO_LAST_IN_QUEUE );	}		//Inform GUI	CommandString cmdstr("", "p2tSessionCreated", p2tDialog->getCallId());	getDialogContainer()->getCallback()->handleCommand("gui", cmdstr );}void DefaultDialogHandler::startP2TSession(const SipSMCommand &command){	string xml;	//Start SipDialogP2T	MRef<SipDialogConfig*> callConf = MRef<SipDialogConfig*>(new SipDialogConfig(phoneconf->inherited) );	MRef<SipDialogP2T*> p2tDialog( new SipDialogP2T(sipStack, callConf, phoneconf)); 			//Create Group Member List from the first parameter of the	//CommandString and set the correct Group Identity	MRef<GroupList*> grpList = new GroupList(command.getCommandString().getParam());	grpList->setGroupIdentity(p2tDialog->getCallId());	p2tDialog->setGroupList(grpList);		//add the Group Member List to the GroupListServer	grpListServer->addGroupList(grpList);			//add SipDialogP2T to the DialogContainer	MRef<SipDialog*> dialog = *p2tDialog;	sipStack->addDialog(dialog);					//Start SipDialogP2Tuser for all participants in the Group Member List	string user="";	for(uint32_t k=0; k<grpList->getAllUser().size(); k++){		user=grpList->getAllUser()[k]->getUri();				//filter out own username		//if(user==getDialogConfig().inherited.userUri)		if(user==getDialogConfig()->inherited->sipIdentity->getSipUri())			continue;						//create callConfig		callConf = MRef<SipDialogConfig*>(new SipDialogConfig(phoneconf->inherited) );					//check user uri and modify DialogConfig		if(modifyDialogConfig(user, callConf)==false){			p2tDialog->removeUser(user, "uri malformed", "");			continue;		}				MRef<SipDialogP2Tuser*> p2tUserDialog = new SipDialogP2Tuser(sipStack, callConf, phoneconf, p2tDialog);		sipStack->addDialog(*p2tUserDialog);				//set CallId and localStarted in GroupMemberList		grpList->getAllUser()[k]->setCallId(p2tUserDialog->getCallId());		grpList->getAllUser()[k]->setLocalStarted(true);				CommandString inv(p2tUserDialog->getCallId(), SipCommandString::invite, user);        	SipSMCommand cmd(SipSMCommand(inv, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer));		getDialogContainer()->enqueueCommand( cmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE );	}	//send GUI the Group Identity	CommandString cmdstr("", "p2tSessionCreated", p2tDialog->getCallId());	getDialogContainer()->getCallback()->handleCommand("gui", cmdstr );	}bool DefaultDialogHandler::getP2TDialog(string GroupId, MRef<SipDialogP2T*>&p2tDialog){	bool match=false;//	list<MRef<SipDialog*> > *dialogs = getDialogContainer()->getDispatcher()->getDialogs();	list<MRef<SipDialog*> > dialogs = getDialogContainer()->getDispatcher()->getDialogs();		for (list<MRef<SipDialog*> >::iterator i=dialogs.begin(); i!=dialogs.end(); i++){		MRef<SipDialog*> tmpd= *i;		if ( tmpd->getCallId()==GroupId){			match=true;			p2tDialog = MRef<SipDialogP2T*>((SipDialogP2T*)*tmpd);			break;		}	}		return match;}#endifbool DefaultDialogHandler::modifyDialogConfig(string user, MRef<SipDialogConfig *> dialogConfig){	int startAddr=0;	if (user.substr(0,4)=="sip:")		startAddr = 4;		if (user.substr(0,4)=="sips:")		startAddr = 5;	bool onlydigits=true;	for (unsigned i=0; i<user.length(); i++)		if (user[i]<'0' || user[i]>'9')			onlydigits=false;	if (onlydigits && phoneconf->usePSTNProxy){		dialogConfig->useIdentity( phoneconf->pstnIdentity, false);	}		if (user.find(":", startAddr)!=string::npos){		if (user.find("@", startAddr)==string::npos){			//malformed			return false;		}				string proxy;		string port;		uint32_t i=startAddr;		while (user[i]!='@')			if (user[i]==':')				return false; //malformed			else				i++;		i++;		while (user[i]!=':')			proxy = proxy + user[i++];		i++;		while (i<user.size())			if (user[i]<'0' || user[i]>'9')				return false; //malformed			else				port = port + user[i++];				int iport = atoi(port.c_str());				//		merr << "IN URI PARSER: Parsed port=<"<< port <<"> and proxy=<"<< proxy<<">"<<end;				try{			//dialogConfig->inherited->sipIdentity->getSipProxy()->sipProxyIpAddr = new IP4Address(proxy);			dialogConfig->inherited->sipIdentity->getSipProxy()->sipProxyAddressString = proxy;			dialogConfig->inherited->sipIdentity->getSipProxy()->sipProxyPort = iport;		}catch(HostNotFound & exc){			merr << "Could not resolve PSTN proxy address:" << end;			merr << exc.what();			merr << "Will use default proxy instead" << end;		}		}		return true;}void DefaultDialogHandler::sendIMOk(MRef<SipRequest*> bye, const string &branch){        MRef<SipResponse*> ok= new SipResponse( branch, 200,"OK", MRef<SipMessage*>(*bye) );        ok->getHeaderValueTo()->setParameter("tag",/*dialogState.localTag*/"libminisip");        MRef<SipMessage*> pref(*ok);        SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);        sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void DefaultDialogHandler::sendIM(const string &branch, string msg, int im_seq_no, string toUri){		size_t posAt;		posAt = toUri.find("@");	if( posAt == string::npos ) { //toUri does not have a domain ...		//get one, from the default identity		if( phoneconf->inherited->sipIdentity->sipDomain != "" ) {			toUri += "@" + phoneconf->inherited->sipIdentity->sipDomain;		} else {			#ifdef DEBUG_OUTPUT			cerr << "DefaultDialogHandler::sendIM - toUri without domain" << endl;			#endif		}	}	#ifdef DEBUG_OUTPUT	cerr << "DefaultDialogHandler::sendIM - toUri = " << toUri <<  endl;	#endif		MRef<SipRequest*> im = SipRequest::createSipMessageIMMessage(			std::string(branch),			itoa(rand()),	//Generate random callId			toUri, 				phoneconf->inherited->sipIdentity->getSipUri(),			im_seq_no,			msg			);	//FIXME: there should be a SipIMDialog, just like for register messages ...	// 	otherwise, we cannot keep track of local/remote tags, callids, etc ... 	//	very useful for matching incoming and outgoing IMs ...	im->getHeaderValueFrom()->setParameter("tag","libminisip"); //we need a from tag ... anything ... 	MRef<SipMessage*> pref(*im);	SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);	sipStack->getDispatcher()->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}

⌨️ 快捷键说明

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