]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
Remove unused parameter
[vlc] / src / network / httpd.c
index 86c7745209ac3208eba141dc6028faa489597cae..c55077ffd64c651df72c54471a08d03423ec9fbc 100644 (file)
@@ -30,8 +30,6 @@
 #include <vlc_common.h>
 #include <vlc_httpd.h>
 
-#ifdef ENABLE_HTTPD
-
 #include <assert.h>
 
 #include <vlc_network.h>
@@ -89,7 +87,7 @@ struct httpd_host_t
     httpd_t     *httpd;
 
     /* ref count */
-    int         i_ref;
+    unsigned    i_ref;
 
     /* address/port and socket for listening at connections */
     char        *psz_hostname;
@@ -98,6 +96,7 @@ struct httpd_host_t
     unsigned     nfd;
 
     vlc_mutex_t lock;
+    vlc_cond_t  wait;
 
     /* all registered url (becarefull that 2 httpd_url_t could point at the same url)
      * This will slow down the url research but make my live easier
@@ -189,7 +188,7 @@ struct httpd_client_t
 /*****************************************************************************
  * Various functions
  *****************************************************************************/
-static struct
+static const struct
 {
     const char psz_ext[8];
     const char *psz_mime;
@@ -227,8 +226,12 @@ static struct
     { ".mpe",   "video/mpeg" },
     { ".mov",   "video/quicktime" },
     { ".moov",  "video/quicktime" },
+    { ".oga",   "audio/ogg" },
     { ".ogg",   "application/ogg" },
     { ".ogm",   "application/ogg" },
+    { ".ogv",   "video/ogg" },
+    { ".ogx",   "application/ogg" },
+    { ".spx",   "audio/ogg" },
     { ".wav",   "audio/wav" },
     { ".wma",   "audio/x-ms-wma" },
     { ".wmv",   "video/x-ms-wmv" },
@@ -960,7 +963,7 @@ void httpd_StreamDelete( httpd_stream_t *stream )
 /*****************************************************************************
  * Low level
  *****************************************************************************/
-static void httpd_HostThread( httpd_host_t * );
+static void* httpd_HostThread( vlc_object_t * );
 
 /* create a new host */
 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host,
@@ -1015,7 +1018,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
 
         ptrval.p_address = httpd;
         libvlc_priv (p_this->p_libvlc)->p_httpd = httpd;
-        vlc_object_yield( httpd );
+        vlc_object_hold( httpd );
         vlc_object_attach( httpd, p_this->p_libvlc );
     }
 
@@ -1030,8 +1033,13 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
          || strcmp( host->psz_hostname, psz_hostname ) )
             continue;
 
-        /* yep found */
+        /* 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
+         * lock is always acquired first. */
+        vlc_mutex_lock( &host->lock );
         host->i_ref++;
+        vlc_mutex_unlock( &host->lock );
 
         vlc_mutex_unlock( lockval.p_address );
         return host;
@@ -1071,17 +1079,9 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
     if (host == NULL)
         goto error;
 
-    vlc_object_lock( host );
-    if( vlc_object_waitpipe( VLC_OBJECT( host ) ) == -1 )
-    {
-        msg_Err( host, "signaling pipe error: %m" );
-        vlc_object_unlock( host );
-        goto error;
-    }
-    vlc_object_unlock( host );
-
     host->httpd = httpd;
     vlc_mutex_init( &host->lock );
+    vlc_cond_init( &host->wait );
     host->i_ref = 1;
 
     host->fds = net_ListenTCP( p_this, psz_host, i_port );
@@ -1092,6 +1092,12 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
     }
     for (host->nfd = 0; host->fds[host->nfd] != -1; host->nfd++);
 
+    if( vlc_object_waitpipe( VLC_OBJECT( host ) ) == -1 )
+    {
+        msg_Err( host, "signaling pipe error: %m" );
+        goto error;
+    }
+
     host->i_port = i_port;
     host->psz_hostname = psz_host;
 
@@ -1104,7 +1110,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
 
     /* create the thread */
     if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
-                           VLC_THREAD_PRIORITY_LOW, false ) )
+                           VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_this, "cannot spawn http host thread" );
         goto error;
