aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_groupcount.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-05 05:39:33 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-05 05:39:33 +0000
commit6a262d98eeee9e0b4bfac92d88aacad6c4fab935 (patch)
treed1f6c678019f87fb5730998dc62af2c209dc66d6 /funcs/func_groupcount.c
parent7fe9220d99afa1950199d7effe66b81aa2ec64b7 (diff)
major re-work of dialplan functions, including:
- locking of functions list during registration/unregistration/searching - rename of function description structure to be consistent with the rest of the API - addition of 'desc' element to description structure, for detailed description (like applications) - addition of 'show function' CLI command to show function details - conversion of existing functions to use uppercase names to match policy - creation of new 'pbx_functions.so' module to contain standard 'builtin' functions - removal of all builtin functions from pbx.c and apps and placement into new 'funcs' directory git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5583 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_groupcount.c')
-rwxr-xr-xfuncs/func_groupcount.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c
new file mode 100755
index 000000000..2cae72922
--- /dev/null
+++ b/funcs/func_groupcount.c
@@ -0,0 +1,81 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Channel group related dialplan functions
+ *
+ * Copyright (C) 2005, Digium, Inc.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+
+static char *group_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ int count;
+ char group[80] = "";
+ char category[80] = "";
+ char *grp;
+
+ ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
+
+ if (ast_strlen_zero(group)) {
+ grp = pbx_builtin_getvar_helper(chan, category);
+ strncpy(group, grp, sizeof(group) - 1);
+ }
+
+ count = ast_app_group_get_count(group, category);
+ snprintf(buf, len, "%d", count);
+
+ return buf;
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function group_count_function = {
+ .name = "GROUP_COUNT",
+ .syntax = "GROUP_COUNT([groupname][@category])",
+ .synopsis = "Counts the number of channels in the specified group",
+ .desc = "Calculates the group count for the specified group, or uses the\n"
+ "channel's current group if not specifed (and non-empty).\n",
+ .read = group_count_function_read,
+};
+
+static char *group_match_count_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ int count;
+ char group[80] = "";
+ char category[80] = "";
+
+ ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category));
+
+ if (!ast_strlen_zero(group)) {
+ count = ast_app_group_match_get_count(group, category);
+ snprintf(buf, len, "%d", count);
+ }
+
+ return buf;
+}
+
+#ifndef BUILTIN_FUNC
+static
+#endif
+struct ast_custom_function group_match_count_function = {
+ .name = "GROUP_MATCH_COUNT",
+ .syntax = "GROUP_MATCH_COUNT(groupmatch[@category])",
+ .synopsis = "Counts the number of channels in the groups matching the specified pattern",
+ .desc = "Calculates the group count for all groups that match the specified pattern.\n"
+ "Uses standard regular expression matching (see regex(7)).\n",
+ .read = group_match_count_function_read,
+ .write = NULL,
+};