📄 sipdialogp2tuser.cxx
字号:
/* 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>*//* Name * SipDialogP2Tuser.cxx * Author * Erik Eliasson, eliasson@it.kth.se * Florian Maurer, florian.maurer@floHweb.ch * Purpose * */#include <config.h>#include<assert.h>#include<libminisip/p2t/SipDialogP2Tuser.h>#include<libmsip/SipDialogContainer.h>#include<libmsip/SipResponse.h>#include<libmsip/SipBye.h>#include<libmsip/SipCancel.h>#include<libmsip/SipAck.h>#include<libmsip/SipMessageTransport.h>#include<libmsip/SipTransactionInviteClientUA.h>#include<libmsip/SipTransactionInviteServerUA.h>#include<libmsip/SipTransactionNonInviteClient.h>#include<libmsip/SipTransactionNonInviteServer.h>#include<libmsip/SipTransactionUtils.h>#include<libmsip/SipDialog.h>#include<libmsip/SipCommandString.h>#include<libminisip/sip/DefaultDialogHandler.h>#include<libmutil/itoa.h>#include<libmutil/Timestamp.h>#include<libmutil/termmanip.h>#include<libmutil/dbg.h>#include<libmsip/SipSMCommand.h>#include <time.h>#include<libminisip/gui/LogEntry.h>#include<libmsip/SipCommandString.h>using namespace std;/* a13:reject/send40X +------------+ | | +---------------+ INVITE +--------------+CANCEL | | | a10:transIR; 180 | |a12:tCncl| | start |------------------->| ringing |---------+ | | | | |a26transport_err +---------------+ +--------------+ |gui(failed) | | | +----------------+ | invite | | | | V a0: new TransInvite | | | +---------------+ | | | +----| |----+ | | | 1xx | |Calling_noauth | | 180 | | |a2:(null)+--->| |<---+ a1: gui(ringing) | | +--------------+---------------+ | | | X ^ | | 2xx/a3: [Xsend ACKX] | | | [XACK/a15X] +---+ | +------------------------------+ | | | | | +----------------+ | 40X | accept_invite | | | V a20: send_auth | a11: send 200 | | +---------------+ | | | +----| |----+ | | | 1xx | |Calling_stored | | 180 | | |a22:(nul)+--->| |<---+ a21: gui(ringing) | | | +---------------+ | | | | | | | | 2xx | | | v a23: [Xsend ACKX] | | | +---------------+ | | | | |<---------------------------+ | | | in call |-------+ | | | | | | | +---------------+ | | | | | bye | |cancel | BYE | a6:TransByeInit | |a8: new TrnsCncl V a5:new ByeResp| | +------------->+---------------+ | | |3-699/a9:gui()| | | | +------------->| termwait |<------+-------------------------------------+ | | | +------------->+---------------+ | | a25: no_transactions V phone(call_terminated) +---------------+ | | | terminated | | | +---------------+ CANCEL a7:TrnsCnclRsp */ bool SipDialogP2Tuser::a0_start_callingnoauth_invite( const SipSMCommand &command){ if (transitionMatch(command, SipCommandString::invite)){ //assert(dynamic_cast<SipDialogP2Tuser*>(sipStateMachine)!=NULL); //MRef<SipDialogP2Tuser *>vc= (SipDialogP2Tuser *)sipStateMachine;#ifdef MINISIP_MEMDEBUG //vc.setUser("WARNING - transaction");#endif#if 0 if( vc->getDialogConfig().inherited.secured ){ KeyAgreement * ka = vc->getKeyAgreement(); ts.save( MIKEY_START ); string keyAgreementMessage = InitiatorCreate( ka, vc->getDialogConfig() ); ts.save( MIKEY_END ); vc->setKeyManagementMessage( keyAgreementMessage ); vc->setKeyAgreement( ka ); if( keyAgreementMessage == "" ){ //TODO: tell the GUI } }#endif //int seqNo = /*vc->*/requestSeqNo(); ++dialogState.seqNo; /*vc->*/setLocalCalled(false); /*vc->*/dialogState.remoteUri = command.getCommandString().getParam(); MRef<SipTransaction*> invtrans = new SipTransactionInviteClientUA(getSipStack(), MRef<SipDialog *>(/* *vc */ this), dialogState.seqNo, dialogState.callId); invtrans->setSocket( /*vc->*/getPhoneConfig()->proxyConnection ); /*vc->*/registerTransaction(invtrans); /*vc->*/sendInvite(invtrans->getBranch()); return true; }else{ return false; }}bool SipDialogP2Tuser::a1_callingnoauth_callingnoauth_18X( const SipSMCommand &command){ if (transitionMatch(command, SipResponse::type, IGN, SipSMCommand::TU, "18*")){ MRef<SipResponse*> resp= (SipResponse*) *command.getCommandPacket(); //MRef<SipDialogP2Tuser *>vc= (SipDialogP2Tuser *)sipStateMachine;#ifndef _MSC_VER ts.save( RINGING );#endif CommandString cmdstr(/*vc->*/getCallId(), SipCommandString::remote_ringing); //vc->getDialogContainer()->getCallback()->sipcb_handleCommand(cmdstr); /*vc->*/dialogState.remoteTag = command.getCommandPacket()->getHeaderValueTo()->getParameter("tag"); MRef<SdpPacket*> sdp((SdpPacket*)*resp->getContent()); if ( !sdp.isNull() ){ /*vc->*/handleSdp( MRef<SdpPacket*>((SdpPacket*)*sdp) ); } // else{ // mdbg << "WARNING: 200 OK did not contain any session description"<< end; // } return true; }else{ return false; }}bool SipDialogP2Tuser::a2_callingnoauth_callingnoauth_1xx( const SipSMCommand &command){ if (transitionMatch(command, SipResponse::type, IGN, SipSMCommand::TU, "1**")){ //MRef<SipDialogP2Tuser *> vc= (SipDialogP2Tuser *)sipStateMachine; /*vc->*/dialogState.remoteTag = command.getCommandPacket()->getHeaderValueTo()->getParameter("tag"); return true; }else{ return false; } }bool SipDialogP2Tuser::a3_callingnoauth_incall_2xx( const SipSMCommand &command){ if (transitionMatch(command, SipResponse::type, IGN, SipSMCommand::TU, "2**")){ //MRef<SipDialogP2Tuser *>vc= (SipDialogP2Tuser *)sipStateMachine; MRef<SipResponse*> resp( (SipResponse*)*command.getCommandPacket() ); /*vc->*/setLogEntry( new LogEntryOutgoingCompletedCall() ); /*vc->*/getLogEntry()->start = time( NULL ); /*vc->*/getLogEntry()->peerSipUri = resp->getFrom().getString(); /*vc->*/dialogState.remoteTag = command.getCommandPacket()->getHeaderValueTo()->getParameter("tag");#if 0 /* Key Agreement response message treatment */ if( vc->getDialogConfig().inherited.secured ){ KeyAgreement * ka = vc->getKeyAgreement(); int32_t kam = vc->getDialogConfig().inherited.ka_type; if( !InitiatorAuthenticate( ((SdpPacket*)*command.getCommandPacket()->getContent())->getKeyMgmt(), ka, vc->getDialogConfig()) ){ merr << "KeyAgreement Response message authentication failed" << end; return false; } /* TODO: send that error message */ string error_message = InitiatorParse( ((SdpPacket*)*command.getCommandPacket()->getContent())->getKeyMgmt(), ka, vc->getDialogConfig().inherited.secured, kam ); vc->getDialogConfig().inherited.ka_type = kam; if( !vc->getDialogConfig().inherited.secured ){ // Some error occured in the key agreement parsing return false; } /* At this point, we can compute the tgk */ //vc->getKeyAgreement()->compute_tgk(); }#endif #if 0 CommandString cmdstr(vc->getCallId(), SipCommandString::invite_ok, "",(vc->getDialogConfig().inherited.secured?"secure":"unprotected"));#else CommandString cmdstr(/*vc->*/getCallId(), SipCommandString::invite_ok, "","unprotected");#endif /*vc->*/getDialogContainer()->getCallback()->sipcb_handleCommand(cmdstr); #if 0 if( vc->getDialogConfig().inherited.secured && vc->getDialogConfig().inherited.ka_type == KEY_MGMT_METHOD_MIKEY_DH ){ ts.save( TGK_START ); ((KeyAgreementDH *)vc->getKeyAgreement())->computeTgk(); ts.save( TGK_END ); }#endif if ( !resp->getContent().isNull() ){ /*vc->*/handleSdp(MRef<SdpPacket*>((SdpPacket*)*resp->getContent())); //vc->openSoundCard(); //vc->getSoundSender()->initCrypto(); //vc->getSoundReceiver()->initCrypto(); //vc->getSoundReceiver()->start(); //vc->getSoundSender()->start(); //vc->getSoundReceiver()->flush(); /*vc->*/reportSipDialogP2T(P2T::STATUS_CONNECTED); }else{ merr << "WARNING: 200 OK did not contain any session description"<< end; } return true; }else return false;}bool SipDialogP2Tuser::a5_incall_termwait_BYE( const SipSMCommand &command){ if (transitionMatch(command, SipBye::type, SipSMCommand::remote, IGN)){ //MRef<SipDialogP2Tuser *> vc = (SipDialogP2Tuser *)sipStateMachine; MRef<SipBye*> bye = (SipBye*) *command.getCommandPacket();/* mdbg << "log stuff"<< end; (dynamic_cast< LogEntrySuccess * >(*( vc->getLogEntry() )) )->duration = std::time( NULL ) - vc->getLogEntry()->start; */ /*vc->*/getLogEntry()->handle(); MRef<SipTransaction*> byeresp = new SipTransactionNonInviteServer(getSipStack(), MRef<SipDialog*>(/* *vc */ this), bye->getCSeq(),bye->getLastViaBranch(), dialogState.callId); //TODO: remove second argument /*vc->*/registerTransaction(byeresp); SipSMCommand cmd(command); cmd.setDestination(SipSMCommand::transaction); cmd.setSource(command.getSource()); /*vc->*/getDialogContainer()->enqueueCommand(cmd, HIGH_PRIO_QUEUE, PRIO_LAST_IN_QUEUE); /*vc->*/sendByeOk(bye, byeresp->getBranch() ); CommandString cmdstr(/*vc->*/getCallId(), SipCommandString::remote_hang_up); /*vc->*/getDialogContainer()->getCallback()->sipcb_handleCommand(cmdstr); // vc->closeSoundCard(); //vc->getSoundSender()->stop(); //vc->getSoundReceiver()->stop(); #if 0 /* FIXME: HACK for the */ if( vc->getDialogContainer()->getPrecomputedKa() == NULL && vc->getDialogConfig().inherited.dh_enabled ) { KeyAgreement * newKa = new KeyAgreementDH( vc->getDialogConfig().inherited.cert, vc->getDialogConfig().inherited.cert_db, DH_GROUP_OAKLEY5 ); vc->getDialogContainer()->setPrecomputedKa( newKa ); }#endif /*vc->*/getP2TDialog()->removeUser(/*vc->*/dialogState.remoteUri, SipCommandString::remote_hang_up, /*vc->*/getCallId()); /*vc->*/signalIfNoTransactions(); return true; }else{ return false; }}bool SipDialogP2Tuser::a6_incall_termwait_hangup(// State<SipSMCommand, string> *fromState,// State<SipSMCommand, string> *toState, const SipSMCommand &command){ if (transitionMatch(command, SipCommandString::hang_up)){ //MRef<SipDialogP2Tuser *>vc = (SipDialogP2Tuser *)sipStateMachine;// /*vc->*/setCurrentState(toState); //int bye_seq_no= /*vc->*/requestSeqNo(); ++dialogState.seqNo; MRef<SipTransaction*> byetrans( new SipTransactionNonInviteClient(getSipStack(), MRef<SipDialog*>(/* *vc */ this), dialogState.seqNo, dialogState.callId)); /*vc->*/registerTransaction(byetrans); /*vc->*/sendBye(byetrans->getBranch(), dialogState.seqNo); /////BUG: Here. Receive Segmentation fault if dialog was started by a incoming INVITE message/* (dynamic_cast< LogEntrySuccess * >(*( vc->getLogEntry() )) )->duration = std::time( NULL ) - vc->getLogEntry()->start; vc->getLogEntry()->handle();*/ // vc->closeSoundCard(); //vc->getSoundSender()->stop(); //vc->getSoundReceiver()->stop();#if 0 /* FIXME: HACK for the */ if( vc->getDialogContainer()->getPrecomputedKa() == NULL && vc->getDialogConfig().inherited.dh_enabled ){ KeyAgreement * newKa = new KeyAgreementDH( vc->getDialogConfig().inherited.cert, vc->getDialogConfig().inherited.cert_db, DH_GROUP_OAKLEY5 ); vc->getDialogContainer()->setPrecomputedKa( newKa ); }#endif //vc->getP2TDialog()->removeUser(vc->getDialogConfig().uri_foreign,"local_hangup", vc->getCallId()); /*vc->*/signalIfNoTransactions();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -