<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13515">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_dial.c: Simplify dialplan using Dial.<br><br>Dialplan has to be careful about passing an empty destination list or<br>empty positions in the list.  As a result, dialplan has to check for<br>these conditions before using Dial.  Simplify dialplan by making Dial<br>handle these conditions gracefully.<br><br>* Made tolerate empty positions in the dialed device list.<br><br>* Reduced some message log levels from notice to verbose.<br><br>ASTERISK-28638<br><br>Change-Id: I6edc731aff451f8bdfaee5498078dd18c3a11ab9<br>---<br>M apps/app_dial.c<br>A doc/CHANGES-staging/app_dial_empty_dial_list.txt<br>2 files changed, 36 insertions(+), 21 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_dial.c b/apps/app_dial.c</span><br><span>index 4adfc47..2744868 100644</span><br><span>--- a/apps/app_dial.c</span><br><span>+++ b/apps/app_dial.c</span><br><span>@@ -74,7 +74,7 @@</span><br><span>                      Attempt to connect to another device or endpoint and bridge the call.</span><br><span>                </synopsis></span><br><span>            <syntax></span><br><span style="color: hsl(0, 100%, 40%);">-                  <parameter name="Technology/Resource" required="true" argsep="&amp;"></span><br><span style="color: hsl(120, 100%, 40%);">+                 <parameter name="Technology/Resource" required="false" argsep="&amp;"></span><br><span>                               <argument name="Technology/Resource" required="true"></span><br><span>                                      <para>Specification of the device(s) to dial.  These must be in the format of</span><br><span>                                  <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable></span><br><span>@@ -1003,7 +1003,8 @@</span><br><span>                   * any Dial operations that happen later won't record CC interfaces.</span><br><span>                      */</span><br><span>                  ast_ignore_cc(o->chan);</span><br><span style="color: hsl(0, 100%, 40%);">-                      ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", ast_channel_name(o->chan));</span><br><span style="color: hsl(120, 100%, 40%);">+                 ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                ast_channel_name(o->chan));</span><br><span>               } else</span><br><span>                       ast_log(LOG_NOTICE,</span><br><span>                          "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",</span><br><span>@@ -2003,7 +2004,7 @@</span><br><span>              /* well, there seems basically two choices. Just patch the caller thru immediately,</span><br><span>                    or,... put 'em thru to voicemail. */</span><br><span>           /* since the callee may have hung up, let's do the voicemail thing, no database decision */</span><br><span style="color: hsl(0, 100%, 40%);">-         ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");</span><br><span>             /* XXX should we set status to DENY ? */</span><br><span>             /* XXX what about the privacy flags ? */</span><br><span>             break;</span><br><span>@@ -2294,12 +2295,6 @@</span><br><span>              return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ast_strlen_zero(data)) {</span><br><span style="color: hsl(0, 100%, 40%);">-            ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");</span><br><span style="color: hsl(0, 100%, 40%);">-            pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);</span><br><span style="color: hsl(0, 100%, 40%);">-             return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-      }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>    if (ast_check_hangup_locked(chan)) {</span><br><span>                 /*</span><br><span>            * Caller hung up before we could dial.  If dial is executed</span><br><span>@@ -2318,7 +2313,7 @@</span><br><span>                 return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   parse = ast_strdupa(data);</span><br><span style="color: hsl(120, 100%, 40%);">+    parse = ast_strdupa(data ?: "");</span><br><span> </span><br><span>       AST_STANDARD_APP_ARGS(args, parse);</span><br><span> </span><br><span>@@ -2328,12 +2323,6 @@</span><br><span>             goto done;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ast_strlen_zero(args.peers)) {</span><br><span style="color: hsl(0, 100%, 40%);">-              ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");</span><br><span style="color: hsl(0, 100%, 40%);">-            pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);</span><br><span style="color: hsl(0, 100%, 40%);">-             goto done;</span><br><span style="color: hsl(0, 100%, 40%);">-      }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>    if (ast_cc_call_init(chan, &ignore_cc)) {</span><br><span>                goto done;</span><br><span>   }</span><br><span>@@ -2359,7 +2348,7 @@</span><br><span>    if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {</span><br><span>            calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);</span><br><span>            if (!calldurationlimit.tv_sec) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);</span><br><span style="color: hsl(120, 100%, 40%);">+                 ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);</span><br><span>                     pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);</span><br><span>                  goto done;</span><br><span>           }</span><br><span>@@ -2506,15 +2495,24 @@</span><br><span> </span><br><span>      /* loop through the list of dial destinations */</span><br><span>     rest = args.peers;</span><br><span style="color: hsl(0, 100%, 40%);">-      while ((cur = strsep(&rest, "&")) ) {</span><br><span style="color: hsl(120, 100%, 40%);">+       while ((cur = strsep(&rest, "&"))) {</span><br><span>               struct ast_channel *tc; /* channel for this destination */</span><br><span style="color: hsl(0, 100%, 40%);">-              /* Get a technology/resource pair */</span><br><span style="color: hsl(0, 100%, 40%);">-            char *number = cur;</span><br><span style="color: hsl(0, 100%, 40%);">-             char *tech = strsep(&number, "/");</span><br><span style="color: hsl(120, 100%, 40%);">+              char *number;</span><br><span style="color: hsl(120, 100%, 40%);">+         char *tech;</span><br><span>          size_t tech_len;</span><br><span>             size_t number_len;</span><br><span>           struct ast_stream_topology *topology;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+             cur = ast_strip(cur);</span><br><span style="color: hsl(120, 100%, 40%);">+         if (ast_strlen_zero(cur)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   /* No tech/resource in this position. */</span><br><span style="color: hsl(120, 100%, 40%);">+                      continue;</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%);">+           /* Get a technology/resource pair */</span><br><span style="color: hsl(120, 100%, 40%);">+          number = cur;</span><br><span style="color: hsl(120, 100%, 40%);">+         tech = strsep(&number, "/");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                 num_dialed++;</span><br><span>                if (ast_strlen_zero(number)) {</span><br><span>                       ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");</span><br><span>@@ -2713,6 +2711,17 @@</span><br><span>               AST_LIST_INSERT_TAIL(&out_chans, tmp, node);</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (AST_LIST_EMPTY(&out_chans)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             if (continue_exec) {</span><br><span style="color: hsl(120, 100%, 40%);">+                  /* There is no point in having RetryDial try again */</span><br><span style="color: hsl(120, 100%, 40%);">+                 *continue_exec = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+           }</span><br><span style="color: hsl(120, 100%, 40%);">+             strcpy(pa.status, "CHANUNAVAIL");</span><br><span style="color: hsl(120, 100%, 40%);">+           res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+              goto out;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  /*</span><br><span>    * PREDIAL: Run gosub on all of the callee channels</span><br><span>   *</span><br><span>diff --git a/doc/CHANGES-staging/app_dial_empty_dial_list.txt b/doc/CHANGES-staging/app_dial_empty_dial_list.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..dc68ee6</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_dial_empty_dial_list.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: app_dial</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The Dial application now tolerates empty positions in the supplied</span><br><span style="color: hsl(120, 100%, 40%);">+destination list.  Dialplan can now be simplified by not having to check</span><br><span style="color: hsl(120, 100%, 40%);">+for empty positions in the destination list.  If there are no endpoints to</span><br><span style="color: hsl(120, 100%, 40%);">+dial then DIALSTATUS is set to CHANUNAVAIL.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13515">change 13515</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/+/13515"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I6edc731aff451f8bdfaee5498078dd18c3a11ab9 </div>
<div style="display:none"> Gerrit-Change-Number: 13515 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.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: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>