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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Fri May 27 05:56:13 PDT 2005


Author: karl
Date: 2005-05-27 05:56:07 -0700 (Fri, 27 May 2005)
New Revision: 9317

Modified:
   icecast/branches/kh/icecast/src/admin.c
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/auth.h
   icecast/branches/kh/icecast/src/cfgfile.c
   icecast/branches/kh/icecast/src/connection.c
   icecast/branches/kh/icecast/src/fserve.c
   icecast/branches/kh/icecast/src/refbuf.h
   icecast/branches/kh/icecast/src/slave.c
   icecast/branches/kh/icecast/src/slave.h
   icecast/branches/kh/icecast/src/source.c
Log:
various type cleanups. Add mechanism for enabling/disabling relays via
admin URL


Modified: icecast/branches/kh/icecast/src/admin.c
===================================================================
--- icecast/branches/kh/icecast/src/admin.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/admin.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -67,10 +67,12 @@
 #define COMMAND_RAW_LISTSTREAM              103
 #define COMMAND_PLAINTEXT_LISTSTREAM        104
 #define COMMAND_RAW_ADMIN_FUNCTION          105
+#define COMMAND_RAW_UPDATE_RELAY            106
 #define COMMAND_TRANSFORMED_LIST_MOUNTS     201
 #define COMMAND_TRANSFORMED_STATS           202
 #define COMMAND_TRANSFORMED_LISTSTREAM      203
 #define COMMAND_TRANSFORMED_ADMIN_FUNCTION  204
+#define COMMAND_TRANSFORMED_UPDATE_RELAY    205
 
 /* Client management commands */
 #define COMMAND_RAW_KILL_CLIENT             301
@@ -106,6 +108,8 @@
 #define MANAGEAUTH_TRANSFORMED_REQUEST "manageauth.xsl"
 #define UPDATEMETADATA_RAW_REQUEST "updatemetadata"
 #define UPDATEMETADATA_TRANSFORMED_REQUEST "updatemetadata.xsl"
+#define UPDATE_RELAY_RAW_REQUEST "updaterelay"
+#define UPDATE_RELAY_TRANSFORMED_REQUEST "updaterelay.xsl"
 #define ADM_FUNCTION_RAW_REQUEST "function"
 #define ADM_FUNCTION_TRANSFORMED_REQUEST "function.xsl"
 #define DEFAULT_RAW_REQUEST ""
@@ -168,6 +172,10 @@
         return COMMAND_TRANSFORMED_UPDATEMETADATA;
     else if(!strcmp(command, BUILDM3U_RAW_REQUEST))
         return COMMAND_BUILDM3U;
+    else if(!strcmp(command, UPDATE_RELAY_RAW_REQUEST))
+        return COMMAND_RAW_UPDATE_RELAY;
+    else if(!strcmp(command, UPDATE_RELAY_TRANSFORMED_REQUEST))
+        return COMMAND_TRANSFORMED_UPDATE_RELAY;
     else if(!strcmp(command, ADM_FUNCTION_RAW_REQUEST))
         return COMMAND_RAW_ADMIN_FUNCTION;
     else if(!strcmp(command, ADM_FUNCTION_TRANSFORMED_REQUEST))
@@ -200,6 +208,7 @@
 static void command_updatemetadata(client_t *client, source_t *source,
         int response);
 static void command_admin_function (client_t *client, int response);
+static void command_update_relay (client_t *client, int response);
 
 static void admin_handle_mount_request(client_t *client, source_t *source,
         int command);
@@ -456,6 +465,9 @@
         case COMMAND_RAW_LISTSTREAM:
             command_list_mounts(client, RAW);
             break;
+        case COMMAND_RAW_UPDATE_RELAY:
+            command_update_relay (client, RAW);
+            break;
         case COMMAND_RAW_ADMIN_FUNCTION:
             command_admin_function(client, RAW);
             break;
