[Asterisk-cvs] asterisk/channels chan_iax2.c, 1.215, 1.216 chan_sip.c, 1.568, 1.569

markster at lists.digium.com markster at lists.digium.com
Tue Nov 16 22:10:06 CST 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv19449/channels

Modified Files:
	chan_iax2.c chan_sip.c 
Log Message:
Merge Tony's uservars (bug #2882)


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.215
retrieving revision 1.216
diff -u -d -r1.215 -r1.216
--- chan_iax2.c	13 Nov 2004 16:13:07 -0000	1.215
+++ chan_iax2.c	17 Nov 2004 03:10:38 -0000	1.216
@@ -15,6 +15,7 @@
 #include <asterisk/frame.h> 
 #include <asterisk/channel.h>
 #include <asterisk/channel_pvt.h>
+#include <asterisk/config_pvt.h>
 #include <asterisk/logger.h>
 #include <asterisk/module.h>
 #include <asterisk/pbx.h>
@@ -207,6 +208,7 @@
 	struct iax2_user *next;
 	int notransfer;
 	int usejitterbuf;
+	struct ast_variable *vars;
 };
 
 struct iax2_peer {
@@ -479,6 +481,7 @@
 	struct iax2_dpcache *dpentries;
 	int notransfer;		/* do we want native bridging */
 	int usejitterbuf;	/* use jitter buffer on this channel? */
+	struct ast_variable *vars;
 };
 
 static struct ast_iax2_queue {
@@ -1417,8 +1420,13 @@
 		if (pvt->reg) {
 			pvt->reg->callno = 0;
 		}
-		if (!owner)
+		if (!owner) {
+			if (pvt->vars) {
+				ast_destroy_realtime(pvt->vars);
+				pvt->vars = NULL;
+			}
 			free(pvt);
+		}
 	}
 	if (owner) {
 		ast_mutex_unlock(&owner->lock);
@@ -2672,6 +2680,8 @@
 {
 	struct ast_channel *tmp;
 	struct chan_iax2_pvt *i;
+	struct ast_variable *v = NULL;
+
 	/* Don't hold call lock */
 	ast_mutex_unlock(&iaxsl[callno]);
 	tmp = ast_channel_alloc(1);
@@ -2737,6 +2747,9 @@
 				tmp = NULL;
 			}
 		}
+		for (v = i->vars ; v ; v = v->next)
+			pbx_builtin_setvar_helper(tmp,v->name,v->value);
+		
 	}
 	return tmp;
 }
@@ -3574,6 +3587,7 @@
 	int bestscore = 0;
 	int gotcapability=0;
 	char iabuf[INET_ADDRSTRLEN];
+	struct ast_variable *v = NULL, *tmpvar = NULL;
 	
 	if (!iaxs[callno])
 		return res;
@@ -3676,7 +3690,14 @@
 	}
 	if (user) {
 		/* We found our match (use the first) */
-		
+		/* copy vars */
+		for (v = user->vars ; v ; v = v->next) {
+			if((tmpvar = ast_new_variable(v->name, v->value))) {
+				tmpvar->next = iaxs[callno]->vars; 
+				iaxs[callno]->vars = tmpvar;
+			}
+		}
+
 		/* Store the requested username if not specified */
 		if (ast_strlen_zero(iaxs[callno]->username))
 			strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
@@ -6573,6 +6594,8 @@
 	struct iax2_context *oldcon = NULL;
 	int format;
 	int found;
+	char *varname = NULL, *varval = NULL;
+	struct ast_variable *tmpvar = NULL;
 	
 	prev = NULL;
 	ast_mutex_lock(&userl.lock);
@@ -6626,6 +6649,16 @@
 			} else if (!strcasecmp(v->name, "permit") ||
 					   !strcasecmp(v->name, "deny")) {
 				user->ha = ast_append_ha(v->name, v->value, user->ha);
+			} else if (!strcasecmp(v->name, "setvar")) {
+				varname = ast_strdupa(v->value);
+				if (varname && (varval = strchr(varname,'='))) {
+					*varval = '\0';
+					varval++;
+					if((tmpvar = ast_new_variable(varname, varval))) {
+						tmpvar->next = user->vars; 
+						user->vars = tmpvar;
+					}
+				}
 			} else if (!strcasecmp(v->name, "allow")) {
 				format = ast_getformatbyname(v->value);
 				if (format < 1) 
@@ -6741,6 +6774,10 @@
 {
 	ast_free_ha(user->ha);
 	free_context(user->contexts);
+	if(user->vars) {
+		ast_destroy_realtime(user->vars);
+		user->vars = NULL;
+	}
 	free(user);
 }
 

Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.568
retrieving revision 1.569
diff -u -d -r1.568 -r1.569
--- chan_sip.c	16 Nov 2004 23:18:37 -0000	1.568
+++ chan_sip.c	17 Nov 2004 03:10:38 -0000	1.569
@@ -18,6 +18,7 @@
 #include <asterisk/lock.h>
 #include <asterisk/channel.h>
 #include <asterisk/channel_pvt.h>
+#include <asterisk/config_pvt.h>
 #include <asterisk/config.h>
 #include <asterisk/logger.h>
 #include <asterisk/module.h>
@@ -352,6 +353,7 @@
 	struct ast_rtp *vrtp;			/* Video RTP session */
 	struct sip_pkt *packets;		/* Packets scheduled for re-transmission */
 	struct sip_history *history;		/* History of this SIP dialog */
+	struct ast_variable *vars;
 	struct sip_pvt *next;			/* Next call in chain */
 } *iflist = NULL;
 
