diff --git a/apps/sbc/CallLeg.cpp b/apps/sbc/CallLeg.cpp index b65ed4fb..e43ebcf3 100644 --- a/apps/sbc/CallLeg.cpp +++ b/apps/sbc/CallLeg.cpp @@ -184,6 +184,12 @@ static bool isHoldRequest(AmSdp &sdp, HoldMethod &method) return true; // no active stream was found } +static bool isDSMEarlyAnnounceForced(const std::string &hdrs) +{ + string announce = getHeader(hdrs, SIP_HDR_P_DSM_APP); + string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); + return p_dsm_app_param == DSM_VALUE_FORCE; +} //////////////////////////////////////////////////////////////////////////////// @@ -554,9 +560,7 @@ void CallLeg::onInitialReply(B2BSipReplyEvent *e) { /* 100-199 */ if (e->reply.code < 200) { - string announce = getHeader(e->reply.hdrs, SIP_HDR_P_DSM_APP); - string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); - dlg->setForcedEarlyAnnounce(p_dsm_app_param == DSM_VALUE_FORCE); + dlg->setForcedEarlyAnnounce(isDSMEarlyAnnounceForced(e->reply.hdrs)); /* exceptionally treat 183 with the 'P-DSM-App: ;early-announce=force', similarly to the 200OK response, this will properly update the caller @@ -568,7 +572,7 @@ void CallLeg::onInitialReply(B2BSipReplyEvent *e) - pre-announce - play-last-caller - office-hours */ - if (e->reply.code == 183 && !announce.empty() && dlg->getForcedEarlyAnnounce()) { + if (e->reply.code == 183 && dlg->getForcedEarlyAnnounce()) { b2bInitial2xx(e->reply, e->forward); } else { b2bInitial1xx(e->reply, e->forward); diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index 25250772..cd536354 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -62,6 +62,23 @@ static void errCode2RelayedReply(AmSipReply &reply, int err_code, unsigned defau } } +static bool isDSMEarlyAnnounceForced(const std::string &hdrs) +{ + string announce = getHeader(hdrs, SIP_HDR_P_DSM_APP); + string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); + return p_dsm_app_param == DSM_VALUE_FORCE; +} + +static bool isDSMPlaybackFinished(const std::string &hdrs) +{ + /** TODO: for the future, we might also want to check + * particular DSM applications, for now plays no role. + */ + string p_dsm_app = getHeader(hdrs, SIP_HDR_P_DSM_APP, true); + string p_dsm_app_param = get_header_param(p_dsm_app, DSM_PARAM_PLAYBACK); + return p_dsm_app_param == DSM_VALUE_FINISHED; +} + // // AmB2BSession methods // @@ -296,9 +313,7 @@ void AmB2BSession::onB2BEvent(B2BEvent* ev) /* ensure that 'P-DSM-App: ;early-announce=force' is not present */ if (reply_ev->reply.code == 183 && !dlg->getForcedEarlyAnnounce()) { - string announce = getHeader(reply_ev->reply.hdrs, SIP_HDR_P_DSM_APP); - string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); - dlg->setForcedEarlyAnnounce(p_dsm_app_param == DSM_VALUE_FORCE); + dlg->setForcedEarlyAnnounce(isDSMEarlyAnnounceForced(reply_ev->reply.hdrs)); } /* don't forget to reset the force_early_announce, if 200 OK in the same leg received */ @@ -353,24 +368,14 @@ void AmB2BSession::onB2BEvent(B2BEvent* ev) /* 480 - processing of the playback completion from DSM applications */ } else if (reply_ev->reply.code == 480 && dlg->getStatus() == AmSipDialog::Connected) { - string p_dsm_app = getHeader(reply_ev->reply.hdrs, SIP_HDR_P_DSM_APP, true); - /* TT#188800, if this is a completion of the playback of one of the DSM applications, (office hours, play last caller, pre announce, early dbprompt) in the session, which has had AA or a transfer before going to this DSM application, then a caller is now likely in the connected state, and requires BYE, not 480 */ - if (p_dsm_app.find(DSM_APP_OH) != std::string::npos || - p_dsm_app.find(DSM_APP_PRE_AN) != std::string::npos || - p_dsm_app.find(DSM_APP_EARLYDB_PR) != std::string::npos || - p_dsm_app.find(DSM_APP_P_L_CALLER) != std::string::npos) { - - /* check the ;playback= parameter */ - string p_dsm_app_param = get_header_param(p_dsm_app, DSM_PARAM_PLAYBACK); - if (p_dsm_app_param == DSM_VALUE_FINISHED) { - DBG("This is the end of DSM playback, the caller is in the connected state.\n"); - DBG("Terminating the original leg with BYE, instead of 480.\n"); - terminateLeg(); - } + if (isDSMPlaybackFinished(reply_ev->reply.hdrs)) { + DBG("This is the end of DSM playback, the caller is in the connected state.\n"); + DBG("Terminating the original leg with BYE, instead of 480.\n"); + terminateLeg(); } } } diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp index f0e5efb6..29ad4d7e 100644 --- a/core/AmSipDialog.cpp +++ b/core/AmSipDialog.cpp @@ -41,6 +41,10 @@ #include "global_defs.h" +// +// helper functions +// + static void addTranscoderStats(string &hdrs) { // add transcoder statistics into request/reply headers @@ -62,6 +66,13 @@ static void addTranscoderStats(string &hdrs) } } +static bool isDSMEarlyAnnounceForced(const std::string &hdrs) +{ + string announce = getHeader(hdrs, SIP_HDR_P_DSM_APP); + string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); + return p_dsm_app_param == DSM_VALUE_FORCE; +} + AmSipDialog::AmSipDialog(AmSipDialogEventHandler* h) : AmBasicSipDialog(h),oa(this),rel100(this,h), offeranswer_enabled(true), @@ -409,9 +420,7 @@ bool AmSipDialog::onRxReplyStatus(const AmSipReply& reply) /* 100-199 */ if (reply.code < 200) { - string announce = getHeader(reply.hdrs, SIP_HDR_P_DSM_APP, true); - string p_dsm_app_param = get_header_param(announce, DSM_PARAM_EARLY_AN); - setForcedEarlyAnnounce(p_dsm_app_param == DSM_VALUE_FORCE); + setForcedEarlyAnnounce(isDSMEarlyAnnounceForced(reply.hdrs)); /* we should always keep Route set for this leg updated in case the provisional response updates the list of routes for any reason */ @@ -429,10 +438,11 @@ bool AmSipDialog::onRxReplyStatus(const AmSipReply& reply) And furthermore will give the possibility to receive and forward BYE. DSM applications using it: - - early-dbprompt (early_announce) + - early-dbprompt - pre-announce + - play-last-caller - office-hours */ - if (reply.code == 183 && !announce.empty() && getForcedEarlyAnnounce()) { + if (reply.code == 183 && getForcedEarlyAnnounce()) { DBG("This is 183 with <;%s=%s>, treated exceptionally as 200OK.\n", DSM_PARAM_EARLY_AN, DSM_VALUE_FORCE); setStatus(Connected);