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

📄 minisiptextui.cxx

📁 MiniSip Client with DomainKeys Authentication, Sip, Audio communications, Echo Cancel
💻 CXX
📖 第 1 页 / 共 3 页
字号:
/* *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program 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 Library General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; 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<stdio.h>#include<vector>#include"MinisipTextUI.h"#include<libminisip/conference/ConferenceControl.h>#include<libminisip/mediahandler/MediaCommandString.h>#include<libmutil/MemObject.h>#include<libmutil/trim.h>#include<libmutil/termmanip.h>#include<libmsip/SipCommandString.h>#include<libmsip/SipCommandDispatcher.h>#include<libminisip/sip/DefaultDialogHandler.h>#include<libminisip/conference/ConfMessageRouter.h>using namespace std;MinisipTextUI::MinisipTextUI(): TextUI(), autoanswer(false){	inCall=false;	p2tmode=false;		//#ifdef DEBUG_OUTPUT	//    mdbg << "Setting global MinisipTextUI"<< end;	//    debugtextui=this;	//#endif		addCommand("quit");	addCommand("answer");	addCommand("disable autoanswer");	addCommand("enable autoanswer");	addCommand("enable debugmsgs");	addCommand("disable debugmsgs");	addCommand("hangup");	addCommand("hide packets");	addCommand("register");	addCommand("show all");	addCommand("show calls");	addCommand("show transactions");	addCommand("show packets");	addCommand("cmd");	addCommand("transfer");	addCommand("refuse");	addCommand("conf");	addCommand("join");	addCommand("accept"); //accept incoming P2T Session	addCommand("deny");   //deny incoming P2T Session	addCommand("im");   //deny incoming P2T Session	//    addCommand("quit");	addCompletionCallback("call", this);	addCompletionCallback("im", this);		state="IDLE";	setPrompt("IDLE");	semSipReady = new Semaphore();}void MinisipTextUI::run(){	guimain();}void MinisipTextUI::displayErrorMessage(string msg){	displayMessage(msg, red);}/** * Required by the TextUI superclass. This method enables "dynamic" * auto-completion where the set of string that are being auto-completed * are not fixed. An example is that this method has been used to implement * auto-completion of all addresses in the phonebook. */minilist<std::string> MinisipTextUI::textuiCompletionSuggestion(string /*match*/){	minilist<std::string> ret;//TODO: implement it with the new phonebook./*	if (!config.isNull()){		list<string> phonebooks = config->phonebooks;		for (list<string>::iterator i=phonebooks.begin(); i!=phonebooks.end(); i++){			if ((*i).size()<=7)				return ret;;			XMLParser *parser;			if ((*i).substr(0,7)=="file://"){				//              cerr << "Creating XML file parser"<< endl;				parser = new XMLFileParser((*i).substr(7));			}else{				continue;			}			string phonebook;			int phonebooks=0;			do{				string q = "phonebook["+itoa(phonebooks)+"]/name";				phonebook=parser->getValue(q,"");				if (phonebook!=""){					string contact;					int contacts=0;					do{						string q = "phonebook["+itoa(phonebooks)+"]/contact["+itoa(contacts)+"]/name";						contact = parser->getValue(q,"");						if (contact!=""){							int pops=0;							string qbase;							string desc;							do{								string qbase = "phonebook["+itoa(phonebooks)+"]/contact["+itoa(contacts)+"]/pop["+itoa(pops)+"]/";								desc = parser->getValue(qbase+"desc","");								if (desc!=""){									string uri = parser->getValue(qbase+"uri","");									ret.push_back("call "+uri);								}								pops++;							}while(desc!="");						}						contacts++;					}while(contact!="");				}				phonebooks++;			}while(phonebook!="");			delete parser;		}	}*/	return ret;}void MinisipTextUI::handleCommand(const CommandString &cmd){#ifdef DEBUG_OUTPUT	mdbg << FG_MAGENTA << "MinisipTextUI::handleCommand: Got "<<cmd.getString() << PLAIN <<end;#endif			if (cmd.getOp()=="register_ok"){		displayMessage("Register to proxy "+cmd.getParam()+" OK", green);	}			if (cmd.getOp()==SipCommandString::incoming_im){		displayMessage("IM to <"+cmd.getParam3()+"> from <"+cmd.getParam2()+">: "+cmd.getParam(), bold);	}			if (cmd.getOp()=="invite_ok"){		state="INCALL";		inCall = true;		setPrompt(state);		displayMessage("PROGRESS: remote participant accepted the call...", blue);				displayMessage("PROGRESS: Unmuting sending of sound.", blue);		CommandString cmdstr( callId,				MediaCommandString::set_session_sound_settings,				"senders", "ON");		//callback->guicb_handleMediaCommand(cmdstr);		sendCommand("media", cmdstr);		}		if (cmd.getOp()=="remote_ringing"){		state="REMOTE RINGING";		setPrompt(state);		displayMessage("PROGRESS: the remote UA is ringing...", blue);	}		if (autoanswer && cmd.getOp()==SipCommandString::incoming_available){		CommandString command(callId, SipCommandString::accept_invite);		//callback->guicb_handleCommand(command);		sendCommand("sip",command);		state="INCALL";		setPrompt(state);		displayMessage("Autoanswered call from "+ cmd.getParam());		displayMessage("Unmuting sending of sound.", blue);		CommandString cmdstr( callId,				MediaCommandString::set_session_sound_settings,				"senders", "ON");		//callback->guicb_handleMediaCommand(cmdstr);		sendCommand("media",cmdstr);			return;	}		if (cmd.getOp()==SipCommandString::remote_user_not_found && !p2tmode){		state="IDLE";		setPrompt(state);		displayMessage("User "+cmd.getParam()+" not found.",red);		callId=""; //FIXME: should check the callId of cmd.	}		if (cmd.getOp()==SipCommandString::remote_hang_up){		state="IDLE";		setPrompt(state);		displayMessage("Remote user ended the call.",red);		callId=""; //FIXME: should check the callId of cmd.		inCall=false;	}			if (cmd.getOp()==SipCommandString::transport_error && !p2tmode){		state="IDLE";		setPrompt(state);		displayMessage("The call could not be completed because of a network error.", red);		callId=""; //FIXME: should check the callId of cmd.	}			if (cmd.getOp()=="error_message"){		displayMessage("ERROR: "+cmd.getParam(), red);	}		if (cmd.getOp()=="remote_reject" && !p2tmode){		state="IDLE";		setPrompt(state);		callId="";		displayMessage("The remote user rejected the call.", red);	}		if (cmd.getOp()==SipCommandString::incoming_available){		if(state=="IDLE"){			state="ANSWER?";			setPrompt(state);			callId=cmd.getDestinationId();			displayMessage("The incoming call from "+cmd.getParam(), blue);		}		else{			displayMessage("You missed call from "+cmd.getParam(), red);			CommandString hup(cmd.getDestinationId(), SipCommandString::reject_invite);			//callback->guicb_handleCommand(hup);			sendCommand("sip",hup);				}			}	if (cmd.getOp()=="conf_join_received"){		if(state=="IDLE"){			state="ANSWER?";			setPrompt(state);			callId=cmd.getDestinationId();			//addCommand("addc");									currentcaller=cmd.getParam();								//conf->setGui(this);			string confid="";			string users=cmd.getParam3();			int i=0;				while (users[i]!=';'&&users.length()!=0 &&!(i>((int)users.length()-1))){				confid=confid+users[i];				i++;			}			string mysipuri = config->inherited->sipIdentity->sipUsername + "@" + config->inherited->sipIdentity->sipDomain;			users=trim(users.substr(i));			cerr<<"confididididididididididididiidididid "+confid<<endl;			currentconf=new ConferenceControl(mysipuri,confid,false);			confCallback->setConferenceController(currentconf);			displayMessage("The incoming conference call from "+cmd.getParam(), blue);			displayMessage("The participants are "+cmd.getParam()+" "+users, blue);			currentconfname=confid;		}		else{			displayMessage("You missed call from "+cmd.getParam(), red);			CommandString hup(cmd.getDestinationId(), SipCommandString::reject_invite);			confCallback->guicb_handleCommand(hup);							}			}		if (cmd.getOp()==SipCommandString::transfer_pending){		if(inCall){			displayMessage( "Call transfer in progress..." );		}			}		if (cmd.getOp()==SipCommandString::transfer_requested){		cerr << "TestUI got transfer_requested" << endl;		if(inCall){			state="TRANSFER?";			setPrompt(state);			displayMessage("Accept call transfer to "+cmd.getParam(), blue );		}			}		if (cmd.getOp()==SipCommandString::call_transferred){		callId = cmd.getParam();		state="INCALL";		displayMessage("Call transferred ...");		setPrompt(state);	}#ifdef P2T_SUPPORT		//P2T commands	if (cmd.getOp()=="p2tFloorGranted"){		displayMessage("Floor is granted!!!", blue);				}else if (cmd.getOp()=="p2tFloorTaken"){		displayMessage("Floor is granted to "+cmd.getParam(),blue);		}	else if (cmd.getOp()=="p2tFloorReleased"){		displayMessage("Floor available!", blue);		state="P2T CONNECTED";		setPrompt(state);	}	else if (cmd.getOp()=="p2tFloorRevokeActive"){		displayMessage("Maximum Floortime reached. Revoking floor...", red);		state="P2T CONNECTED";		setPrompt(state);	}		/****	* p2tFloorRevokePassiv	* DestinationID: GroupIdentity	* Param:	      user SIP URI	* Param2:	      warning code	* Description:   remote user revoked floor.	****/	else if (cmd.getOp()=="p2tFloorRevokePassiv"){		if(cmd.getParam2()=="1"){			displayMessage("User " + cmd.getParam() + ":", bold);			displayMessage("Please stop talking. Maximum floortime reached.", blue);		}		else if(cmd.getParam2()=="3"){			displayMessage("User " + cmd.getParam() + " stopped listening!", red);		}	}		/****	* p2tAddUser	* DestinationID: CallId (SipDialogP2Tuser) 	* Param1:        SIP URI	* Description:   a remote user wants to be added to a P2T Session. 	*                This command is received when the SipDialogP2Tuser	*                is in the RINGING state and waits for an accept.	****/	else if (cmd.getOp()=="p2tAddUser"){		if(inCall==true && p2tmode==true){			//send automatically an accept back			CommandString command(cmd.getDestinationId(),  SipCommandString::accept_invite);			callback->guicb_handleCommand(command);						if(grpList->isParticipant(cmd.getParam())==false){				grpList->addUser(cmd.getParam());				displayMessage("User " + cmd.getParam() + " added!", blue);			}					}		else if(inCall==true && p2tmode==false){			//do nothing, because			//the user has first to accept or deny			//a incoming P2T Session. The answer will			//be sent there to this user		}	}		/****	* p2tRemoveUser	* DestinationID: GroupId (SipDialogP2T) 	* Param1:        SIP URI	* Param2:        reason	* Description:   a remote user wants to be added to a P2T Session. 	*                This command is received when the SipDialogP2Tuser	*                is in the RINGING state and waits for an accept.	****/	else if (cmd.getOp()=="p2tRemoveUser"){		if(inCall==true && p2tmode==true){			displayMessage("User " + cmd.getParam() + " removed ("+ cmd.getParam2() +").", red);			grpList->removeUser(cmd.getParam());		}	}		/****	* p2tModifyUser	* DestinationID: GroupId (SipDialogP2T) 	* Param1:        SIP URI	* Param2:        status	* Description:   information about a state (in the floor control)	*                of a user.	****/	else if (cmd.getOp()=="p2tModifyUser"){		if(inCall==true && p2tmode==true){						int status=0;			for(uint32_t k=0;k<cmd.getParam2().size();k++) 				status = (status*10) + (cmd.getParam2()[k]-'0');						grpList->getUser(cmd.getParam())->setStatus(status);		}	}		/****	* p2tInvitation	* DestinationID: GroupID (SipDialogP2T)	* Param1:        Group Member List (XML-code)	* Param2:        uri inviting user	* 	* Description:   an invitation to a P2T Session	****/	else if (cmd.getOp()=="p2tInvitation"){		//if already in a call, send DENY back		if(inCall){					//Close SipDialogP2T			//CommandString cmd_term(cmd.getDestinationId(), "p2tTerminate");			//callback->guicb_handleCommand(cmd_term);							//inform SipDialogP2Tuser			//CommandString cmd_rej(cmd.getParam3(), SipCommandString::reject_invite);			//callback->guicb_handleCommand(cmd_rej);					//displayMessage("You missed P2T invitation from " + cmd.getParam2() +".", red);	    		}		//aks user to accept		else{			inCall=true;			grpList = new GroupList(cmd.getParam());			inviting_user=cmd.getParam2();			//inviting_callId=cmd.getParam3();

⌨️ 快捷键说明

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