<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15951">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: 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;">app_originate: Allow setting Caller ID and variables<br><br>Caller ID can now be set on the called channel and<br>Variables can now be set on the destination<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, 83 insertions(+), 8 deletions(-)<br><br></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..2af46e3 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,26 @@</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="c"></span><br><span style="color: hsl(120, 100%, 40%);">+                                     <para>The caller ID number to use for the called channel. Default is</span><br><span style="color: hsl(120, 100%, 40%);">+                                    the current channel's Caller ID number.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                              </option></span><br><span style="color: hsl(120, 100%, 40%);">+                               <option name="n"></span><br><span style="color: hsl(120, 100%, 40%);">+                                     <para>The caller ID name to use for the called channel. Default is</span><br><span style="color: hsl(120, 100%, 40%);">+                                      the current channel's Caller ID name.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                </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" multiple="true" argsep="="></span><br><span style="color: hsl(120, 100%, 40%);">+                                         <argument name="name" 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 +139,17 @@</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_CALLER_NUM =        (1 << 3),</span><br><span style="color: hsl(120, 100%, 40%);">+       OPT_CALLER_NAME =       (1 << 4),</span><br><span style="color: hsl(120, 100%, 40%);">+       OPT_VARIABLES =         (1 << 5),</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_CALLER_NUM,</span><br><span style="color: hsl(120, 100%, 40%);">+   OPT_ARG_CALLER_NAME,</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 +158,11 @@</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('c', OPT_CALLER_NUM, OPT_ARG_CALLER_NUM),</span><br><span style="color: hsl(120, 100%, 40%);">+  AST_APP_OPTION_ARG('n', OPT_CALLER_NAME, OPT_ARG_CALLER_NAME),</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>@@ -158,7 +177,9 @@</span><br><span>     struct ast_flags64 opts = { 0, };</span><br><span>    char *opt_args[OPT_ARG_ARRAY_SIZE];</span><br><span>  char *predial_callee = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-    char *parse;</span><br><span style="color: hsl(120, 100%, 40%);">+  char *parse, *cnum = NULL, *cname = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+     </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>@@ -236,7 +257,50 @@</span><br><span>                 goto return_cleanup;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_test_flag64(&opts, OPT_CALLER_NUM)) {</span><br><span style="color: hsl(120, 100%, 40%);">+             if (!ast_strlen_zero(opt_args[OPT_ARG_CALLER_NUM])) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 cnum = opt_args[OPT_ARG_CALLER_NUM];</span><br><span style="color: hsl(120, 100%, 40%);">+          } else if (ast_channel_caller(chan)->id.number.str) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      cnum = ast_channel_caller(chan)->id.number.str;</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%);">+   if (ast_test_flag64(&opts, OPT_CALLER_NAME)) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!ast_strlen_zero(opt_args[OPT_ARG_CALLER_NAME])) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        cname = opt_args[OPT_ARG_CALLER_NAME];</span><br><span style="color: hsl(120, 100%, 40%);">+                } else if (ast_channel_caller(chan)->id.name.str) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        cname = ast_channel_caller(chan)->id.name.str;</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%);">+   /* 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 *vartext;</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 ((vartext = ast_strsep(&text, '^', 0))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   struct ast_variable *var;</span><br><span style="color: hsl(120, 100%, 40%);">+                     char *varname, *varvalue;</span><br><span style="color: hsl(120, 100%, 40%);">+                     if (!(varname = ast_strsep(&vartext, '=', 0))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                          ast_log(LOG_ERROR, "Variable syntax error: %s\n", vartext);</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%);">+                     if (!(varvalue = ast_strsep(&vartext, '=', 0))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                         varvalue = ""; /* empty values are allowed */</span><br><span style="color: hsl(120, 100%, 40%);">+                       }</span><br><span style="color: hsl(120, 100%, 40%);">+                     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 style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (!strcasecmp(args.type, "exten")) {</span><br><span style="color: hsl(120, 100%, 40%);">+              const char *cid_num = cnum;</span><br><span style="color: hsl(120, 100%, 40%);">+           const char *cid_name = cname;</span><br><span>                int priority = 1; /* Initialized in case priority not specified */</span><br><span>           const char *exten = args.arg2;</span><br><span> </span><br><span>@@ -257,16 +321,18 @@</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%);">+                                cid_num, cid_name, vars, NULL, NULL, 0, NULL,</span><br><span>                                predial_callee);</span><br><span>     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              const char *cid_num = cnum;</span><br><span style="color: hsl(120, 100%, 40%);">+           const char *cid_name = cname;</span><br><span>                ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",</span><br><span>                                chantech, chandata, args.arg1, S_OR(args.arg2, ""));</span><br><span> </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%);">+                           cid_num, cid_name, vars, NULL, NULL, NULL,</span><br><span>                           predial_callee);</span><br><span>     }</span><br><span> </span><br><span>@@ -311,6 +377,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><div style="white-space:pre-wrap"></div><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: 9 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.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-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>