@@ -474,6 +486,9 @@
         case COMMAND_TRANSFORMED_MOVE_CLIENTS:
             command_list_mounts(client, TRANSFORMED);
             break;
+        case COMMAND_TRANSFORMED_UPDATE_RELAY:
+            command_update_relay (client, TRANSFORMED);
+            break;
         case COMMAND_TRANSFORMED_ADMIN_FUNCTION:
             command_admin_function(client, TRANSFORMED);
             break;
@@ -694,6 +709,51 @@
 }
 
 
+static void command_update_relay (client_t *client, int response)
+{
+    char *relay_mount, *enable;
+    const char *msg;
+    relay_server *relay;
+    xmlDocPtr doc;
+    xmlNodePtr node;
+
+    COMMAND_REQUIRE (client, "relay", relay_mount);
+    COMMAND_REQUIRE (client, "enable", enable);
+
+    if (relay_mount == NULL)
+        return;
+
+    thread_mutex_lock (&(config_locks()->relay_lock));
+
+    relay = slave_find_relay (global.relays, relay_mount);
+    if (relay == NULL)
+        relay = slave_find_relay (global.master_relays, relay_mount);
+
+    msg = "no such relay";
+    if (relay)
+    {
+        relay->enable = atoi (enable);
+        msg = "relay has been changed";
+        if (relay->enable == 0)
+        {
+            if (relay->source && relay->source->running == 0)
+                relay->source->on_demand = 0;
+        }
+        slave_rebuild_mounts();
+    }
+    thread_mutex_unlock (&(config_locks()->relay_lock));
+
+    doc = xmlNewDoc("1.0");
+    node = xmlNewDocNode(doc, NULL, "iceresponse", NULL);
+    xmlDocSetRootElement(doc, node);
+    xmlNewChild(node, NULL, "message", msg);
+    xmlNewChild(node, NULL, "return", "1");
+    admin_send_response(doc, client, response, ADMIN_XSL_RESPONSE);
+    xmlFreeDoc(doc);
+    client_destroy(client);
+}
+
+
 static void command_show_listeners(client_t *client, source_t *source,
     int response)
 {

Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/auth.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -218,8 +218,8 @@
         unsigned int total;
         thread_mutex_lock (&source->lock);
         total = source->new_listeners + source->listeners;
-        DEBUG2 ("max on %s is %d", source->mount, source->max_listeners);
-        DEBUG2 ("pending %d, current %d", source->new_listeners, source->listeners);
+        DEBUG2 ("max on %s is %lu", source->mount, source->max_listeners);
+        DEBUG2 ("pending %d, current %lu", source->new_listeners, source->listeners);
         if (source->max_listeners == -1)
             break;
         if (client->is_slave)

Modified: icecast/branches/kh/icecast/src/auth.h
===================================================================
--- icecast/branches/kh/icecast/src/auth.h	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/auth.h	2005-05-27 12:56:07 UTC (rev 9317)
@@ -70,7 +70,7 @@
     int allow_duplicate_users;
 
     void *state;
-    void *type;
+    char *type;
 } auth_t;
 
 void add_client (const char *mount, client_t *client);

Modified: icecast/branches/kh/icecast/src/cfgfile.c
===================================================================
--- icecast/branches/kh/icecast/src/cfgfile.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/cfgfile.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -695,6 +695,7 @@
 
     relay->next = NULL;
     relay->mp3metadata = 1;
+    relay->enable = 1;
     relay->on_demand = configuration->on_demand;
 
     do {
@@ -736,6 +737,11 @@
             relay->on_demand = atoi(tmp);
             if (tmp) xmlFree(tmp);
         }
+        else if (strcmp(node->name, "enable") == 0) {
+            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+            relay->enable = atoi(tmp);
+            if (tmp) xmlFree(tmp);
+        }
     } while ((node = node->next));
     if (relay->localmount == NULL)
         relay->localmount = xmlStrdup (relay->mount);

Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/connection.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -506,10 +506,9 @@
 
         source->running = 1;
         mountinfo = config_find_mount (config, source->mount);