@@ -405,6 +407,7 @@
 	int progressinband;
 	struct ast_ha *ha;		/* ACL setting */
 	int temponly;			/* Flag for temporary users (realtime) */
+	struct ast_variable *vars;
 	struct sip_user *next;
 };
 
@@ -1151,6 +1154,10 @@
 static void destroy_user(struct sip_user *user)
 {
 	ast_free_ha(user->ha);
+	if(user->vars) {
+		ast_destroy_realtime(user->vars);
+		user->vars = NULL;
+	}
 	free(user);
 }
 
@@ -1557,6 +1564,10 @@
 			free(cp);
 		}
 		ast_mutex_destroy(&p->lock);
+		if(p->vars) {
+			ast_destroy_realtime(p->vars);
+			p->vars = NULL;
+		}
 		free(p);
 	}
 }
@@ -1957,8 +1968,9 @@
 static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
 {
 	struct ast_channel *tmp;
+	struct ast_variable *v = NULL;
 	int fmt;
-
+	
 	ast_mutex_unlock(&i->lock);
 	/* Don't hold a sip pvt lock while we allocate a channel */
 	tmp = ast_channel_alloc(1);
@@ -2062,6 +2074,8 @@
 				tmp = NULL;
 			}
 		}
+		for (v = i->vars ; v ; v = v->next)
+			pbx_builtin_setvar_helper(tmp,v->name,v->value);
 	} else
 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
 	return tmp;
@@ -2294,6 +2308,10 @@
 	if (!p->rtp) {
 		ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
                 ast_mutex_destroy(&p->lock);
+		if(p->vars) {
+			ast_destroy_realtime(p->vars);
+			p->vars = NULL;
+		}
 		free(p);
 		return NULL;
 	}
@@ -5257,6 +5275,7 @@
 	char *t;
 	char calleridname[50];
 	int debug=sip_debug_test_addr(sin);
+	struct ast_variable *tmpvar = NULL, *v = NULL;
 
 	/* Terminate URI */
 	t = uri;
@@ -5304,6 +5323,13 @@
 	user = find_user(of);
 	/* Find user based on user name in the from header */
 	if (user && ast_apply_ha(user->ha, sin)) {
+		/* copy vars */
+		for (v = user->vars ; v ; v = v->next) {
+			if((tmpvar = ast_new_variable(v->name, v->value))) {
+				tmpvar->next = p->vars; 
+				p->vars = tmpvar;
+			}
+		}
 		p->nat = user->nat;
 #ifdef OSP_SUPPORT
 		p->ospauth = user->ospauth;
@@ -8126,6 +8152,9 @@
 	struct sip_user *user;
 	int format;
 	struct ast_ha *oldha = NULL;
+	char *varname = NULL, *varval = NULL;
+	struct ast_variable *tmpvar = NULL;
+
 	user = (struct sip_user *)malloc(sizeof(struct sip_user));
 	if (user) {
 		memset(user, 0, sizeof(struct sip_user));
@@ -8150,6 +8179,17 @@
 		while(v) {
 			if (!strcasecmp(v->name, "context")) {
 				strncpy(user->context, v->value, sizeof(user->context) - 1);
+			} else if (!strcasecmp(v->name, "setvar")) {
+				varname = ast_strdupa(v->value);
+				if (varname && (varval = strchr(varname,'='))) {
+					*varval = '\0';
+					varval++;
+					if((tmpvar = ast_new_variable(varname, varval))) {
+						tmpvar->next = user->vars;
+						user->vars = tmpvar;
+					}
+
+				}
 			} else if (!strcasecmp(v->name, "permit") ||
 					   !strcasecmp(v->name, "deny")) {
 				user->ha = ast_append_ha(v->name, v->value, user->ha);
@@ -9203,6 +9243,10 @@
 			p = p->next;
 			/* Free associated memory */
 			ast_mutex_destroy(&pl->lock);
+			if(pl->vars) {
+				ast_destroy_realtime(pl->vars);
+				pl->vars = NULL;
+			}
 			free(pl);
 		}
 		iflist = NULL;




More information about the svn-commits mailing list