[xiph-cvs] cvs commit: net sock.c sock.h

Michael Smith msmith at xiph.org
Fri Mar 7 06:57:36 PST 2003



msmith      03/03/07 09:57:36

  Modified:    .        News
               src      admin.c
               .        sock.c sock.h
  Log:
  Implement listing of all currently connected clients on a mountpoint

Revision  Changes    Path
1.2       +11 -0     icecast/News

Index: News
===================================================================
RCS file: /usr/local/cvsroot/icecast/News,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- News	5 Mar 2003 13:03:35 -0000	1.1
+++ News	7 Mar 2003 14:57:36 -0000	1.2
@@ -1,3 +1,14 @@
+2003-03-08
+    Started implementing generic admin interface. Supports (so far): 
+    - dynamic configuration of mount fallbacks
+        /admin/fallbacks?mount=/mount&fallback=/fallback
+    - setting of mp3 metadata
+        /admin/metadata?mount=/mount&mode=updinfo&song=New%20Title
+    - dumping raw xml stats
+        /admin/rawstats
+    - listing all connected clients on a mountpoint: 
+        /admin/listclients?mount=/mountname
+
 2003-03-05
     Implemented the ability to reread the config file on SIGHUP. For now, this
     does not affect configuration for currently running sources (only new

<p><p>1.2       +70 -4     icecast/src/admin.c

Index: admin.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/admin.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- admin.c	6 Mar 2003 14:17:33 -0000	1.1
+++ admin.c	7 Mar 2003 14:57:36 -0000	1.2
@@ -1,5 +1,7 @@
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
+#include <time.h>
 
 #include "config.h"
 #include "connection.h"
@@ -21,6 +23,7 @@
 #define COMMAND_FALLBACK          1
 #define COMMAND_RAW_STATS         2
 #define COMMAND_METADATA_UPDATE   3
+#define COMMAND_SHOW_LISTENERS    4
 
 int admin_get_command(char *command)
 {
@@ -32,12 +35,15 @@
         return COMMAND_RAW_STATS;
     else if(!strcmp(command, "metadata"))
         return COMMAND_METADATA_UPDATE;
+    else if(!strcmp(command, "listclients"))
+        return COMMAND_SHOW_LISTENERS;
     else
         return COMMAND_ERROR;
 }
 
 static void command_fallback(client_t *client, source_t *source);
 static void command_metadata(client_t *client, source_t *source);
+static void command_show_listeners(client_t *client, source_t *source);
 
 static void command_raw_stats(client_t *client);
 
@@ -132,10 +138,13 @@
         case COMMAND_METADATA_UPDATE:
             command_metadata(client, source);
             break;
+        case COMMAND_SHOW_LISTENERS:
+            command_show_listeners(client, source);
+            break;
         default:
             WARN0("Mount request not recognised");
             client_send_400(client, "Mount request unknown");
-            return;
+            break;
     }
 }
 
@@ -148,7 +157,7 @@
         } \
     } while(0);
 
-static void command_success(client_t *client, char *message)
+static void html_success(client_t *client, char *message)
 {
     int bytes;
 
@@ -161,6 +170,63 @@
     client_destroy(client);
 }
 
+static void html_head(client_t *client)
+{
+    int bytes;
+
+    client->respcode = 200;
+    bytes = sock_write(client->con->sock,
+            "HTTP/1.0 200 OK\r\n"
+            "Content-Type: text/html\r\n"
+            "\r\n"
+            "<html><head><title>Admin request</title></head>"
+            "<body>");
+    if(bytes > 0) client->con->sent_bytes = bytes;
+}
+
+static void html_write(client_t *client, char *fmt, ...)
+{
+    int bytes;
+    va_list ap;
+
+    va_start(ap, fmt);
+    bytes = sock_write_fmt(client->con->sock, fmt, ap);
+    va_end(ap);
+    if(bytes > 0) client->con->sent_bytes = bytes;
+}
+
+static void command_show_listeners(client_t *client, source_t *source)
+{
+    avl_node *client_node;
+    client_t *current;
+    time_t now = time(NULL);
+
+    DEBUG1("Dumping listeners on mountpoint %s", source->mount);
+
+    html_head(client);
+
+    html_write(client, 
+            "<table><tr><td>IP</td><td>Connected</td><td>ID</td></tr>");
+
+    avl_tree_rlock(source->client_tree);
+
+    client_node = avl_get_first(source->client_tree);
+    while(client_node) {
+        current = (client_t *)client_node->key;
+
+        html_write(client, "<tr><td>%s</td><td>%d</td><td>%ld</td></tr>",
+                current->con->ip, now-current->con->con_time, current->con->id);
+
+        client_node = avl_get_next(client_node);
+    }
+
+    avl_tree_unlock(source->client_tree);
+
+    html_write(client, "</table></body></html>");
+
+    client_destroy(client);
+}
+
 static void command_fallback(client_t *client, source_t *source)
 {
     char *fallback;
@@ -174,7 +240,7 @@
     source->fallback_mount = strdup(fallback);
     free(old);
 
-    command_success(client, "Fallback configured");
+    html_success(client, "Fallback configured");
 }
 
 static void command_metadata(client_t *client, source_t *source)
@@ -210,7 +276,7 @@
     DEBUG2("Metadata on mountpoint %s changed to \"%s\"", source->mount, value);
     stats_event(source->mount, "title", value);
 
-    command_success(client, "Metadata update successful");
+    html_success(client, "Metadata update successful");
 }
 
 static void command_raw_stats(client_t *client) {

<p><p>1.18      +9 -0      net/sock.c

Index: sock.c
===================================================================
RCS file: /usr/local/cvsroot/net/sock.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- sock.c	14 Feb 2003 11:14:55 -0000	1.17
+++ sock.c	7 Mar 2003 14:57:36 -0000	1.18
@@ -314,6 +314,15 @@
         return sock_write_bytes(sock, buff, strlen(buff));
 }
 
+int sock_write_fmt(sock_t sock, char *fmt, va_list ap)
+{
+    char buff[1024];
+
+    vsnprintf(buff, 1024, fmt, ap);
+
+    return sock_write_bytes(sock, buff, strlen(buff));
+}
+
 int sock_read_bytes(sock_t sock, char *buff, const int len)
 {
 

<p><p>1.12      +2 -0      net/sock.h

Index: sock.h
===================================================================
RCS file: /usr/local/cvsroot/net/sock.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- sock.h	13 Feb 2003 11:29:07 -0000	1.11
+++ sock.h	7 Mar 2003 14:57:36 -0000	1.12
@@ -22,6 +22,7 @@
 #ifndef __SOCK_H
 #define __SOCK_H
 
+#include <stdarg.h>
 
 #ifdef _WIN32
 #include <winsock2.h>
@@ -87,6 +88,7 @@
 /* Socket write functions */
 int sock_write_bytes(sock_t sock, const void *buff, const size_t len);
 int sock_write(sock_t sock, const char *fmt, ...);
+int sock_write_fmt(sock_t sock, char *fmt, va_list ap);
 int sock_write_string(sock_t sock, const char *buff);
 ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count);
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list