示例#1
0
static int group_match_count_function_read(struct ast_channel *chan,
        const char *cmd, char *data, char *buf,
        size_t len)
{
    char group[80] = "";
    char category[80] = "";

    ast_app_group_split_group(data, group, sizeof(group), category,
                              sizeof(category));

    if (!ast_strlen_zero(group)) {
        int count;
        count = ast_app_group_match_get_count(group, category);
        snprintf(buf, len, "%d", count);
        return 0;
    }

    return -1;
}
示例#2
0
static int group_count_function_read(struct ast_channel *chan, const char *cmd,
				     char *data, char *buf, size_t len)
{
	int ret = -1;
	int count = -1;
	char group[80] = "", category[80] = "";

	if (!chan) {
		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
		return -1;
	}

	ast_app_group_split_group(data, group, sizeof(group), category,
				  sizeof(category));

	/* If no group has been provided let's find one */
	if (ast_strlen_zero(group)) {
		struct ast_group_info *gi = NULL;

		ast_app_group_list_rdlock();
		for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) {
			if (gi->chan != chan)
				continue;
			if (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))
				break;
		}
		if (gi) {
			ast_copy_string(group, gi->group, sizeof(group));
			if (!ast_strlen_zero(gi->category))
				ast_copy_string(category, gi->category, sizeof(category));
		}
		ast_app_group_list_unlock();
	}

	if ((count = ast_app_group_get_count(group, category)) == -1) {
		ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", ast_channel_name(chan));
	} else {
		snprintf(buf, len, "%d", count);
		ret = 0;
	}

	return ret;
}