[asterisk-commits] trunk - r7648 /trunk/funcs/func_strings.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Dec 27 00:50:27 CST 2005


Author: tilghman
Date: Tue Dec 27 00:50:25 2005
New Revision: 7648

URL: http://svn.digium.com/view/asterisk?rev=7648&view=rev
Log:
Bug 5906 - ARRAY dialplan function

Modified:
    trunk/funcs/func_strings.c

Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?rev=7648&r1=7647&r2=7648&view=diff
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Tue Dec 27 00:50:25 2005
@@ -157,6 +157,64 @@
 	.read = builtin_function_regex,
 };
 
+static void builtin_function_array(struct ast_channel *chan, char *cmd, char *data, const char *value)
+{
+	char *varv[100];
+	char *valuev[100];
+	char *var, *value2;
+	int varcount, valuecount, i;
+
+	var = ast_strdupa(data);
+	value2 = ast_strdupa(value);
+	if (!var || !value2) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		return;
+	}
+
+	/* The functions this will generally be used with are SORT and ODBC_*, which
+	 * both return comma-delimited lists.  However, if somebody uses literal lists,
+	 * their commas will be translated to vertical bars by the load, and I don't
+	 * want them to be surprised by the result.  Hence, we prefer commas as the
+	 * delimiter, but we'll fall back to vertical bars if commas aren't found.
+	 */
+	if (strchr(var, ',')) {
+		varcount = ast_app_separate_args(var, ',', varv, 100);
+	} else {
+		varcount = ast_app_separate_args(var, '|', varv, 100);
+	}
+
+	if (strchr(value2, ',')) {
+		valuecount = ast_app_separate_args(value2, ',', valuev, 100);
+	} else {
+		valuecount = ast_app_separate_args(value2, '|', valuev, 100);
+	}
+
+	for (i = 0; i < varcount; i++) {
+		if (i < valuecount) {
+			pbx_builtin_setvar_helper(chan, varv[i], valuev[i]);
+		} else {
+			/* We could unset the variable, by passing a NULL, but due to
+			 * pushvar semantics, that could create some undesired behavior. */
+			pbx_builtin_setvar_helper(chan, varv[i], "");
+		}
+	}
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function array_function = {
+	.name = "ARRAY",
+	.synopsis = "Allows setting multiple variables at once",
+	.syntax = "ARRAY(var1[,var2[...][,varN]])",
+	.write = builtin_function_array,
+	.desc =
+"The comma-separated list passed as a value to which the function is set\n"
+"will be interpreted as a set of values to which the comma-separated list\n"
+"of variable names in the argument should be set.\n"
+"Hence, Set(ARRAY(var1,var2)=1,2) will set var1 to 1 and var2 to 2\n",
+};
+
 static char *builtin_function_len(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
 {
 	int length = 0;



More information about the asterisk-commits mailing list