<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19744">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">config.c: Make ast_variable_retrieve return last match.<br><br>ast_variable_retrieve currently returns the first match<br>for a variable, as opposed to the last one. This is problematic<br>because modules that load config settings by explicitly<br>calling ast_variable_retrieve on a variable name (as opposed<br>to iterating through all the directives as specified) will<br>end up taking the first specified value, such as the default<br>value from the template rather than the actual effective value<br>in an individual config section, leading to the wrong config.<br><br>This fixes this by making ast_variable_retrieve return the last<br>match, or the most recently overridden one, as the effective setting.<br>This is similar to what the -1 index in the AST_CONFIG function does.<br><br>There is another function, ast_variable_find_last_in_list, that does<br>something similar. However, it's a slightly different API, and it<br>sees virtually no usage in Asterisk. ast_variable_retrieve is what<br>most things use so this is currently the relevant point of breakage.<br><br>ASTERISK-30370 #close<br><br>Change-Id: Ia681407275a557c1462f93832a4d45f31c580354<br>---<br>M main/config.c<br>1 file changed, 40 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/44/19744/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/config.c b/main/config.c</span><br><span>index 1074407..b7ecd81 100644</span><br><span>--- a/main/config.c</span><br><span>+++ b/main/config.c</span><br><span>@@ -783,11 +783,19 @@</span><br><span> const char *ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)</span><br><span> {</span><br><span>    struct ast_variable *v;</span><br><span style="color: hsl(120, 100%, 40%);">+       const char *match = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* We can't return as soon as we find a match, because if a config section overrides</span><br><span style="color: hsl(120, 100%, 40%);">+       * something specified in a template, then the actual effective value is the last</span><br><span style="color: hsl(120, 100%, 40%);">+      * one encountered, not the first one.</span><br><span style="color: hsl(120, 100%, 40%);">+         * (This is like using the -1 index for the AST_CONFIG function.)</span><br><span style="color: hsl(120, 100%, 40%);">+      * Also see ast_variable_find_last_in_list</span><br><span style="color: hsl(120, 100%, 40%);">+     */</span><br><span> </span><br><span>      if (category) {</span><br><span>              for (v = ast_variable_browse(config, category); v; v = v->next) {</span><br><span>                         if (!strcasecmp(variable, v->name)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                return v->value;</span><br><span style="color: hsl(120, 100%, 40%);">+                           match = v->value;</span><br><span>                         }</span><br><span>            }</span><br><span>    } else {</span><br><span>@@ -796,13 +804,13 @@</span><br><span>             for (cat = config->root; cat; cat = cat->next) {</span><br><span>                       for (v = cat->root; v; v = v->next) {</span><br><span>                          if (!strcasecmp(variable, v->name)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                        return v->value;</span><br><span style="color: hsl(120, 100%, 40%);">+                                   match = v->value;</span><br><span>                                 }</span><br><span>                    }</span><br><span>            }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  return match;</span><br><span> }</span><br><span> </span><br><span> const char *ast_variable_retrieve_filtered(struct ast_config *config,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19744">change 19744</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/+/19744"/><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: Ia681407275a557c1462f93832a4d45f31c580354 </div>
<div style="display:none"> Gerrit-Change-Number: 19744 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>