[Asterisk-code-review] app_originate: Allow variables to be set (asterisk[master])
N A
asteriskteam at digium.com
Tue May 25 10:37:43 CDT 2021
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15951 )
Change subject: app_originate: Allow variables to be set
......................................................................
app_originate: Allow variables to be set
Variables can now be set on the new channel
using the Originate application, just as
they can be currently using call files
or the Manager Action.
ASTERISK-29450
Change-Id: Ia64cfe97d2792bcbf4775b3126cad662922a8b66
---
M apps/app_originate.c
A doc/CHANGES-staging/app_originate_vars.txt
2 files changed, 54 insertions(+), 7 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/51/15951/1
diff --git a/apps/app_originate.c b/apps/app_originate.c
index 107be84..5fcb4ad 100644
--- a/apps/app_originate.c
+++ b/apps/app_originate.c
@@ -27,9 +27,6 @@
*
* \ingroup applications
*
- * \todo Make a way to be able to set variables (and functions) on the outbound
- * channel, similar to the Variable headers for the AMI Originate, and the
- * Set options for call files.
*/
/*** MODULEINFO
@@ -98,12 +95,18 @@
<argument name="argN" />
</argument>
</option>
+ <option name="v" argsep="^">
+ <para>A series of channel variables to set on the destination channel.</para>
+ <argument name="var1" required="false" argsep="=">
+ <argument name="name" multiple="true" required="true" />
+ <argument name="value" required="true" />
+ </argument>
+ </option>
</optionlist>
</parameter>
</syntax>
<description>
<para>This application originates an outbound call and connects it to a specified extension or application. This application will block until the outgoing call fails or gets answered. At that point, this application will exit with the status variable set and dialplan processing will continue.</para>
-
<para>This application sets the following channel variable before exiting:</para>
<variablelist>
<variable name="ORIGINATE_STATUS">
@@ -128,11 +131,13 @@
OPT_PREDIAL_CALLEE = (1 << 0),
OPT_PREDIAL_CALLER = (1 << 1),
OPT_ASYNC = (1 << 2),
+ OPT_VARIABLES = (1 << 3),
};
enum {
OPT_ARG_PREDIAL_CALLEE,
OPT_ARG_PREDIAL_CALLER,
+ OPT_ARG_VARIABLES,
/* note: this entry _MUST_ be the last one in the enum */
OPT_ARG_ARRAY_SIZE,
};
@@ -141,9 +146,9 @@
AST_APP_OPTION('a', OPT_ASYNC),
AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
+ AST_APP_OPTION_ARG('v', OPT_VARIABLES, OPT_ARG_VARIABLES),
END_OPTIONS );
-
static int originate_exec(struct ast_channel *chan, const char *data)
{
AST_DECLARE_APP_ARGS(args,
@@ -159,6 +164,7 @@
char *opt_args[OPT_ARG_ARRAY_SIZE];
char *predial_callee = NULL;
char *parse;
+ struct ast_variable *vars = NULL;
char *chantech, *chandata;
int res = -1;
int continue_in_dialplan = 0;
@@ -235,6 +241,38 @@
args.type);
goto return_cleanup;
}
+
+ /* Assign variables */
+ if (ast_test_flag64(&opts, OPT_VARIABLES)
+ && !ast_strlen_zero(opt_args[OPT_ARG_VARIABLES])) {
+ char *text = opt_args[OPT_ARG_VARIABLES];
+ while (text && text[0] != '\0') {
+ char *varname, *varvalue, *tmp = NULL;
+ tmp = strchr(text, '='); /* use = sign to separate var value from name */
+ if (!tmp) {
+ ast_log(LOG_ERROR, "Variable syntax error: %s\n", tmp);
+ goto return_cleanup;
+ }
+ *tmp = '\0';
+ varname = text;
+ tmp = ast_skip_blanks(tmp + 1);
+ varvalue = tmp;
+ tmp = strchr(varvalue, '^'); /* start of the next variable, if there is one */
+ if (tmp) {
+ *tmp = '\0';
+ text = ast_skip_blanks(tmp + 1); /* for the next variable */
+ } else {
+ text = NULL; /* this was the last variable */
+ }
+ struct ast_variable *var = ast_variable_new(varname, varvalue, "");
+ if (!var) {
+ ast_log(LOG_ERROR, "Failed to allocate variable: %s\n", varname);
+ goto return_cleanup;
+ }
+ ast_debug(1, "Appending variable '%s' with value '%s'", varname, varvalue);
+ ast_variable_list_append(&vars, var);
+ }
+ }
if (!strcasecmp(args.type, "exten")) {
int priority = 1; /* Initialized in case priority not specified */
@@ -257,7 +295,7 @@
res = ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,
timeout * 1000, args.arg1, exten, priority, &outgoing_status,
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
- NULL, NULL, NULL, NULL, NULL, 0, NULL,
+ NULL, NULL, vars, NULL, NULL, 0, NULL,
predial_callee);
} else {
ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
@@ -266,7 +304,7 @@
res = ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,
timeout * 1000, args.arg1, args.arg2, &outgoing_status,
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
- NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, vars, NULL, NULL, NULL,
predial_callee);
}
@@ -311,6 +349,9 @@
break;
}
}
+ if (vars) {
+ ast_variables_destroy(vars);
+ }
ao2_cleanup(cap_slin);
ast_autoservice_stop(chan);
diff --git a/doc/CHANGES-staging/app_originate_vars.txt b/doc/CHANGES-staging/app_originate_vars.txt
new file mode 100644
index 0000000..4e08ae6
--- /dev/null
+++ b/doc/CHANGES-staging/app_originate_vars.txt
@@ -0,0 +1,6 @@
+Subject: Add variable support to Originate
+
+The Originate application now allows
+variables to be set on the new channel
+through a new option.
+
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15951
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia64cfe97d2792bcbf4775b3126cad662922a8b66
Gerrit-Change-Number: 15951
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210525/9f356b02/attachment.html>
More information about the asterisk-code-review
mailing list