Index: UPGRADE.txt =================================================================== RCS file: /usr/cvsroot/asterisk/UPGRADE.txt,v retrieving revision 1.8 diff -u -r1.8 UPGRADE.txt --- UPGRADE.txt 3 Apr 2005 00:25:21 -0000 1.8 +++ UPGRADE.txt 7 May 2005 05:16:01 -0000 @@ -38,6 +38,21 @@ * The CallerPres application has been removed. Use SetCallerPres instead. It accepts both numeric and symbolic names. +* The applications GetGroupCount, GetGroupMatchCount, SetGroup, and + CheckGroup have been deprecated in favor of functions. Here is a + table of their replacements: + + GetGroupCount([groupname][@category] GROUP_COUNT([groupname][@category]) SetVar(GROUPCOUNT=${GROUP_COUNT()}) + GroupMatchCount(groupmatch[@category]) GROUP_MATCH_COUNT(groupmatch[@category]) SetVar(GROUPCOUNT=${GROUP_MATCH_COUNT(SIP/.*)}) + SetGroup(groupname[@category]) GROUP([category])=groupname SetVar(GROUP()=test) + CheckGroup(max[@category]) N/A GotoIf($[ ${GROUP_COUNT()} > 5 ]?103) + + Note that CheckGroup does not have a direct replacement. There is + also a new function called GROUP_LIST() which will return a space + separated list of all of the groups set on a channel. The GROUP() + function can also return the name of the group set on a channel when + used in a read environment. + Queues: * A queue is now considered empty not only if there are no members but if Index: apps/app_groupcount.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_groupcount.c,v retrieving revision 1.13 diff -u -r1.13 app_groupcount.c --- apps/app_groupcount.c 5 May 2005 05:39:33 -0000 1.13 +++ apps/app_groupcount.c 7 May 2005 05:16:01 -0000 @@ -32,8 +32,6 @@ LOCAL_USER_DECL; -static int deprecation_warning = 0; - static int group_count_exec(struct ast_channel *chan, void *data) { int res = 0; @@ -43,11 +41,12 @@ char category[80] = ""; char ret[80] = ""; char *grp; + static int deprecation_warning = 0; LOCAL_USER_ADD(u); if (!deprecation_warning) { - ast_log(LOG_WARNING, "The GetGroupCount and GetGroupMatchCount applications have been deprecated, please use the GROUP_COUNT and GROUP_MATCH_COUNT functions.\n"); + ast_log(LOG_WARNING, "The GetGroupCount application has been deprecated, please use the GROUP_COUNT function.\n"); deprecation_warning = 1; } @@ -75,11 +74,12 @@ char group[80] = ""; char category[80] = ""; char ret[80] = ""; + static int deprecation_warning = 0; LOCAL_USER_ADD(u); if (!deprecation_warning) { - ast_log(LOG_WARNING, "The GetGroupCount and GetGroupMatchCount applications have been deprecated, please use the GROUP_COUNT and GROUP_MATCH_COUNT functions.\n"); + ast_log(LOG_WARNING, "The GetGroupMatchCount application has been deprecated, please use the GROUP_MATCH_COUNT function.\n"); deprecation_warning = 1; } @@ -100,6 +100,12 @@ { int res = 0; struct localuser *u; + static int deprecation_warning = 0; + + if (!deprecation_warning) { + ast_log(LOG_WARNING, "The SetGroup application has been deprecated, please use the GROUP() function.\n"); + deprecation_warning = 1; + } LOCAL_USER_ADD(u); @@ -117,8 +123,14 @@ struct localuser *u; char limit[80]=""; char category[80]=""; + static int deprecation_warning = 0; LOCAL_USER_ADD(u); + + if (!deprecation_warning) { + ast_log(LOG_WARNING, "The CheckGroup application has been deprecated, please use a combination of the GotoIf application and the GROUP_COUNT() function.\n"); + deprecation_warning = 1; + } if (!data || ast_strlen_zero(data)) { ast_log(LOG_WARNING, "CheckGroup requires an argument(max[@category])\n"); Index: funcs/func_groupcount.c =================================================================== RCS file: /usr/cvsroot/asterisk/funcs/func_groupcount.c,v retrieving revision 1.1 diff -u -r1.1 func_groupcount.c --- funcs/func_groupcount.c 5 May 2005 05:39:33 -0000 1.1 +++ funcs/func_groupcount.c 7 May 2005 05:16:01 -0000 @@ -30,7 +30,7 @@ if (ast_strlen_zero(group)) { grp = pbx_builtin_getvar_helper(chan, category); - strncpy(group, grp, sizeof(group) - 1); + ast_copy_string(group, grp, sizeof(group)); } count = ast_app_group_get_count(group, category); @@ -79,3 +79,89 @@ .read = group_match_count_function_read, .write = NULL, }; + +static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + char varname[256]; + char *group; + + if (data && !ast_strlen_zero(data)) { + snprintf(varname, sizeof(varname), "%s_%s", GROUP_CATEGORY_PREFIX, data); + } else { + ast_copy_string(varname, GROUP_CATEGORY_PREFIX, sizeof(varname)); + } + + group = pbx_builtin_getvar_helper(chan, varname); + if (group) + ast_copy_string(buf, group, len); + + return buf; +} + +static void group_function_write(struct ast_channel *chan, char *cmd, char *data, const char *value) +{ + char grpcat[256]; + + if (data && !ast_strlen_zero(data)) { + snprintf(grpcat, sizeof(grpcat), "%s@%s", data, value); + } else { + ast_copy_string(grpcat, value, sizeof(grpcat)); + } + + if (ast_app_group_set_channel(chan, grpcat)) + ast_log(LOG_WARNING, "Setting a group requires an argument (group name)\n"); +} + +#ifndef BUILTIN_FUNC +static +#endif +struct ast_custom_function group_function = { + .name = "GROUP", + .syntax = "GROUP([category])", + .synopsis = "Gets or sets the channel group.", + .desc = "Gets or sets the channel group.\n", + .read = group_function_read, + .write = group_function_write, +}; + +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] = ""; + + 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); + return buf; +} + +#ifndef BUILTIN_FUNC +static +#endif +struct ast_custom_function group_list_function = { + .name = "GROUP_LIST", + .syntax = "GROUP_LIST()", + .synopsis = "Gets a list of the groups set on a channel.", + .desc = "Gets a list of the groups set on a channel.\n", + .read = group_list_function_read, + .write = NULL, +}; +