📄 sipdialogregister.cxx
字号:
/* Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien 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*//* * Authors: Erik Eliasson <eliasson@it.kth.se> * Johan Bilien <jobi@via.ecp.fr>*/#include<config.h>#include<libmsip/SipTransaction.h>#include<libmsip/SipStack.h>#include<libmsip/SipDialogConfig.h>#include<libmsip/SipDialogRegister.h>#include<libmsip/SipCommandDispatcher.h>#include<libmsip/SipTransactionUtils.h>#include<libmsip/SipTransactionNonInviteClient.h>#include<libmsip/SipRequest.h>#include<libmsip/SipResponse.h>#include<libmsip/SipHeaderWWWAuthenticate.h>#include<libmsip/SipHeaderProxyAuthenticate.h>#include<libmsip/SipCommandString.h>#include<libmsip/SipSMCommand.h>#include<libmutil/massert.h>#ifdef DEBUG_OUTPUT//# include<libmutil/Timestamp.h># include<libmutil/dbg.h>#endif/* (a11 does not exist) +-------------+ | S0 | | Start | | | transport_error +-------------+ a10 GUI(failed) | +-----------------------------+---------------------------------+cmdstr:proxy_regist| | 401&&haspass +------+--------+ | a0 send_noauth | | a2 send_auth | S3 |---------------------+ | | | +------------------->| Trying_stored | | | V | | 1xx +-| |-+ | | +-------------+ a15 - +>+---------------+ | 401 | | |S1 | 401&&nopass | a4 ask_dialog | | +-->|Trying_noauth| a3 ask_dialog +---------------+ | | | | | |----------------->| S4 |<+ | | | +-------------+ | Ask password |---+ cmdstr:setpass | | | | | ^ | | | a5 send_auth | | | | +--+ +---------------+<--+ | | | 2xx OK | 1xx | | ^ |cancel +----------+ | | | a1 - | a14 - | +------+ +------>| S5 |<---)--+ | V 200 | 401 a9 | Failed | | | +-------------+ a6 - | a7 ask_dialog a8 | | | | | S2 |<-------------------+ +----------+ | +---| Registred | | | register | |<---------------------------------------------^---------+ send_noauth+-------------+ 2xx V a13: notransactions | | a8 +----------+ --------+ | | a12 cmdstr:register <proxy> |terminated| | | +----------+ TODO: handle all possible responses */ using namespace std;//a12 also deals with proxy_register ... but once it is already registered ...bool SipDialogRegister::a0_start_tryingnoauth_register( const SipSMCommand &command){ if (transitionMatch(command, SipCommandString::proxy_register, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer)){ //Set user and password for the register if (command.getCommandString().getParam()!="" && command.getCommandString().getParam2()!=""){ getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyUsername = command.getCommandString().getParam(); getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyPassword = command.getCommandString().getParam2(); } //Set expires param ... in seconds (in param3) if (command.getCommandString().getParam3()!="" ) { getDialogConfig()->inherited->sipIdentity->getSipProxy()->setRegisterExpires( command.getCommandString().getParam3() ); } //if it comes with an identity ... use it to filter out commands not for this dialog ... if (command.getCommandString()["identityId"]!="" ) { string identity; identity = command.getCommandString()["identityId"]; if( identity != getDialogConfig()->inherited->sipIdentity->getId() ) { //we got a proxy_register not for our identity ... return false; } } ++dialogState.seqNo;/* MRef<SipTransaction*> trans = new SipTransactionNonInviteClient( sipStack, //this, dialogState.seqNo, "REGISTER", dialogState.callId); dispatcher->getLayerTransaction()->addTransaction(trans); registerTransactionToDialog(trans);*/ send_noauth(/*trans->getBranch()*/""); CommandString cmdstr( dialogState.callId, SipCommandString::register_sent); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); dispatcher->getCallback()->handleCommand("gui", cmdstr ); return true; }else{ cerr << "EEEE: Error: command is "<<command<<endl; massert(1==0); // this should never happen - the first transaction MUST be register command return false; }}bool SipDialogRegister::a1_tryingnoauth_registred_2xx( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "2**")){ ///FIXME: XXXXXX Removed socket from packet - this functionality needs to be looked over/// regcall->getDialogContainer()->getPhoneConfig()->proxyConnection = command.getCommandPacket()->getSocket(); //Mark the identity as currently registered (or not, maybe we are unregistering) getDialogConfig()->inherited->sipIdentity->setIsRegistered ( true ); CommandString cmdstr( dialogState.callId, SipCommandString::register_ok, getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyAddressString); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); if (getGuiFeedback()){ dispatcher->getCallback()->handleCommand("gui", cmdstr ); setGuiFeedback(false); } //this is for the shutdown dialog SipSMCommand cmd( cmdstr, SipSMCommand::dialog_layer, SipSMCommand::dispatcher ); dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/ ); //request a timeout to retx a proxy_register only if we are registered ... //otherwise we would just be unregistering every now and then ... if( getDialogConfig()->inherited->sipIdentity->isRegistered () ) { requestTimeout( getDialogConfig()->inherited->sipIdentity->getSipProxy()->getRegisterExpires_int() * 1000, SipCommandString::proxy_register); } return true; }else{ return false; }}bool SipDialogRegister::a2_tryingnoauth_tryingstored_401haspass( const SipSMCommand &command){ if ( hasPassword() && transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "401")){ ++dialogState.seqNo;/* MRef<SipTransaction*> trans( new SipTransactionNonInviteClient( sipStack, //this, dialogState.seqNo, "REGISTER", dialogState.callId)); dispatcher->getLayerTransaction()->addTransaction(trans); registerTransactionToDialog(trans);*/ //extract authentication info from received response MRef<SipResponse*> resp( (SipResponse *)*command.getCommandPacket()); //setRealm( resp->getRealm() ); setRealm(resp->getAuthenticateProperty("realm")); //setNonce( resp->getNonce() ); setNonce(resp->getAuthenticateProperty("nonce")); send_auth(/*trans->getBranch()*/""); //TODO: inform GUI return true; }else{ return false; }}bool SipDialogRegister::a3_tryingnoauth_askpassword_401nopass( const SipSMCommand &command){ if ( !hasPassword() && transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "401")){ //TODO: Ask password CommandString cmdstr( dialogState.callId, SipCommandString::ask_password, getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyAddressString); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); dispatcher->getCallback()->handleCommand("gui", cmdstr ); //extract authentication info from received response MRef<SipResponse*> resp( (SipResponse *)*command.getCommandPacket()); //setRealm( resp->getRealm() ); setRealm(resp->getAuthenticateProperty("realm")); //setNonce( resp->getNonce() ); setNonce(resp->getAuthenticateProperty("nonce")); return true; }else{ return false; }}bool SipDialogRegister::a4_tryingstored_askpassword_401( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "401")){ //TODO: Ask password CommandString cmdstr( dialogState.callId, SipCommandString::ask_password, getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyAddressString); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); dispatcher->getCallback()->handleCommand("gui", cmdstr ); //extract authentication info from received response MRef<SipResponse*> resp( (SipResponse *)*command.getCommandPacket()); //setRealm( resp->getRealm() ); setRealm(resp->getAuthenticateProperty("realm")); //setNonce( resp->getNonce() ); setNonce(resp->getAuthenticateProperty("nonce")); return true; }else{ return false; }}bool SipDialogRegister::a5_askpassword_askpassword_setpassword( const SipSMCommand &command){ if (transitionMatch(command, SipCommandString::setpassword, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer)){ //TODO: Ask password getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyUsername = command.getCommandString().getParam(); getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyPassword= command.getCommandString().getParam2(); ++dialogState.seqNo;/* MRef<SipTransaction*> trans( new SipTransactionNonInviteClient( sipStack, //this, dialogState.seqNo, "REGISTER", dialogState.callId)); dispatcher->getLayerTransaction()->addTransaction(trans); registerTransactionToDialog(trans);*/ send_auth(/*trans->getBranch()*/""); return true; }else{ return false; }}bool SipDialogRegister::a6_askpassword_registred_2xx( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "2**")){ //Mark the identity as currently registered (or not, maybe we are unregistering) getDialogConfig()->inherited->sipIdentity->setIsRegistered ( true ); CommandString cmdstr( dialogState.callId, SipCommandString::register_ok, getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyAddressString); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); //TODO: inform GUI if (getGuiFeedback()){ dispatcher->getCallback()->handleCommand("gui", cmdstr ); setGuiFeedback(false); } //this is for the shutdown dialog SipSMCommand cmd( cmdstr, SipSMCommand::dialog_layer, SipSMCommand::dispatcher ); dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/ ); //requestTimeout(1000*60*14,SipCommandString::proxy_register); //request a timeout to retx a proxy_register only if we are registered ... //otherwise we would just be unregistering every now and then ... if( getDialogConfig()->inherited->sipIdentity->isRegistered () ) { //requestTimeout(1000*60*14,SipCommandString::proxy_register); requestTimeout( getDialogConfig()->inherited->sipIdentity->getSipProxy()->getRegisterExpires_int() * 1000, SipCommandString::proxy_register); } return true; }else{ return false; }}bool SipDialogRegister::a7_askpassword_askpassword_401( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "401")){ //TODO: Ask password CommandString cmdstr( dialogState.callId, SipCommandString::ask_password, getDialogConfig()->inherited->sipIdentity->getSipProxy()->sipProxyAddressString); cmdstr["identityId"] = getDialogConfig()->inherited->sipIdentity->getId(); dispatcher->getCallback()->handleCommand("gui", cmdstr ); //extract authentication info from received response MRef<SipResponse*> resp = (SipResponse *)*command.getCommandPacket(); setRealm( getRealm() ); setNonce( getNonce() ); return true; }else{ return false; }}bool SipDialogRegister::a8_tryingstored_registred_2xx( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "2**")){ //Mark the identity as currently registered (or not, maybe we are unregistering) getDialogConfig()->inherited->sipIdentity->setIsRegistered ( true ); //TODO: inform GUI CommandString cmdstr( dialogState.callId,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -