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

karl at svn.xiph.org karl at svn.xiph.org
Sat Feb 2 20:52:54 PST 2008


Author: karl
Date: 2008-02-02 20:52:49 -0800 (Sat, 02 Feb 2008)
New Revision: 14451

Modified:
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/auth_url.c
   icecast/branches/kh/icecast/src/cfgfile.c
   icecast/branches/kh/icecast/src/connection.c
   icecast/branches/kh/icecast/src/source.c
   icecast/branches/kh/icecast/src/util.c
   icecast/branches/kh/icecast/src/yp.c
Log:
sync up work. a few minor changes to internal settings and possible race fix eliminated


Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/auth.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -573,7 +573,7 @@
     const char *mount = auth_user->mount;
 
     if (client == NULL)
-        return 0;
+        return -1;
 
     if (client->authenticated == 0)
     {
@@ -583,7 +583,7 @@
         else if (auth->rejected_mount)
             mount = auth->rejected_mount;
         else
-            return 0;
+            return -1;
     }
     config = config_get_config();
     mountinfo = config_find_mount (config, mount);
@@ -602,14 +602,20 @@
 void auth_postprocess_source (auth_client *auth_user)
 {
     client_t *client = auth_user->client;
-    const char *uri = auth_user->mount;
+    const char *mount = auth_user->mount;
+    const char *req = httpp_getvar (client->parser, HTTPP_VAR_URI);
 
-    DEBUG1 ("checking reference (%s)", uri);
     auth_user->client = NULL;
-    if (strcmp (uri, "/admin.cgi") != 0 && strncmp("/admin/", uri, 7) != 0)
-        source_startup (client, uri, 0);
+    if (strcmp (req, "/admin.cgi") == 0 || strncmp ("/admin/metadata", req, 15) == 0)
+    {
+        DEBUG2 ("metadata request (%s, %s)", req, mount);
+        admin_mount_request (client, "metadata");
+    }
     else
-        admin_mount_request (client, uri);
+    {
+        DEBUG1 ("on mountpoint %s", mount);
+        source_startup (client, mount, 0);
+    }
 }
 
 

Modified: icecast/branches/kh/icecast/src/auth_url.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_url.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/auth_url.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -502,13 +502,9 @@
     curl_easy_setopt (atd->curl, CURLOPT_URL, url->stream_auth);
     curl_easy_setopt (atd->curl, CURLOPT_POSTFIELDS, post);
     curl_easy_setopt (atd->curl, CURLOPT_WRITEHEADER, auth_user);
-    if (strncmp (auth_user->mount, "/admin/", 7) == 0)
-    {
-        mount = util_url_escape (httpp_get_query_param (client->parser, "mount"));
+    if (strcmp (auth_user->mount, httpp_getvar (client->parser, HTTPP_VAR_URI)) != 0)
         admin = "&admin=1";
-    }
-    else
-        mount = util_url_escape (auth_user->mount);
+    mount = util_url_escape (auth_user->mount);
     host = util_url_escape (auth_user->hostname);
     user = util_url_escape (client->username);
     pass = util_url_escape (client->password);

Modified: icecast/branches/kh/icecast/src/cfgfile.c
===================================================================
--- icecast/branches/kh/icecast/src/cfgfile.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/cfgfile.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -857,6 +857,26 @@
     return 0;
 }
 
