<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12744">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Guido Falsi: 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;">channels: Allow updating variable value<br><br>When modifying an already defined variable in some channel drivers they<br>add a new variable with the same name to the list, but that value is<br>never used, only the first one found.<br><br>Introduce ast_variable_list_replace() and use it where appropriate.<br><br>ASTERISK-23756 #close<br>Patches:<br> setvar-multiplie.patch submitted by Michael Goryainov<br><br>Change-Id: Ie1897a96c82b8945e752733612ee963686f32839<br>---<br>M channels/chan_dahdi.c<br>M channels/chan_iax2.c<br>M channels/chan_sip.c<br>M include/asterisk/config.h<br>M main/config.c<br>M res/res_pjsip/pjsip_configuration.c<br>6 files changed, 55 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c</span><br><span>index 1a3b158..5ff12c6 100644</span><br><span>--- a/channels/chan_dahdi.c</span><br><span>+++ b/channels/chan_dahdi.c</span><br><span>@@ -12873,8 +12873,10 @@</span><br><span> struct ast_variable *v, *tmpvar;</span><br><span> for (v = conf->chan.vars ; v ; v = v->next) {</span><br><span> if ((tmpvar = ast_variable_new(v->name, v->value, v->file))) {</span><br><span style="color: hsl(0, 100%, 40%);">- tmpvar->next = tmp->vars;</span><br><span style="color: hsl(0, 100%, 40%);">- tmp->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_variable_list_replace(&tmp->vars, tmpvar)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tmpvar->next = tmp->vars;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> }</span><br><span>diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c</span><br><span>index 3bf06d0..81bdf15 100644</span><br><span>--- a/channels/chan_iax2.c</span><br><span>+++ b/channels/chan_iax2.c</span><br><span>@@ -7941,9 +7941,11 @@</span><br><span> /* We found our match (use the first) */</span><br><span> /* copy vars */</span><br><span> for (v = user->vars ; v ; v = v->next) {</span><br><span style="color: hsl(0, 100%, 40%);">- if((tmpvar = ast_variable_new(v->name, v->value, v->file))) {</span><br><span style="color: hsl(0, 100%, 40%);">- tmpvar->next = iaxs[callno]->vars;</span><br><span style="color: hsl(0, 100%, 40%);">- iaxs[callno]->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((tmpvar = ast_variable_new(v->name, v->value, v->file))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_variable_list_replace(&iaxs[callno]->vars, tmpvar)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tmpvar->next = iaxs[callno]->vars;</span><br><span style="color: hsl(120, 100%, 40%);">+ iaxs[callno]->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> /* If a max AUTHREQ restriction is in place, activate it */</span><br><span>@@ -13212,9 +13214,11 @@</span><br><span> if ((varval = strchr(varname, '='))) {</span><br><span> *varval = '\0';</span><br><span> varval++;</span><br><span style="color: hsl(0, 100%, 40%);">- if((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span style="color: hsl(0, 100%, 40%);">- tmpvar->next = user->vars;</span><br><span style="color: hsl(0, 100%, 40%);">- user->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_variable_list_replace(&user->vars, tmpvar)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tmpvar->next = user->vars;</span><br><span style="color: hsl(120, 100%, 40%);">+ user->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> } else if (!strcasecmp(v->name, "allow")) {</span><br><span>diff --git a/channels/chan_sip.c b/channels/chan_sip.c</span><br><span>index 223ff3c..ea78d23 100644</span><br><span>--- a/channels/chan_sip.c</span><br><span>+++ b/channels/chan_sip.c</span><br><span>@@ -31126,8 +31126,10 @@</span><br><span> if ((varval = strchr(varname, '='))) {</span><br><span> *varval++ = '\0';</span><br><span> if ((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span style="color: hsl(0, 100%, 40%);">- tmpvar->next = list;</span><br><span style="color: hsl(0, 100%, 40%);">- list = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_variable_list_replace(&list, tmpvar)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tmpvar->next = list;</span><br><span style="color: hsl(120, 100%, 40%);">+ list = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> return list;</span><br><span>diff --git a/include/asterisk/config.h b/include/asterisk/config.h</span><br><span>index 5ab1f68..04b858a 100644</span><br><span>--- a/include/asterisk/config.h</span><br><span>+++ b/include/asterisk/config.h</span><br><span>@@ -961,6 +961,24 @@</span><br><span> #define ast_variable_list_append(head, new_var) ast_variable_list_append_hint(head, NULL, new_var)</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Replace a variable in the given list with a new value</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.30.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ * but the content may be to initialize a new list. If so, upon return, this parameter will be updated</span><br><span style="color: hsl(120, 100%, 40%);">+ * with a pointer to the new list head.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param replacement The variable that replaces another variable in the list with the</span><br><span style="color: hsl(120, 100%, 40%);">+ * same name.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if a variable was replaced in the list</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 if no replacement occured</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note The variable name comparison is performed case-sensitively</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note If a variable is replaced, its memory is freed.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Update variable value within a config</span><br><span> *</span><br><span> * \param category Category element within the config</span><br><span>diff --git a/main/config.c b/main/config.c</span><br><span>index 0267979..8731ebb 100644</span><br><span>--- a/main/config.c</span><br><span>+++ b/main/config.c</span><br><span>@@ -669,6 +669,22 @@</span><br><span> return curr;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *v, **prev = head;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (v = *head; v; prev = &v->next, v = v->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(v->name, replacement->name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ replacement->next = v->next;</span><br><span style="color: hsl(120, 100%, 40%);">+ *prev = replacement;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(v);</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%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</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> const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var)</span><br><span> {</span><br><span> const char *tmp;</span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 4f7beb6..b5525be 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1036,7 +1036,9 @@</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_variable_list_append(&endpoint->channel_vars, new_var);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_variable_list_replace(&endpoint->channel_vars, new_var)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_variable_list_append(&endpoint->channel_vars, new_var);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12744">change 12744</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/+/12744"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Ie1897a96c82b8945e752733612ee963686f32839 </div>
<div style="display:none"> Gerrit-Change-Number: 12744 </div>
<div style="display:none"> Gerrit-PatchSet: 8 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.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: Guido Falsi <madpilot@freebsd.org> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-CC: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>