aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 06:50:25 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 06:50:25 +0000
commit1cff9118712533eb3f68e7eaf6332d9d455ca973 (patch)
treeeffc953747f7e8442ec05700d048c61c5ef7b284 /funcs/func_strings.c
parent3472d69fa7dcce4707c3a49ad86506d76c167552 (diff)
Bug 5906 - ARRAY dialplan function
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7648 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_strings.c')
-rw-r--r--funcs/func_strings.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index b9c45014e..48c3e8a5d 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -157,6 +157,64 @@ struct ast_custom_function regex_function = {
.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;