+static int _parse_master (xmlNodePtr node, void *arg)
+{
+    ice_config_t *config = arg;
+
+    struct cfg_tag icecast_tags[] =
+    {
+        { "server",             config_get_str,     &config->master_server },
+        { "port",               config_get_int,     &config->master_server_port },
+        { "ssl-port",           config_get_int,     &config->master_ssl_port },
+        { "username",           config_get_str,     &config->master_username },
+        { "password",           config_get_str,     &config->master_password },
+        { "bind",               config_get_str,     &config->master_bind },
+        { "update-interval",    config_get_int,     &config->master_update_interval },
+        { "relay-auth",         config_get_bool,    &config->master_relay_auth },
+        { "redirect",           config_get_bool,    &config->master_redirect },
+        { NULL, NULL, NULL },
+    };
+}
+
+
 static int _parse_listen_sock (xmlNodePtr node, void *arg)
 {
     ice_config_t *config = arg;
@@ -936,6 +956,7 @@
         { "limits",             _parse_limits,      config },
         { "relay",              _parse_relay,       config },
         { "mount",              _parse_mount,       config },
+        { "master",             _parse_master,      config },
         { "directory",          _parse_directory,   config },
         { "paths",              _parse_paths,       config },
         { "logging",            _parse_logging,     config },

Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/connection.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -711,7 +711,7 @@
 {
     connection_t *con;
     ice_config_t *config;
-    int duration = 200;
+    int duration = 300;
 
     connection_running = 1;
     INFO0 ("connection thread started");
@@ -759,7 +759,6 @@
             if (duration > 5)
             {
                 duration = 5;
-                continue;
             }
         }
         else

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/source.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -807,7 +807,6 @@
     source->prev_listeners = -1;
     source->bytes_sent_since_update = 0;
     source->stats_interval = 5;
-    source->running = 1;
     /* so the first set of average stats after 3 seconds */
     source->client_stats_update = global.time + 3;
 
@@ -862,6 +861,7 @@
 
     source->format->in_bitrate = rate_setup (source->avg_bitrate_duration+1);
     source->format->out_bitrate = rate_setup (source->avg_bitrate_duration+1);
+    source->running = 1;
 }
 
 

