Index: app_groupcount.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_groupcount.c,v
retrieving revision 1.4
diff -u -3 -r1.4 app_groupcount.c
--- app_groupcount.c	20 May 2004 16:30:10 -0000	1.4
+++ app_groupcount.c	15 Jul 2004 13:28:54 -0000
@@ -29,23 +29,23 @@
 static char *app_group_set = "SetGroup";
 static char *app_group_check = "CheckGroup";
 
-static char *group_count_synopsis = "GetGroupCount([groupname])";
-static char *group_set_synopsis = "SetGroup([groupname])";
-static char *group_check_synopsis = "CheckGroup(max)";
+static char *group_count_synopsis = "GetGroupCount([group[|idgroup]])";
+static char *group_set_synopsis = "SetGroup(group[|idgroup])";
+static char *group_check_synopsis = "CheckGroup(max[|idgroup])";
 
 static char *group_count_descrip =
-"GetGroupCount([group])\n"
+"GetGroupCount([group[|idgroup]])\n"
 "  Calculates the group count for the specified group, or uses\n"
 "the current channel's group if not specifed (and non-empty).\n"
 "Stores result in GROUPCOUNT.  Always returns 0.\n";
 
 static char *group_set_descrip =
-"SetGroup(group)\n"
+"SetGroup(group[|idgroup])\n"
 "  Sets the channel group to the specified value.  Equivalent to\n"
 "SetVar(GROUP=group).  Always returns 0.\n";
 
 static char *group_check_descrip =
-"CheckGroup(max)\n"
+"CheckGroup(max[|idgroup])\n"
 "  Checks that the current number of total channels in the\n"
 "current channel's group does not exceed 'max'.  If the number\n"
 "does not exceed 'max', we continue to the next step. If the\n"
@@ -56,15 +56,22 @@
 
 LOCAL_USER_DECL;
 
-static int group_get_count(char *group)
+static int group_get_count(char *group, char* idgroup)
 {
 	struct ast_channel *chan;
 	int count = 0;
 	char *test;
+	char groupname[256];
+	    
+	if (idgroup == NULL)
+		strcpy(groupname, "GROUP");
+	else
+		snprintf(groupname, sizeof(groupname) - 1, "GROUP-%s", idgroup);
+
 	if (group && !ast_strlen_zero(group)) {
 		chan = ast_channel_walk_locked(NULL);
 		while(chan) {
-			test = pbx_builtin_getvar_helper(chan, "GROUP");
+			test = pbx_builtin_getvar_helper(chan, groupname);
 			if (test && !strcasecmp(test, group))
 				count++;
 			ast_mutex_unlock(&chan->lock);
@@ -81,16 +88,21 @@
 	struct localuser *u;
 	char *group=NULL;
 	char ret[80];
+	char* idgroup = NULL;
+	char groupname[256];
 
 	LOCAL_USER_ADD(u);
 
 	/* Check and parse arguments */
-	if (data && !ast_strlen_zero(data)) {
-		group = (char *)data;
+	if (data && !ast_strlen_zero(data)) {		
+		strncpy(groupname, (char*)data, sizeof(groupname) - 1);
+		group = groupname;
+		idgroup = groupname;
+		strsep(&idgroup, "|");
 	} else {
 		group = pbx_builtin_getvar_helper(chan, "GROUP");
 	}
-	count = group_get_count(group);
+	count = group_get_count(group, idgroup);
 	snprintf(ret, sizeof(ret), "%d", count);
 	pbx_builtin_setvar_helper(chan, "GROUPCOUNT", ret);
 	LOCAL_USER_REMOVE(u);
@@ -101,11 +113,23 @@
 {
 	int res=0;
 	struct localuser *u;
+	char groupname[256];
+	char groupvalue[256];
+	char* idgroup;
 
 	LOCAL_USER_ADD(u);
 	/* Check and parse arguments */
 	if (data && !ast_strlen_zero(data)) {
-		pbx_builtin_setvar_helper(chan, "GROUP", (char *)data);
+		strncpy(groupvalue, (char*)data, sizeof(groupvalue) - 1);
+		idgroup = groupvalue;
+		strsep(&idgroup, "|");
+	
+		if (idgroup == NULL)
+			strcpy(groupname, "GROUP");
+		else
+			snprintf(groupname, sizeof(groupname) - 1, "GROUP-%s", idgroup);
+		
+		pbx_builtin_setvar_helper(chan, groupname, groupvalue);
 	} else
 		ast_log(LOG_WARNING, "GroupSet requires an argument (group name)\n");
 
@@ -121,16 +145,35 @@
 
 	LOCAL_USER_ADD(u);
 
-	if (data && (sscanf((char *)data, "%i", &max) == 1) && (max > -1)) {	
-		count = group_get_count(pbx_builtin_getvar_helper(chan, "GROUP"));
-		if (count > max) {
-			if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
-				chan->priority += 100;
+	if (data && !ast_strlen_zero((char*)data)) {
+		char number[256];
+		char* idgroup;
+		
+		strncpy(number, (char*)data, sizeof(number) - 1);
+		idgroup = number;
+		strsep(&idgroup, "|");
+		
+		if ((sscanf((char*)number, "%i", &max) == 1) && (max > -1)) {	
+			char groupname[256];
+			if (idgroup == NULL)
+				strcpy(groupname, "GROUP");
 			else
-				res = -1;
+				snprintf(groupname, sizeof(groupname) - 1, "GROUP-%s", idgroup);
+
+			count = group_get_count(pbx_builtin_getvar_helper(chan, groupname), idgroup);
+			if (count > max) {
+				if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
+					chan->priority += 100;
+				else
+					res = -1;
+			}
+		} else {
+		    ast_log(LOG_WARNING, "GroupCheck requires a positive integer argument (max)\n");
 		}
-	} else
+	} else {
 		ast_log(LOG_WARNING, "GroupCheck requires a positive integer argument (max)\n");
+	}
+	
 	LOCAL_USER_REMOVE(u);
 	return res;
 }
