<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15951">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_originate: Allow variables to be set<br><br>Variables can now be set on the new channel<br>using the Originate application, just as<br>they can be currently using call files<br>or the Manager Action.<br><br>ASTERISK-29450<br><br>Change-Id: Ia64cfe97d2792bcbf4775b3126cad662922a8b66<br>---<br>M apps/app_originate.c<br>A doc/CHANGES-staging/app_originate_vars.txt<br>2 files changed, 54 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/51/15951/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_originate.c b/apps/app_originate.c</span><br><span>index 107be84..5fcb4ad 100644</span><br><span>--- a/apps/app_originate.c</span><br><span>+++ b/apps/app_originate.c</span><br><span>@@ -27,9 +27,6 @@</span><br><span> *</span><br><span> * \ingroup applications</span><br><span> *</span><br><span style="color: hsl(0, 100%, 40%);">- * \todo Make a way to be able to set variables (and functions) on the outbound</span><br><span style="color: hsl(0, 100%, 40%);">- * channel, similar to the Variable headers for the AMI Originate, and the</span><br><span style="color: hsl(0, 100%, 40%);">- * Set options for call files.</span><br><span> */</span><br><span> </span><br><span> /*** MODULEINFO</span><br><span>@@ -98,12 +95,18 @@</span><br><span> <argument name="argN" /></span><br><span> </argument></span><br><span> </option></span><br><span style="color: hsl(120, 100%, 40%);">+ <option name="v" argsep="^"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>A series of channel variables to set on the destination channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <argument name="var1" required="false" argsep="="></span><br><span style="color: hsl(120, 100%, 40%);">+ <argument name="name" multiple="true" required="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <argument name="value" required="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </argument></span><br><span style="color: hsl(120, 100%, 40%);">+ </option></span><br><span> </optionlist></span><br><span> </parameter></span><br><span> </syntax></span><br><span> <description></span><br><span> <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></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> <para>This application sets the following channel variable before exiting:</para></span><br><span> <variablelist></span><br><span> <variable name="ORIGINATE_STATUS"></span><br><span>@@ -128,11 +131,13 @@</span><br><span> OPT_PREDIAL_CALLEE = (1 << 0),</span><br><span> OPT_PREDIAL_CALLER = (1 << 1),</span><br><span> OPT_ASYNC = (1 << 2),</span><br><span style="color: hsl(120, 100%, 40%);">+ OPT_VARIABLES = (1 << 3),</span><br><span> };</span><br><span> </span><br><span> enum {</span><br><span> OPT_ARG_PREDIAL_CALLEE,</span><br><span> OPT_ARG_PREDIAL_CALLER,</span><br><span style="color: hsl(120, 100%, 40%);">+ OPT_ARG_VARIABLES,</span><br><span> /* note: this entry _MUST_ be the last one in the enum */</span><br><span> OPT_ARG_ARRAY_SIZE,</span><br><span> };</span><br><span>@@ -141,9 +146,9 @@</span><br><span> AST_APP_OPTION('a', OPT_ASYNC),</span><br><span> AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),</span><br><span> AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_OPTION_ARG('v', OPT_VARIABLES, OPT_ARG_VARIABLES),</span><br><span> END_OPTIONS );</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int originate_exec(struct ast_channel *chan, const char *data)</span><br><span> {</span><br><span> AST_DECLARE_APP_ARGS(args,</span><br><span>@@ -159,6 +164,7 @@</span><br><span> char *opt_args[OPT_ARG_ARRAY_SIZE];</span><br><span> char *predial_callee = NULL;</span><br><span> char *parse;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *vars = NULL;</span><br><span> char *chantech, *chandata;</span><br><span> int res = -1;</span><br><span> int continue_in_dialplan = 0;</span><br><span>@@ -235,6 +241,38 @@</span><br><span> args.type);</span><br><span> goto return_cleanup;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Assign variables */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_test_flag64(&opts, OPT_VARIABLES)</span><br><span style="color: hsl(120, 100%, 40%);">+ && !ast_strlen_zero(opt_args[OPT_ARG_VARIABLES])) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *text = opt_args[OPT_ARG_VARIABLES];</span><br><span style="color: hsl(120, 100%, 40%);">+ while (text && text[0] != '\0') {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *varname, *varvalue, *tmp = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = strchr(text, '='); /* use = sign to separate var value from name */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!tmp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Variable syntax error: %s\n", tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ goto return_cleanup;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ *tmp = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ varname = text;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = ast_skip_blanks(tmp + 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ varvalue = tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = strchr(varvalue, '^'); /* start of the next variable, if there is one */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tmp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *tmp = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ text = ast_skip_blanks(tmp + 1); /* for the next variable */</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ text = NULL; /* this was the last variable */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *var = ast_variable_new(varname, varvalue, "");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!var) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to allocate variable: %s\n", varname);</span><br><span style="color: hsl(120, 100%, 40%);">+ goto return_cleanup;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Appending variable '%s' with value '%s'", varname, varvalue);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variable_list_append(&vars, var);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (!strcasecmp(args.type, "exten")) {</span><br><span> int priority = 1; /* Initialized in case priority not specified */</span><br><span>@@ -257,7 +295,7 @@</span><br><span> res = ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,</span><br><span> timeout * 1000, args.arg1, exten, priority, &outgoing_status,</span><br><span> ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,</span><br><span style="color: hsl(0, 100%, 40%);">- NULL, NULL, NULL, NULL, NULL, 0, NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, NULL, vars, NULL, NULL, 0, NULL,</span><br><span> predial_callee);</span><br><span> } else {</span><br><span> ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",</span><br><span>@@ -266,7 +304,7 @@</span><br><span> res = ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,</span><br><span> timeout * 1000, args.arg1, args.arg2, &outgoing_status,</span><br><span> ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,</span><br><span style="color: hsl(0, 100%, 40%);">- NULL, NULL, NULL, NULL, NULL, NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, NULL, vars, NULL, NULL, NULL,</span><br><span> predial_callee);</span><br><span> }</span><br><span> </span><br><span>@@ -311,6 +349,9 @@</span><br><span> break;</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (vars) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variables_destroy(vars);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> ao2_cleanup(cap_slin);</span><br><span> ast_autoservice_stop(chan);</span><br><span> </span><br><span>diff --git a/doc/CHANGES-staging/app_originate_vars.txt b/doc/CHANGES-staging/app_originate_vars.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..4e08ae6</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_originate_vars.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: Add variable support to Originate</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The Originate application now allows</span><br><span style="color: hsl(120, 100%, 40%);">+variables to be set on the new channel</span><br><span style="color: hsl(120, 100%, 40%);">+through a new option.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15951">change 15951</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/+/15951"/><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: Ia64cfe97d2792bcbf4775b3126cad662922a8b66 </div>
<div style="display:none"> Gerrit-Change-Number: 15951 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>