@@ -1120,6 +1126,7 @@ error:
     free( psz_host );
     if( httpd->i_host <= 0 )
     {
+        libvlc_priv (httpd->p_libvlc)->p_httpd = NULL;
         vlc_object_release( httpd );
         vlc_object_detach( httpd );
         vlc_object_release( httpd );
@@ -1129,6 +1136,7 @@ error:
     if( host != NULL )
     {
         net_ListenClose( host->fds );
+        vlc_cond_destroy( &host->wait );
         vlc_mutex_destroy( &host->lock );
         vlc_object_release( host );
     }
@@ -1149,7 +1157,11 @@ void httpd_HostDelete( httpd_host_t *host )
     var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
     vlc_mutex_lock( lockval.p_address );
 
+    vlc_mutex_lock( &host->lock );
     host->i_ref--;
+    if( host->i_ref == 0 )
+        vlc_cond_signal( &host->wait );
+    vlc_mutex_unlock( &host->lock );
     if( host->i_ref > 0 )
     {
         /* still used */
@@ -1185,6 +1197,7 @@ void httpd_HostDelete( httpd_host_t *host )
     net_ListenClose( host->fds );
     free( host->psz_hostname );
 
+    vlc_cond_destroy( &host->wait );
     vlc_mutex_destroy( &host->lock );
     vlc_object_release( host );
 
@@ -1241,6 +1254,7 @@ static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url
     }
 
     TAB_APPEND( host->i_url, host->url, url );
+    vlc_cond_signal( &host->wait );
     vlc_mutex_unlock( &host->lock );
 
     return url;
@@ -1307,7 +1321,7 @@ void httpd_UrlDelete( httpd_url_t *url )
     vlc_mutex_unlock( &host->lock );
 }
 
-void httpd_MsgInit( httpd_message_t *msg )
+static void httpd_MsgInit( httpd_message_t *msg )
 {
     msg->cl         = NULL;
     msg->i_type     = HTTPD_MSG_NONE;
@@ -1331,7 +1345,7 @@ void httpd_MsgInit( httpd_message_t *msg )
     msg->p_body        = NULL;
 }
 
-void httpd_MsgClean( httpd_message_t *msg )
+static void httpd_MsgClean( httpd_message_t *msg )
 {
     int i;
 
@@ -1744,12 +1758,16 @@ static void httpd_ClientRecv( httpd_client_t *cl )
                         {
                             *p2++ = '\0';
                         }
-                        if( !strncasecmp( p, "rtsp:", 5 ) )
-                        {
-                            /* for rtsp url, you have rtsp://localhost:port/path */
-                            p += 5;
-                            while( *p == '/' ) p++;
-                            while( *p && *p != '/' ) p++;
+                        if( !strncasecmp( p, ( cl->query.i_proto
+                                   == HTTPD_PROTO_HTTP ) ? "http" : "rtsp", 4 )
+                         && p[4 + !!strchr( "sS", p[4] )] == ':' )
+                        {   /* Skip hier-part of URL (if present) */
+                            p = strchr( p, ':' ) + 1; /* skip URI scheme */
+                            if( !strncmp( p, "//", 2 ) ) /* skip authority */
+                            {   /* see RFC3986 ยง3.2 */
+                                p += 2;
+                                while( *p && !strchr( "/?#", *p ) ) p++;
+                            }
                         }
                         cl->query.psz_url = strdup( p );
                         if( ( p3 = strchr( cl->query.psz_url, '?' ) )  )
@@ -2019,29 +2037,17 @@ static void httpd_ClientTlsHsOut( httpd_client_t *cl )
     }
 }
 
-static void httpd_HostThread( httpd_host_t *host )
+static void* httpd_HostThread( vlc_object_t *p_this )
 {
+    httpd_host_t *host = (httpd_host_t *)p_this;
     tls_session_t *p_tls = NULL;
     counter_t *p_total_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER );
     counter_t *p_active_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER );
-    int evfd;
-    bool b_die;
-
-retry:
-    vlc_object_lock( host );
-    evfd = vlc_object_waitpipe( VLC_OBJECT( host ) );
-    b_die = !vlc_object_alive( host );
-    vlc_object_unlock( host );
+    int canc = vlc_savecancel ();
+    int evfd = vlc_object_waitpipe( VLC_OBJECT( host ) );
 
-    while( !b_die )
+    for( ;; )
     {
-        if( host->i_url <= 0 )
-        {
-            /* 0.2s (FIXME: use a condition variable) */
-            msleep( 200000 );
-            goto retry;
-        }
-
         /* prepare a new TLS session */
         if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
             p_tls = tls_ServerSessionPrepare( host->p_tls );
@@ -2057,6 +2063,9 @@ retry:
 
         /* add all socket that should be read/write and close dead connection */
         vlc_mutex_lock( &host->lock );
+        while( host->i_url <= 0 && host->i_ref > 0 )
+            vlc_cond_wait( &host->wait, &host->lock );
+
         mtime_t now = mdate();
         bool b_low_delay = false;
 
@@ -2349,8 +2358,8 @@ retry:
                     }
 
                     if( ( ( cl->query.i_proto == HTTPD_PROTO_HTTP ) &&
-                          ( ( cl->answer.i_version == 0 && b_keepalive ) ||
-                            ( cl->answer.i_version == 1 && !b_connection ) ) ) ||
+                          ( ( cl->query.i_version == 0 && b_keepalive ) ||
+                            ( cl->query.i_version == 1 && !b_connection ) ) ) ||
                         ( ( cl->query.i_proto == HTTPD_PROTO_RTSP ) &&
                           !b_query && !b_connection ) )
                     {
@@ -2451,27 +2460,23 @@ retry:
                 continue;
         }
 
-        vlc_object_lock( host );
         if( ufd[nfd - 1].revents )
-        {
-            b_die = !vlc_object_alive( host );
-            if( !b_die )
-                vlc_object_wait( host );
-        }
-        vlc_object_unlock( host );
+            break;
 
         /* Handle client sockets */
         vlc_mutex_lock( &host->lock );
         now = mdate();
+        nfd = host->nfd;
         for( int i_client = 0; i_client < host->i_client; i_client++ )
         {
             httpd_client_t *cl = host->client[i_client];
-            const struct pollfd *pufd = &ufd[host->nfd + i_client];
+            const struct pollfd *pufd = &ufd[nfd];
 
             assert( pufd < &ufd[sizeof(ufd) / sizeof(ufd[0])] );
 
             if( cl->fd != pufd->fd )
                 continue; // we were not waiting for this client
+            ++nfd;
             if( pufd->revents == 0 )
                 continue; // no event received
 
@@ -2567,149 +2572,6 @@ retry:
         stats_CounterClean( p_total_counter );
     if( p_active_counter )
         stats_CounterClean( p_active_counter );
-}
-
-#else /* ENABLE_HTTPD */
-
-/* We just define an empty wrapper */
-httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, const char *b, 
-                                int c,
-                                const char *e, const char *f,
-                                const char *g, const char* h)
-{
-    msg_Err( a, "HTTP daemon support is disabled" );
-    return NULL;
-}
-
-httpd_host_t *httpd_HostNew( vlc_object_t *a, const char *b,
-                             int c )
-{
-    msg_Err( a, "HTTP daemon support is disabled" );
+    vlc_restorecancel (canc);
     return NULL;
 }
-
-void httpd_HostDelete( httpd_host_t *a )
-{
-}
-
-httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url,
-                           const char *psz_user, const char *psz_password,
-                           const vlc_acl_t *p_acl )
-{
-    return NULL;
-}
-
-httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url,
-                                 const char *psz_user, const char *psz_password,
-                                 const vlc_acl_t *p_acl )
-{
-    return NULL;
-}
-
-int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
-                    httpd_callback_sys_t *d )
-{
-    return 0;
-}
-
-void httpd_UrlDelete( httpd_url_t *a )
-{
-}
-
-char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip )
-{
-    return NULL;
-}
-
-char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip )
-{
-    return NULL;
-}
-
-void httpd_ClientModeStream( httpd_client_t *a )
-{
-}
-
-void httpd_ClientModeBidir( httpd_client_t *a )
-{
-}
-
-httpd_file_sys_t *httpd_FileDelete( httpd_file_t *file )
-{
-        return NULL;
-}
-
-httpd_file_t *httpd_FileNew( httpd_host_t *host,
-                             const char *psz_url, const char *psz_mime,
-                             const char *psz_user, const char *psz_password,
-                             const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill,
-                             httpd_file_sys_t *p_sys )
-{
-    return NULL;
-}
-
-httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
-                                   const char *psz_user,
-                                   const char *psz_password,
-                                   const vlc_acl_t *p_acl,
-                                   httpd_handler_callback_t pf_fill,
-                                   httpd_handler_sys_t *p_sys )
-{
-    return NULL;
-}
-
-httpd_handler_sys_t *httpd_HandlerDelete( httpd_handler_t *handler )
-{
-        return NULL;
-}
-
-void httpd_RedirectDelete( httpd_redirect_t *a )
-{
-}
-
-httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst,
-                                     const char *psz_url_src )
-{
-    return NULL;
-}
-
-void httpd_StreamDelete( httpd_stream_t *a )
-{
-}
-
-int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c )
-{
-    return 0;
-}
-
-int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c )
-{
-    return 0;
-}
-
-httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
-                                 const char *psz_url, const char *psz_mime,
-                                 const char *psz_user, const char *psz_password,
-                                 const vlc_acl_t *p_acl )
-{
-    return NULL;
-}
-
-void httpd_MsgInit ( httpd_message_t *a )
-{
-}
-
-void httpd_MsgAdd  ( httpd_message_t *a, const char *b, const char *c, ... )
-{
-}
-
-const char *httpd_MsgGet( const httpd_message_t *msg, const char *name )
-{
-    return "";
-}
-
-void httpd_MsgClean( httpd_message_t *a )
-{
-}
-
-#endif /* ENABLE_HTTPD */