aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app.c113
-rw-r--r--apps/app_groupcount.c32
-rw-r--r--channel.c21
-rw-r--r--channels/chan_modem.c2
-rw-r--r--channels/chan_phone.c4
-rw-r--r--channels/chan_sip.c2
-rw-r--r--channels/chan_zap.c10
-rw-r--r--channels/misdn/isdn_lib.c100
-rw-r--r--channels/misdn/isdn_lib.h1
-rw-r--r--channels/misdn/isdn_lib_intern.h4
-rw-r--r--funcs/func_groupcount.c102
-rw-r--r--include/asterisk/app.h19
-rw-r--r--manager.c3
13 files changed, 239 insertions, 174 deletions
diff --git a/app.c b/app.c
index bbd3bfdad..dd4a1853b 100644
--- a/app.c
+++ b/app.c
@@ -48,9 +48,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'
@@ -1023,61 +1025,74 @@ int ast_app_group_split_group(char *data, char *group, int group_max, char *cate
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, char *data)
{
- int res=0;
- char group[80] = "";
- char category[80] = "";
+ 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 (!ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
- pbx_builtin_setvar_helper(chan, category, group);
- } else
+ 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(char *group, char *category)
{
- struct ast_channel *chan;
+ struct ast_group_info *gi = NULL;
int count = 0;
- char *test;
- char cat[80];
- char *s;
if (ast_strlen_zero(group))
return 0;
- s = (!ast_strlen_zero(category)) ? 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_mutex_unlock(&chan->lock);
+ 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(char *groupmatch, char *category)
{
+ struct ast_group_info *gi = NULL;
regex_t regexbuf;
- struct ast_channel *chan;
int count = 0;
- char *test;
- char cat[80];
- char *s;
if (ast_strlen_zero(groupmatch))
return 0;
@@ -1086,22 +1101,50 @@ int ast_app_group_match_get_count(char *groupmatch, char *category)
if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
return 0;
- s = (!ast_strlen_zero(category)) ? 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_mutex_unlock(&chan->lock);
}
+ 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/apps/app_groupcount.c b/apps/app_groupcount.c
index 87d313209..496f62b8f 100644
--- a/apps/app_groupcount.c
+++ b/apps/app_groupcount.c
@@ -201,10 +201,8 @@ static int group_show_channels(int fd, int argc, char *argv[])
{
#define FORMAT_STRING "%-25s %-20s %-20s\n"
- struct ast_channel *c = NULL;
int numchans = 0;
- struct ast_var_t *current;
- struct varshead *headp;
+ struct ast_group_info *gi = NULL;
regex_t regexbuf;
int havepattern = 0;
@@ -218,26 +216,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_mutex_unlock(&c->lock);
+ gi = AST_LIST_NEXT(gi, list);
}
+ ast_app_group_list_unlock();
+
if (havepattern)
regfree(&regexbuf);
diff --git a/channel.c b/channel.c
index c218c437e..55276c9ec 100644
--- a/channel.c
+++ b/channel.c
@@ -954,6 +954,9 @@ void ast_channel_free(struct ast_channel *chan)
while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
ast_var_delete(vardata);
+ /* Drop out of the group counting radar */
+ ast_app_group_discard(chan);
+
free(chan);
ast_mutex_unlock(&chlock);
@@ -2920,22 +2923,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))
@@ -3118,6 +3105,8 @@ int ast_do_masquerade(struct ast_channel *original)
for (x = 0; x < AST_MAX_FDS; x++) {
original->fds[x] = clone->fds[x];
}
+ /* Drop group from original */
+ ast_app_group_discard(original);
clone_variables(original, clone);
AST_LIST_HEAD_INIT_NOLOCK(&clone->varshead);
/* Presense of ADSI capable CPE follows clone */
diff --git a/channels/chan_modem.c b/channels/chan_modem.c
index 8be355ea5..d95d175bb 100644
--- a/channels/chan_modem.c
+++ b/channels/chan_modem.c
@@ -717,8 +717,8 @@ static int restart_monitor()
return -1;
}
if (monitor_thread != AST_PTHREADT_NULL) {
+ /* Wake up the thread */
pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
} else {
/* Start a new monitor */
if (ast_pthread_create(&monitor_thread, NULL, do_monitor, NULL) < 0) {
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index ad7b87013..669e87507 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -1092,10 +1092,8 @@ static int restart_monitor()
ast_log(LOG_WARNING, "Unable to lock the interface list\n");
return -1;
}
+ /* Wake up the thread */
pthread_cancel(monitor_thread);
-#if 0
- pthread_join(monitor_thread, NULL);
-#endif
ast_mutex_unlock(&iflock);
}
/* Start a new monitor */
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 9ef5e9fab..b1af16381 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -7425,6 +7425,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme
p->noncodeccapability |= AST_RTP_DTMF;
else
p->noncodeccapability &= ~AST_RTP_DTMF;
+ p->jointnoncodeccapability = p->noncodeccapability;
}
if (user && debug)
ast_verbose("Found user '%s'\n", user->name);
@@ -7534,6 +7535,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme
p->noncodeccapability |= AST_RTP_DTMF;
else
p->noncodeccapability &= ~AST_RTP_DTMF;
+ p->jointnoncodeccapability = p->noncodeccapability;
}
ASTOBJ_UNREF(peer,sip_destroy_peer);
} else {
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index ab3e15ef7..755e80661 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -5281,7 +5281,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int
if (!ast_strlen_zero(i->cid_name))
tmp->cid.cid_name = strdup(i->cid_name);
if (!ast_strlen_zero(i->cid_ani))
- tmp->cid.cid_ani = strdup(i->cid_num);
+ tmp->cid.cid_ani = strdup(i->cid_ani);
else if (!ast_strlen_zero(i->cid_num))
tmp->cid.cid_ani = strdup(i->cid_num);
#else
@@ -6836,14 +6836,8 @@ static int restart_monitor(void)
return -1;
}
if (monitor_thread != AST_PTHREADT_NULL) {
- /* Just signal it to be sure it wakes up */
-#if 0
- pthread_cancel(monitor_thread);
-#endif
+ /* Wake up the thread */
pthread_kill(monitor_thread, SIGURG);
-#if 0
- pthread_join(monitor_thread, NULL);
-#endif
} else {
/* Start a new monitor */
if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
diff --git a/channels/misdn/isdn_lib.c b/channels/misdn/isdn_lib.c
index 5f2d847c5..439f3a880 100644
--- a/channels/misdn/isdn_lib.c
+++ b/channels/misdn/isdn_lib.c
@@ -1085,6 +1085,10 @@ int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, in
cb_log(8, port, "Init.BC %d.\n",bidx);
memset(bc, 0,sizeof(struct misdn_bchannel));
+
+ bc->send_lock=malloc(sizeof(struct send_lock));
+
+ pthread_mutex_init(&bc->send_lock->lock, NULL);
if (msn) {
int l = sizeof(bc->msn);
@@ -1189,6 +1193,7 @@ struct misdn_stack* stack_init( int midev, int port, int ptp )
stack->nt=1;
break;
+#ifndef MISDN_1_2
case ISDN_PID_L0_TE_U:
break;
case ISDN_PID_L0_NT_U:
@@ -1197,6 +1202,7 @@ struct misdn_stack* stack_init( int midev, int port, int ptp )
break;
case ISDN_PID_L0_NT_UP2:
break;
+#endif
case ISDN_PID_L0_TE_E1:
cb_log(8, port, "TE S2M Stack\n");
stack->nt=0;
@@ -1521,14 +1527,6 @@ int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
case EVENT_RELEASE_COMPLETE:
case EVENT_RELEASE:
- if (bc->channel>0)
- empty_chan_in_stack(stack,bc->channel);
- int tmpcause=bc->cause;
- int tmp_out_cause=bc->out_cause;
- empty_bc(bc);
- bc->cause=tmpcause;
- bc->out_cause=tmp_out_cause;
- clean_up_bc(bc);
break;
default:
break;
@@ -1584,17 +1582,18 @@ int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo);
if (bc->channel>0)
empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
-
- clean_up_bc(bc);
- dump_chan_list(stack);
/*bc->pid = 0;*/
bc->need_disconnect=0;
bc->need_release=0;
bc->need_release_complete=0;
-
+
cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data);
+
+ empty_bc(bc);
+ clean_up_bc(bc);
+ dump_chan_list(stack);
+
if (bc->stack_holder) {
cb_log(4,stack->port, "REMOVEING Holder\n");
stack_holder_remove( stack, bc);
@@ -2653,6 +2652,18 @@ int handle_frm(msg_t *msg)
}
}
+ if (event == EVENT_RELEASE_COMPLETE) {
+ /* release bchannel only after we've anounced the RELEASE_COMPLETE */
+ if (bc->channel>0)
+ empty_chan_in_stack(stack,bc->channel);
+ int tmpcause=bc->cause;
+ int tmp_out_cause=bc->out_cause;
+ empty_bc(bc);
+ bc->cause=tmpcause;
+ bc->out_cause=tmp_out_cause;
+ clean_up_bc(bc);
+ }
+
cb_log(5, stack->port, "Freeing Msg on prim:%x \n",frm->prim);
@@ -3167,21 +3178,37 @@ void misdn_lib_log_ies(struct misdn_bchannel *bc)
cb_log(5, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
}
+#define RETURN(a,b) {retval=a; goto b;}
+
+void misdn_send_lock(struct misdn_bchannel *bc)
+{
+ //cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
+ pthread_mutex_lock(&bc->send_lock->lock);
+}
+
+void misdn_send_unlock(struct misdn_bchannel *bc)
+{
+ //cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
+ pthread_mutex_unlock(&bc->send_lock->lock);
+}
+
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
{
msg_t *msg;
- int err = -1 ;
- int ret=0;
+ int retval=0;
- if (!bc) goto ERR;
+ if (!bc) RETURN(-1,OUT_POST_UNLOCK);
struct misdn_stack *stack=get_stack_by_bc(bc);
if (!stack) {
cb_log(0,bc->port,"SENDEVENT: no Stack for event:%s oad:%s dad:%s \n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad);
- return -1;
+ RETURN(-1,OUT);
}
+ misdn_send_lock(bc);
+
+
cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id);
if ( stack->nt && !stack->l1link) {
@@ -3189,7 +3216,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
bc->evq=event;
cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0));
misdn_lib_get_l1_up(stack);
- return 0;
+ RETURN(0,OUT);
}
cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s pid:%d\n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad, bc->pid);
@@ -3201,8 +3228,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
if (create_process(glob_mgr->midev, bc)<0) {
cb_log(0, stack->port, " No free channel at the moment @ send_event\n");
- err=-ENOCHAN;
- goto ERR;
+ RETURN(-ENOCHAN,OUT);
}
#if 0
if (stack->nt) {
@@ -3218,8 +3244,6 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_ALERTING:
case EVENT_PROCEEDING:
case EVENT_SETUP_ACKNOWLEDGE:
- if (!bc->nt && !stack->ptp) break;
-
case EVENT_CONNECT:
case EVENT_RETRIEVE_ACKNOWLEDGE:
@@ -3229,21 +3253,19 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
if (!bc->channel) {
cb_log(0, stack->port, " No free channel at the moment\n");
/*FIXME: add disconnect*/
- err=-ENOCHAN;
- goto ERR;
+ RETURN(-ENOCHAN,OUT);
}
if (set_chan_in_stack(stack ,bc->channel)<0) {
/*FIXME: add disconnect*/
- err=-ENOCHAN;
- goto ERR;
+ RETURN(-ENOCHAN,OUT);
}
}
/* Its that i generate channels */
}
- ret=setup_bc(bc);
- if (ret == -EINVAL) {
+ retval=setup_bc(bc);
+ if (retval == -EINVAL) {
cb_log(0,bc->port,"send_event: setup_bc failed\n");
}
@@ -3276,7 +3298,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
struct misdn_bchannel *holded_bc=malloc(sizeof(struct misdn_bchannel));
if (!holded_bc) {
cb_log(0,bc->port, "Could not allocate holded_bc!!!\n");
- return -1;
+ RETURN(-1,OUT);
}
/*backup the bc*/
@@ -3311,7 +3333,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_DISCONNECT:
if (!bc->need_disconnect) {
cb_log(0,bc->port," --> we have already send Disconnect\n");
- return -1;
+ RETURN(-1,OUT);
}
bc->need_disconnect=0;
@@ -3319,7 +3341,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_RELEASE:
if (!bc->need_release) {
cb_log(0,bc->port," --> we have already send Release\n");
- return -1;
+ RETURN(-1,OUT);
}
bc->need_disconnect=0;
bc->need_release=0;
@@ -3327,7 +3349,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_RELEASE_COMPLETE:
if (!bc->need_release_complete) {
cb_log(0,bc->port," --> we have already send Release_complete\n");
- return -1;
+ RETURN(-1,OUT);
}
bc->need_disconnect=0;
bc->need_release=0;
@@ -3349,13 +3371,12 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_CONNECT_ACKNOWLEDGE:
if ( bc->nt || misdn_cap_is_speech(bc->capability)) {
- int ret=setup_bc(bc);
- if (ret == -EINVAL){
+ int retval=setup_bc(bc);
+ if (retval == -EINVAL){
cb_log(0,bc->port,"send_event: setup_bc failed\n");
}
}
-
if (misdn_cap_is_speech(bc->capability)) {
if ( !bc->nodsp) manager_ph_control(bc, DTMF_TONE_START, 0);
@@ -3381,10 +3402,11 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
msg_queue_tail(&stack->downqueue, msg);
sem_post(&glob_mgr->new_msg);
- return 0;
-
- ERR:
- return -1;
+OUT:
+ misdn_send_unlock(bc);
+
+OUT_POST_UNLOCK:
+ return retval;
}
diff --git a/channels/misdn/isdn_lib.h b/channels/misdn/isdn_lib.h
index 4b687c3b6..9ddac45bb 100644
--- a/channels/misdn/isdn_lib.h
+++ b/channels/misdn/isdn_lib.h
@@ -213,6 +213,7 @@ union facility {
struct misdn_bchannel {
+ struct send_lock *send_lock;
int nt;
int port;
diff --git a/channels/misdn/isdn_lib_intern.h b/channels/misdn/isdn_lib_intern.h
index ff63339bc..fad1acead 100644
--- a/channels/misdn/isdn_lib_intern.h
+++ b/channels/misdn/isdn_lib_intern.h
@@ -24,6 +24,10 @@
ibuffer_t *astbuf;
ibuffer_t *misdnbuf;
+struct send_lock {
+ pthread_mutex_t lock;
+};
+
struct isdn_msg {
unsigned long misdn_msg;
diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c
index 87bcdf4f5..862966bd8 100644
--- a/funcs/func_groupcount.c
+++ b/funcs/func_groupcount.c
@@ -37,22 +37,15 @@
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;
+ 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 buf;
}
@@ -100,18 +93,25 @@ struct ast_custom_function group_match_count_function = {
static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- char varname[256];
- char *group;
+ struct ast_group_info *gi = NULL;
- 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));
- }
+ 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 buf;
}
@@ -144,33 +144,35 @@ struct ast_custom_function group_function = {
static char *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;
- char tmp1[1024] = "";
- char tmp2[1024] = "";
-
- if (!chan)
- return "";
-
- 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_copy_string(buf, tmp1, len);
+ struct ast_group_info *gi = NULL;
+ char tmp1[1024] = "";
+ char tmp2[1024] = "";
+
+ 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 buf;
}
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index 972314c57..b09cc8eb8 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -166,7 +166,12 @@ int ast_unlock_path(const char *path);
/*! Read a file into asterisk*/
char *ast_read_textfile(const char *file);
-#define GROUP_CATEGORY_PREFIX "GROUP"
+struct ast_group_info {
+ struct ast_channel *chan;
+ char *category;
+ char *group;
+ AST_LIST_ENTRY(ast_group_info) list;
+};
/*! Split a group string into group and category, returning a default category if none is provided. */
int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max);
@@ -180,6 +185,18 @@ int ast_app_group_get_count(char *group, char *category);
/*! Get the current channel count of all groups that match the specified pattern and category. */
int ast_app_group_match_get_count(char *groupmatch, char *category);
+/*! Discard all group counting for a channel */
+int ast_app_group_discard(struct ast_channel *chan);
+
+/*! Lock the group count list */
+int ast_app_group_list_lock(void);
+
+/*! Get the head of the group count list */
+struct ast_group_info *ast_app_group_list_head(void);
+
+/*! Unlock the group count list */
+int ast_app_group_list_unlock(void);
+
/*!
\brief Define an application argument
\param name The name of the argument
diff --git a/manager.c b/manager.c
index e83c55e20..f884a9d24 100644
--- a/manager.c
+++ b/manager.c
@@ -533,7 +533,8 @@ static int authenticate(struct mansession *s, struct message *m)
} else if (ha)
ast_free_ha(ha);
if (!strcasecmp(authtype, "MD5")) {
- if (!ast_strlen_zero(key) && s->challenge) {
+ if (!ast_strlen_zero(key) &&
+ !ast_strlen_zero(s->challenge) && !ast_strlen_zero(password)) {
int x;
int len=0;
char md5key[256] = "";