[svn-commits] oej: branch oej/bufo-manager-varfix r282978 - /team/oej/bufo-manager-varfix/m...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 20 06:52:02 CDT 2010


Author: oej
Date: Fri Aug 20 06:51:59 2010
New Revision: 282978

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=282978
Log:
Precautions taken

Modified:
    team/oej/bufo-manager-varfix/main/manager.c

Modified: team/oej/bufo-manager-varfix/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-varfix/main/manager.c?view=diff&rev=282978&r1=282977&r2=282978
==============================================================================
--- team/oej/bufo-manager-varfix/main/manager.c (original)
+++ team/oej/bufo-manager-varfix/main/manager.c Fri Aug 20 06:51:59 2010
@@ -249,6 +249,27 @@
 static struct manager_action *first_action;
 AST_RWLOCK_DEFINE_STATIC(actionlock);
 
+/*! \brief copy variables, preserving order */
+static 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;
+}
+
 /*! \brief Convert authority code to string with serveral options */
 static char *authority_to_str(int authority, char *res, int reslen)
 {
@@ -1918,6 +1939,9 @@
 	/* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
 	if (chan)
 		ast_channel_unlock(chan);
+	if (in->vars) {
+		ast_variables_destroy(in->vars);
+	}
 	free(in);
 	return NULL;
 }
@@ -1952,7 +1976,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 = astman_get_variables(m);
+	struct ast_variable *vars = NULL;
 	char *tech, *data;
 	char *l = NULL, *n = NULL;
 	int pi = 0;
@@ -2002,6 +2026,12 @@
 		format = 0;
 		ast_parse_allow_disallow(NULL, &format, codecs, 1);
 	}
+
+	/* read variables from manager command and allocate memory now
+	   when we're ready to start acting.
+	*/
+	vars = astman_get_variables(m);
+
 	if (ast_true(async)) {
 		struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
 		if (!fast) {
@@ -2017,7 +2047,7 @@
 				ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
 			if (n)
 				ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
-			fast->vars = vars;	
+			fast->vars = ast_variable_copy(vars);
 			ast_copy_string(fast->context, context, sizeof(fast->context));
 			ast_copy_string(fast->exten, exten, sizeof(fast->exten));
 			ast_copy_string(fast->account, account, sizeof(fast->account));
@@ -2027,6 +2057,9 @@
 			pthread_attr_init(&attr);
 			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 			if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
+				if (fast->vars) {
+					ast_variables_destroy(fast->vars);
+				}
 				ast_free(fast);
 				res = -1;
 			} else {
@@ -2041,6 +2074,9 @@
 	        	res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
 		else {
 			astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
+			if (vars) {
+				ast_variables_destroy(vars);
+			}
 			return 0;
 		}
 	}   
@@ -2048,6 +2084,9 @@
 		astman_send_ack(s, m, "Originate successfully queued");
 	else
 		astman_send_error(s, m, "Originate failed");
+	if (vars) {
+		ast_variables_destroy(vars);
+	}
 	return 0;
 }
 




More information about the svn-commits mailing list