mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-11-03 04:17:17 -05:00
update stats code to support hidden attribute, and update callers to
use them svn path=/icecast/branches/kh/icecast/; revision=7650
This commit is contained in:
parent
37d0fb32bc
commit
946d62483b
@ -64,6 +64,7 @@ void event_config_read(void *arg)
|
||||
source_update (config_get_config_unlocked());
|
||||
|
||||
config_release_config();
|
||||
source_recheck_mounts();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,10 @@ static void *start_relay_stream (void *arg)
|
||||
source_main (relay->source);
|
||||
|
||||
if (relay->on_demand == 0)
|
||||
{
|
||||
stats_event (relay->localmount, "listeners", NULL);
|
||||
source_recheck_mounts();
|
||||
}
|
||||
/* initiate an immediate relay cleanup run */
|
||||
relay->cleanup = 1;
|
||||
slave_rescan();
|
||||
@ -306,6 +309,7 @@ static void check_relay_stream (relay_server *relay)
|
||||
DEBUG1("Adding relay source at mountpoint \"%s\"", relay->localmount);
|
||||
if (relay->on_demand)
|
||||
{
|
||||
stats_event (relay->localmount, NULL, NULL);
|
||||
stats_event (relay->localmount, "listeners", "0");
|
||||
DEBUG0 ("setting on_demand");
|
||||
}
|
||||
|
57
src/source.c
57
src/source.c
@ -653,19 +653,22 @@ static void source_init (source_t *source)
|
||||
char *str = NULL;
|
||||
|
||||
thread_mutex_lock (&source->lock);
|
||||
if (source->yp_prevent == 0)
|
||||
do
|
||||
{
|
||||
str = "0";
|
||||
if (source->yp_prevent)
|
||||
break;
|
||||
if ((str = httpp_getvar (source->parser, "ice-public")))
|
||||
source->yp_public = atoi (str);
|
||||
break;
|
||||
if ((str = httpp_getvar (source->parser, "icy-pub")))
|
||||
source->yp_public = atoi (str);
|
||||
break;
|
||||
/* handle header from icecast v2 release */
|
||||
if ((str = httpp_getvar (source->parser, "icy-public")))
|
||||
source->yp_public = atoi (str);
|
||||
if (str == NULL)
|
||||
str = "0";
|
||||
stats_event (source->mount, "public", str);
|
||||
}
|
||||
break;
|
||||
str = "0";
|
||||
} while (0);
|
||||
source->yp_public = atoi (str);
|
||||
stats_event (source->mount, "public", str);
|
||||
|
||||
str = httpp_getvar(source->parser, "ice-genre");
|
||||
if (str == NULL)
|
||||
@ -1096,7 +1099,6 @@ static void source_shutdown (source_t *source)
|
||||
stats_event (source->mount, "ice-bitrate", NULL);
|
||||
|
||||
thread_mutex_unlock (&source->lock);
|
||||
source_recheck_mounts ();
|
||||
|
||||
global_lock();
|
||||
global.sources--;
|
||||
@ -1187,6 +1189,7 @@ static void source_apply_mount (source_t *source, mount_proxy *mountinfo)
|
||||
source->max_listeners = mountinfo->max_listeners;
|
||||
source->fallback_override = mountinfo->fallback_override;
|
||||
source->no_mount = mountinfo->no_mount;
|
||||
source->hidden = mountinfo->hidden;
|
||||
|
||||
if (mountinfo->fallback_mount)
|
||||
source->fallback_mount = strdup (mountinfo->fallback_mount);
|
||||
@ -1257,6 +1260,13 @@ void source_update_settings (ice_config_t *config, source_t *source)
|
||||
DEBUG1 ("disconnect script \"%s\"", source->on_disconnect);
|
||||
if (source->on_demand)
|
||||
DEBUG0 ("on-demand set");
|
||||
if (source->hidden)
|
||||
{
|
||||
stats_event (source->mount, NULL, "hidden");
|
||||
DEBUG0 ("hidden from xsl");
|
||||
}
|
||||
else
|
||||
stats_event (source->mount, NULL, NULL);
|
||||
|
||||
DEBUG1 ("max listeners to %d", source->max_listeners);
|
||||
DEBUG1 ("queue size to %u", source->queue_size_limit);
|
||||
@ -1311,6 +1321,7 @@ void *source_client_thread (void *arg)
|
||||
stats_event (source->mount, "listeners", "0");
|
||||
source_main (source);
|
||||
stats_event (source->mount, "listeners", NULL);
|
||||
source_recheck_mounts();
|
||||
}
|
||||
source_free_source (source);
|
||||
return NULL;
|
||||
@ -1363,14 +1374,32 @@ void source_recheck_mounts (void)
|
||||
|
||||
while (mount)
|
||||
{
|
||||
char *value = NULL;
|
||||
int update_stats = 0;
|
||||
const char *hidden = NULL;
|
||||
source_t *source = source_find_mount (mount->mountname);
|
||||
if (source && mount->hidden == 0)
|
||||
|
||||
if (mount->hidden)
|
||||
hidden = "hidden";
|
||||
if (source)
|
||||
{
|
||||
if (source->running || source->on_demand)
|
||||
value = "0";
|
||||
/* something is active, maybe a fallback */
|
||||
if (strcmp (source->mount, mount->mountname) == 0)
|
||||
{
|
||||
/* normally the source thread would deal with this there
|
||||
* isn't one for inactive on-demand relays */
|
||||
if (source->on_demand && source->running == 0)
|
||||
update_stats = 1;
|
||||
}
|
||||
else
|
||||
update_stats = 1;
|
||||
}
|
||||
else
|
||||
stats_event (mount->mountname, "listeners", NULL);
|
||||
if (update_stats)
|
||||
{
|
||||
stats_event (mount->mountname, NULL, hidden);
|
||||
stats_event (mount->mountname, "listeners", "0");
|
||||
}
|
||||
stats_event (mount->mountname, "listeners", value);
|
||||
|
||||
mount = mount->next;
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ typedef struct source_tag
|
||||
unsigned timeout; /* source timeout in seconds */
|
||||
int on_demand;
|
||||
int on_demand_req;
|
||||
int hidden;
|
||||
int recheck_settings;
|
||||
|
||||
time_t last_read;
|
||||
|
117
src/stats.c
117
src/stats.c
@ -35,6 +35,8 @@
|
||||
#include "client.h"
|
||||
#include "stats.h"
|
||||
#include "xslt.h"
|
||||
#define CATMODULE "stats"
|
||||
#include "logging.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define vsnprintf _vsnprintf
|
||||
@ -155,18 +157,17 @@ stats_t *stats_get_stats()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void stats_event(const char *source, char *name, char *value)
|
||||
void stats_event(const char *source, const char *name, const char *value)
|
||||
{
|
||||
stats_event_t *node;
|
||||
stats_event_t *event;
|
||||
|
||||
if (name == NULL || strcmp(name, "") == 0) return;
|
||||
|
||||
/* build event */
|
||||
event = (stats_event_t *)malloc(sizeof(stats_event_t));
|
||||
event->source = NULL;
|
||||
event->name = NULL;
|
||||
if (source != NULL) event->source = (char *)strdup(source);
|
||||
event->name = (char *)strdup(name);
|
||||
if (name) event->name = (char *)strdup(name);
|
||||
event->value = NULL;
|
||||
event->next = NULL;
|
||||
if (value != NULL) event->value = (char *)strdup(value);
|
||||
@ -340,11 +341,25 @@ static stats_event_t *_copy_event(stats_event_t *event)
|
||||
copy->value = (char *)strdup(event->value);
|
||||
else
|
||||
copy->value = NULL;
|
||||
copy->hidden = event->hidden;
|
||||
copy->next = NULL;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void _mark_hidden (stats_source_t *snode, int hidden)
|
||||
{
|
||||
avl_node *node = avl_get_first (snode->stats_tree);
|
||||
|
||||
snode->hidden = hidden;
|
||||
while (node)
|
||||
{
|
||||
stats_node_t *stats = (stats_node_t*)node->key;
|
||||
stats->hidden = hidden;
|
||||
node = avl_get_next (node);
|
||||
}
|
||||
}
|
||||
|
||||
static void *_stats_thread(void *arg)
|
||||
{
|
||||
stats_event_t *event;
|
||||
@ -376,6 +391,7 @@ static void *_stats_thread(void *arg)
|
||||
anode = (stats_node_t *)malloc(sizeof(stats_node_t));
|
||||
anode->name = (char *)strdup(event->name);
|
||||
anode->value = (char *)strdup(event->value);
|
||||
anode->hidden = 0;
|
||||
|
||||
avl_insert(_stats.global_tree, (void *)anode);
|
||||
} else {
|
||||
@ -396,46 +412,65 @@ static void *_stats_thread(void *arg)
|
||||
snode = _find_source(_stats.source_tree, event->source);
|
||||
if (snode != NULL) {
|
||||
/* this is a source we already have a tree for */
|
||||
if (event->value != NULL) {
|
||||
if (event->name) {
|
||||
/* we're add/updating */
|
||||
node = _find_node(snode->stats_tree, event->name);
|
||||
if (node == NULL) {
|
||||
/* adding node */
|
||||
anode = (stats_node_t *)malloc(sizeof(stats_node_t));
|
||||
anode->name = (char *)strdup(event->name);
|
||||
anode->value = (char *)strdup(event->value);
|
||||
if (event->value)
|
||||
{
|
||||
DEBUG1 ("new node %s", event->name);
|
||||
anode = (stats_node_t *)malloc(sizeof(stats_node_t));
|
||||
anode->name = (char *)strdup(event->name);
|
||||
anode->value = (char *)strdup(event->value);
|
||||
anode->hidden = snode->hidden;
|
||||
|
||||
avl_insert(snode->stats_tree, (void *)anode);
|
||||
avl_insert(snode->stats_tree, (void *)anode);
|
||||
}
|
||||
} else {
|
||||
/* updating node */
|
||||
free(node->value);
|
||||
node->value = (char *)strdup(event->value);
|
||||
}
|
||||
} else {
|
||||
/* we're deleting */
|
||||
node = _find_node(snode->stats_tree, event->name);
|
||||
if (node != NULL) {
|
||||
avl_delete(snode->stats_tree, (void *)node, _free_stats);
|
||||
|
||||
if (event->value) {
|
||||
/* updating node */
|
||||
DEBUG1 ("update node %s", event->name);
|
||||
free(node->value);
|
||||
node->value = (char *)strdup(event->value);
|
||||
} else {
|
||||
/* we're deleting */
|
||||
node = _find_node(snode->stats_tree, event->name);
|
||||
if (node != NULL) {
|
||||
DEBUG1 ("delete node %s", event->name);
|
||||
avl_delete(snode->stats_tree, (void *)node, _free_stats);
|
||||
}
|
||||
avlnode = avl_get_first(snode->stats_tree);
|
||||
if (avlnode == NULL) {
|
||||
avl_delete(_stats.source_tree, (void *)snode, _free_source_stats);
|
||||
if (avlnode == NULL) {
|
||||
DEBUG1 ("delete source node %s", event->source);
|
||||
avl_delete(_stats.source_tree, (void *)snode, _free_source_stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (event->value)
|
||||
else
|
||||
{
|
||||
/* this is a new source */
|
||||
if (event->value)
|
||||
_mark_hidden (snode, 1);
|
||||
else
|
||||
_mark_hidden (snode, 0);
|
||||
}
|
||||
} else {
|
||||
/* this is a new source */
|
||||
if (event->name)
|
||||
{
|
||||
DEBUG1 ("new source node %s needed before settings", event->source);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG1 ("new source stat %s", event->source);
|
||||
asnode = (stats_source_t *)malloc(sizeof(stats_source_t));
|
||||
asnode->source = (char *)strdup(event->source);
|
||||
asnode->stats_tree = avl_tree_new(_compare_stats, NULL);
|
||||
|
||||
anode = (stats_node_t *)malloc(sizeof(stats_node_t));
|
||||
anode->name = (char *)strdup(event->name);
|
||||
anode->value = (char *)strdup(event->value);
|
||||
|
||||
avl_insert(asnode->stats_tree, (void *)anode);
|
||||
if (event->value)
|
||||
asnode->hidden = 1;
|
||||
else
|
||||
asnode->hidden = 0;
|
||||
|
||||
avl_insert(_stats.source_tree, (void *)asnode);
|
||||
}
|
||||
@ -502,6 +537,7 @@ static stats_event_t *_make_event_from_node(stats_node_t *node, char *source)
|
||||
event->source = NULL;
|
||||
event->name = (char *)strdup(node->name);
|
||||
event->value = (char *)strdup(node->value);
|
||||
event->hidden = node->hidden;
|
||||
event->next = NULL;
|
||||
|
||||
return event;
|
||||
@ -742,16 +778,19 @@ void stats_get_xml(xmlDocPtr *doc)
|
||||
|
||||
event = _get_event_from_queue(&queue);
|
||||
while (event) {
|
||||
xmlChar *name, *value;
|
||||
name = xmlEncodeEntitiesReentrant (*doc, event->name);
|
||||
value = xmlEncodeEntitiesReentrant (*doc, event->value);
|
||||
srcnode = node;
|
||||
if (event->source) {
|
||||
srcnode = _find_xml_node(event->source, &src_nodes, node);
|
||||
if (event->hidden == 0)
|
||||
{
|
||||
xmlChar *name, *value;
|
||||
name = xmlEncodeEntitiesReentrant (*doc, event->name);
|
||||
value = xmlEncodeEntitiesReentrant (*doc, event->value);
|
||||
srcnode = node;
|
||||
if (event->source) {
|
||||
srcnode = _find_xml_node(event->source, &src_nodes, node);
|
||||
}
|
||||
xmlNewChild(srcnode, NULL, name, value);
|
||||
xmlFree (value);
|
||||
xmlFree (name);
|
||||
}
|
||||
xmlNewChild(srcnode, NULL, name, value);
|
||||
xmlFree (value);
|
||||
xmlFree (name);
|
||||
|
||||
_free_event(event);
|
||||
event = _get_event_from_queue(&queue);
|
||||
|
@ -31,6 +31,7 @@ typedef struct _stats_node_tag
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
int hidden;
|
||||
} stats_node_t;
|
||||
|
||||
typedef struct _stats_event_tag
|
||||
@ -38,6 +39,7 @@ typedef struct _stats_event_tag
|
||||
char *source;
|
||||
char *name;
|
||||
char *value;
|
||||
int hidden;
|
||||
|
||||
struct _stats_event_tag *next;
|
||||
} stats_event_t;
|
||||
@ -45,6 +47,7 @@ typedef struct _stats_event_tag
|
||||
typedef struct _stats_source_tag
|
||||
{
|
||||
char *source;
|
||||
int hidden;
|
||||
avl_tree *stats_tree;
|
||||
} stats_source_t;
|
||||
|
||||
@ -77,7 +80,7 @@ void stats_shutdown();
|
||||
|
||||
stats_t *stats_get_stats();
|
||||
|
||||
void stats_event(const char *source, char *name, char *value);
|
||||
void stats_event(const char *source, const char *name, const char *value);
|
||||
void stats_event_args(const char *source, char *name, char *format, ...);
|
||||
void stats_event_inc(char *source, char *name);
|
||||
void stats_event_add(char *source, char *name, unsigned long value);
|
||||
|
Loading…
Reference in New Issue
Block a user