[Asterisk-code-review] chan sip, chan iax2: Allow updating variable value in channe... (asterisk[master])

Guido Falsi asteriskteam at digium.com
Mon Jan 28 14:15:58 CST 2019


Guido Falsi has uploaded this change for review. ( https://gerrit.asterisk.org/10930


Change subject: chan_sip, chan_iax2: Allow updating variable value in channel drivers.
......................................................................

chan_sip, chan_iax2: Allow updating variable value in channel drivers.

When modifying an already defined variable in chan_sip and chan_iax2
drivers they add a new variable with the same name to the linked
list, but that value is never used, only the first one found. This
patch makes the code replace the old value with the new one.
Chan_dahdi already conforms to this, more logical, behaviour.

ASTERISK-23756
patches:
  setvar-multiplie.patch submitted by Michael Goryainov

Change-Id: Ie1897a96c82b8945e752733612ee963686f32839
---
M channels/chan_iax2.c
M channels/chan_sip.c
2 files changed, 57 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/30/10930/1

diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 6f88d09..457d9f8 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -583,6 +583,7 @@
 
 	struct stasis_subscription *mwi_event_sub;	/*!< This subscription lets pollmailboxes know which mailboxes need to be polled */
 
+	struct ast_variable *vars;
 	struct ast_acl_list *acl;
 	enum calltoken_peer_enum calltoken_required;	/*!< Is calltoken validation required or not, can be YES, NO, or AUTO */
 
@@ -3868,6 +3869,12 @@
 		ast_cli(a->fd, "  Defaddr->IP  : %s Port %s\n", str_defaddr, str_defport);
 		ast_cli(a->fd, "  Username     : %s\n", peer->username);
 		ast_cli(a->fd, "  Codecs       : %s\n", iax2_getformatname_multiple(peer->capability, &codec_buf));
+		if (peer->vars) {
+			ast_cli(a->fd, "  Variables    :\n");
+			struct ast_variable *v;
+			for (v = peer->vars; v; v = v->next)
+				ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
+		}
 
 		if (iax2_codec_pref_string(&peer->prefs, cbuf, sizeof(cbuf)) < 0) {
 			strcpy(cbuf, "Error"); /* Safe */
@@ -13040,6 +13047,29 @@
 				} else {
 					ast_log(LOG_WARNING, "requirecalltoken must be set to a valid value. at line %d\n", v->lineno);
 				}
+			} else if (!strcasecmp(v->name, "setvar")) {
+				char *varname = ast_strdupa(v->value);
+				char *varval;
+				if ((varval = strchr(varname, '='))) {
+					*varval++ = '\0';
+					struct ast_variable *cur = NULL, *prev = NULL, *tmpvar = NULL;
+					for (cur = peer->vars; cur; prev = cur, cur = cur->next) {
+						if(!strcmp(varname, cur->name)) {
+							/* for duplicate entries use last in the user */
+							if(prev == NULL)
+								peer->vars = cur->next;
+							else
+								prev->next = cur->next;
+							free(cur);
+
+							break;
+						}
+					}
+					if((tmpvar = ast_variable_new(varname, varval, ""))) {
+						tmpvar->next = peer->vars;
+						peer->vars = tmpvar;
+					}
+				}
 			} /* else if (strcasecmp(v->name,"type")) */
 			/*	ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
 			v = v->next;
@@ -13183,6 +13213,19 @@
 				if ((varval = strchr(varname, '='))) {
 					*varval = '\0';
 					varval++;
+					struct ast_variable *cur = NULL,*prev = NULL;
+					for (cur = user->vars; cur; prev = cur, cur = cur->next) {
+						if(!strcmp(varname, cur->name)) {
+							/* for duplicate entries use last in the user */
+							if(prev == NULL)
+								user->vars = cur->next;
+							else
+								prev->next = cur->next;
+
+							free(cur);
+							break;
+						}
+					}
 					if((tmpvar = ast_variable_new(varname, varval, ""))) {
 						tmpvar->next = user->vars;
 						user->vars = tmpvar;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 328c18d..940116e 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -31362,6 +31362,20 @@
 
 	if ((varval = strchr(varname, '='))) {
 		*varval++ = '\0';
+		struct ast_variable *prev = NULL;
+		for (tmpvar = list; tmpvar; prev = tmpvar, tmpvar = tmpvar->next) {
+			if (!strcmp(varname, tmpvar->name)) {
+				/* for duplicate entries use last in the list */
+				if(prev == NULL) {
+					list = tmpvar->next;
+				} else {
+					prev->next = tmpvar->next;
+				}
+
+				free(tmpvar);
+				break;
+			}
+		}
 		if ((tmpvar = ast_variable_new(varname, varval, ""))) {
 			tmpvar->next = list;
 			list = tmpvar;

-- 
To view, visit https://gerrit.asterisk.org/10930
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1897a96c82b8945e752733612ee963686f32839
Gerrit-Change-Number: 10930
Gerrit-PatchSet: 1
Gerrit-Owner: Guido Falsi <madpilot at freebsd.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190128/0e23bb0e/attachment.html>


More information about the asterisk-code-review mailing list