From a25f4808976a75c7d76a1510682e042acef072dc Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Tue, 4 Apr 2023 10:08:49 +0200 Subject: [PATCH] MT#56321 DSM: Introduce processing of the ';reset-to-tag=' parameter The new parameter of the 'P-DSM-App:' header is introduced: - ';reset-to-tag='' It affects the processing of 18X (especially it relates to 183). If this is set to '1', then the To-tag stored as the remote tag in the 'dlg' object, must be updated to the latest one provided by this 183. This fixes the case as the following one: - A calls B (B is an owner of the callqueue) - B starts ringing, and provides the To-tag with 180 - this in its turn, will initiate generation of own "internally" generated To-tags in all the internal legs between Proxy <-> B2B, which are crossed by this 180 - B responds with 486 Busy and a processing gets inside the route[ROUTE_EARLY_REJECT] - the brand-new INVITE is generated and sent to the DSM early_dbprompt app - A brand-new 183 is provided by the DSM app, which has another (new) To-tag - this will mismatch in the very original leg with Proxy and B2B and 183 will be not sent towards the caller, which makes impossible to provide an early reject playback to it Original ticket number: 0055878 Change-Id: I96abbe0b8427d40752967607d2fdd0e11145a06a --- core/AmB2BSession.cpp | 25 +++++++++++++++++++------ core/sip/defs.h | 10 ++++++---- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index d9b73aa4..79171f72 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -64,9 +64,8 @@ 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; + string p_dsm_app = getHeader(hdrs, SIP_HDR_P_DSM_APP, true); + return get_header_param(p_dsm_app, DSM_PARAM_EARLY_AN) == DSM_VALUE_FORCE; } static bool isDSMPlaybackFinished(const std::string &hdrs) @@ -75,8 +74,13 @@ static bool isDSMPlaybackFinished(const std::string &hdrs) * 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; + return get_header_param(p_dsm_app, DSM_PARAM_PLAYBACK) == DSM_VALUE_FINISHED; +} + +static bool isDSMToTagReset(const std::string &hdrs) +{ + string p_dsm_app = getHeader(hdrs, SIP_HDR_P_DSM_APP, true); + return get_header_param(p_dsm_app, DSM_PARAM_RESET_TOTAG) == DSM_VALUE_IS_SET; } // @@ -553,12 +557,21 @@ void AmB2BSession::onSipReply(const AmSipRequest& req, const AmSipReply& reply, { TransMap::iterator t = relayed_req.find(reply.cseq); bool fwd = (t != relayed_req.end()) && (reply.code != 100); + bool to_tag_reset = isDSMToTagReset(reply.hdrs); /* check P-DSM-App: ;reset-to-tag=1 */ DBG("onSipReply: %s -> %i %s (fwd=%s), c-t=%s\n", reply.cseq_method.c_str(), reply.code,reply.reason.c_str(), fwd?"true":"false",reply.body.getCTStr().c_str()); - if(!dlg->getRemoteTag().empty() && dlg->getRemoteTag() != reply.to_tag) { + if (to_tag_reset && !dlg->getRemoteTag().empty() && reply.code >= 180 && reply.code <= 183 ) { + DBG("onSipReply: sess %p received %i reply with remote-tag %s", this, reply.code, reply.to_tag.c_str()); + DBG("dlg->getRemoteTag(%s)\n", dlg->getRemoteTag().c_str()); + DBG("dlg->setRemoteTag(%s)\n", reply.to_tag.c_str()); + + // Overwrite the existing to RemoteTag with the received one in order to store always the last + dlg->setRemoteTag(reply.to_tag.c_str()); + } + else if(!dlg->getRemoteTag().empty() && dlg->getRemoteTag() != reply.to_tag) { DBG("sess %p received %i reply with != to-tag: %s (remote-tag:%s)", this, reply.code, reply.to_tag.c_str(),dlg->getRemoteTag().c_str()); return; // drop packet diff --git a/core/sip/defs.h b/core/sip/defs.h index 35a51927..b4fed09b 100644 --- a/core/sip/defs.h +++ b/core/sip/defs.h @@ -56,11 +56,13 @@ #define SIP_HDR_REPLACES "Replaces" #define SIP_HDR_P_DSM_APP "P-DSM-App" -#define DSM_PARAM_EARLY_AN "early-announce" -#define DSM_PARAM_PLAYBACK "playback" +#define DSM_PARAM_EARLY_AN "early-announce" +#define DSM_PARAM_PLAYBACK "playback" +#define DSM_PARAM_RESET_TOTAG "reset-to-tag" -#define DSM_VALUE_FORCE "force" -#define DSM_VALUE_FINISHED "finished" +#define DSM_VALUE_FORCE "force" +#define DSM_VALUE_FINISHED "finished" +#define DSM_VALUE_IS_SET "1" #define SIP_HDR_COL(_hdr) _hdr ":" #define SIP_HDR_COLSP(_hdr) SIP_HDR_COL(_hdr) " "