[Asterisk-cvs] asterisk/apps app_cut.c,1.6,1.7
kpfleming at lists.digium.com
kpfleming at lists.digium.com
Fri Apr 1 16:09:56 CST 2005
Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv2517/apps
Modified Files:
app_cut.c
Log Message:
add FIELDQTY function to split variable contents and get any desired field (bug #3731)
Index: app_cut.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_cut.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- app_cut.c 14 Jul 2004 07:22:30 -0000 1.6
+++ app_cut.c 1 Apr 2005 22:03:17 -0000 1.7
@@ -169,14 +169,44 @@
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);
}
More information about the svn-commits
mailing list