aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_groupcount.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-25 19:21:54 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-25 19:21:54 +0000
commit6038c1b458cb5fdf4b376054d550a59936775ce4 (patch)
tree984c0ba0ef8d6d6187522d0e47795733059fdb99 /funcs/func_groupcount.c
parent9c435dda79d5e9608ab446151502b193391d84e9 (diff)
Merged revisions 61804 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2 ........ r61804 | file | 2007-04-25 14:52:50 -0400 (Wed, 25 Apr 2007) | 2 lines Merge rewritten group counting support. No more storing data on the variable list of the channels. That was bad, mmmk? (issue #7497 reported by sabbathbh) ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@61805 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_groupcount.c')
-rw-r--r--funcs/func_groupcount.c98
1 files changed, 47 insertions, 51 deletions
diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c
index d804e0c1d..f08f0241c 100644
--- a/funcs/func_groupcount.c
+++ b/funcs/func_groupcount.c
@@ -39,24 +39,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
static int 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] = "";
- const char *grp;
+ int count = -1;
+ char group[80] = "", category[80] = "";
ast_app_group_split_group(data, group, sizeof(group), category,
sizeof(category));
- if (ast_strlen_zero(group)) {
- if ((grp = pbx_builtin_getvar_helper(chan, category)))
- ast_copy_string(group, grp, sizeof(group));
- else
- ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n",
- chan->name);
- }
-
- count = ast_app_group_get_count(group, category);
- snprintf(buf, len, "%d", count);
+ if ((count = ast_app_group_get_count(group, category)) == -1)
+ ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
+ else
+ snprintf(buf, len, "%d", count);
return 0;
}
@@ -105,20 +97,26 @@ static struct ast_custom_function group_match_count_function = {
static int group_function_read(struct ast_channel *chan, char *cmd,
char *data, char *buf, size_t len)
{
- char varname[256];
- const char *group;
-
- if (!ast_strlen_zero(data)) {
- snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX,
- data);
- } else {
- ast_copy_string(varname, GROUP_CATEGORY_PREFIX, sizeof(varname));
+ struct ast_group_info *gi = NULL;
+
+ ast_app_group_list_lock();
+
+ gi = ast_app_group_list_head();
+ while (gi) {
+ if (gi->chan != chan)
+ continue;
+ if (ast_strlen_zero(data))
+ break;
+ if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
+ break;
+ gi = AST_LIST_NEXT(gi, list);
}
-
- group = pbx_builtin_getvar_helper(chan, varname);
- if (group)
- ast_copy_string(buf, group, len);
-
+
+ if (gi)
+ ast_copy_string(buf, gi->group, len);
+
+ ast_app_group_list_unlock();
+
return 0;
}
@@ -152,38 +150,36 @@ static struct ast_custom_function group_function = {
static int group_list_function_read(struct ast_channel *chan, char *cmd,
char *data, char *buf, size_t len)
{
- struct ast_var_t *current;
- struct varshead *headp;
+ struct ast_group_info *gi = NULL;
char tmp1[1024] = "";
char tmp2[1024] = "";
if (!chan)
return -1;
- headp = &chan->varshead;
- AST_LIST_TRAVERSE(headp, current, entries) {
- if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) {
- if (!ast_strlen_zero(tmp1)) {
- ast_copy_string(tmp2, tmp1, sizeof(tmp2));
- snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2,
- ast_var_value(current),
- (ast_var_name(current) +
- strlen(GROUP_CATEGORY_PREFIX) + 1));
- } else {
- snprintf(tmp1, sizeof(tmp1), "%s@%s", ast_var_value(current),
- (ast_var_name(current) +
- strlen(GROUP_CATEGORY_PREFIX) + 1));
- }
- } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) {
- if (!ast_strlen_zero(tmp1)) {
- ast_copy_string(tmp2, tmp1, sizeof(tmp2));
- snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2,
- ast_var_value(current));
- } else {
- snprintf(tmp1, sizeof(tmp1), "%s", ast_var_value(current));
- }
+ ast_app_group_list_lock();
+
+ gi = ast_app_group_list_head();
+ while (gi) {
+ if (gi->chan != chan)
+ continue;
+ if (!ast_strlen_zero(tmp1)) {
+ ast_copy_string(tmp2, tmp1, sizeof(tmp2));
+ if (!ast_strlen_zero(gi->category))
+ snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
+ else
+ snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
+ } else {
+ if (!ast_strlen_zero(gi->category))
+ snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
+ else
+ snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
}
+ gi = AST_LIST_NEXT(gi, list);
}
+
+ ast_app_group_list_unlock();
+
ast_copy_string(buf, tmp1, len);
return 0;