[vlc-commits] Revert "Use separate HTTPd host per protocol"

Pierre Ynard git at videolan.org
Mon Oct 24 03:35:34 CEST 2011


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon Oct 24 03:33:11 2011 +0200| [40f931378bd37ec7a0b07e9908fcb05fb8d8d745] | committer: Pierre Ynard

Revert "Use separate HTTPd host per protocol"

This reverts commit f06b4d30510f4528dac682d9c02ab0238a0993ed.
This way provides more use-cases that are more useful.

Conflicts:

	src/network/httpd.c

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=40f931378bd37ec7a0b07e9908fcb05fb8d8d745
---

 src/network/httpd.c |   57 ++++++++++++++++++++++++++-------------------------
 1 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index 7c08192..73ca028 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -79,6 +79,7 @@ struct httpd_host_t
     /* address/port and socket for listening at connections */
     int         *fds;
     unsigned     nfd;
+    unsigned     port;
 
     vlc_thread_t thread;
     vlc_mutex_t lock;
@@ -951,21 +952,13 @@ void httpd_StreamDelete( httpd_stream_t *stream )
  * Low level
  *****************************************************************************/
 static void* httpd_HostThread( void * );
-static httpd_host_t *httpd_HostCreate( vlc_object_t *, httpd_host_t **,
-                                       const char *, const char *,
-                                       vlc_tls_creds_t * );
-
-static struct httpd_t
-{
-    vlc_mutex_t  mutex;
-    httpd_host_t *http, *https, *rtsp;
-} httpd = { VLC_STATIC_MUTEX, NULL, NULL, NULL };
+static httpd_host_t *httpd_HostCreate( vlc_object_t *, const char *,
+                                       const char *, vlc_tls_creds_t * );
 
 /* create a new host */
 httpd_host_t *vlc_http_HostNew( vlc_object_t *p_this )
 {
-    return httpd_HostCreate( p_this, &httpd.http,
-                             "http-host", "http-port", NULL );
+    return httpd_HostCreate( p_this, "http-host", "http-port", NULL );
 }
 
 httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
@@ -1015,8 +1008,7 @@ httpd_host_t *vlc_https_HostNew( vlc_object_t *obj )
         free( crl );
     }
 
-    return httpd_HostCreate( obj, &httpd.https,
-                             "http-host", "https-port", tls );
+    return httpd_HostCreate( obj, "http-host", "https-port", tls );
 
 error:
     vlc_tls_ServerDelete( tls );
@@ -1025,25 +1017,38 @@ error:
 
 httpd_host_t *vlc_rtsp_HostNew( vlc_object_t *p_this )
 {
-    return httpd_HostCreate( p_this, &httpd.rtsp,
-                             "rtsp-host", "rtsp-port", NULL );
+    return httpd_HostCreate( p_this, "rtsp-host", "rtsp-port", NULL );
 }
 
+static struct httpd_t
+{
+    vlc_mutex_t  mutex;
+
+    httpd_host_t **host;
+    int          i_host;
+} httpd = { VLC_STATIC_MUTEX, NULL, 0 };
+
 static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
-                                       httpd_host_t **hostp,
                                        const char *hostvar,
                                        const char *portvar,
                                        vlc_tls_creds_t *p_tls )
 {
     httpd_host_t *host;
+    unsigned port = var_InheritInteger( p_this, portvar );
 
     /* to be sure to avoid multiple creation */
     vlc_mutex_lock( &httpd.mutex );
 
     /* verify if it already exist */
-    host = *hostp;
-    if( host != NULL )
+    for( int i = 0; i < httpd.i_host; i++ )
     {
+        host = httpd.host[i];
+
+        /* cannot mix TLS and non-TLS hosts */
+        if( host->port != port
+         || (host->p_tls != NULL) != (p_tls != NULL) )
+            continue;
+
         /* Increase existing matching host reference count.
          * The reference count is written under both the global httpd and the
          * host lock. It is read with either or both locks held. The global
@@ -1058,6 +1063,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
         return host;
     }
 
+    host = NULL;
+
     /* create the new host */
     host = (httpd_host_t *)vlc_custom_create( p_this, sizeof (*host),
                                               "http host" );
@@ -1069,7 +1076,6 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
     host->i_ref = 1;
 
     char *hostname = var_InheritString( p_this, hostvar );
-    unsigned port = var_InheritInteger( p_this, portvar );
     host->fds = net_ListenTCP( p_this, hostname, port );
     free( hostname );
     if( host->fds == NULL )
@@ -1085,6 +1091,7 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
         goto error;
     }
 
+    host->port     = port;
     host->i_url    = 0;
     host->url      = NULL;
     host->i_client = 0;
@@ -1099,7 +1106,8 @@ static httpd_host_t *httpd_HostCreate( vlc_object_t *p_this,
         goto error;
     }
 
-    *hostp = host;
+    /* now add it to httpd */
+    TAB_APPEND( httpd.i_host, httpd.host, host );
     vlc_mutex_unlock( &httpd.mutex );
 
     return host;
@@ -1144,6 +1152,7 @@ void httpd_HostDelete( httpd_host_t *host )
         msg_Dbg( host, "httpd_HostDelete: host still in use" );
         return;
     }
+    TAB_REMOVE( httpd.i_host, httpd.host, host );
 
     vlc_object_kill( host );
     vlc_join( host->thread, NULL );
@@ -1172,14 +1181,6 @@ void httpd_HostDelete( httpd_host_t *host )
     vlc_cond_destroy( &host->wait );
     vlc_mutex_destroy( &host->lock );
     vlc_object_release( host );
-    if( host == httpd.http )
-        httpd.http = NULL;
-    else if( host == httpd.https )
-        httpd.https = NULL;
-    else if( host == httpd.rtsp )
-        httpd.rtsp = NULL;
-    else
-        assert(0);
     vlc_mutex_unlock( &httpd.mutex );
 }
 



More information about the vlc-commits mailing list