Modified: icecast/branches/kh/icecast/src/util.c
===================================================================
--- icecast/branches/kh/icecast/src/util.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/util.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -278,11 +278,16 @@
 
 char *util_url_escape (const char *src)
 {
-    int len = strlen(src);
+    int len, i, j=0;
+    char *dst;
+    unsigned char *source;
+
+    if (src == NULL)
+        return strdup ("");
+    len = strlen(src);
     /* Efficiency not a big concern here, keep the code simple/conservative */
-    char *dst = calloc(1, len*3 + 1); 
-    unsigned char *source = (unsigned char *)src;
-    int i,j=0;
+    dst = calloc(1, len*3 + 1); 
+    source = (unsigned char *)src;
 
     for(i=0; i < len; i++) {
         if(safechars[source[i]]) {
@@ -774,7 +779,7 @@
  */
 long rate_avg (struct rate_calc *calc)
 {
-    if (calc->blocks < 2)
+    if (calc == NULL || calc->blocks < 2)
         return 0;
     return (long)(calc->total / (calc->blocks-1));
 }

Modified: icecast/branches/kh/icecast/src/yp.c
===================================================================
--- icecast/branches/kh/icecast/src/yp.c	2008-02-03 03:11:54 UTC (rev 14450)
+++ icecast/branches/kh/icecast/src/yp.c	2008-02-03 04:52:49 UTC (rev 14451)
@@ -73,7 +73,7 @@
     time_t      next_update;
     unsigned    touch_interval;
     char        *error_msg;
-    unsigned    (*process)(struct ypdata_tag *yp, char *s, unsigned len);
+    int    (*process)(struct ypdata_tag *yp, char *s, unsigned len);
 
     struct ypdata_tag *next;
 } ypdata_t;
@@ -91,9 +91,9 @@
 
 static void *yp_update_thread(void *arg);
 static void add_yp_info (ypdata_t *yp, void *info, int type);
-static unsigned do_yp_remove (ypdata_t *yp, char *s, unsigned len);
-static unsigned do_yp_add (ypdata_t *yp, char *s, unsigned len);
-static unsigned do_yp_touch (ypdata_t *yp, char *s, unsigned len);
+static int do_yp_remove (ypdata_t *yp, char *s, unsigned len);
+static int do_yp_add (ypdata_t *yp, char *s, unsigned len);
+static int do_yp_touch (ypdata_t *yp, char *s, unsigned len);
 static void yp_destroy_ypdata(ypdata_t *ypdata);
 
 
@@ -277,7 +277,9 @@
 
 
 
-/* handler for curl, checks if successful handling occurred */
+/* handler for curl, checks if successful handling occurred
+ * return 0 for ok, -1 for this entry failed, -2 for server fail
+ */
 static int send_to_yp (const char *cmd, ypdata_t *yp, char *post)
 {
     int curlcode;
@@ -291,9 +293,9 @@
     if (curlcode)
     {
         yp->process = do_yp_add;
-        yp->next_update += 300;
+        yp->next_update += 900;
         ERROR2 ("connection to %s failed with \"%s\"", server->url, server->curl_error);
-        return -1;
+        return -2;
     }
     if (yp->cmd_ok == 0)
     {
@@ -310,16 +312,18 @@
 
 
 /* routines for building and issues requests to the YP server */
-static unsigned do_yp_remove (ypdata_t *yp, char *s, unsigned len)
+static int do_yp_remove (ypdata_t *yp, char *s, unsigned len)
 {
+    int ret = 0;
+
     if (yp->sid)
     {
-        int ret = snprintf (s, len, "action=remove&sid=%s", yp->sid);
+        ret = snprintf (s, len, "action=remove&sid=%s", yp->sid);
         if (ret >= (signed)len)
             return ret+1;
 
         INFO1 ("clearing up YP entry for %s", yp->mount);
-        send_to_yp ("remove", yp, s);
+        ret = send_to_yp ("remove", yp, s);
         free (yp->sid);
         yp->sid = NULL;
     }
@@ -327,11 +331,11 @@
     yp->remove = 1;
     yp->process = do_yp_add;
 
-    return 0;
+    return ret;
 }
 
 
-static unsigned do_yp_add (ypdata_t *yp, char *s, unsigned len)
+static int do_yp_add (ypdata_t *yp, char *s, unsigned len)
 {
     int ret;
     char *value;
@@ -377,18 +381,18 @@
                     yp->server_type, yp->subtype, yp->bitrate, yp->audio_info);
     if (ret >= (signed)len)
         return ret+1;
-    if (send_to_yp ("add", yp, s) == 0)
+    ret =  send_to_yp ("add", yp, s);
+    if (ret == 0)
     {
         yp->process = do_yp_touch;
         /* force first touch in 5 secs */
         yp->next_update = global.time + 5;
     }
-
-    return 0;
+    return ret;
 }
 
 
-static unsigned do_yp_touch (ypdata_t *yp, char *s, unsigned len)
+static int do_yp_touch (ypdata_t *yp, char *s, unsigned len)
 {
     unsigned listeners = 0, max_listeners = 1;
     char *val, *artist, *title;
@@ -445,27 +449,26 @@
     if (ret >= (signed)len)
         return ret+1; /* space required for above text and nul*/
 
-    send_to_yp ("touch", yp, s);
-    return 0;
+    return send_to_yp ("touch", yp, s);
 }
 
 
 
-static void process_ypdata (struct yp_server *server, ypdata_t *yp)
+static int process_ypdata (struct yp_server *server, ypdata_t *yp)
 {
     unsigned len = 512;
     char *s = NULL, *tmp;
 
     if (now < yp->next_update)
-        return;
+        return 0;
     yp->next_update = now + yp->touch_interval;
 
     /* loop just in case the memory area isn't big enough */
     while (1)
     {
-        unsigned ret;
+        int ret;
         if ((tmp = realloc (s, len)) == NULL)
-            return;
+            return 0;
         s = tmp;
 
         if (yp->release)
@@ -475,26 +478,38 @@
         }
 
         ret = yp->process (yp, s, len);
-        if (ret == 0)
+        if (ret <= 0)
         {
            free (s);
-           return;
+           return ret;
         }
         len = ret;
     }
+    return 0;
 }
 
 
 static void yp_process_server (struct yp_server *server)
 {
     ypdata_t *yp;
+    int state = 0;
 
     /* DEBUG1("processing yp server %s", server->url); */
     yp = server->mounts;
     while (yp)
     {
         now = global.time;
-        process_ypdata (server, yp);
+        /* if one of the streams shows that the server cannot be contacted then mark the
+         * other entries for an update later. Assume YP server is dead and skip it for now
+         */
+        if (state == -2)
+        {
+            DEBUG2 ("skiping %s on %s", yp->mount, server->url);
+            yp->process = do_yp_add;
+            yp->next_update += 900;
+        }
+        else
+            state = process_ypdata (server, yp);
         yp = yp->next;
     }
 }



More information about the commits mailing list