📄 sipdialogvoipclient.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,2005,2006 * * Authors: Erik Eliasson <eliasson@it.kth.se> * Johan Bilien <jobi@via.ecp.fr> * Joachim Orrblad <joachim[at]orrblad.com>*//* Name * SipDialogVoipClient.cxx * Author * Erik Eliasson, eliasson@it.kth.se * Purpose * */#include<config.h>#include<libminisip/sip/SipDialogVoipClient.h>#include<libmutil/massert.h>#include<libmsip/SipTransactionInviteClientUA.h>#include<libmsip/SipTransactionInviteServerUA.h>#include<libmsip/SipTransactionNonInviteClient.h>#include<libmsip/SipTransactionNonInviteServer.h>#include<libmsip/SipTransactionUtils.h>#include<libmsip/SipCommandString.h>#include<libmsip/SipHeaderWarning.h>#include<libmsip/SipHeaderContact.h>#include<libmsip/SipHeaderFrom.h>#include<libmsip/SipHeaderRoute.h>#include<libmsip/SipHeaderRequire.h>#include<libmsip/SipHeaderTo.h>#include<libmsip/SipMIMEContent.h>#include<libmsip/SipMessageContent.h>#include<libmutil/itoa.h>#include<libmcrypto/base64.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<libmutil/print_hex.h>#include <iostream>#include<time.h>#ifdef _WIN32_WCE# include"../include/minisip_wce_extra_includes.h"#endifusing namespace std;/* This class is responsible for starting up a session and ending up in the in_call state. The "dotted" states are implemented in SipDialogVoip.cxx. +---------------+ | | | start | | |a26transport_err +---------------+ 100relgui(failed) | a2015:PRACK +------------------+ +----------------+ | invite | | | | V a2001: new TransInvite | prack_sent | | +---------------+----------------->| | | +----| |<------------(*)--+------------------+ | 1xx | |Calling_noauth |----+ 180 |a3:(null)+--->| | | a2002: gui(ringing) (*) 200 OK +--------------+---------------+<---+ a2016: - | | | 2xx/a2004: | cancel|hangup | +------------------------------+ | a2014 | | +----------------+ | 40X | accept_invite | | V a2008: send_auth | a11: send 200 | +---------------+ | | +----| |----+ | | | |Calling_stored | | 180 | | 1XX +--->| |<---+ a2009: gui(ringing) | | a2010 +---------------+ | | | | | | 2xx | | v a2011: | | +. . . . . . . .+ | | . .<---------------------------+ | . in call . | . . | +. . . . . . . .+ | |CANCEL/cancel |a2005/a2006: new TrnsCncl +------------->+. . . . . . . .+ |33/a2007:gui()| . +------------->| termwait . |trnsperr/a2013| . +------------->+. . . . . . . .+ +. . . . . . . .+ . . . terminated . . . +. . . . . . . .+ */bool SipDialogVoipClient::a2001_start_callingnoauth_invite( const SipSMCommand &command){ if (transitionMatch(command, SipCommandString::invite, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer)){#ifdef ENABLE_TS ts.save("a0_start_callingnoauth_invite");#endif ++dialogState.seqNo; //set an "early" remoteUri ... we will update this later dialogState.remoteUri= command.getCommandString().getParam();/* MRef<SipTransaction*> invtrans = new SipTransactionInviteClientUA(sipStack, //MRef<SipDialog *>(this), dialogState.seqNo, "INVITE", dialogState.callId); invtrans->setSocket( phoneconf->proxyConnection ); notifyEarlyTermination = true; // set to true, once sent the first command, set to false dispatcher->getLayerTransaction()->addTransaction(invtrans); //registerTransactionToDialog(invtrans);*/ sendInvite(""/*invtrans->getBranch()*/); return true; }else{ return false; }}bool SipDialogVoipClient::a2002_callingnoauth_callingnoauth_18X( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "18*")){ MRef<SipResponse*> resp= (SipResponse*) *command.getCommandPacket();#ifdef ENABLE_TS ts.save( RINGING );#endif CommandString cmdstr(dialogState.callId, SipCommandString::remote_ringing); sipStack->getCallback()->handleCommand("gui", cmdstr); //We must maintain the dialog state. dialogState.updateState( resp ); //string peerUri = command.getCommandPacket()->getTo().getString(); string peerUri = dialogState.remoteUri; //use the dialog state ... MRef<SipMessageContent *> content = resp->getContent(); if( !content.isNull() ){ MRef<SdpPacket*> sdp((SdpPacket*)*content); //Early media getMediaSession()->setSdpAnswer( sdp, peerUri ); } return true; }else{ return false; }}bool SipDialogVoipClient::a2003_callingnoauth_callingnoauth_1xx( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "1**")){ dialogState.updateState( MRef<SipResponse*>((SipResponse *)*command.getCommandPacket()) ); return true; }else{ return false; } }bool SipDialogVoipClient::a2004_callingnoauth_incall_2xx( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "2**")){#ifdef ENABLE_TS ts.save("a3_callingnoauth_incall_2xx");#endif MRef<SipResponse*> resp( (SipResponse*)*command.getCommandPacket() ); string peerUri = dialogState.remoteUri; if(!sortMIME(*resp->getContent(), peerUri, 3)) return false; dialogState.updateState( resp ); //string peerUri = resp->getFrom().getString(); setLogEntry( new LogEntryOutgoingCompletedCall() ); getLogEntry()->start = time( NULL ); getLogEntry()->peerSipUri = peerUri;//FIXME: CESC: for now, route set is updated at the transaction layer CommandString cmdstr(dialogState.callId, SipCommandString::invite_ok, "", (getMediaSession()->isSecure()?"secure":"unprotected")); sipStack->getCallback()->handleCommand("gui", cmdstr); #ifdef IPSEC_SUPPORT // Check if IPSEC was required if (ipsecSession->required() && !ipsecSession->offered) return false;#endif return true; }else{ return false; }}bool SipDialogVoipClient::a2005_callingnoauth_termwait_CANCEL( const SipSMCommand &command){ if (transitionMatch("CANCEL", command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer)){// setCurrentState(toState);/* MRef<SipTransaction*> cancelresp( new SipTransactionNonInviteServer( sipStack, //MRef<SipDialog*>(this), command.getCommandPacket()->getCSeq(), command.getCommandPacket()->getCSeqMethod(), command.getCommandPacket()->getLastViaBranch(), dialogState.callId )); dispatcher->getLayerTransaction()->addTransaction(cancelresp); //registerTransactionToDialog(cancelresp); SipSMCommand cmd(command); cmd.setSource(SipSMCommand::dialog_layer); cmd.setDestination(SipSMCommand::transaction_layer); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE);*/ getMediaSession()->stop(); signalIfNoTransactions(); return true; }else{ return false; }}bool SipDialogVoipClient::a2006_callingnoauth_termwait_cancel( const SipSMCommand &command){ if ( transitionMatch(command, SipCommandString::cancel, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer) || transitionMatch(command, SipCommandString::hang_up, SipSMCommand::dialog_layer, SipSMCommand::dialog_layer)){// setCurrentState(toState);/* string inv_branch = getLastInvite()->getFirstViaBranch(); MRef<SipTransaction*> canceltrans( new SipTransactionNonInviteClient(sipStack, //MRef<SipDialog*>( this ), dialogState.seqNo, "CANCEL", dialogState.callId)); canceltrans->setBranch(inv_branch); dispatcher->getLayerTransaction()->addTransaction(canceltrans); //registerTransactionToDialog(canceltrans);*/ sendCancel(""/*inv_branch*/); getMediaSession()->stop(); signalIfNoTransactions(); return true; }else{ return false; }}//Note: This is also used as: callingauth_terminated_36bool SipDialogVoipClient::a2007_callingnoauth_termwait_36( const SipSMCommand &command){ if (transitionMatch(SipResponse::type, command, SipSMCommand::transaction_layer, SipSMCommand::dialog_layer, "3**\n4**\n5**\n6**")){ MRef<LogEntry *> rejectedLog( new LogEntryCallRejected() ); rejectedLog->start = time( NULL ); rejectedLog->peerSipUri = dialogState.remoteTag; if (sipResponseFilterMatch(MRef<SipResponse*>((SipResponse*)*command.getCommandPacket()),"404")){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -