From 7248d653c05ae0ee9b2135fc05807767d1948d2d Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Thu, 9 Aug 2007 23:36:29 +0000 Subject: [PATCH] Update the streamlist handler for slaves. Get the list of non-hidden mountpoints from the stats engine instead of the mount or source list, as the stats are populated by non-mount defined streams and mounts with active fallbacks. svn path=/icecast/trunk/icecast/; revision=13500 --- src/admin.c | 34 +++------------------------------- src/stats.c | 35 +++++++++++++++++++++++++++++++++++ src/stats.h | 1 + 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/admin.c b/src/admin.c index 4adc582a..9f76b42f 100644 --- a/src/admin.c +++ b/src/admin.c @@ -968,52 +968,24 @@ static void command_list_mounts(client_t *client, int response) { DEBUG0("List mounts request"); - avl_tree_rlock (global.source_tree); if (response == PLAINTEXT) { char *buf; int remaining = PER_CLIENT_REFBUF_SIZE; int ret; - ice_config_t *config = config_get_config (); - mount_proxy *mountinfo = config->mounts; buf = client->refbuf->data; ret = snprintf (buf, remaining, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"); - while (mountinfo && ret > 0 && ret < remaining) - { - mount_proxy *current = mountinfo; - source_t *source; - mountinfo = mountinfo->next; + stats_get_streamlist (client->refbuf->data+ret, remaining-ret); - /* now check that a source is available */ - source = source_find_mount (current->mountname); - - if (source == NULL) - continue; - if (source->running == 0 && source->on_demand == 0) - continue; - if (source->hidden) - continue; - remaining -= ret; - buf += ret; - ret = snprintf (buf, remaining, "%s\n", current->mountname); - } - avl_tree_unlock (global.source_tree); - config_release_config(); - - /* handle last line */ - if (ret > 0 && ret < remaining) - { - remaining -= ret; - buf += ret; - } - client->refbuf->len = PER_CLIENT_REFBUF_SIZE - remaining; + client->refbuf->len = strlen (client->refbuf->data); fserve_add_client (client, NULL); } else { + avl_tree_rlock (global.source_tree); xmlDocPtr doc = admin_build_sourcelist(NULL); avl_tree_unlock (global.source_tree); diff --git a/src/stats.c b/src/stats.c index 98591f75..3c1e644f 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1027,3 +1027,38 @@ static void _free_event(stats_event_t *event) if (event->value) free(event->value); free(event); } + + +/* get a list of mountpoints that are in the stats but are not marked as hidden */ +void stats_get_streamlist (char *buffer, size_t remaining) +{ + avl_node *node; + + /* now the stats for each source */ + thread_mutex_lock (&_stats_mutex); + node = avl_get_first(_stats.source_tree); + while (node) + { + int ret; + stats_source_t *source = (stats_source_t *)node->key; + + if (source->hidden == 0) + { + if (remaining <= strlen (source->source)+2) + { + WARN0 ("streamlist was truncated"); + break; + } + ret = snprintf (buffer, remaining, "%s\r\n", source->source); + if (ret > 0) + { + buffer += ret; + remaining -= ret; + } + } + + node = avl_get_next(node); + } + thread_mutex_unlock (&_stats_mutex); +} + diff --git a/src/stats.h b/src/stats.h index eedb550a..3d897524 100644 --- a/src/stats.h +++ b/src/stats.h @@ -74,6 +74,7 @@ void stats_initialize(void); void stats_shutdown(void); stats_t *stats_get_stats(void); +void stats_get_streamlist (char *buffer, size_t remaining); void stats_event(const char *source, const char *name, const char *value); void stats_event_args(const char *source, char *name, char *format, ...);