<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18369">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core_local: Fix local channel parsing with slashes<br><br>Currently, trying to call a Local channel with a slash<br>in the extension will fail due to the parsing of characters<br>after such a slash as being dial modifiers. Additionally,<br>core_local is inconsistent and incomplete with<br>its parsing of Local dial strings in that sometimes it<br>uses the first slash and at other times it uses the last.<br><br>This creates inconsistent behavior for users, since using<br>a slash in an extension is perfectly acceptable, and using<br>a Goto to accomplish this works fine, but if specified<br>through a Local channel, the parsing prevents this.<br><br>This fixes this and improves the consistency of the dial<br>string parsing to always check for options after the last<br>slash in the dial string and only treat them as options if,<br>in fact, they are actually options; otherwise, it will leave<br>them alone.<br><br>ASTERISK-30013 #close<br><br>Change-Id: I8e85bc14072e452d0537a801aba17779569d0360<br>---<br>M main/core_local.c<br>1 file changed, 40 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/18369/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/core_local.c b/main/core_local.c</span><br><span>index 26b1ba1..4436a9b 100644</span><br><span>--- a/main/core_local.c</span><br><span>+++ b/main/core_local.c</span><br><span>@@ -304,6 +304,24 @@</span><br><span>  return peer;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Determine if text after a '/' is really options or just part of the exten */</span><br><span style="color: hsl(120, 100%, 40%);">+static int really_local_options(char *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        char *ptr = data;</span><br><span style="color: hsl(120, 100%, 40%);">+     if (strlen(ptr) > 4) {</span><br><span style="color: hsl(120, 100%, 40%);">+             return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     while (*ptr) {</span><br><span style="color: hsl(120, 100%, 40%);">+                /* b option no longer exists, but accept it for this purpose for compatibility */</span><br><span style="color: hsl(120, 100%, 40%);">+             if (*ptr != '/' && *ptr != 'n' && *ptr != 'j' && *ptr != 'm' && *ptr != 'b') {</span><br><span style="color: hsl(120, 100%, 40%);">+                        return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+             }</span><br><span style="color: hsl(120, 100%, 40%);">+             ptr++;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Okay, fine, these are definitely options... */</span><br><span style="color: hsl(120, 100%, 40%);">+     return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Adds devicestate to local channels */</span><br><span> static int local_devicestate(const char *data)</span><br><span> {</span><br><span>@@ -316,8 +334,8 @@</span><br><span>      struct ao2_iterator it;</span><br><span> </span><br><span>  /* Strip options if they exist */</span><br><span style="color: hsl(0, 100%, 40%);">-       opts = strchr(exten, '/');</span><br><span style="color: hsl(0, 100%, 40%);">-      if (opts) {</span><br><span style="color: hsl(120, 100%, 40%);">+   opts = strrchr(exten, '/');</span><br><span style="color: hsl(120, 100%, 40%);">+   if (opts && really_local_options(opts)) {</span><br><span>            *opts = '\0';</span><br><span>        }</span><br><span> </span><br><span>@@ -713,7 +731,7 @@</span><br><span>   * that off for our argument to setting up the CC_INTERFACES</span><br><span>          * variable.</span><br><span>          */</span><br><span style="color: hsl(0, 100%, 40%);">-     if ((slash = strrchr(reduced_dest, '/'))) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if ((slash = strrchr(reduced_dest, '/')) && really_local_options(slash)) {</span><br><span>           *slash = '\0';</span><br><span>       }</span><br><span>    ast_set_cc_interfaces_chanvar(chan, reduced_dest);</span><br><span>@@ -885,20 +903,26 @@</span><br><span>   ast_set_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);</span><br><span> </span><br><span>       /* Look for options */</span><br><span style="color: hsl(0, 100%, 40%);">-  if ((opts = strchr(parse, '/'))) {</span><br><span style="color: hsl(0, 100%, 40%);">-              *opts++ = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">-         if (strchr(opts, 'n')) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        ast_set_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION);</span><br><span style="color: hsl(0, 100%, 40%);">-            }</span><br><span style="color: hsl(0, 100%, 40%);">-               if (strchr(opts, 'j')) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        if (ast_test_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                             ast_set_flag(&pvt->base.jb_conf, AST_JB_ENABLED);</span><br><span style="color: hsl(0, 100%, 40%);">-                        } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                                ast_log(LOG_ERROR, "You must use the 'n' option with the 'j' option to enable the jitter buffer\n");</span><br><span style="color: hsl(120, 100%, 40%);">+        if ((opts = strrchr(parse, '/'))) {</span><br><span style="color: hsl(120, 100%, 40%);">+           /* The stuff after the slash might actually be part of the exten, not options. If so, don't lop them off. */</span><br><span style="color: hsl(120, 100%, 40%);">+              if (really_local_options(opts)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     *opts++ = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (strchr(opts, 'n')) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              ast_set_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION);</span><br><span>                         }</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-               if (strchr(opts, 'm')) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        ast_clear_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);</span><br><span style="color: hsl(120, 100%, 40%);">+                  if (strchr(opts, 'j')) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              if (ast_test_flag(&pvt->base, AST_UNREAL_NO_OPTIMIZATION)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                   ast_set_flag(&pvt->base.jb_conf, AST_JB_ENABLED);</span><br><span style="color: hsl(120, 100%, 40%);">+                              } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      ast_log(LOG_ERROR, "You must use the 'n' option with the 'j' option to enable the jitter buffer\n");</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 (strchr(opts, 'm')) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              ast_clear_flag(&pvt->base, AST_UNREAL_MOH_INTERCEPT);</span><br><span style="color: hsl(120, 100%, 40%);">+                  }</span><br><span style="color: hsl(120, 100%, 40%);">+             } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                      /* This isn't any kind of problem. Slashes are okay in the extension. */</span><br><span style="color: hsl(120, 100%, 40%);">+                  ast_debug(3, "Local dial string '%s' contains slash, but no options detected\n", parse);</span><br><span>           }</span><br><span>    }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18369">change 18369</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/+/18369"/><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: I8e85bc14072e452d0537a801aba17779569d0360 </div>
<div style="display:none"> Gerrit-Change-Number: 18369 </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>