📄 sipdialogconfvoip.cxx
字号:
//return; } } else mikey = NULL; MRef<SipMimeContent*> multi; if (mikey && mediaSession){ multi = new SipMimeContent("multipart/mixed"); multi->addPart(*mikey); multi->addPart(*sdp); ack->setContent( *multi); } if (mikey && !mediaSession) ack->setContent( *mikey); if (!mikey && mediaSession) ack->setContent( *sdp );#else ack->setContent( *sdp );#endif//-------------------------------------------------------------------------------------------------------------//// /* Get the SDP Answer from the MediaSession */// MRef<SdpPacket *> sdpAnswer = mediaSession->getSdpAnswer();//// if( sdpAnswer ){// ok->setContent( *sdpAnswer );// }// /* if sdp is NULL, the offer was refused, send 606 */// // FIXME// else return; ///modifyConfOk(ack);// setLastResponse(ok); modifyConfAck(ack); MRef<SipProxy *> proxy = getDialogConfig()->inherited->sipIdentity->getSipProxy(); ack->addRoute( proxy->sipProxyAddressString, proxy->sipProxyPort, proxy->getTransport() ); MRef<SipMessage*> pref(*ack); dispatcher->getLayerTransport()->sendMessage(pref, string("ACK"), true); // SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd);// dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE, PRIO_FIRST_IN_QUEUE);}//#endifvoid SipDialogConfVoip::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 ); 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 SipDialogConfVoip::sendCancel(const string &branch){ massert( !lastInvite.isNull()); //MRef<SipCancel*> cancel = new SipCancel( MRef<SipRequest*> cancel = SipRequest::createSipMessageCancel( branch, lastInvite, dialogState.remoteUri ); cancel->getHeaderValueFrom()->setParameter("tag",dialogState.localTag); cancel->getHeaderValueTo()->setParameter("tag",dialogState.remoteTag); MRef<SipMessage*> pref(*cancel); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand( cmd ); dispatcher->enqueueCommand( cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/ );}void SipDialogConfVoip::sendInviteOk(const string &branch){ MRef<SipResponse*> ok= new SipResponse(branch, 200,"OK", MRef<SipMessage*>(*getLastInvite())); ok->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// There might be so that there are no SDP. Check! MRef<SdpPacket *> sdp; if (mediaSession){#ifdef ENABLE_TS ts.save("getSdpAnswer");#endif sdp = mediaSession->getSdpAnswer();#ifdef ENABLE_TS ts.save("getSdpAnswer");#endif if( !sdp ){ // FIXME: this most probably means that the // creation of the MIKEY message failed, it // should not happen merr << "Sdp was NULL in sendInvite" << end; return; } } /* Add the latter to the INVITE message */ // If it exists //-------------------------------------------------------------------------------------------------------------//#ifdef IPSEC_SUPPORT // Create a MIKEY message for IPSEC if stated in the config file. MRef<SipMimeContent*> mikey; if (getIpsecSession()->required()){ ts.save("getMikeyIpsecAnswer"); mikey = ipsecSession->getMikeyIpsecAnswer(); ts.save("getMikeyIpsecAnswer"); if (!mikey){ merr << "Mikey was NULL in sendInviteOk" << end; merr << "Still some errors with IPSEC" << end; //return; } } else mikey = NULL; MRef<SipMimeContent*> multi; if (mikey && mediaSession){ multi = new SipMimeContent("multipart/mixed"); multi->addPart(*mikey); multi->addPart(*sdp); ok->setContent( *multi); } if (mikey && !mediaSession) ok->setContent( *mikey); if (!mikey && mediaSession) ok->setContent( *sdp );#else ok->setContent( *sdp );#endif//-------------------------------------------------------------------------------------------------------------//// /* Get the SDP Answer from the MediaSession */// MRef<SdpPacket *> sdpAnswer = mediaSession->getSdpAnswer();//// if( sdpAnswer ){// ok->setContent( *sdpAnswer );// }// /* if sdp is NULL, the offer was refused, send 606 */// // FIXME// else return; modifyConfOk(ok);// //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 SipDialogConfVoip::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 SipDialogConfVoip::sendReject(const string &branch){ MRef<SipResponse*> ringing = new SipResponse(branch,486,"Temporary unavailable", MRef<SipMessage*>(*getLastInvite())); ringing->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// setLastResponse(ringing); MRef<SipMessage*> pref(*ringing); SipSMCommand cmd( pref,SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogConfVoip::sendRinging(const string &branch){ MRef<SipResponse*> ringing = new SipResponse(branch,180,"Ringing", MRef<SipMessage*>(*getLastInvite())); ringing->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// setLastResponse(ringing); MRef<SipMessage*> pref(*ringing); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}void SipDialogConfVoip::sendNotAcceptable(const string &branch){ MRef<SipResponse*> not_acceptable = new SipResponse(branch,606,"Not Acceptable", MRef<SipMessage*>(*getLastInvite())); if( mediaSession && mediaSession->getErrorString() != "" ){ not_acceptable->addHeader( new SipHeader(new SipHeaderValueWarning(getDialogConfig()->inherited->externalContactIP, 399, mediaSession->getErrorString() ) )); } not_acceptable->getHeaderValueTo()->setParameter("tag",dialogState.localTag);// setLastResponse(not_acceptable); MRef<SipMessage*> pref(*not_acceptable); SipSMCommand cmd( pref, SipSMCommand::dialog_layer, SipSMCommand::transaction_layer);// handleCommand(cmd); dispatcher->enqueueCommand(cmd, HIGH_PRIO_QUEUE/*, PRIO_LAST_IN_QUEUE*/);}bool SipDialogConfVoip::handleCommand(const SipSMCommand &c){ mdbg << "SipDialogConfVoip::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; } } // if (c.getType()!=SipSMCommand::COMMAND_PACKET && // c.getCommandPacket()->getCSeq()!= command_seq_no)// return false; mdbg << "SipDialogConfVoip::handlePacket() got "<< 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 (c.getCommandString().getDestinationId() == dialogState.callId ){ mdbg << "Warning: SipDialogConfVoip ignoring command with matching call id"<< end; return true; } } if (c.getType()==SipSMCommand::COMMAND_PACKET && dialogState.callId.length()>0){ if (c.getCommandPacket()->getCallId() == dialogState.callId){ mdbg << "Warning: SipDialogConfVoip ignoring packet with matching call id"<< end; return true; } } return handled;}MRef<SipRequest*> SipDialogConfVoip::getLastInvite(){ return lastInvite;}void SipDialogConfVoip::setLastInvite(MRef<SipRequest*> i){ lastInvite = i; }MRef<LogEntry *> SipDialogConfVoip::getLogEntry(){ return logEntry;}void SipDialogConfVoip::setLogEntry( MRef<LogEntry *> logEntry ){ this->logEntry = logEntry;}MRef<Session *> SipDialogConfVoip::getMediaSession(){ return mediaSession;}#ifdef IPSEC_SUPPORTMRef<MsipIpsecAPI *> SipDialogConfVoip::getIpsecSession(){ return ipsecSession;}#endifbool SipDialogConfVoip::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 ) ) return false; getMediaSession()->start();#ifdef ENABLE_TS ts.save("setSdpAnswer");#endif return true; default: merr << "No SDP match" << end; return false; } } } return true;}void SipDialogConfVoip::modifyConfJoinInvite(MRef<SipRequest*>inv){ //Add Accept-Contact Header //inv->set_ConfJoin(); MRef<SipHeaderValueAcceptContact*> acp = new SipHeaderValueAcceptContact("+sip.confjoin=\"TRUE\"",false,true); inv->addHeader(new SipHeader(*acp) ); //Add SDP Session Level Attributes //cerr<<"modify join 1111111111111111"<<endl; massert(dynamic_cast<SdpPacket*>(*inv->getContent())!=NULL); MRef<SdpPacket*> sdp = (SdpPacket*)*inv->getContent(); sdp->setSessionLevelAttribute("confId", confId); sdp->setSessionLevelAttribute("conf_#participants", itoa((*adviceList).size())); for(int t=0;t<numConnected;t++) { sdp->setSessionLevelAttribute("participant_"+itoa(t+1), ((*adviceList)[t]).uri); } //cerr<<"modify join 22222222222222222"<<endl;}void SipDialogConfVoip::modifyConfAck(MRef<SipRequest*>ack){ //Add Accept-Contact Header ack->addHeader(new SipHeader(new SipHeaderValueAcceptContact("+sip.conf=\"TRUE\"",true,false)) ); //cerr<<"modify ack 1111111111111111"<<endl; //Add SDP Session Level Attributes massert(dynamic_cast<SdpPacket*>(*ack->getContent())!=NULL); MRef<SdpPacket*> sdp = (SdpPacket*)*ack->getContent(); int numParticipants=(*adviceList).size(); for(int t=0;t<(*adviceList).size();t++) { //cerr<<"*adviceList))[t]).uri: "+(((*adviceList))[t]).uri<<endl; //cerr<<"dialogState.remoteUri "+dialogState.remoteUri<<endl; if((((*adviceList))[t]).uri!=dialogState.remoteUri) { sdp->setSessionLevelAttribute("participant_"+itoa(t+1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -