[xiph-commits] r7650 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Sat Aug 28 06:38:33 PDT 2004


Author: karl
Date: 2004-08-28 06:38:32 -0700 (Sat, 28 Aug 2004)
New Revision: 7650

Modified:
   icecast/branches/kh/icecast/src/event.c
   icecast/branches/kh/icecast/src/slave.c
   icecast/branches/kh/icecast/src/source.c
   icecast/branches/kh/icecast/src/source.h
   icecast/branches/kh/icecast/src/stats.c
   icecast/branches/kh/icecast/src/stats.h
Log:
update stats code to support hidden attribute, and update callers to
use them


Modified: icecast/branches/kh/icecast/src/event.c
===================================================================
--- icecast/branches/kh/icecast/src/event.c	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/event.c	2004-08-28 13:38:32 UTC (rev 7650)
@@ -64,6 +64,7 @@
         source_update (config_get_config_unlocked());
 
         config_release_config();
+        source_recheck_mounts();
     }
 }
 

Modified: icecast/branches/kh/icecast/src/slave.c
===================================================================
--- icecast/branches/kh/icecast/src/slave.c	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/slave.c	2004-08-28 13:38:32 UTC (rev 7650)
@@ -268,7 +268,10 @@
         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 @@
             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");
             }

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/source.c	2004-08-28 13:38:32 UTC (rev 7650)
@@ -653,19 +653,22 @@
     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 @@
     stats_event (source->mount, "ice-bitrate", NULL);
 
     thread_mutex_unlock (&source->lock);
-    source_recheck_mounts ();
 
     global_lock();
     global.sources--;
@@ -1187,6 +1189,7 @@
     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 @@
         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 @@
         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 @@
 
     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;
         }
-        stats_event (mount->mountname, "listeners", value);
+        else
+            stats_event (mount->mountname, "listeners", NULL);
+        if (update_stats)
+        {
+            stats_event (mount->mountname, NULL, hidden);
+            stats_event (mount->mountname, "listeners", "0");
+        }
 
         mount = mount->next;
     }

Modified: icecast/branches/kh/icecast/src/source.h
===================================================================
--- icecast/branches/kh/icecast/src/source.h	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/source.h	2004-08-28 13:38:32 UTC (rev 7650)
@@ -73,6 +73,7 @@
     unsigned timeout;  /* source timeout in seconds */
     int on_demand;
     int on_demand_req;
+    int hidden;
     int recheck_settings;
 
     time_t last_read;

Modified: icecast/branches/kh/icecast/src/stats.c
===================================================================
--- icecast/branches/kh/icecast/src/stats.c	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/stats.c	2004-08-28 13:38:32 UTC (rev 7650)
@@ -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 @@
     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 @@
         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 @@
                         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,47 +412,66 @@
                 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)
+                            _mark_hidden (snode, 1);
+                        else
+                            _mark_hidden (snode, 0);
+                    }
                 } else {
-                    if (event->value)
+                    /* this is a new source */
+                    if (event->name)
                     {
-                        /* this is a new source */
+                        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);
+                        if (event->value)
+                            asnode->hidden = 1;
+                        else
+                            asnode->hidden = 0;
 
-                        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);
-
                         avl_insert(_stats.source_tree, (void *)asnode);
                     }
                 }
@@ -502,6 +537,7 @@
         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 @@
 
     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);

Modified: icecast/branches/kh/icecast/src/stats.h
===================================================================
--- icecast/branches/kh/icecast/src/stats.h	2004-08-27 18:51:43 UTC (rev 7649)
+++ icecast/branches/kh/icecast/src/stats.h	2004-08-28 13:38:32 UTC (rev 7650)
@@ -31,6 +31,7 @@
 {
     char *name;
     char *value;
+    int hidden;
 } stats_node_t;
 
 typedef struct _stats_event_tag
@@ -38,6 +39,7 @@
     char *source;
     char *name;
     char *value;
+    int  hidden;
 
     struct _stats_event_tag *next;
 } stats_event_t;
@@ -45,6 +47,7 @@
 typedef struct _stats_source_tag
 {
     char *source;
+    int  hidden;
     avl_tree *stats_tree;
 } stats_source_t;
 
@@ -77,7 +80,7 @@
 
 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);



More information about the commits mailing list