mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
Bug 5906 - ARRAY dialplan function
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7648 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user