<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15368">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip, app_transfer: Add TRANSFERSTATUSPROTOCOL variable<br><br>When a Transfer/REFER is executed, TRANSFERSTATUSPROTOCOL variable is<br>0 when no protocl specific error<br>SIP example of failure, 3xx-6xx for the SIP error code received<br><br>This allows applications to perform actions based on the failure<br>reason.<br><br>ASTERISK-29252 #close<br>Reported-by: Dan Cropp<br><br>Change-Id: Ia6a94784b4925628af122409cdd733c9f29abfc4<br>---<br>M apps/app_transfer.c<br>M channels/chan_pjsip.c<br>A doc/CHANGES-staging/app_transferprotocol.txt<br>M include/asterisk/channel.h<br>M main/channel.c<br>5 files changed, 86 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_transfer.c b/apps/app_transfer.c</span><br><span>index 4fe3dca..d152340 100644</span><br><span>--- a/apps/app_transfer.c</span><br><span>+++ b/apps/app_transfer.c</span><br><span>@@ -69,6 +69,14 @@</span><br><span> Transfer unsupported by channel driver.</span><br><span> </value></span><br><span> </variable></span><br><span style="color: hsl(120, 100%, 40%);">+ <variable name="TRANSFERSTATUSPROTOCOL"></span><br><span style="color: hsl(120, 100%, 40%);">+ <value name="0"></span><br><span style="color: hsl(120, 100%, 40%);">+ No error.</span><br><span style="color: hsl(120, 100%, 40%);">+ </value></span><br><span style="color: hsl(120, 100%, 40%);">+ <value name="3xx-6xx"></span><br><span style="color: hsl(120, 100%, 40%);">+ SIP example - Error result code.</span><br><span style="color: hsl(120, 100%, 40%);">+ </value></span><br><span style="color: hsl(120, 100%, 40%);">+ </variable></span><br><span> </variablelist></span><br><span> </description></span><br><span> </application></span><br><span>@@ -85,6 +93,8 @@</span><br><span> char *dest = NULL;</span><br><span> char *status;</span><br><span> char *parse;</span><br><span style="color: hsl(120, 100%, 40%);">+ int protocol = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ char status_protocol[20];</span><br><span> AST_DECLARE_APP_ARGS(args,</span><br><span> AST_APP_ARG(dest);</span><br><span> );</span><br><span>@@ -92,6 +102,8 @@</span><br><span> if (ast_strlen_zero((char *)data)) {</span><br><span> ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");</span><br><span> pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);</span><br><span> return 0;</span><br><span> } else</span><br><span> parse = ast_strdupa(data);</span><br><span>@@ -106,6 +118,8 @@</span><br><span> /* Allow execution only if the Tech/destination agrees with the type of the channel */</span><br><span> if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) {</span><br><span> pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);</span><br><span> return 0;</span><br><span> }</span><br><span> }</span><br><span>@@ -113,10 +127,14 @@</span><br><span> /* Check if the channel supports transfer before we try it */</span><br><span> if (!ast_channel_tech(chan)->transfer) {</span><br><span> pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_transfer(chan, dest);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* New transfer API returns a protocol code</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP example, 0 = success, 3xx-6xx are sip error codes for the REFER */</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_transfer_protocol(chan, dest, &protocol);</span><br><span> </span><br><span> if (res < 0) {</span><br><span> status = "FAILURE";</span><br><span>@@ -126,7 +144,11 @@</span><br><span> res = 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "ast_transfer channel %s TRANSFERSTATUS=%s, TRANSFERSTATUSPROTOCOL=%s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_name(chan), status, status_protocol);</span><br><span> pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);</span><br><span style="color: hsl(120, 100%, 40%);">+ pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);</span><br><span> </span><br><span> return res;</span><br><span> }</span><br><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index e0c0eeb..3b03621 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -1966,12 +1966,17 @@</span><br><span> rdata = event->body.tsx_state.src.rdata;</span><br><span> msg = rdata->msg_info.msg;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!pjsip_method_cmp(&msg->line.req.method, pjsip_get_notify_method())) {</span><br><span style="color: hsl(0, 100%, 40%);">- body = msg->body;</span><br><span style="color: hsl(0, 100%, 40%);">- if (body && !pj_stricmp2(&body->content_type.type, "message")</span><br><span style="color: hsl(0, 100%, 40%);">- && !pj_stricmp2(&body->content_type.subtype, "sipfrag")) {</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_parse_status_line((char *)body->data, body->len, &status_line);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg->type == PJSIP_REQUEST_MSG) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pjsip_method_cmp(&msg->line.req.method, pjsip_get_notify_method())) {</span><br><span style="color: hsl(120, 100%, 40%);">+ body = msg->body;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (body && !pj_stricmp2(&body->content_type.type, "message")</span><br><span style="color: hsl(120, 100%, 40%);">+ && !pj_stricmp2(&body->content_type.subtype, "sipfrag")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_parse_status_line((char *)body->data, body->len, &status_line);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ status_line.code = msg->line.status.code;</span><br><span style="color: hsl(120, 100%, 40%);">+ status_line.reason = msg->line.status.reason;</span><br><span> }</span><br><span> } else {</span><br><span> status_line.code = 500;</span><br><span>@@ -1984,12 +1989,16 @@</span><br><span> res = -1;</span><br><span> </span><br><span> /* If the subscription has terminated, return AST_TRANSFER_SUCCESS for 2XX.</span><br><span style="color: hsl(0, 100%, 40%);">- * Any other status code returns AST_TRANSFER_FAILED.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Return AST_TRANSFER_FAILED for any code < 200.</span><br><span style="color: hsl(120, 100%, 40%);">+ * Otherwise, return the status code.</span><br><span> * The subscription should not terminate for any code < 200,</span><br><span> * but if it does, that constitutes a failure. */</span><br><span style="color: hsl(0, 100%, 40%);">- if (status_line.code < 200 || status_line.code >= 300) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (status_line.code < 200) {</span><br><span> message = AST_TRANSFER_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (status_line.code >= 300) {</span><br><span style="color: hsl(120, 100%, 40%);">+ message = status_line.code;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* If subscription not terminated and subscription is finished (status code >= 200)</span><br><span> * terminate it */</span><br><span> if (!is_last) {</span><br><span>diff --git a/doc/CHANGES-staging/app_transferprotocol.txt b/doc/CHANGES-staging/app_transferprotocol.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..5d3521b</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_transferprotocol.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: chan_pjsip, app_transfer</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Added TRANSFERSTATUSPROTOCOL variable. When transfer is performed,</span><br><span style="color: hsl(120, 100%, 40%);">+transfers can pass a protocol specific error code.</span><br><span style="color: hsl(120, 100%, 40%);">+Example, in SIP 3xx-6xx represent any SIP specific error received when</span><br><span style="color: hsl(120, 100%, 40%);">+performing a REFER.</span><br><span>diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index 1013003..5bf6c51 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2579,6 +2579,18 @@</span><br><span> int ast_transfer(struct ast_channel *chan, char *dest);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Transfer a channel (if supported) receieve protocol result.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on error</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if not supported</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 if supported and requested</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan current channel</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param dest destination extension for transfer</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param protocol specific error code in case of failure</span><br><span style="color: hsl(120, 100%, 40%);">+ * Example, sip 0 success, else sip error code</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Inherits channel variable from parent to child channel</span><br><span> * \param parent Parent channel</span><br><span> * \param child Child channel</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index 67c17db..253b663 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -6487,8 +6487,30 @@</span><br><span> */</span><br><span> int ast_transfer(struct ast_channel *chan, char *dest)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ int protocol;</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_transfer_protocol(chan, dest, &protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ \brief Transfer a call to dest, if the channel supports transfer</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ \param chan channel to transfer</span><br><span style="color: hsl(120, 100%, 40%);">+ \param dest destination to transfer to</span><br><span style="color: hsl(120, 100%, 40%);">+ \param protocol is the protocol result</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP example, 0=success, 3xx-6xx is SIP error code</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ Called by:</span><br><span style="color: hsl(120, 100%, 40%);">+ \arg app_transfer</span><br><span style="color: hsl(120, 100%, 40%);">+ \arg the manager interface</span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span> int res = -1;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (protocol) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *protocol = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Stop if we're a zombie or need a soft hangup */</span><br><span> ast_channel_lock(chan);</span><br><span> if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {</span><br><span>@@ -6522,6 +6544,13 @@</span><br><span> res = 1;</span><br><span> } else {</span><br><span> res = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Message can contain a protocol specific code</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TRANSFER_SUCCESS indicates success</span><br><span style="color: hsl(120, 100%, 40%);">+ Else, failure. Protocol will be set to the failure reason.</span><br><span style="color: hsl(120, 100%, 40%);">+ SIP example, 0 is success, else error code 3xx-6xx */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (protocol) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *protocol = *message;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> ast_frfree(fr);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15368">change 15368</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15368"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Ia6a94784b4925628af122409cdd733c9f29abfc4 </div>
<div style="display:none"> Gerrit-Change-Number: 15368 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Dan Cropp <dan@amtelco.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-CC: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>