📄 sipdialogvoip.cxx
字号:
(bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1202_transferrequested_transferpending_202, s_transferrequested, s_transferpending); new StateTransition<SipSMCommand,string>(this, "transition_transferrequested_incall_36", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1203_transferrequested_incall_36, s_transferrequested, s_incall); new StateTransition<SipSMCommand,string>(this, "transition_transferpending_transferpending_notify", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1204_transferpending_transferpending_notify, s_transferpending, s_transferpending); new StateTransition<SipSMCommand,string>(this, "transition_transferpending_termwait_BYE", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1001_incall_termwait_BYE, s_transferpending, s_termwait); new StateTransition<SipSMCommand,string>(this, "transition_transferpending_byerequest_hangup", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1002_incall_byerequest_hangup, s_transferpending, s_byerequest); // Remotely initiated call transfer new StateTransition<SipSMCommand,string>(this, "transition_incall_transferaskuser_REFER", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1301_incall_transferaskuser_REFER, s_incall, s_transferaskuser); new StateTransition<SipSMCommand,string>(this, "transition_transferaskuser_transferstarted_accept", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1302_transferaskuser_transferstarted_accept, s_transferaskuser, s_transferstarted); new StateTransition<SipSMCommand,string>(this, "transition_transferaskuser_incall_refuse", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1303_transferaskuser_incall_refuse, s_transferaskuser, s_incall); new StateTransition<SipSMCommand,string>(this, "transition_transferstarted_termwait_bye", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1001_incall_termwait_BYE, s_transferstarted, s_termwait); new StateTransition<SipSMCommand,string>(this, "transition_transferstarted_byerequest_hangup", (bool (StateMachine<SipSMCommand,string>::*)(const SipSMCommand&)) &SipDialogVoip::a1002_incall_byerequest_hangup, s_transferstarted, s_byerequest);}SipDialogVoip::SipDialogVoip( MRef<SipStack*> stack, MRef<SipDialogConfig*> callconfig, MRef<SipSoftPhoneConfiguration*> pconf, MRef<Session *> mediaSession, string cid#ifdef IPSEC_SUPPORT , MRef<MsipIpsecAPI *> ipsecSession#endif ) : SipDialog(stack,callconfig), phoneconf(pconf), mediaSession(mediaSession), lastInvite(NULL)#ifdef IPSEC_SUPPORT , ipsecSession(ipsecSession)#endif{ if (cid=="") dialogState.callId = itoa(rand())+"@"+getDialogConfig()->inherited->externalContactIP; else dialogState.callId = cid; dialogState.localTag = itoa(rand()); /* We will fill that later, once we know if that succeeded */ logEntry = NULL; setUpStateMachine();}SipDialogVoip::~SipDialogVoip(){ mediaSession->unregister();}void SipDialogVoip::sendBye(const string &branch, int bye_seq_no){ MRef<SipRequest*> bye = SipRequest::createSipMessageBye( branch, dialogState.callId, dialogState.getRemoteTarget(), dialogState.remoteUri, getDialogConfig()->inherited->sipIdentity->getSipUri(), bye_seq_no ); //add route headers, if needed if( dialogState.routeSet.size() > 0 ) { //merr << "SipDlgVoip:sendBYE : adding header route! " << end; MRef<SipHeaderValueRoute *> rset = new SipHeaderValueRoute (dialogState.routeSet); bye->addHeader(new SipHeader(*rset) ); } else { //merr << "SipDlgVoip:sendBYE : dialog route set is EMPTY!!! " << end; } bye->getHeaderValueFrom()->setParameter("tag",dialogState.localTag); bye->getHeaderValueTo()->setParameter("tag",dialogState.remoteTag); MRef<SipMessage*> pref(*bye); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogVoip::sendRefer(const string &branch, int refer_seq_no, const string referredUri){/* string tmp = getDialogConfig()->inherited.sipIdentity->getSipUri(); uint32_t i = tmp.find("@"); massert(i!=string::npos); i++; string domain; for ( ; i < tmp.length() ; i++) domain = domain+tmp[i];*/ //MRef<SipRefer*> refer = new SipRefer( MRef<SipRequest*> refer = SipRequest::createSipMessageRefer( branch, getLastInvite(), dialogState.getRemoteTarget(), getDialogConfig()->inherited->sipIdentity->getSipUri(), referredUri, refer_seq_no ); refer->getHeaderValueFrom()->setParameter("tag",dialogState.localTag); refer->getHeaderValueTo()->setParameter("tag",dialogState.remoteTag); MRef<SipMessage*> pref(*refer); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogVoip::sendCancel(const string &branch){ massert( !lastInvite.isNull()); //merr << "SipDialogVoip::sendCancel : dialogstate.remoteUri=" << dialogState.remoteUri << end; //MRef<SipCancel*> cancel = new SipCancel( MRef<SipRequest*> cancel = SipRequest::createSipMessageCancel( branch, lastInvite, dialogState.remoteUri ); cancel->getHeaderValueFrom()->setParameter("tag",dialogState.localTag); // Don't include to-tag, allowing it to be forked by proxies. MRef<SipMessage*> pref(*cancel); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer); dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/ );}void SipDialogVoip::sendReferOk(const string &branch){ MRef<SipResponse*> ok= new SipResponse(branch, 202,"OK", MRef<SipMessage*>(*lastRefer)); ok->getHeaderValueTo()->setParameter("tag",dialogState.localTag); MRef<SipHeaderValue *> contact = new SipHeaderValueContact( getDialogConfig()->inherited->sipIdentity->getSipUri(), getDialogConfig()->inherited->externalContactIP, getDialogConfig()->inherited->getLocalSipPort(phoneconf->useSTUN), "", getDialogConfig()->inherited->getTransport(), -1); //set expires to -1, we do not use it (only in register) ok->addHeader( new SipHeader(*contact) ); MRef<SipMessage*> pref(*ok); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogVoip::sendByeOk(MRef<SipRequest*> bye, const string &branch){ MRef<SipResponse*> ok= new SipResponse( branch, 200,"OK", MRef<SipMessage*>(*bye) ); ok->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// setLastResponse(ok); MRef<SipMessage*> pref(*ok); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogVoip::sendNotifyOk(MRef<SipRequest*> notif, const string &branch){ MRef<SipResponse*> ok= new SipResponse( branch, 200, "OK", MRef<SipMessage*>(*notif) ); ok->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// setLastResponse(ok); MRef<SipMessage*> pref(*ok); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogVoip::sendReferReject(const string &branch){ MRef<SipResponse*> forbidden = new SipResponse(branch, 403,"Forbidden", *lastRefer ); forbidden->getHeaderValueTo()->setParameter("tag",dialogState.localTag); MRef<SipMessage*> pref(*forbidden); SipSMCommand cmd( pref,SipSMCommand::dialog_layer, SipSMCommand::transaction_layer); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}bool SipDialogVoip::handleCommand(const SipSMCommand &c){ mdbg << "SipDialogVoip::handleCommand got "<< c << end; if (c.getType()==SipSMCommand::COMMAND_STRING && dialogState.callId.length()>0){ if (c.getCommandString().getDestinationId() != dialogState.callId ) return false; } if (c.getType()==SipSMCommand::COMMAND_PACKET && dialogState.callId.length()>0){ if (c.getCommandPacket()->getCallId() != dialogState.callId ){ return false; } if (c.getType()!=SipSMCommand::COMMAND_PACKET && c.getCommandPacket()->getCSeq()!= dialogState.seqNo){ return false; } } mdbg << "SipDialogVoip::handleCommand() sending command to Dialog: "<< c << end; bool handled = SipDialog::handleCommand(c); if (!handled && c.getType()==SipSMCommand::COMMAND_STRING && c.getCommandString().getOp()==SipCommandString::no_transactions){ return true; } if (c.getType()==SipSMCommand::COMMAND_STRING && dialogState.callId.length()>0){ if (!handled && c.getCommandString().getDestinationId() == dialogState.callId ){ mdbg << "Warning: SipDialogVoIP ignoring command with matching call id"<< end; return true; } } if (c.getType()==SipSMCommand::COMMAND_PACKET && dialogState.callId.length()>0){ if (!handled && c.getCommandPacket()->getCallId() == dialogState.callId){ mdbg << "Warning: SipDialogVoIP ignoring packet with matching call id"<< end; return true; } } return handled;}MRef<SipRequest*> SipDialogVoip::getLastInvite(){ return lastInvite;}void SipDialogVoip::setLastInvite(MRef<SipRequest*> i){ lastInvite = i; }MRef<LogEntry *> SipDialogVoip::getLogEntry(){ return logEntry;}void SipDialogVoip::setLogEntry( MRef<LogEntry *> logEntry ){ this->logEntry = logEntry;}MRef<Session *> SipDialogVoip::getMediaSession(){ return mediaSession;}#ifdef IPSEC_SUPPORTMRef<MsipIpsecAPI *> SipDialogVoip::getIpsecSession(){ return ipsecSession;}#endifbool SipDialogVoip::sortMIME(MRef<SipMessageContent *> Offer, string peerUri, int type){ if (Offer){ if ( Offer->getContentType().substr(0,9) == "multipart"){ MRef<SipMessageContent *> part; part = ((SipMimeContent*)*Offer)->popFirstPart(); while( *part != NULL){ sortMIME(part, peerUri, type); part = ((SipMimeContent*)*Offer)->popFirstPart(); } }#ifdef IPSEC_SUPPORT if( (Offer->getContentType()).substr(0,17) == "application/mikey"){ switch (type){ case 10: ts.save("setMikeyIpsecOffer"); if(!getIpsecSession()->setMikeyIpsecOffer((SipMimeContent*)*Offer)) return false; ts.save("setMikeyIpsecOffer"); return true; case 3: ts.save("setMikeyIpsecAnswer"); if(!getIpsecSession()->setMikeyIpsecAnswer((SipMimeContent*)*Offer)) return false; ts.save("setMikeyIpsecAnswer"); return true; default: return false; } }#endif if( (Offer->getContentType()).substr(0,15) == "application/sdp"){ switch (type){ case 10:#ifdef ENABLE_TS ts.save("setSdpOffer");#endif if( !getMediaSession()->setSdpOffer( (SdpPacket*)*Offer, peerUri ) ) return false;#ifdef ENABLE_TS ts.save("setSdpOffer");#endif return true; case 3:#ifdef ENABLE_TS ts.save("setSdpAnswer");#endif if( !getMediaSession()->setSdpAnswer( (SdpPacket*)*Offer, peerUri ) ){ cerr << "SDP answer rejected" << endl; return false; } getMediaSession()->start();#ifdef ENABLE_TS ts.save("setSdpAnswer");#endif return true; default: merr << "No SDP match" << end; return false; } } } return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -