chan_pjsip, app_transfer: Add TRANSFERSTATUSPROTOCOL variable

When a Transfer/REFER is executed, TRANSFERSTATUSPROTOCOL variable is
0 when no protocl specific error
SIP example of failure, 3xx-6xx for the SIP error code received

This allows applications to perform actions based on the failure
reason.

ASTERISK-29252 #close
Reported-by: Dan Cropp

Change-Id: Ia6a94784b4925628af122409cdd733c9f29abfc4
This commit is contained in:
Dan Cropp
2021-01-22 09:12:12 -06:00
committed by Friendly Automation
parent 6d980de282
commit 55891227e8
5 changed files with 86 additions and 8 deletions

View File

@@ -69,6 +69,14 @@
Transfer unsupported by channel driver.
</value>
</variable>
<variable name="TRANSFERSTATUSPROTOCOL">
<value name="0">
No error.
</value>
<value name="3xx-6xx">
SIP example - Error result code.
</value>
</variable>
</variablelist>
</description>
</application>
@@ -85,6 +93,8 @@ static int transfer_exec(struct ast_channel *chan, const char *data)
char *dest = NULL;
char *status;
char *parse;
int protocol = 0;
char status_protocol[20];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(dest);
);
@@ -92,6 +102,8 @@ static int transfer_exec(struct ast_channel *chan, const char *data)
if (ast_strlen_zero((char *)data)) {
ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
return 0;
} else
parse = ast_strdupa(data);
@@ -106,6 +118,8 @@ static int transfer_exec(struct ast_channel *chan, const char *data)
/* Allow execution only if the Tech/destination agrees with the type of the channel */
if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) {
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
return 0;
}
}
@@ -113,10 +127,14 @@ static int transfer_exec(struct ast_channel *chan, const char *data)
/* Check if the channel supports transfer before we try it */
if (!ast_channel_tech(chan)->transfer) {
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
return 0;
}
res = ast_transfer(chan, dest);
/* New transfer API returns a protocol code
SIP example, 0 = success, 3xx-6xx are sip error codes for the REFER */
res = ast_transfer_protocol(chan, dest, &protocol);
if (res < 0) {
status = "FAILURE";
@@ -126,7 +144,11 @@ static int transfer_exec(struct ast_channel *chan, const char *data)
res = 0;
}
snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
ast_debug(1, "ast_transfer channel %s TRANSFERSTATUS=%s, TRANSFERSTATUSPROTOCOL=%s\n",
ast_channel_name(chan), status, status_protocol);
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
return res;
}