static int group_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { int ret = -1; 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(data)) break; if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data)) break; } if (gi) { ast_copy_string(buf, gi->group, len); ret = 0; } ast_app_group_list_unlock(); return ret; }
static int group_list_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { struct ast_group_info *gi = NULL; char tmp1[1024] = ""; char tmp2[1024] = ""; if (!chan) return -1; 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(tmp1)) { ast_copy_string(tmp2, tmp1, sizeof(tmp2)); if (!ast_strlen_zero(gi->category)) snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category); else snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group); } else { if (!ast_strlen_zero(gi->category)) snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category); else snprintf(tmp1, sizeof(tmp1), "%s", gi->group); } } ast_app_group_list_unlock(); ast_copy_string(buf, tmp1, len); return 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; }