-        if (mountinfo)
-            source_recheck_mounts ();
-        else
+        if (mountinfo == NULL)
             source_update_settings (config, source, mountinfo);
+        source_recheck_mounts ();
         config_release_config();
 
         source->shutdown_rwlock = &_source_shutdown_rwlock;

Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/fserve.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -452,7 +452,7 @@
     if (S_ISREG (file_buf.st_mode) == 0)
     {
         client_send_404 (httpclient, "The file you requested could not be found");
-        INFO1 ("found requested file but there is no handler for it", fullpath);
+        WARN1 ("found requested file but there is no handler for it: %s", fullpath);
         free (fullpath);
         return 0;
     }

Modified: icecast/branches/kh/icecast/src/refbuf.h
===================================================================
--- icecast/branches/kh/icecast/src/refbuf.h	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/refbuf.h	2005-05-27 12:56:07 UTC (rev 9317)
@@ -21,7 +21,7 @@
 typedef struct _refbuf_tag
 {
     char *data;
-    unsigned int len;
+    unsigned long len;
     int sync_point;
     struct _refbuf_tag *associated;
     struct _refbuf_tag *next;

Modified: icecast/branches/kh/icecast/src/slave.c
===================================================================
--- icecast/branches/kh/icecast/src/slave.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/slave.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -104,6 +104,7 @@
         copy->port = r->port;
         copy->mp3metadata = r->mp3metadata;
         copy->on_demand = r->on_demand;
+        copy->enable = r->enable;
         copy->source = r->source;
         r->source = NULL;
     }
@@ -371,21 +372,7 @@
         /* new relay, reserve the name */
         relay->source = source_reserve (relay->localmount);
         if (relay->source)
-        {
             DEBUG1("Adding relay source at mountpoint \"%s\"", relay->localmount);
-            relay->source->on_demand = relay->on_demand;
-            if (relay->on_demand)
-            {
-                ice_config_t *config = config_get_config ();
-                mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
-                if (mountinfo)
-                    slave_rebuild_mounts();
-                else
-                    source_update_settings (config, relay->source, mountinfo);
-                config_release_config ();
-                stats_event (relay->localmount, "listeners", "0");
-            }
-        }
         else
             WARN1 ("new relay but source \"%s\" already exists", relay->localmount);
     }
@@ -394,8 +381,23 @@
         source_t *source = relay->source;
         if (relay->source == NULL || relay->running)
             break;
