mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-24 22:58:21 +00:00
Allow multiple groups (group categories)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3445 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -29,12 +29,12 @@ static char *app_group_count = "GetGroupCount";
|
|||||||
static char *app_group_set = "SetGroup";
|
static char *app_group_set = "SetGroup";
|
||||||
static char *app_group_check = "CheckGroup";
|
static char *app_group_check = "CheckGroup";
|
||||||
|
|
||||||
static char *group_count_synopsis = "GetGroupCount([groupname])";
|
static char *group_count_synopsis = "GetGroupCount([groupname][@category])";
|
||||||
static char *group_set_synopsis = "SetGroup([groupname])";
|
static char *group_set_synopsis = "SetGroup(groupname[@category])";
|
||||||
static char *group_check_synopsis = "CheckGroup(max)";
|
static char *group_check_synopsis = "CheckGroup(max[@category])";
|
||||||
|
|
||||||
static char *group_count_descrip =
|
static char *group_count_descrip =
|
||||||
"GetGroupCount([group])\n"
|
"GetGroupCount([group][@category])\n"
|
||||||
" Calculates the group count for the specified group, or uses\n"
|
" Calculates the group count for the specified group, or uses\n"
|
||||||
"the current channel's group if not specifed (and non-empty).\n"
|
"the current channel's group if not specifed (and non-empty).\n"
|
||||||
"Stores result in GROUPCOUNT. Always returns 0.\n";
|
"Stores result in GROUPCOUNT. Always returns 0.\n";
|
||||||
@@ -56,7 +56,9 @@ STANDARD_LOCAL_USER;
|
|||||||
|
|
||||||
LOCAL_USER_DECL;
|
LOCAL_USER_DECL;
|
||||||
|
|
||||||
static int group_get_count(char *group)
|
#define DEFAULT_CATEGORY "GROUP"
|
||||||
|
|
||||||
|
static int group_get_count(char *group, char *category)
|
||||||
{
|
{
|
||||||
struct ast_channel *chan;
|
struct ast_channel *chan;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -64,7 +66,7 @@ static int group_get_count(char *group)
|
|||||||
if (group && !ast_strlen_zero(group)) {
|
if (group && !ast_strlen_zero(group)) {
|
||||||
chan = ast_channel_walk_locked(NULL);
|
chan = ast_channel_walk_locked(NULL);
|
||||||
while(chan) {
|
while(chan) {
|
||||||
test = pbx_builtin_getvar_helper(chan, "GROUP");
|
test = pbx_builtin_getvar_helper(chan, category);
|
||||||
if (test && !strcasecmp(test, group))
|
if (test && !strcasecmp(test, group))
|
||||||
count++;
|
count++;
|
||||||
ast_mutex_unlock(&chan->lock);
|
ast_mutex_unlock(&chan->lock);
|
||||||
@@ -80,17 +82,31 @@ static int group_count_exec(struct ast_channel *chan, void *data)
|
|||||||
int count;
|
int count;
|
||||||
struct localuser *u;
|
struct localuser *u;
|
||||||
char *group=NULL;
|
char *group=NULL;
|
||||||
char ret[80];
|
char *cat = NULL;
|
||||||
|
char ret[80]="";
|
||||||
|
char tmp[256]="";
|
||||||
|
|
||||||
LOCAL_USER_ADD(u);
|
LOCAL_USER_ADD(u);
|
||||||
|
|
||||||
/* Check and parse arguments */
|
/* Check and parse arguments */
|
||||||
if (data && !ast_strlen_zero(data)) {
|
if (data && !ast_strlen_zero(data)) {
|
||||||
group = (char *)data;
|
strncpy(tmp, data, sizeof(tmp) - 1);
|
||||||
} else {
|
group = tmp;
|
||||||
group = pbx_builtin_getvar_helper(chan, "GROUP");
|
cat = strchr(tmp, '@');
|
||||||
|
if (cat) {
|
||||||
|
*cat = '\0';
|
||||||
|
cat++;
|
||||||
}
|
}
|
||||||
count = group_get_count(group);
|
}
|
||||||
|
if (cat)
|
||||||
|
snprintf(ret, sizeof(ret), "GROUP_%s", cat);
|
||||||
|
else
|
||||||
|
strncpy(ret, DEFAULT_CATEGORY, sizeof(ret) - 1);
|
||||||
|
|
||||||
|
if (!group || ast_strlen_zero(group)) {
|
||||||
|
group = pbx_builtin_getvar_helper(chan, ret);
|
||||||
|
}
|
||||||
|
count = group_get_count(group, ret);
|
||||||
snprintf(ret, sizeof(ret), "%d", count);
|
snprintf(ret, sizeof(ret), "%d", count);
|
||||||
pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret);
|
pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret);
|
||||||
LOCAL_USER_REMOVE(u);
|
LOCAL_USER_REMOVE(u);
|
||||||
@@ -101,13 +117,31 @@ static int group_set_exec(struct ast_channel *chan, void *data)
|
|||||||
{
|
{
|
||||||
int res=0;
|
int res=0;
|
||||||
struct localuser *u;
|
struct localuser *u;
|
||||||
|
char ret[80] = "";
|
||||||
|
char tmp[256] = "";
|
||||||
|
char *cat=NULL, *group=NULL;
|
||||||
|
|
||||||
LOCAL_USER_ADD(u);
|
LOCAL_USER_ADD(u);
|
||||||
|
|
||||||
/* Check and parse arguments */
|
/* Check and parse arguments */
|
||||||
if (data && !ast_strlen_zero(data)) {
|
if (data && !ast_strlen_zero(data)) {
|
||||||
pbx_builtin_setvar_helper(chan, "GROUP", (char *)data);
|
strncpy(tmp, data, sizeof(tmp) - 1);
|
||||||
|
group = tmp;
|
||||||
|
cat = strchr(tmp, '@');
|
||||||
|
if (cat) {
|
||||||
|
*cat = '\0';
|
||||||
|
cat++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cat)
|
||||||
|
snprintf(ret, sizeof(ret), "GROUP_%s", cat);
|
||||||
|
else
|
||||||
|
strncpy(ret, DEFAULT_CATEGORY, sizeof(ret) - 1);
|
||||||
|
|
||||||
|
if (group && !ast_strlen_zero(group)) {
|
||||||
|
pbx_builtin_setvar_helper(chan, ret, group);
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "GroupSet requires an argument (group name)\n");
|
ast_log(LOG_WARNING, "SetGroup requires an argument (group name)\n");
|
||||||
|
|
||||||
LOCAL_USER_REMOVE(u);
|
LOCAL_USER_REMOVE(u);
|
||||||
return res;
|
return res;
|
||||||
@@ -118,11 +152,27 @@ static int group_check_exec(struct ast_channel *chan, void *data)
|
|||||||
int res=0;
|
int res=0;
|
||||||
int max, count;
|
int max, count;
|
||||||
struct localuser *u;
|
struct localuser *u;
|
||||||
|
char ret[80] = "";
|
||||||
|
char tmp[256] = "";
|
||||||
|
char *cat, *group;
|
||||||
|
|
||||||
LOCAL_USER_ADD(u);
|
LOCAL_USER_ADD(u);
|
||||||
|
|
||||||
if (data && (sscanf((char *)data, "%i", &max) == 1) && (max > -1)) {
|
if (data && !ast_strlen_zero(data)) {
|
||||||
count = group_get_count(pbx_builtin_getvar_helper(chan, "GROUP"));
|
strncpy(tmp, data, sizeof(tmp) - 1);
|
||||||
|
group = tmp;
|
||||||
|
cat = strchr(tmp, '@');
|
||||||
|
if (cat) {
|
||||||
|
*cat = '\0';
|
||||||
|
cat++;
|
||||||
|
}
|
||||||
|
if ((sscanf((char *)tmp, "%i", &max) == 1) && (max > -1)) {
|
||||||
|
if (cat)
|
||||||
|
snprintf(ret, sizeof(ret), "GROUP_%s", cat);
|
||||||
|
else
|
||||||
|
strncpy(ret, DEFAULT_CATEGORY, sizeof(ret) - 1);
|
||||||
|
|
||||||
|
count = group_get_count(pbx_builtin_getvar_helper(chan, ret), ret);
|
||||||
if (count > max) {
|
if (count > max) {
|
||||||
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
|
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
|
||||||
chan->priority += 100;
|
chan->priority += 100;
|
||||||
@@ -130,7 +180,9 @@ static int group_check_exec(struct ast_channel *chan, void *data)
|
|||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "GroupCheck requires a positive integer argument (max)\n");
|
ast_log(LOG_WARNING, "CheckGroup requires a positive integer argument (max)\n");
|
||||||
|
} else
|
||||||
|
ast_log(LOG_WARNING, "CheckGroup requires an argument(max)\n");
|
||||||
LOCAL_USER_REMOVE(u);
|
LOCAL_USER_REMOVE(u);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user