<p>Guido Falsi has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10930">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_sip, chan_iax2: Allow updating variable value in channel drivers.<br><br>When modifying an already defined variable in chan_sip and chan_iax2<br>drivers they add a new variable with the same name to the linked<br>list, but that value is never used, only the first one found. This<br>patch makes the code replace the old value with the new one.<br>Chan_dahdi already conforms to this, more logical, behaviour.<br><br>ASTERISK-23756<br>patches:<br> setvar-multiplie.patch submitted by Michael Goryainov<br><br>Change-Id: Ie1897a96c82b8945e752733612ee963686f32839<br>---<br>M channels/chan_iax2.c<br>M channels/chan_sip.c<br>2 files changed, 57 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/30/10930/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c</span><br><span>index 6f88d09..457d9f8 100644</span><br><span>--- a/channels/chan_iax2.c</span><br><span>+++ b/channels/chan_iax2.c</span><br><span>@@ -583,6 +583,7 @@</span><br><span> </span><br><span> struct stasis_subscription *mwi_event_sub; /*!< This subscription lets pollmailboxes know which mailboxes need to be polled */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *vars;</span><br><span> struct ast_acl_list *acl;</span><br><span> enum calltoken_peer_enum calltoken_required; /*!< Is calltoken validation required or not, can be YES, NO, or AUTO */</span><br><span> </span><br><span>@@ -3868,6 +3869,12 @@</span><br><span> ast_cli(a->fd, " Defaddr->IP : %s Port %s\n", str_defaddr, str_defport);</span><br><span> ast_cli(a->fd, " Username : %s\n", peer->username);</span><br><span> ast_cli(a->fd, " Codecs : %s\n", iax2_getformatname_multiple(peer->capability, &codec_buf));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (peer->vars) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, " Variables :\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *v;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (v = peer->vars; v; v = v->next)</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, " %s = %s\n", v->name, v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (iax2_codec_pref_string(&peer->prefs, cbuf, sizeof(cbuf)) < 0) {</span><br><span> strcpy(cbuf, "Error"); /* Safe */</span><br><span>@@ -13040,6 +13047,29 @@</span><br><span> } else {</span><br><span> ast_log(LOG_WARNING, "requirecalltoken must be set to a valid value. at line %d\n", v->lineno);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(v->name, "setvar")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *varname = ast_strdupa(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ char *varval;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((varval = strchr(varname, '='))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ *varval++ = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *cur = NULL, *prev = NULL, *tmpvar = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (cur = peer->vars; cur; prev = cur, cur = cur->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if(!strcmp(varname, cur->name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* for duplicate entries use last in the user */</span><br><span style="color: hsl(120, 100%, 40%);">+ if(prev == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+ peer->vars = cur->next;</span><br><span style="color: hsl(120, 100%, 40%);">+ else</span><br><span style="color: hsl(120, 100%, 40%);">+ prev->next = cur->next;</span><br><span style="color: hsl(120, 100%, 40%);">+ free(cur);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</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((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ tmpvar->next = peer->vars;</span><br><span style="color: hsl(120, 100%, 40%);">+ peer->vars = tmpvar;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } /* else if (strcasecmp(v->name,"type")) */</span><br><span> /* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */</span><br><span> v = v->next;</span><br><span>@@ -13183,6 +13213,19 @@</span><br><span> if ((varval = strchr(varname, '='))) {</span><br><span> *varval = '\0';</span><br><span> varval++;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *cur = NULL,*prev = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (cur = user->vars; cur; prev = cur, cur = cur->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if(!strcmp(varname, cur->name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* for duplicate entries use last in the user */</span><br><span style="color: hsl(120, 100%, 40%);">+ if(prev == NULL)</span><br><span style="color: hsl(120, 100%, 40%);">+ user->vars = cur->next;</span><br><span style="color: hsl(120, 100%, 40%);">+ else</span><br><span style="color: hsl(120, 100%, 40%);">+ prev->next = cur->next;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ free(cur);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> if((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span> tmpvar->next = user->vars;</span><br><span> user->vars = tmpvar;</span><br><span>diff --git a/channels/chan_sip.c b/channels/chan_sip.c</span><br><span>index 328c18d..940116e 100644</span><br><span>--- a/channels/chan_sip.c</span><br><span>+++ b/channels/chan_sip.c</span><br><span>@@ -31362,6 +31362,20 @@</span><br><span> </span><br><span> if ((varval = strchr(varname, '='))) {</span><br><span> *varval++ = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_variable *prev = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (tmpvar = list; tmpvar; prev = tmpvar, tmpvar = tmpvar->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(varname, tmpvar->name)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* for duplicate entries use last in the list */</span><br><span style="color: hsl(120, 100%, 40%);">+ if(prev == NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ list = tmpvar->next;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ prev->next = tmpvar->next;</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%);">+ free(tmpvar);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> if ((tmpvar = ast_variable_new(varname, varval, ""))) {</span><br><span> tmpvar->next = list;</span><br><span> list = tmpvar;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10930">change 10930</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/10930"/><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-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ie1897a96c82b8945e752733612ee963686f32839 </div>
<div style="display:none"> Gerrit-Change-Number: 10930 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Guido Falsi <madpilot@freebsd.org> </div>