[xiph-cvs] cvs commit: icecast/src connection.c connection.h source.c source.h

Karl Heyes karl at xiph.org
Thu Feb 19 13:17:00 PST 2004



karl        04/02/19 16:17:00

  Modified:    src      connection.c connection.h source.c source.h
  Log:
  Make source client connections reserve the source mountpoint and get rid
  of the unused source setup code.

Revision  Changes    Path
1.88      +21 -106   icecast/src/connection.c

Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -r1.87 -r1.88
--- connection.c	19 Feb 2004 20:28:21 -0000	1.87
+++ connection.c	19 Feb 2004 21:16:59 -0000	1.88
@@ -520,98 +520,6 @@
 }
 
 
-int connection_create_source(client_t *client, connection_t *con, http_parser_t *parser, char *mount) {
-    source_t *source;
-    char *contenttype;
-    mount_proxy *mountproxy, *mountinfo = NULL;
-    int source_limit;
-    ice_config_t *config;
-
-    config = config_get_config();
-    source_limit = config->source_limit;
-    config_release_config();
-
-    /* check to make sure this source wouldn't
-    ** be over the limit
-    */
-    global_lock();
-    if (global.sources >= source_limit) {
-        INFO1("Source (%s) logged in, but there are too many sources", mount);
-        global_unlock();
-        return 0;
-    }
-    global.sources++;
-    global_unlock();
-
-    stats_event_inc(NULL, "sources");
-    
-    config = config_get_config();
-    mountproxy = config->mounts;
-    thread_mutex_lock(&(config_locks()->mounts_lock));
-
-    while(mountproxy) {
-        if(!strcmp(mountproxy->mountname, mount)) {
-            mountinfo = mountproxy;
-            break;
-        }
-        mountproxy = mountproxy->next;
-    }
-
-    contenttype = httpp_getvar(parser, "content-type");
-
-    if (contenttype != NULL) {
-        format_type_t format = format_get_type(contenttype);
-        if (format == FORMAT_ERROR) {
-            WARN1("Content-type \"%s\" not supported, dropping source", contenttype);
-            thread_mutex_unlock(&(config_locks()->mounts_lock));
-            config_release_config();
-            goto fail;
-        } else {
-            source = source_create(client, con, parser, mount, 
-                    format, mountinfo);
-            thread_mutex_unlock(&(config_locks()->mounts_lock));
-        }
-    } else {
-        format_type_t format = FORMAT_TYPE_MP3;
-        ERROR0("No content-type header, falling back to backwards compatibility mode for icecast 1.x relays. Assuming content is mp3.");
-        source = source_create(client, con, parser, mount, format, mountinfo);
-        thread_mutex_unlock(&(config_locks()->mounts_lock));
-    }
-    config_release_config();
-
-    /* we need to add this source into the tree but fail if this mountpoint
-     * already exists
-     */
-    avl_tree_wlock(global.source_tree);
-    if (source_find_mount_raw (mount) != NULL)
-    {
-        avl_tree_unlock(global.source_tree);
-        global_lock();
-        global.sources--;
-        global_unlock();
-        stats_event_dec(NULL, "sources");
-        INFO1("source \"%s\" already in use", mount);
-        client_send_404 (client, "Mountpoint in use");
-        return 0;
-    }
-    avl_insert(global.source_tree, (void *)source);
-    avl_tree_unlock(global.source_tree);
-
-    source->send_return = 1;
-    source->shutdown_rwlock = &_source_shutdown_rwlock;
-    sock_set_blocking(con->sock, SOCK_NONBLOCK);
-    thread_create("Source Thread", source_client_thread, (void *)source, THREAD_DETACHED);
-    return 1;
-
-fail:
-    global_lock();
-    global.sources--;
-    global_unlock();
-
-    stats_event_dec(NULL, "sources");
-    return 0;
-}
-
 static int _check_pass_http(http_parser_t *parser, 
         char *correctuser, char *correctpass)
 {
@@ -761,10 +669,12 @@
     return ret;
 }
 
+
 static void _handle_source_request(connection_t *con, 
         http_parser_t *parser, char *uri)
 {
     client_t *client;
+    source_t *source;
 
     client = client_create(con, parser);
 
@@ -780,23 +690,28 @@
         client_send_401(client);
         return;
     }
-
-    /* check to make sure this source has
-    ** a unique mountpoint
-    */
-
-    avl_tree_rlock(global.source_tree);
-    if (source_find_mount_raw(uri) != NULL) {
-        avl_tree_unlock(global.source_tree);
-        INFO1("Source tried to log in as %s, but mountpoint is already used", uri);
-        client_send_404(client, "Mountpoint in use");
-        return;
+    source = source_reserve (uri);
+    if (source)
+    {
+        source->client = client;
+        source->parser = parser;
+        source->con = con;
+        if (connection_complete_source (source) < 0)
+        {
+            source->client = NULL;
+            source_free_source (source);
+        }
+        else
+            thread_create ("Source Thread", source_client_thread,
+                    source, THREAD_DETACHED);
+    }
+    else
+    {
+        client_send_404 (client, "Mountpoint in use");
     }
-    avl_tree_unlock(global.source_tree);
-
-    connection_create_source(client, con, parser, uri);
 }
 
