Commit cbb7643b authored by Karl Heyes's avatar Karl Heyes

Allow any number of mountpoints to be returned for streamlist. You would

need a large number of mountpoints to trigger a truncation.  Allow file
serving thread to process a list of blocks for sending back to
the client. Then build the block list in the stats engine for returning.

svn path=/icecast/trunk/icecast/; revision=14812
parent 2822e350
...@@ -995,17 +995,12 @@ static void command_list_mounts(client_t *client, int response) ...@@ -995,17 +995,12 @@ static void command_list_mounts(client_t *client, int response)
if (response == PLAINTEXT) if (response == PLAINTEXT)
{ {
char *buf; snprintf (client->refbuf->data, PER_CLIENT_REFBUF_SIZE,
int remaining = PER_CLIENT_REFBUF_SIZE;
int ret;
buf = client->refbuf->data;
ret = snprintf (buf, remaining,
"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"); "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
stats_get_streamlist (client->refbuf->data+ret, remaining-ret);
client->refbuf->len = strlen (client->refbuf->data); client->refbuf->len = strlen (client->refbuf->data);
client->respcode = 200;
client->refbuf->next = stats_get_streams ();
fserve_add_client (client, NULL); fserve_add_client (client, NULL);
} }
else else
......
...@@ -262,13 +262,19 @@ static void *fserv_thread_function(void *arg) ...@@ -262,13 +262,19 @@ static void *fserv_thread_function(void *arg)
bytes = 0; bytes = 0;
if (bytes == 0) if (bytes == 0)
{ {
fserve_t *to_go = fclient; if (refbuf->next == NULL)
fclient = fclient->next; {
*trail = fclient; fserve_t *to_go = fclient;
fserve_client_destroy (to_go); fclient = fclient->next;
fserve_clients--; *trail = fclient;
client_tree_changed = 1; fserve_client_destroy (to_go);
continue; fserve_clients--;
client_tree_changed = 1;
continue;
}
client_set_queue (client, refbuf->next);
refbuf = client->refbuf;
bytes = refbuf->len;
} }
refbuf->len = (unsigned int)bytes; refbuf->len = (unsigned int)bytes;
client->pos = 0; client->pos = 0;
......
...@@ -1096,10 +1096,13 @@ static void _free_event(stats_event_t *event) ...@@ -1096,10 +1096,13 @@ static void _free_event(stats_event_t *event)
} }
/* get a list of mountpoints that are in the stats but are not marked as hidden */ refbuf_t *stats_get_streams (void)
void stats_get_streamlist (char *buffer, size_t remaining)
{ {
#define STREAMLIST_BLKSIZE 4096
avl_node *node; avl_node *node;
int remaining = STREAMLIST_BLKSIZE;
refbuf_t *start = refbuf_new (remaining), *cur = start;
char *buffer = cur->data;
/* now the stats for each source */ /* now the stats for each source */
thread_mutex_lock (&_stats_mutex); thread_mutex_lock (&_stats_mutex);
...@@ -1111,10 +1114,13 @@ void stats_get_streamlist (char *buffer, size_t remaining) ...@@ -1111,10 +1114,13 @@ void stats_get_streamlist (char *buffer, size_t remaining)
if (source->hidden == 0) if (source->hidden == 0)
{ {
if (remaining <= strlen (source->source)+2) if (remaining <= strlen (source->source) + 3)
{ {
WARN0 ("streamlist was truncated"); cur->len = STREAMLIST_BLKSIZE - remaining;
break; cur->next = refbuf_new (STREAMLIST_BLKSIZE);
remaining = STREAMLIST_BLKSIZE;
cur = cur->next;
buffer = cur->data;
} }
ret = snprintf (buffer, remaining, "%s\r\n", source->source); ret = snprintf (buffer, remaining, "%s\r\n", source->source);
if (ret > 0) if (ret > 0)
...@@ -1123,12 +1129,15 @@ void stats_get_streamlist (char *buffer, size_t remaining) ...@@ -1123,12 +1129,15 @@ void stats_get_streamlist (char *buffer, size_t remaining)
remaining -= ret; remaining -= ret;
} }
} }
node = avl_get_next(node); node = avl_get_next(node);
} }
thread_mutex_unlock (&_stats_mutex); thread_mutex_unlock (&_stats_mutex);
cur->len = STREAMLIST_BLKSIZE - remaining;
return start;
} }
/* This removes any source stats from virtual mountpoints, ie mountpoints /* This removes any source stats from virtual mountpoints, ie mountpoints
* where no source_t exists. This function requires the global sources lock * where no source_t exists. This function requires the global sources lock
* to be held before calling. * to be held before calling.
......
...@@ -76,7 +76,7 @@ void stats_shutdown(void); ...@@ -76,7 +76,7 @@ void stats_shutdown(void);
void stats_global(ice_config_t *config); void stats_global(ice_config_t *config);
stats_t *stats_get_stats(void); stats_t *stats_get_stats(void);
void stats_get_streamlist (char *buffer, size_t remaining); refbuf_t *stats_get_streams (void);
void stats_clear_virtual_mounts (void); void stats_clear_virtual_mounts (void);
void stats_event(const char *source, const char *name, const char *value); void stats_event(const char *source, const char *name, const char *value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment