[xiph-commits] r9509 - in icecast/branches/kh/icecast: admin src

karl at svn.xiph.org karl at svn.xiph.org
Wed Jun 22 20:22:53 PDT 2005


Author: karl
Date: 2005-06-22 20:22:48 -0700 (Wed, 22 Jun 2005)
New Revision: 9509

Modified:
   icecast/branches/kh/icecast/admin/stats.xsl
   icecast/branches/kh/icecast/src/admin.c
   icecast/branches/kh/icecast/src/admin.h
   icecast/branches/kh/icecast/src/stats.c
Log:
dump listeners stats with stats tree information for admin requests, but
make sure that stats.xsl skips over them. 


Modified: icecast/branches/kh/icecast/admin/stats.xsl
===================================================================
--- icecast/branches/kh/icecast/admin/stats.xsl	2005-06-22 23:06:20 UTC (rev 9508)
+++ icecast/branches/kh/icecast/admin/stats.xsl	2005-06-23 03:22:48 UTC (rev 9509)
@@ -72,10 +72,15 @@
 <br />
 <table cellpadding="5" cellspacing="0" border="0">
 	<xsl:for-each select="*">
-	<tr>
-		<td width="130"><xsl:value-of select="name()" /></td>
-		<td class="streamdata"><xsl:value-of select="." /></td>
-	</tr>
+      <xsl:choose>
+        <xsl:when test="name()='listener'"></xsl:when>
+        <xsl:otherwise>
+          <tr>
+              <td width="130"><xsl:value-of select="name()" /></td>
+              <td class="streamdata"><xsl:value-of select="." /></td>
+          </tr>
+        </xsl:otherwise>
+      </xsl:choose>
 	</xsl:for-each>
 </table>
 <br />

Modified: icecast/branches/kh/icecast/src/admin.c
===================================================================
--- icecast/branches/kh/icecast/src/admin.c	2005-06-22 23:06:20 UTC (rev 9508)
+++ icecast/branches/kh/icecast/src/admin.c	2005-06-23 03:22:48 UTC (rev 9509)
@@ -196,7 +196,7 @@
         int response);
 static void command_move_clients(client_t *client, source_t *source,
         int response);
-static void command_stats(client_t *client, int response);
+static void command_stats(client_t *client);
 static void command_list_mounts(client_t *client, int response);
 static void command_kill_client(client_t *client, source_t *source,
         int response);
@@ -272,9 +272,12 @@
 
             if (source->running)
             {
-                snprintf (buf, sizeof(buf), "%lu",
-                        (unsigned long)(now - source->client->con->con_time));
-                xmlNewChild (srcnode, NULL, "Connected", buf);
+                if (source->client->con)
+                {
+                    snprintf (buf, sizeof(buf), "%lu",
+                            (unsigned long)(now - source->client->con->con_time));
+                    xmlNewChild (srcnode, NULL, "Connected", buf);
+                }
                 xmlNewChild (srcnode, NULL, "content-type", 
                         source->format->contenttype);
             }
@@ -348,13 +351,6 @@
     DEBUG1("Got command (%s)", command_string);
     command = admin_get_command(command_string);
 
-    if(command < 0) {
-        ERROR1("Error parsing command string or unrecognised command: %s",
-                command_string);
-        client_send_400(client, "Unrecognised command");
-        return;
-    }
-
     if (command == COMMAND_SHOUTCAST_METADATA_UPDATE) {
 
         ice_config_t *config;
@@ -457,9 +453,6 @@
 static void admin_handle_general_request(client_t *client, int command)
 {
     switch(command) {
-        case COMMAND_RAW_STATS:
-            command_stats(client, RAW);
-            break;
         case COMMAND_RAW_LIST_MOUNTS:
             command_list_mounts(client, RAW);
             break;
@@ -475,9 +468,6 @@
         case COMMAND_PLAINTEXT_LISTSTREAM:
             command_list_mounts(client, PLAINTEXT);
             break;
-        case COMMAND_TRANSFORMED_STATS:
-            command_stats(client, TRANSFORMED);
-            break;
         case COMMAND_TRANSFORMED_LIST_MOUNTS:
             command_list_mounts(client, TRANSFORMED);
             break;
@@ -494,9 +484,8 @@
             command_admin_function(client, TRANSFORMED);
             break;
         default:
-            WARN0("General admin request not recognised");
-            client_send_400(client, "Unknown admin request");
-            return;
+            command_stats (client);
+            break;
     }
 }
 
@@ -774,56 +763,64 @@
 }
 
 