+
 static void _handle_stats_request(connection_t *con, 
         http_parser_t *parser, char *uri)
 {

<p><p>1.15      +0 -2      icecast/src/connection.h

Index: connection.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- connection.h	19 Feb 2004 16:32:23 -0000	1.14
+++ connection.h	19 Feb 2004 21:16:59 -0000	1.15
@@ -48,8 +48,6 @@
 void connection_accept_loop(void);
 void connection_close(connection_t *con);
 connection_t *create_connection(sock_t sock, sock_t serversock, char *ip);
-int connection_create_source(struct _client_tag *client, connection_t *con, 
-        http_parser_t *parser, char *mount);
 int connection_complete_source (struct source_tag *source);
 
 void connection_inject_event(int eventnum, void *event_data);

<p><p>1.74      +10 -52    icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- source.c	19 Feb 2004 20:28:21 -0000	1.73
+++ source.c	19 Feb 2004 21:16:59 -0000	1.74
@@ -101,58 +101,6 @@
 }
 
 
-source_t *source_create(client_t *client, connection_t *con, 
-    http_parser_t *parser, const char *mount, format_type_t type, 
-    mount_proxy *mountinfo)
-{
-    source_t *src;
-
-    src = (source_t *)malloc(sizeof(source_t));
-    src->client = client;
-    src->mount = (char *)strdup(mount);
-    src->fallback_mount = NULL;
-    src->format = format_get_plugin(type, src->mount, parser);
-    src->con = con;
-    src->parser = parser;
-    src->client_tree = avl_tree_new(_compare_clients, NULL);
-    src->pending_tree = avl_tree_new(_compare_clients, NULL);
-    src->running = 1;
-    src->num_yp_directories = 0;
-    src->listeners = 0;
-    src->max_listeners = -1;
-    src->send_return = 0;
-    src->dumpfilename = NULL;
-    src->dumpfile = NULL;
-    src->audio_info = util_dict_new();
-    src->yp_public = 0;
-    src->fallback_override = 0;
-    src->no_mount = 0;
-    src->authenticator = NULL;
-
-    if(mountinfo != NULL) {
-        if (mountinfo->fallback_mount != NULL)
-            src->fallback_mount = strdup (mountinfo->fallback_mount);
-        src->max_listeners = mountinfo->max_listeners;
-        if (mountinfo->dumpfile != NULL)
-            src->dumpfilename = strdup (mountinfo->dumpfile);
-        if(mountinfo->auth_type != NULL)
-            src->authenticator = auth_get_authenticator(
-                    mountinfo->auth_type, mountinfo->auth_options);
-        src->fallback_override = mountinfo->fallback_override;
-        src->no_mount = mountinfo->no_mount;
-    }
-
-    if(src->dumpfilename != NULL) {
-        src->dumpfile = fopen(src->dumpfilename, "ab");
-        if(src->dumpfile == NULL) {
-            WARN2("Cannot open dump file \"%s\" for appending: %s, disabling.",
-                    src->dumpfilename, strerror(errno));
-        }
-    }
-
-    return src;
-}
-
 /* Find a mount with this raw name - ignoring fallbacks. You should have the
  * global source tree locked to call this.
  */
@@ -562,6 +510,16 @@
     if (listenurl) {
         free(listenurl);
     }
+    if (source->dumpfilename != NULL)
+    {
+        source->dumpfile = fopen (source->dumpfilename, "ab");
+        if (source->dumpfile == NULL)
+        {
+            WARN2("Cannot open dump file \"%s\" for appending: %s, disabling.",
+                    source->dumpfilename, strerror(errno));
+        }
+    }
+
 
     DEBUG0("Source creation complete");
     source->running = 1;

<p><p>1.20      +0 -3      icecast/src/source.h

Index: source.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- source.h	19 Feb 2004 16:32:26 -0000	1.19
+++ source.h	19 Feb 2004 21:16:59 -0000	1.20
@@ -59,9 +59,6 @@
     int no_mount;
 } source_t;
 
-source_t *source_create(client_t *client, connection_t *con, 
-        http_parser_t *parser, const char *mount, format_type_t type,
-        mount_proxy *mountinfo);
 source_t *source_reserve (const char *mount);
 void *source_client_thread (void *arg);
 void source_apply_mount (source_t *source, mount_proxy *mountinfo);

<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