+        if (relay->enable == 0)
+        {
+            stats_event (relay->localmount, NULL, NULL);
+            break;
+        }
         if (relay->on_demand)
         {
+            ice_config_t *config = config_get_config ();
+            mount_proxy *mountinfo = config_find_mount (config, relay->localmount);
+
+            if (mountinfo == NULL)
+                source_update_settings (config, relay->source, mountinfo);
+            config_release_config ();
+            slave_rebuild_mounts();
+            stats_event (relay->localmount, "listeners", "0");
+            relay->source->on_demand = relay->on_demand;
+
             if (source->fallback_mount && source->fallback_override)
             {
                 source_t *fallback;
@@ -404,7 +406,7 @@
                 fallback = source_find_mount (source->fallback_mount);
                 if (fallback && fallback->running && fallback->listeners)
                 {
-                   DEBUG2 ("fallback running %d with %d listeners", fallback->running, fallback->listeners);
+                   DEBUG2 ("fallback running %d with %lu listeners", fallback->running, fallback->listeners);
                    source->on_demand_req = 1;
                 }
                 avl_tree_unlock (global.source_tree);
@@ -426,8 +428,13 @@
         relay->thread = NULL;
         relay->cleanup = 0;
         relay->running = 0;
-        relay->source->on_demand = relay->on_demand;
 
+        if (relay->enable == 0)
+        {
+            stats_event (relay->localmount, NULL, NULL);
+            slave_rebuild_mounts();
+            return;
+        }
         if (relay->on_demand)
         {
             ice_config_t *config = config_get_config ();
@@ -746,6 +753,18 @@
 }
 
 
+relay_server *slave_find_relay (relay_server *relays, const char *mount)
+{
+    while (relays)
+    {
+        if (strcmp (relays->localmount, mount) == 0)
+            break;
+        relays = relays->next;
+    }
+    return relays;
+}
+
+
 /* remove this slave clients entry in the slave host list */
 void slave_host_remove (client_t *client)
 {

Modified: icecast/branches/kh/icecast/src/slave.h
===================================================================
--- icecast/branches/kh/icecast/src/slave.h	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/slave.h	2005-05-27 12:56:07 UTC (rev 9317)
@@ -29,6 +29,7 @@
     int on_demand;
     int running;
     int cleanup;
+    int enable;
     thread_type *thread;
     struct _relay_server *next;
 } relay_server;
@@ -46,6 +47,7 @@
 void slave_recheck_mounts (void);
 void slave_rebuild_mounts (void);
 void slave_rescan (void);
+relay_server *slave_find_relay (relay_server *relays, const char *mount);
 int slave_redirect (const char *mountpoint, struct _client_tag *client);
 void slave_host_add (struct _client_tag *client, const char *header);
 void slave_host_remove (struct _client_tag *client);

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-05-26 05:10:44 UTC (rev 9316)
+++ icecast/branches/kh/icecast/src/source.c	2005-05-27 12:56:07 UTC (rev 9317)
@@ -261,6 +261,7 @@
         source->intro_file = NULL;
     }
 
+    source->on_demand = 0;
     source->on_demand_req = 0;
 }
 
@@ -377,7 +378,7 @@
             count++;
         }
         if (count != source->listeners)
-            WARN2 ("count %u, listeners %u", count, source->listeners);
+            WARN2 ("count %u, listeners %lu", count, source->listeners);
         count = 0;
         while (source->pending_clients)
         {
@@ -562,10 +563,9 @@
 /* general send routine per listener.  The deletion_expected tells us whether
  * the last in the queue is about to disappear, so if this client is still
  * referring to it after writing then drop the client as it's fallen too far
- * behind.
+ * behind
  *
- * return 1 for client should be specially handled, either removed or placed
- *          elsewhere
+ * return 1 for fast client, limiter kicked in
  *        0 for normal case.
  */
 static int send_to_listener (source_t *source, client_t *client, int deletion_expected)
@@ -676,8 +676,8 @@
     /* has the listener count changed */
     if (source->listeners != listeners)
     {
-        INFO2("listener count on %s now %d", source->mount, source->listeners);
-        stats_event_args (source->mount, "listeners", "%d", source->listeners);
+        INFO2("listener count on %s now %lu", source->mount, source->listeners);
+        stats_event_args (source->mount, "listeners", "%lu", source->listeners);
         if (source->listeners == 0)
             rate_add (source->format->out_bitrate, 0, 0);
         if (source->listeners == 0 && source->on_demand)
@@ -1237,7 +1237,7 @@
         stats_event (source->mount, "on_demand", NULL);
 
     DEBUG1 ("public set to %d", source->yp_public);
-    DEBUG1 ("max listeners to %d", source->max_listeners);
+    DEBUG1 ("max listeners to %ld", source->max_listeners);
     DEBUG1 ("queue size to %u", source->queue_size_limit);
     DEBUG1 ("burst size to %u", source->burst_size);
     DEBUG1 ("source timeout to %u", source->timeout);
@@ -1269,10 +1269,12 @@
     stats_event_inc(NULL, "source_client_connections");
     stats_event (source->mount, "listeners", "0");
     stats_event (source->mount, "source_ip", source->client->con->ip);
+
     source_main (source);
+
     source_free_source (source);
+    source_recheck_mounts ();
 
-    source_recheck_mounts ();
     return NULL;
 }
 



More information about the commits mailing list