Index: funcs/func_strings.c =================================================================== RCS file: /usr/cvsroot/asterisk/funcs/func_strings.c,v retrieving revision 1.17 diff -u -r1.17 func_strings.c --- funcs/func_strings.c 30 Nov 2005 08:50:00 -0000 1.17 +++ funcs/func_strings.c 1 Dec 2005 17:07:25 -0000 @@ -119,6 +119,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;