[asterisk-commits] oej: branch group/bufo-manager-setvar-trunk r287638 - in /team/group/bufo-man...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 20 15:14:49 CDT 2010


Author: oej
Date: Mon Sep 20 15:14:43 2010
New Revision: 287638

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=287638
Log:
Porting manager setvar to trunk

Modified:
    team/group/bufo-manager-setvar-trunk/include/asterisk/config.h
    team/group/bufo-manager-setvar-trunk/main/config.c
    team/group/bufo-manager-setvar-trunk/main/manager.c

Modified: team/group/bufo-manager-setvar-trunk/include/asterisk/config.h
URL: http://svnview.digium.com/svn/asterisk/team/group/bufo-manager-setvar-trunk/include/asterisk/config.h?view=diff&rev=287638&r1=287637&r2=287638
==============================================================================
--- team/group/bufo-manager-setvar-trunk/include/asterisk/config.h (original)
+++ team/group/bufo-manager-setvar-trunk/include/asterisk/config.h Mon Sep 20 15:14:43 2010
@@ -436,6 +436,11 @@
 
 /*! \brief Check if there's any realtime engines loaded */
 int ast_realtime_enabled(void);
+
+/*! \brief copy variables, preserving order 
+ *  \param in the linked list of variables to copy
+ */
+struct ast_variable *ast_variable_copy(struct ast_variable *in);
 
 /*!
  * \brief Free variable list

Modified: team/group/bufo-manager-setvar-trunk/main/config.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bufo-manager-setvar-trunk/main/config.c?view=diff&rev=287638&r1=287637&r2=287638
==============================================================================
--- team/group/bufo-manager-setvar-trunk/main/config.c (original)
+++ team/group/bufo-manager-setvar-trunk/main/config.c Mon Sep 20 15:14:43 2010
@@ -394,6 +394,27 @@
 	}
 
 	*comment = NULL;
+}
+
+/*! \brief copy variables, preserving order */
+struct ast_variable *ast_variable_copy(struct ast_variable *in)
+{
+	/* This really belongs in config.c, and will move there in non-releases */
+
+	struct ast_variable *out = NULL, *tmp, *v, *prev = NULL;
+
+	for (v = in ; v ; v = v->next) {
+		if ((tmp = ast_variable_new(v->name, v->value, ""))) {
+			if (!out) {
+				out = tmp;	/* The first record */
+			}
+			if (prev) {
+				prev->next = tmp; 
+			}
+			prev = tmp;
+		}
+	}
+	return out;
 }
 
 void ast_variables_destroy(struct ast_variable *v)

Modified: team/group/bufo-manager-setvar-trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bufo-manager-setvar-trunk/main/manager.c?view=diff&rev=287638&r1=287637&r2=287638
==============================================================================
--- team/group/bufo-manager-setvar-trunk/main/manager.c (original)
+++ team/group/bufo-manager-setvar-trunk/main/manager.c Mon Sep 20 15:14:43 2010
@@ -939,6 +939,7 @@
 	int inlen;		/*!< number of buffered bytes */
 	struct ao2_container *whitefilters;	/*!< Manager event filters - white list */
 	struct ao2_container *blackfilters;	/*!< Manager event filters - black list */
+	struct ast_variable *chanvars;  /*!< Channel variables to set for originate */
 	int send_events;	/*!<  XXX what ? */
 	struct eventqent *last_ev;	/*!< last event processed. */
 	int writetimeout;	/*!< Timeout for ast_carefulwrite() */
@@ -992,6 +993,7 @@
 	struct ao2_container *whitefilters; /*!< Manager event filters - white list */
 	struct ao2_container *blackfilters; /*!< Manager event filters - black list */
 	char *a1_hash;			/*!< precalculated A1 for Digest auth */
+	struct ast_variable *chanvars;  /*!< Channel variables to set for originate */
 	AST_RWLIST_ENTRY(ast_manager_user) list;
 };
 
@@ -1241,6 +1243,9 @@
 	if (eqe) {
 		ast_atomic_fetchadd_int(&eqe->usecount, -1);
 	}
+	if (session->chanvars) {
+		ast_variables_destroy(session->chanvars);
+	}
 
 	if (session->whitefilters) {
 		ao2_t_callback(session->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters");
@@ -1500,6 +1505,7 @@
 		"      read perm: %s\n"
 		"     write perm: %s\n"
 		"displayconnects: %s\n",
+/* XXX Add setvar channel variables */
 		(user->username ? user->username : "(N/A)"),
 		(user->secret ? "<Set>" : "(N/A)"),
 		(user->ha ? "yes" : "no"),
@@ -2293,6 +2299,7 @@
 	s->session->readperm = user->readperm;
 	s->session->writeperm = user->writeperm;
 	s->session->writetimeout = user->writetimeout;
+	s->session->chanvars = ast_variable_copy(user->chanvars);
 
 	filter_iter = ao2_iterator_init(user->whitefilters, 0);
 	while ((regex_filter = ao2_iterator_next(&filter_iter))) {
@@ -3814,7 +3821,7 @@
 	const char *async = astman_get_header(m, "Async");
 	const char *id = astman_get_header(m, "ActionID");
 	const char *codecs = astman_get_header(m, "Codecs");
-	struct ast_variable *vars;
+	struct ast_variable *vars = NULL;
 	char *tech, *data;
 	char *l = NULL, *n = NULL;
 	int pi = 0;
@@ -3865,8 +3872,30 @@
 		format = 0;
 		ast_parse_allow_disallow(NULL, &format, codecs, 1);
 	}
-	/* Allocate requested channel variables */
+
+	/* read variables from manager command and allocate memory now */
 	vars = astman_get_variables(m);
+	if (s->session->chanvars) {
+		struct ast_variable *v, *old;
+		old = vars;
+		vars = NULL;
+
+		/* The variables in the originate command is appended at the
+			end of the list, to override */
+
+		vars = ast_variable_copy(s->session->chanvars);
+		/* copy channel vars */
+		if (old ) {
+			for (v = vars ; v ; ) {
+				if (!v->next) {
+					v->next = old;	/* Append originate variables at end of list */
+					v = NULL;
+				} else {
+					v = v->next;	/* Loop */
+				}
+			}
+		}
+	}
 
 	if (ast_true(async)) {
 		struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
@@ -6440,6 +6469,18 @@
 				} else {
 					user->writetimeout = value;
 				}
+			} else if (!strcasecmp(var->name, "setvar")) {
+				struct ast_variable *tmpvar;
+				char *varval;
+				char *varname = ast_strdupa(var->value);
+
+				if ((varval = strchr(varname,'='))) {
+					*varval++ = '\0';
+					if ((tmpvar = ast_variable_new(varname, varval, ""))) {
+						tmpvar->next = user->chanvars;
+						user->chanvars = tmpvar;
+					}
+				}
 			} else if (!strcasecmp(var->name, "eventfilter")) {
 				const char *value = var->value;
 				regex_t *new_filter = ao2_t_alloc(sizeof(*new_filter), event_filter_destructor, "event_filter allocation");




More information about the asterisk-commits mailing list