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

📄 minisiptextui.cxx

📁 这是一个开源码的sip用户代理 写的都很清楚是用C++语言开发的 对于研究sip协议的朋友绝对是有很好的参考价值
💻 CXX
📖 第 1 页 / 共 2 页
字号:
				displayMessage("                        (no timeouts)");		}	}}void MinisipTextUI::showStat(string command){	list<MRef<SipDialog*> > calls = config->sip->getDialogContainer()->getDispatcher()->getDialogs();	list <TPRequest<string, MRef<StateMachine<SipSMCommand,string>*> > > torequests = config->timeoutProvider->getTimeoutRequests();//	displayMessage(" Default dialog handler:", bold);	showDialogInfo(config->sip->getDialogContainer()->getDefaultHandler(), false, "  Default dialog handler: ");	displayMessage(" Calls:", bold);	if (calls.size()==0)		displayMessage("    (no calls)");	else{		int ii=0;		for (list<MRef<SipDialog*> >::iterator i=calls.begin(); i!= calls.end(); i++, ii++){			showDialogInfo(*i,true, string("    (")+itoa(ii)+") ");		}	}}void MinisipTextUI::showMem(){	displayMessage("(not implemented any more)");//    displayMessage(memhandler.listObjs());}void MinisipTextUI::showGroupList(){    if (grpList->getDescription().substr(0,5)=="ERROR"){    	displayMessage(grpList->getDescription(), red);	return;    }            displayMessage("Session Parameters:", bold);        if(grpList->getDescription()!="")    	displayMessage("Description:      " + grpList->getDescription());        if(grpList->getGroupIdentity()!="")    	displayMessage("Group Id:         " + grpList->getGroupIdentity());        if(grpList->getGroupOwner()!="")        	displayMessage("Group Owner:      " + grpList->getGroupOwner());            displayMessage("Session Type:     " + P2T::getSessionType(grpList->getSessionType()));    displayMessage("Membership:       " + P2T::getMembership(grpList->getMembership()));           if(grpList->getMaxFloorTime()>0)    	displayMessage("Max Floor Time:   " + itoa(grpList->getMaxFloorTime()));        if(grpList->getMaxParticipants()>0)    	displayMessage("Max Participants: " + itoa(grpList->getMaxParticipants()));    if(grpList->getAllMember().size()>0){        displayMessage("Members:", bold);    	for(uint32_t k=0;k<grpList->getAllMember().size();k++)        	displayMessage(grpList->getAllMember().at(k));    }    if(grpList->getAllUser().size()>0){    	displayMessage("Participants:", bold);        for(uint32_t k=0;k<grpList->getAllUser().size();k++)        	displayMessage(grpList->getAllUser().at(k)->getUri() + " (" + 			itoa(grpList->getAllUser().at(k)->getPriority()) + ") " +			P2T::getStatus(grpList->getAllUser().at(k)->getStatus()));    }}void MinisipTextUI::showP2TInfo(){	displayMessage("*********************************************", blue);	displayMessage("*          You are now in P2T-Mode          *",blue);	displayMessage("*********************************************",blue);					displayMessage("The following commands are possible:", blue);	displayMessage("add <uri>      add a user to the session",blue);	//displayMessage("edit           set the parameters",blue);	displayMessage("download <url> load group member list from",blue);	displayMessage("               http server, e.g.",blue);	displayMessage("               http://1.2.3.4:3365/grouplist.xml",blue);	//displayMessage("load <file>    load group member list form file",blue);	//displayMessage("save <file>    save group member list to file",blue);	displayMessage("show           shows the group member list",blue);	displayMessage("connect        start p2t session",blue);	displayMessage("talk           get the floor",blue);	displayMessage("stop           release the floor",blue);	displayMessage("exit           leave P2T Mode",blue);}void MinisipTextUI::keyPressed(int key){	switch(key){	case '*':		showMem();		break;	case '+':		showStat("");		break;	}}void MinisipTextUI::guiExecute(string cmd){	string command = trim(cmd);	string regproxy;	bool handled = false;/*	if (cmd=="quit"){		exit(0);	}*/		if (command.substr(0,8) == "register"){		displayMessage("Registering to proxy", blue);		regproxy = trim(command.substr(8));		mdbg << "Regproxy=<"<<regproxy<<">"<< end;		CommandString command("",SipCommandString::proxy_register/*, regproxy*/);//		if (regproxy=="pstn")//			command.setDestinationId("pstn");		command["proxy_domain"] = regproxy;		callback->guicb_handleCommand(command);		handled=true;	}	if (command == "show calls"){		showCalls(command);		handled=true;	}	if (command == "enable autoanswer"){		autoanswer=true;		displayMessage("Autoanswer is now enabled.");		handled=true;	}	if (command == "disable autoanswer"){		autoanswer=false;		displayMessage("Autoanswer is now disabled.");		handled=true;	}	if (command == "enable debugmsgs"){		mdbg.setEnabled(true);		displayMessage("Debug messages is now enabled.");		handled=true;	}	if (command == "disable debugmsgs"){		mdbg.setEnabled(false);		displayMessage("Debug messages is now disabled.");		handled=true;	}	if (command == "show timeouts"){		showTimeouts(command);		handled=true;	}#ifdef DEBUG_OUTPUT	if (command == "show packets"){		sipdebug_print_packets=true;		displayMessage("SIP messages will be displayed on the screen", blue);		handled=true;	}	if (command == "hide packets"){		sipdebug_print_packets=false;		displayMessage("SIP messages will NOT be displayed on the screen", blue);		handled=true;	}#endif	if (command.substr(0,17) == "show transactions"){		showTransactions(command);		handled=true;	}	if (command == "answer"){		CommandString command(callId, SipCommandString::accept_invite);		callback->guicb_handleCommand(command);		displayMessage("A call with the most recent callId will be accepted");		handled=true;	}	if (command == "show all"){		showCalls(command);		list<MRef<SipDialog*> > calls = config->sip->getDialogContainer()->getDispatcher()->getDialogs();		for (uint32_t i=0; i<calls.size(); i++){			showTransactions("show transactions "+itoa(i));		}		showTimeouts(command);		handled=true;	}	if (trim(command) == "hangup"){		CommandString hup(callId, SipCommandString::hang_up);		callback->guicb_handleCommand(hup);		state="IDLE";		setPrompt(state);		displayMessage("hangup");		handled=true;	}	if ((command.size()>=4) && (command.substr(0,4) == "call")){		if (command.size()>=6){			if (state!="IDLE"){				displayMessage("UNIMPLEMENTED - only one call at the time with this UI.", red);			}else{				string uri = trim(command.substr(5));				displayMessage("Uri: "+uri);				callId = callback->guicb_doInvite(uri);				if (callId=="malformed"){					state="IDLE";					setPrompt(state);					displayMessage("The URI is not a valid SIP URI", red);					callId="";				}else{					state="TRYING";					setPrompt(state);					displayMessage(string("Created call with id=")+callId);    				}			}		}else{			displayMessage("Usage: call <userid>");//			displayHelp("call");		}		handled=true;	}	/**	 * send any command you want.	 * Syntax: cmd <command> <param>	 **/	if ((command.size()>=3) && (command.substr(0,3) == "cmd")) {		if(command.size()>=5) {			string s_cmd = "";			string s_param = "";			uint32_t x = 4;			for( ;x<command.size();x++) {				if (command[x]!=' ')					s_cmd+=command[x];				else					break;			}			x++;			for( ;x<command.size();x++)				s_param+=command[x];			CommandString command("",s_cmd, s_param);			displayMessage("Created cmd=" + s_cmd + " param=" + s_param);			callback->guicb_handleCommand(command);		}		else {			displayMessage("HELP: cmd\nSyntax: cmd <command> <param>", bold);		}		handled=true;	}	/**	 * Commands for Push-2-Talk	 */	if ((command.size()>=3) && (command.substr(0,3) == "add") && inCall){		if (command.size()>=5){			string uri = trim(command.substr(4));			grpList->addUser(uri);							//if session is already going on, establish SIP Session			if(p2tmode==true) {				CommandString command("", "p2tAddUser",p2tGroupId, uri);				callback->guicb_handleCommand(command);			}						}else{//			displayHelp("call");		}		handled=true;	}			//accept a p2t invitation	if (command == "accept" ){				//add P2T commands		addCommand("add");    		addCommand("edit");		addCommand("download");		addCommand("load");		addCommand("save");		addCommand("show");		addCommand("connect");		addCommand("talk");		addCommand("stop");		addCommand("exit");		addCompletionCallback("add", this);			//inform DefaultDialogHandler		CommandString cmd1("",  "p2tSessionAccepted", p2tGroupId, inviting_user);		callback->guicb_handleCommand(cmd1);						//Info Screen		showP2TInfo();		p2tmode=true;		handled=true;		state = "P2T IDLE";		setPrompt(state);	}		//deny a p2t invitation	if (command == "deny" ){				//Close SipDialogP2T and he will terminate all		//SipDialogP2Tuser Sessions.		CommandString command(p2tGroupId, "p2tTerminate");		callback->guicb_handleCommand(command);					//reset states		inCall=false;		p2tmode=false;		state = "IDLE";		setPrompt("IDLE");		handled=true;	}		//enter the P2T Mode	if (command == "p2t" && p2tmode == false){		//add possible p2t commands to the TextUI		addCommand("add");    		addCommand("edit");		addCommand("download");		addCommand("load");		addCommand("save");		addCommand("show");		addCommand("connect");		addCommand("talk");		addCommand("stop");		addCommand("exit");		addCompletionCallback("add", this);				//start p2tGroupListServer		CommandString command("","p2tStartGroupListServer");		callback->guicb_handleCommand(command);				//initiate Group Member List and add		//own username to it		grpList = MRef<GroupList*>(new GroupList());		//grpList->addUser(config->inherited.userUri);			grpList->addUser(config->inherited.sipIdentity->getSipUri());					//InfoScreen		showP2TInfo();				//set p2tmode variable and state		inCall=true;		//p2tmode = true;		state = "P2T IDLE";		setPrompt("P2T IDLE");		handled=true;	}	if (command == "exit" && inCall == true){		//remove p2t commands		//TODO: add this function to <libmutil/TextUI>				//delete Group Member List		grpList=NULL;				//inform user		displayMessage("You left the P2T-Mode...", blue);		p2tmode = false;				//stop SipDialogP2T		CommandString term(p2tGroupId, "p2tTerminate");		callback->guicb_handleCommand(term);			//stop p2tGroupListServer		CommandString command("","p2tStopGroupListServer");		callback->guicb_handleCommand(command);						//set state		inCall=false;		state = "IDLE";		setPrompt("IDLE");		handled=true;	}	if (command == "connect" && inCall == true){		CommandString cmd ("", "p2tStartSession", grpList->print());		callback->guicb_handleCommand(cmd);		p2tmode=true;		handled=true;	}		if (command == "talk" && p2tmode == true){		CommandString cmd (p2tGroupId, "p2tGetFloor");		callback->guicb_handleCommand(cmd);				handled=true;	}	if (command == "stop" && p2tmode == true){		CommandString cmd (p2tGroupId, "p2tReleaseFloor");		callback->guicb_handleCommand(cmd);		handled=true;	}	if (command == "edit" && inCall == true){		displayMessage("Not implemented!");		handled=true;	}	if (command == "save" && inCall == true){		displayMessage("Not implemented!");		handled=true;	}		if (command == "load" && inCall == true){		displayMessage("Not implemented!");		handled=true;	}		if (command == "show" && inCall == true){		showGroupList();		handled=true;	}		//download Group Member List from a server	if ((command.size()>=8) && (command.substr(0,8) == "download") && inCall==true){		string file="";		string server="";		string s_port = "";		int port=0;		uint32_t x=0;				displayMessage(command.substr(9,7));				if(command.substr(9,7)=="http://" && command.size()>10)			x=16;		else			x=9;				//parse server		for( ;x<command.size();x++){			if(command[x]==':')				break;			else if(command[x]=='/') {				s_port="80";				break;			}			 			server+=command[x];		}				//parse port		for(++x;x<command.size();x++){			if(s_port=="80"){				--x;				break;			}						if(command[x]=='/')				break;							s_port+=command[x];		}				//parse file		for( ;x<command.size();x++){			file+=command[x];		}				if(s_port==""){			port=80;		}		else{			for(uint32_t k=0;k<s_port.size();k++) {				port = (port*10) + (s_port[k]-'0');			}		}		displayMessage("Server: " + server);		displayMessage("File: " + file);		displayMessage("Port: " + s_port);		//download GroupList				MRef<GroupListClient*>client = new GroupListClient();		grpList = client->downloadGroupList(file, &server[0], port);				displayMessage("Received GroupList:",bold);		showGroupList();				client=NULL;		handled=true;	}	if (!handled && command.substr(0,2) == "im"){		handled=true;		string arg = command.substr(2);		arg = trim(arg);		unsigned spos = arg.find(" ");		if (spos==string::npos){			displayMessage("im usage: im <user> <message>",red);		}else{			string addr =arg.substr(0,spos);			addr = trim(addr);			string msg = arg.substr(spos);			msg = trim(msg);			cerr << "Sending instant message to <"<< addr <<"> and message is <"<< msg<<">"<< endl;			CommandString command("",SipCommandString::outgoing_im, msg, addr);			//command["proxy_domain"] = regproxy;			callback->guicb_handleCommand(command);		}	}	if (!handled && command.size()>0){		displayMessage("Unknown command: "+command, red);	}}void MinisipTextUI::setSipSoftPhoneConfiguration(MRef<SipSoftPhoneConfiguration *>sipphoneconfig){	config = sipphoneconfig;       }

⌨️ 快捷键说明

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