aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-04-01 22:03:17 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-04-01 22:03:17 +0000
commita606c8bd6a74870fa75e72203dc5361ac4d4cde5 (patch)
treef16b8a10d9117fdf91b1d76898a6642bc7487008 /apps
parentd40a3ddc7708392188c8dcb1a4c291256d1c48cf (diff)
add FIELDQTY function to split variable contents and get any desired field (bug #3731)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5353 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-xapps/app_cut.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/apps/app_cut.c b/apps/app_cut.c
index da397f66e..6bcc9be20 100755
--- a/apps/app_cut.c
+++ b/apps/app_cut.c
@@ -169,14 +169,44 @@ static int cut_exec(struct ast_channel *chan, void *data)
return res;
}
+static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ char *varname, *varval="", workspace[256];
+ char *delim = ast_strdupa(data);
+ int fieldcount=0;
+
+ if (delim) {
+ varname = strsep(&delim, "|");
+ pbx_retrieve_variable(chan, varname, &varval, workspace, sizeof(workspace), NULL);
+ while (strsep(&varval, delim)) {
+ fieldcount++;
+ }
+ snprintf(buf, len, "%d", fieldcount);
+ } else {
+ ast_log(LOG_ERROR, "Out of memory\n");
+ strncpy(buf, "1", len);
+ }
+ return buf;
+}
+
+static struct ast_custom_function_obj fieldqty_function = {
+ .name = "FIELDQTY",
+ .desc = "Count the fields, with an arbitrary delimiter",
+ .syntax = "FIELDQTY(<varname>,<delim>)",
+ .read = function_fieldqty,
+ .write = NULL,
+};
+
int unload_module(void)
{
STANDARD_HANGUP_LOCALUSERS;
+ ast_custom_function_unregister(&fieldqty_function);
return ast_unregister_application(app_cut);
}
int load_module(void)
{
+ ast_custom_function_register(&fieldqty_function);
return ast_register_application(app_cut, cut_exec, cut_synopsis, cut_descrip);
}