[asterisk-commits] tilghman: branch 1.4 r87262 - /branches/1.4/funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Oct 28 08:46:56 CDT 2007


Author: tilghman
Date: Sun Oct 28 08:46:55 2007
New Revision: 87262

URL: http://svn.digium.com/view/asterisk?view=rev&rev=87262
Log:
Add autoservice to several more functions which might delay in their responses.
Also, make sure that func_odbc functions have a channel on which to set
variables.
Reported by russell
Fixed by tilghman
Closes issue #11099

Modified:
    branches/1.4/funcs/func_cut.c
    branches/1.4/funcs/func_odbc.c
    branches/1.4/funcs/func_realtime.c
    branches/1.4/funcs/func_strings.c

Modified: branches/1.4/funcs/func_cut.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/funcs/func_cut.c?view=diff&rev=87262&r1=87261&r2=87262
==============================================================================
--- branches/1.4/funcs/func_cut.c (original)
+++ branches/1.4/funcs/func_cut.c Sun Oct 28 08:46:55 2007
@@ -125,7 +125,7 @@
 	);
 
 	memset(buffer, 0, buflen); 
-	
+
 	parse = ast_strdupa(data);
 
 	AST_STANDARD_APP_ARGS(args, parse);
@@ -253,7 +253,10 @@
 	int ret = -1;
 	struct ast_module_user *u;
 
-	u = ast_module_user_add(chan);
+	if (chan) {
+		ast_autoservice_start(chan);
+		u = ast_module_user_add(chan);
+	}
 
 	switch (cut_internal(chan, data, buf, len)) {
 	case ERROR_NOARG:
@@ -272,7 +275,10 @@
 		ast_log(LOG_ERROR, "Unknown internal error\n");
 	}
 
-	ast_module_user_remove(u);
+	if (chan) {
+		ast_module_user_remove(u);
+		ast_autoservice_stop(chan);
+	}
 
 	return ret;
 }

Modified: branches/1.4/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/funcs/func_odbc.c?view=diff&rev=87262&r1=87261&r2=87262
==============================================================================
--- branches/1.4/funcs/func_odbc.c (original)
+++ branches/1.4/funcs/func_odbc.c Sun Oct 28 08:46:55 2007
@@ -99,7 +99,7 @@
 	struct odbc_obj *obj;
 	struct acf_odbc_query *query;
 	char *t, buf[2048]="", varname[15];
-	int i;
+	int i, bogus_chan = 0;
 	AST_DECLARE_APP_ARGS(values,
 		AST_APP_ARG(field)[100];
 	);
@@ -130,12 +130,24 @@
 		return -1;
 	}
 
+	if (!chan) {
+		if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc")))
+			bogus_chan = 1;
+	}
+
+	if (chan)
+		ast_autoservice_start(chan);
+
 	/* Parse our arguments */
 	t = value ? ast_strdupa(value) : "";
 
 	if (!s || !t) {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		AST_LIST_UNLOCK(&queries);
+		if (chan)
+			ast_autoservice_stop(chan);
+		if (bogus_chan)
+			ast_channel_free(chan);
 		return -1;
 	}
 
@@ -193,6 +205,11 @@
 	if (obj)
 		ast_odbc_release_obj(obj);
 
+	if (chan)
+		ast_autoservice_stop(chan);
+	if (bogus_chan)
+		ast_channel_free(chan);
+
 	return 0;
 }
 
@@ -201,7 +218,7 @@
 	struct odbc_obj *obj;
 	struct acf_odbc_query *query;
 	char sql[2048] = "", varname[15];
-	int res, x, buflen = 0, escapecommas;
+	int res, x, buflen = 0, escapecommas, bogus_chan = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(field)[100];
 	);
@@ -230,6 +247,14 @@
 		return -1;
 	}
 
+	if (!chan) {
+		if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc")))
+			bogus_chan = 1;
+	}
+
+	if (chan)
+		ast_autoservice_start(chan);
+
 	AST_STANDARD_APP_ARGS(args, s);
 	for (x = 0; x < args.argc; x++) {
 		snprintf(varname, sizeof(varname), "ARG%d", x + 1);
@@ -253,6 +278,10 @@
 
 	if (!stmt) {
 		ast_odbc_release_obj(obj);
+		if (chan)
+			ast_autoservice_stop(chan);
+		if (bogus_chan)
+			ast_channel_free(chan);
 		return -1;
 	}
 
@@ -262,6 +291,10 @@
 		SQLCloseCursor(stmt);
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		ast_odbc_release_obj(obj);
+		if (chan)
+			ast_autoservice_stop(chan);
+		if (bogus_chan)
+			ast_channel_free(chan);
 		return -1;
 	}
 
