<p>Dan Cropp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15338">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip: Transfer failure sip result passed through<br>channel: Transfer parameter returns the sip protocol error code<br>control: Redirect support additional transfer protocol parameter<br>app_transfer: TRANSFERSTATUSPROTOCOL channel variable addition<br><br>When a Transfer/REFER is executed, the SIP protocol code is now<br>passed from chan_pjsip through the channel to the application<br>layer. Application layer sets the TRANSFERSTATUSPROTOCOL<br>channel variable to this value.<br><br>This allows applications to detect the failure reason and<br>take different actions based on the failure 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>M include/asterisk/channel.h<br>M main/channel.c<br>M res/stasis/control.c<br>5 files changed, 49 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/38/15338/1</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..9640f03 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 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,7 +102,10 @@</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 style="color: hsl(120, 100%, 40%);">+ </span><br><span> } else</span><br><span> parse = ast_strdupa(data);</span><br><span> </span><br><span>@@ -106,6 +119,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 +128,12 @@</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%);">+ res = ast_transfer(chan, dest, &protocol);</span><br><span> </span><br><span> if (res < 0) {</span><br><span> status = "FAILURE";</span><br><span>@@ -126,7 +143,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 483cd3e..c741425 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -1982,12 +1982,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>@@ -2000,12 +2005,17 @@</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> }</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 style="color: hsl(120, 100%, 40%);">+ }</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/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index baefedd..45ef0c2 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -2637,8 +2637,9 @@</span><br><span> * \retval 1 if supported and requested</span><br><span> * \param chan current channel</span><br><span> * \param dest destination extension for transfer</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param protocol result code for transfer (0 success, else sip error code)</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-int ast_transfer(struct ast_channel *chan, char *dest);</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_transfer(struct ast_channel *chan, char *dest, int *protocol);</span><br><span> </span><br><span> /*!</span><br><span> * \brief Inherits channel variable from parent to child channel</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index d75c615..5e269d9 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -6466,10 +6466,13 @@</span><br><span> \arg app_transfer</span><br><span> \arg the manager interface</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">-int ast_transfer(struct ast_channel *chan, char *dest)</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_transfer(struct ast_channel *chan, char *dest, int *protocol)</span><br><span> {</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> /* 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>@@ -6503,6 +6506,8 @@</span><br><span> res = 1;</span><br><span> } else {</span><br><span> res = -1;</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> }</span><br><span> </span><br><span> ast_frfree(fr);</span><br><span>diff --git a/res/stasis/control.c b/res/stasis/control.c</span><br><span>index 584e60e..c95b4f2 100644</span><br><span>--- a/res/stasis/control.c</span><br><span>+++ b/res/stasis/control.c</span><br><span>@@ -483,11 +483,12 @@</span><br><span> {</span><br><span> char *endpoint = data;</span><br><span> int res;</span><br><span style="color: hsl(120, 100%, 40%);">+ int protocol = 0;</span><br><span> </span><br><span> ast_assert(control->channel != NULL);</span><br><span> ast_assert(endpoint != NULL);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- res = ast_transfer(control->channel, endpoint);</span><br><span style="color: hsl(120, 100%, 40%);">+ res = ast_transfer(control->channel, endpoint, &protocol);</span><br><span> if (!res) {</span><br><span> ast_log(LOG_NOTICE, "Unsupported transfer requested on channel '%s'\n",</span><br><span> ast_channel_name(control->channel));</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15338">change 15338</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/+/15338"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ia6a94784b4925628af122409cdd733c9f29abfc4 </div>
<div style="display:none"> Gerrit-Change-Number: 15338 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Dan Cropp <dan@amtelco.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>