aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-25 19:27:42 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-04-25 19:27:42 +0000
commitec529b6fa3aea0532ffb5043ec261f020187d0b7 (patch)
treeed6ec8f5e250d0dbcf7b06317f5e74301c1b033c /main
parent6f4a7aa6e9302e6d1a3ea9395a2b95592cc80370 (diff)
Merged revisions 61805 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ................ r61805 | file | 2007-04-25 15:21:54 -0400 (Wed, 25 Apr 2007) | 10 lines 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/trunk@61806 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/app.c119
-rw-r--r--main/channel.c18
-rw-r--r--main/cli.c34
3 files changed, 96 insertions, 75 deletions
diff --git a/main/app.c b/main/app.c
index eb8101709..91441f64e 100644
--- a/main/app.c
+++ b/main/app.c
@@ -49,9 +49,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/indications.h"
+#include "asterisk/linkedlists.h"
#define MAX_OTHER_FORMATS 10
+static AST_LIST_HEAD_STATIC(groups, ast_group_info);
/* !
This function presents a dialtone and reads an extension into 'collect'
@@ -804,61 +806,74 @@ int ast_app_group_split_group(const char *data, char *group, int group_max, char
else
res = -1;
- if (cat)
- snprintf(category, category_max, "%s_%s", GROUP_CATEGORY_PREFIX, cat);
- else
- ast_copy_string(category, GROUP_CATEGORY_PREFIX, category_max);
+ if (!ast_strlen_zero(cat))
+ ast_copy_string(category, cat, category_max);
return res;
}
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
{
- int res=0;
- char group[80] = "";
- char category[80] = "";
-
- if (!ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
- pbx_builtin_setvar_helper(chan, category, group);
- } else
+ int res = 0;
+ char group[80] = "", category[80] = "";
+ struct ast_group_info *gi = NULL;
+ size_t len = 0;
+
+ if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)))
+ return -1;
+
+ /* Calculate memory we will need if this is new */
+ len = sizeof(*gi) + strlen(group) + 1;
+ if (!ast_strlen_zero(category))
+ len += strlen(category) + 1;
+
+ AST_LIST_LOCK(&groups);
+ AST_LIST_TRAVERSE(&groups, gi, list) {
+ if (gi->chan == chan && !strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
+ break;
+ }
+
+ if (!gi && (gi = calloc(1, len))) {
+ gi->chan = chan;
+ gi->group = (char *) gi + sizeof(*gi);
+ strcpy(gi->group, group);
+ if (!ast_strlen_zero(category)) {
+ gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
+ strcpy(gi->category, category);
+ }
+ AST_LIST_INSERT_TAIL(&groups, gi, list);
+ } else {
res = -1;
-
+ }
+
+ AST_LIST_UNLOCK(&groups);
+
return res;
}
int ast_app_group_get_count(const char *group, const char *category)
{
- struct ast_channel *chan;
+ struct ast_group_info *gi = NULL;
int count = 0;
- const char *test;
- char cat[80];
- const char *s;
if (ast_strlen_zero(group))
return 0;
-
- s = S_OR(category, GROUP_CATEGORY_PREFIX);
- ast_copy_string(cat, s, sizeof(cat));
-
- chan = NULL;
- while ((chan = ast_channel_walk_locked(chan)) != NULL) {
- test = pbx_builtin_getvar_helper(chan, cat);
- if (test && !strcasecmp(test, group))
- count++;
- ast_channel_unlock(chan);
+
+ AST_LIST_LOCK(&groups);
+ AST_LIST_TRAVERSE(&groups, gi, list) {
+ if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category)))
+ count++;
}
+ AST_LIST_UNLOCK(&groups);
return count;
}
int ast_app_group_match_get_count(const char *groupmatch, const char *category)
{
+ struct ast_group_info *gi = NULL;
regex_t regexbuf;
- struct ast_channel *chan;
int count = 0;
- const char *test;
- char cat[80];
- const char *s;
if (ast_strlen_zero(groupmatch))
return 0;
@@ -867,22 +882,50 @@ int ast_app_group_match_get_count(const char *groupmatch, const char *category)
if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
return 0;
- s = S_OR(category, GROUP_CATEGORY_PREFIX);
- ast_copy_string(cat, s, sizeof(cat));
-
- chan = NULL;
- while ((chan = ast_channel_walk_locked(chan)) != NULL) {
- test = pbx_builtin_getvar_helper(chan, cat);
- if (test && !regexec(&regexbuf, test, 0, NULL, 0))
+ AST_LIST_LOCK(&groups);
+ AST_LIST_TRAVERSE(&groups, gi, list) {
+ if (!regexec(&regexbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category)))
count++;
- ast_channel_unlock(chan);
}
+ AST_LIST_UNLOCK(&groups);
regfree(&regexbuf);
return count;
}
+int ast_app_group_discard(struct ast_channel *chan)
+{
+ struct ast_group_info *gi = NULL;
+
+ AST_LIST_LOCK(&groups);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
+ if (gi->chan == chan) {
+ AST_LIST_REMOVE_CURRENT(&groups, list);
+ free(gi);
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END
+ AST_LIST_UNLOCK(&groups);
+
+ return 0;
+}
+
+int ast_app_group_list_lock(void)
+{
+ return AST_LIST_LOCK(&groups);
+}
+
+struct ast_group_info *ast_app_group_list_head(void)
+{
+ return AST_LIST_FIRST(&groups);
+}
+
+int ast_app_group_list_unlock(void)
+{
+ return AST_LIST_UNLOCK(&groups);
+}
+
unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
{
int argc;
diff --git a/main/channel.c b/main/channel.c
index eb5877bd7..fc3a31b61 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -3349,22 +3349,6 @@ void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_
*/
static void clone_variables(struct ast_channel *original, struct ast_channel *clone)
{
- struct ast_var_t *varptr;
-
- /* we need to remove all app_groupcount related variables from the original
- channel before merging in the clone's variables; any groups assigned to the
- original channel should be released, only those assigned to the clone
- should remain
- */
-
- AST_LIST_TRAVERSE_SAFE_BEGIN(&original->varshead, varptr, entries) {
- if (!strncmp(ast_var_name(varptr), GROUP_CATEGORY_PREFIX, strlen(GROUP_CATEGORY_PREFIX))) {
- AST_LIST_REMOVE_CURRENT(&original->varshead, entries);
- ast_var_delete(varptr);
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
-
/* Append variables from clone channel into original channel */
/* XXX Is this always correct? We have to in order to keep MACROS working XXX */
if (AST_LIST_FIRST(&clone->varshead))
@@ -3558,6 +3542,8 @@ int ast_do_masquerade(struct ast_channel *original)
original->fds[x] = clone->fds[x];
}
+ ast_app_group_discard(original);
+
/* move any whisperer over */
ast_channel_whisper_stop(original);
if (ast_test_flag(clone, AST_FLAG_WHISPER)) {
diff --git a/main/cli.c b/main/cli.c
index b84739984..1f0d063f7 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -905,10 +905,8 @@ static int group_show_channels(int fd, int argc, char *argv[])
{
#define FORMAT_STRING "%-25s %-20s %-20s\n"
- struct ast_channel *c = NULL;
+ struct ast_group_info *gi = NULL;
int numchans = 0;
- struct ast_var_t *current;
- struct varshead *headp;
regex_t regexbuf;
int havepattern = 0;
@@ -922,26 +920,20 @@ static int group_show_channels(int fd, int argc, char *argv[])
}
ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
- while ( (c = ast_channel_walk_locked(c)) != NULL) {
- headp=&c->varshead;
- AST_LIST_TRAVERSE(headp,current,entries) {
- if (!strncmp(ast_var_name(current), GROUP_CATEGORY_PREFIX "_", strlen(GROUP_CATEGORY_PREFIX) + 1)) {
- if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
- ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current),
- (ast_var_name(current) + strlen(GROUP_CATEGORY_PREFIX) + 1));
- numchans++;
- }
- } else if (!strcmp(ast_var_name(current), GROUP_CATEGORY_PREFIX)) {
- if (!havepattern || !regexec(&regexbuf, ast_var_value(current), 0, NULL, 0)) {
- ast_cli(fd, FORMAT_STRING, c->name, ast_var_value(current), "(default)");
- numchans++;
- }
- }
+
+ ast_app_group_list_lock();
+
+ gi = ast_app_group_list_head();
+ while (gi) {
+ if (!havepattern || !regexec(&regexbuf, gi->group, 0, NULL, 0)) {
+ ast_cli(fd, FORMAT_STRING, gi->chan->name, gi->group, (ast_strlen_zero(gi->category) ? "(default)" : gi->category));
+ numchans++;
}
- numchans++;
- ast_channel_unlock(c);
+ gi = AST_LIST_NEXT(gi, list);
}
-
+
+ ast_app_group_list_unlock();
+
if (havepattern)
regfree(&regexbuf);