Skip to content
Snippets Groups Projects
app.c 26.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	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
    		res = -1;
    
    	return res;
    }
    
    int ast_app_group_get_count(char *group, char *category)
    {
    	struct ast_channel *chan;
    	int count = 0;
    	char *test;
    	char cat[80] = "";
    
    	if (category && !ast_strlen_zero(category)) {
    		strncpy(cat, category, sizeof(cat) - 1);
    	} else {
    		strncpy(cat, GROUP_CATEGORY_PREFIX, sizeof(cat) - 1);
    	}
    
    	if (group && !ast_strlen_zero(group)) {
    		chan = ast_channel_walk_locked(NULL);
    		while(chan) {
    			test = pbx_builtin_getvar_helper(chan, cat);
    			if (test && !strcasecmp(test, group))
    				count++;
    			ast_mutex_unlock(&chan->lock);
    			chan = ast_channel_walk_locked(chan);
    		}
    	}
    
    	return count;
    }
    
    int ast_app_group_match_get_count(char *groupmatch, char *category)
    {
    	regex_t regexbuf;
    	struct ast_channel *chan;
    	int count = 0;
    	char *test;
    	char cat[80] = "";
    
    	if (!groupmatch || ast_strlen_zero(groupmatch))
    		return 0;
    
    	/* if regex compilation fails, return zero matches */
    	if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
    		return 0;
    
    	if (category && !ast_strlen_zero(category)) {
    		strncpy(cat, category, sizeof(cat) - 1);
    	} else {
    		strncpy(cat, GROUP_CATEGORY_PREFIX, sizeof(cat) - 1);
    	}
    
    	chan = ast_channel_walk_locked(NULL);
    	while(chan) {
    		test = pbx_builtin_getvar_helper(chan, cat);
    		if (test && !regexec(&regexbuf, test, 0, NULL, 0))
    			count++;
    		ast_mutex_unlock(&chan->lock);
    		chan = ast_channel_walk_locked(chan);
    	}
    
    	regfree(&regexbuf);
    
    	return count;
    }