+/* populata,e within srcnode, groups of 0 or more listener tags detailing
+ * information about each listener connected on the provide source.
+ */
+void admin_source_listeners (source_t *source, xmlNodePtr srcnode)
+{
+    client_t *listener;
+    char buf[30];
+
+    if (source == NULL)
+        return;
+
+    thread_mutex_lock (&source->lock);
+
+    listener = source->active_clients;
+    while (listener)
+    {
+        char *useragent;
+        xmlNodePtr node = xmlNewChild (srcnode, NULL, "listener", NULL);
+
+        snprintf (buf, sizeof (buf), "%lu", listener->con->id);
+        xmlNewChild (node, NULL, "ID", buf);
+
+        xmlNewChild (node, NULL, "IP", listener->con->ip);
+
+        useragent = httpp_getvar (listener->parser, "user-agent");
+        xmlNewChild (node, NULL, "UserAgent", useragent); 
+
+        snprintf (buf, sizeof (buf), "%lu",
+                (unsigned long)(global.time - listener->con->con_time));
+        xmlNewChild (node, NULL, "Connected", buf);
+        if (listener->username)
+            xmlNewChild (node, NULL, "Username", listener->username);
+
+        listener = listener->next;
+    }
+    thread_mutex_unlock (&source->lock);
+}
+
+
 static void command_show_listeners(client_t *client, source_t *source,
     int response)
 {
     xmlDocPtr doc;
-    xmlNodePtr node, srcnode, listenernode;
-    client_t *current;
+    xmlNodePtr node, srcnode;
     char buf[22];
-    char *userAgent = NULL;
-    time_t now = time(NULL);
 
     doc = xmlNewDoc("1.0");
     node = xmlNewDocNode(doc, NULL, "icestats", NULL);
     srcnode = xmlNewChild(node, NULL, "source", NULL);
 
-    thread_mutex_lock (&source->lock);
-
     xmlSetProp(srcnode, "mount", source->mount);
     xmlDocSetRootElement(doc, node);
 
-    memset(buf, '\000', sizeof(buf));
     snprintf(buf, sizeof(buf), "%lu", source->listeners);
     xmlNewChild(srcnode, NULL, "Listeners", buf);
 
-    current = source->active_clients;
-    while (current)
-    {
-        listenernode = xmlNewChild(srcnode, NULL, "listener", NULL);
-        xmlNewChild(listenernode, NULL, "IP", current->con->ip);
-        userAgent = httpp_getvar(current->parser, "user-agent");
-        if (userAgent) {
-            xmlNewChild(listenernode, NULL, "UserAgent", userAgent);
-        }
-        else {
-            xmlNewChild(listenernode, NULL, "UserAgent", "Unknown");
-        }
-        memset(buf, '\000', sizeof(buf));
-        snprintf (buf, sizeof(buf), "%lu",
-                (unsigned long)(now - current->con->con_time));
-        xmlNewChild(listenernode, NULL, "Connected", buf);
-        memset(buf, '\000', sizeof(buf));
-        snprintf(buf, sizeof(buf)-1, "%lu", current->con->id);
-        xmlNewChild(listenernode, NULL, "ID", buf);
-        if (current->username)
-            xmlNewChild(listenernode, NULL, "username", current->username);
+    admin_source_listeners (source, srcnode);
 
-        current = current->next;
-    }
-
-    thread_mutex_unlock (&source->lock);
-
     admin_send_response(doc, client, response, 
         LISTCLIENTS_TRANSFORMED_REQUEST);
     xmlFreeDoc(doc);
@@ -1127,13 +1124,28 @@
     }
 }
 
-static void command_stats(client_t *client, int response) {
+
+/* catch all function for admin requests.  If file has xsl extension then
+ * transform it usinf the available stats, else send the XML tree of the
+ * stats
+ */
+static void command_stats (client_t *client)
+{
+    char *uri = httpp_getvar (client->parser, HTTPP_VAR_URI);
+    int response = RAW;
+    char *xslfile = strrchr (uri, '/');
     xmlDocPtr doc;
 
-    DEBUG0("Stats request, sending xml stats");
+    if (xslfile == NULL)
+    {
+        client_send_404 (client, "bad request");
+        return;
+    }
+    if (util_check_valid_extension (uri) == XSLT_CONTENT)
+        response = TRANSFORMED;
 
     stats_get_xml(&doc, 1);
-    admin_send_response(doc, client, response, STATS_TRANSFORMED_REQUEST);
+    admin_send_response (doc, client, response, xslfile+1);
     xmlFreeDoc(doc);
     return;
 }

Modified: icecast/branches/kh/icecast/src/admin.h
===================================================================
--- icecast/branches/kh/icecast/src/admin.h	2005-06-22 23:06:20 UTC (rev 9508)
+++ icecast/branches/kh/icecast/src/admin.h	2005-06-23 03:22:48 UTC (rev 9509)
@@ -17,5 +17,6 @@
 #include "client.h"
 
 void admin_handle_request(client_t *client, char *uri);
+void admin_source_listeners (source_t *source, xmlNodePtr node);
 
 #endif  /* __ADMIN_H__ */

Modified: icecast/branches/kh/icecast/src/stats.c
===================================================================
--- icecast/branches/kh/icecast/src/stats.c	2005-06-22 23:06:20 UTC (rev 9508)
+++ icecast/branches/kh/icecast/src/stats.c	2005-06-23 03:22:48 UTC (rev 9509)
@@ -30,6 +30,8 @@
 
 #include "connection.h"
 
+#include "source.h"
+#include "admin.h"
 #include "global.h"
 #include "refbuf.h"
 #include "client.h"
@@ -935,7 +937,23 @@
         _free_event(event);
         event = _get_event_from_queue(&queue);
     }
+    if (show_hidden)
+    {
+        /* process each listener */
+        source_xml_t *src = src_nodes;
+        avl_tree_rlock (global.source_tree);
+        while (src)
+        {
+            source_t *source = source_find_mount_raw (src->mount);
 
+            if (source)
+                admin_source_listeners (source, src->node);
+
+            src = src->next;
+        }
+        avl_tree_unlock (global.source_tree);
+    }
+
     while (src_nodes) {
         next = src_nodes->next;
         free(src_nodes->mount);



More information about the commits mailing list