@@ -281,6 +314,10 @@
 		SQLCloseCursor(stmt);
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 		ast_odbc_release_obj(obj);
+		if (chan)
+			ast_autoservice_stop(chan);
+		if (bogus_chan)
+			ast_channel_free(chan);
 		return res1;
 	}
 
@@ -300,6 +337,10 @@
 			SQLCloseCursor(stmt);
 			SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 			ast_odbc_release_obj(obj);
+			if (chan)
+				ast_autoservice_stop(chan);
+			if (bogus_chan)
+				ast_channel_free(chan);
 			return -1;
 		}
 
@@ -326,6 +367,10 @@
 	SQLCloseCursor(stmt);
 	SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 	ast_odbc_release_obj(obj);
+	if (chan)
+		ast_autoservice_stop(chan);
+	if (bogus_chan)
+		ast_channel_free(chan);
 	return 0;
 }
 

Modified: branches/1.4/funcs/func_realtime.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/funcs/func_realtime.c?view=diff&rev=87262&r1=87261&r2=87262
==============================================================================
--- branches/1.4/funcs/func_realtime.c (original)
+++ branches/1.4/funcs/func_realtime.c Sun Oct 28 08:46:55 2007
@@ -74,10 +74,15 @@
 	if (!args.delim2)
 		args.delim2 = "=";
 
+	if (chan)
+		ast_autoservice_start(chan);
+
 	head = ast_load_realtime(args.family, args.fieldmatch, args.value, NULL);
 
 	if (!head) {
 		ast_module_user_remove(u);
+		if (chan)
+			ast_autoservice_stop(chan);
 		return -1;
 	}
 	for (var = head; var; var = var->next)
@@ -89,6 +94,9 @@
 	ast_copy_string(buf, result_begin, len);
 
 	ast_module_user_remove(u);
+
+	if (chan)
+		ast_autoservice_stop(chan);
 
 	return 0;
 }
@@ -109,7 +117,10 @@
 		return -1;
 	}
 
-	u = ast_module_user_add(chan);
+	if (chan) {
+		ast_autoservice_start(chan);
+		u = ast_module_user_add(chan);
+	}
 
 	AST_STANDARD_APP_ARGS(args, data);
 
@@ -119,7 +130,10 @@
 		ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
 	}
 
-	ast_module_user_remove(u);
+	if (chan) {
+		ast_module_user_remove(u);
+		ast_autoservice_stop(chan);
+	}
 
 	return 0;
 }

Modified: branches/1.4/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/funcs/func_strings.c?view=diff&rev=87262&r1=87261&r2=87262
==============================================================================
--- branches/1.4/funcs/func_strings.c (original)
+++ branches/1.4/funcs/func_strings.c Sun Oct 28 08:46:55 2007
@@ -53,6 +53,9 @@
 			     AST_APP_ARG(delim);
 		);
 
+	if (chan)
+		ast_autoservice_start(chan);
+
 	AST_STANDARD_APP_ARGS(args, parse);
 	if (args.delim) {
 		varsubst = alloca(strlen(args.varname) + 4);
@@ -70,6 +73,9 @@
 	}
 	snprintf(buf, len, "%d", fieldcount);
 
+	if (chan)
+		ast_autoservice_stop(chan);
+
 	return 0;
 }
 
@@ -177,6 +183,9 @@
 	value2 = ast_strdupa(value);
 	if (!var || !value2)
 		return -1;
+
+	if (chan)
+		ast_autoservice_start(chan);
 
 	/* The functions this will generally be used with are SORT and ODBC_*, which
 	 * both return comma-delimited lists.  However, if somebody uses literal lists,
@@ -208,6 +217,9 @@
 			pbx_builtin_setvar_helper(chan, arg1.var[i], "");
 		}
 	}
+
+	if (chan)
+		ast_autoservice_stop(chan);
 
 	return 0;
 }
@@ -517,7 +529,11 @@
 		return -1;
 	}
 
+	if (chan)
+		ast_autoservice_start(chan);
 	pbx_substitute_variables_helper(chan, data, buf, len - 1);
+	if (chan)
+		ast_autoservice_stop(chan);
 
 	return 0;
 }




More information about the asterisk-commits mailing list