]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
Privatize httpd_MsgInit and httpd_MsgClean
[vlc] / src / network / httpd.c
index 544410cf467c27b09e162c50aaec2a4f56009c00..e95661faba643f44c7470c7b91e30b08b4b29aeb 100644 (file)
@@ -27,7 +27,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_httpd.h>
 
 #ifdef ENABLE_HTTPD
@@ -189,7 +189,7 @@ struct httpd_client_t
 /*****************************************************************************
  * Various functions
  *****************************************************************************/
-static struct
+static const struct
 {
     const char psz_ext[8];
     const char *psz_mime;
@@ -394,7 +394,6 @@ httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
                     httpd_message_t *answer, const httpd_message_t *query )
 {
     httpd_file_t *file = (httpd_file_t*)p_sys;
-    uint8_t *psz_args = query->psz_args;
     uint8_t **pp_body, *p_body;
     const char *psz_connection;
     int *pi_body, i_body;
@@ -431,6 +430,7 @@ httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
         /* msg_Warn not supported */
     }
 
+    uint8_t *psz_args = query->psz_args;
     file->pf_fill( file->p_sys, file, psz_args, pp_body, pi_body );
 
     if( query->i_type == HTTPD_MSG_HEAD && p_body != NULL )
@@ -520,7 +520,6 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
                        httpd_message_t *answer, const httpd_message_t *query )
 {
     httpd_handler_t *handler = (httpd_handler_t*)p_sys;
-    uint8_t *psz_args = query->psz_args;
     char psz_remote_addr[NI_MAXNUMERICHOST];
 
     if( answer == NULL || query == NULL )
@@ -536,6 +535,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
     if( httpd_ClientIP( cl, psz_remote_addr ) == NULL )
         *psz_remote_addr = '\0';
 
+    uint8_t *psz_args = query->psz_args;
     handler->pf_fill( handler->p_sys, handler, query->psz_url, psz_args,
                       query->i_type, query->p_body, query->i_body,
                       psz_remote_addr, NULL,
@@ -960,7 +960,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,
@@ -989,10 +989,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
 
     psz_host = strdup( psz_hostname );
     if( psz_host == NULL )
-    {
-        msg_Err( p_this, "memory error" );
         return NULL;
-    }
 
     /* to be sure to avoid multiple creation */
     var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
@@ -1018,7 +1015,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 );
     }
 
@@ -1069,7 +1066,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
 
     /* create the new host */
     host = (httpd_host_t *)vlc_custom_create( p_this, sizeof (*host),
-                                              VLC_OBJECT_HTTPD_HOST,
+                                              VLC_OBJECT_GENERIC,
                                               psz_object_type );
     if (host == NULL)
         goto error;
@@ -1123,6 +1120,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 );
@@ -1310,7 +1308,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;
@@ -1334,7 +1332,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;
 
@@ -1457,26 +1455,32 @@ static httpd_client_t *httpd_ClientNew( int fd, tls_session_t *p_tls, mtime_t no
     return cl;
 }
 
-static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len )
+static
+ssize_t httpd_NetRecv (httpd_client_t *cl, uint8_t *p, size_t i_len)
 {
     tls_session_t *p_tls;
+    ssize_t val;
 
     p_tls = cl->p_tls;
-    if( p_tls != NULL)
-        return tls_Recv( p_tls, p, i_len );
-
-    return recv( cl->fd, p, i_len, 0 );
+    do
+        val = p_tls ? tls_Recv (p_tls, p, i_len)
+                    : recv (cl->fd, p, i_len, 0);
+    while (val == -1 && errno == EINTR);
+    return val;
 }
 
-static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len )
+static
+ssize_t httpd_NetSend (httpd_client_t *cl, const uint8_t *p, size_t i_len)
 {
     tls_session_t *p_tls;
+    ssize_t val;
 
     p_tls = cl->p_tls;
-    if( p_tls != NULL)
-        return tls_Send( p_tls, p, i_len );
-
-    return send( cl->fd, p, i_len, 0 );
+    do
+        val = p_tls ? tls_Send( p_tls, p, i_len )
+                    : send (cl->fd, p, i_len, 0);
+    while (val == -1 && errno == EINTR);
+    return val;
 }
 
 
@@ -1830,7 +1834,7 @@ static void httpd_ClientRecv( httpd_client_t *cl )
 #if defined( WIN32 ) || defined( UNDER_CE )
     if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
 #else
-    if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
+    if( ( i_len < 0 && errno != EAGAIN ) || ( i_len == 0 ) )
 #endif
     {
         if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
@@ -1970,7 +1974,7 @@ static void httpd_ClientSend( httpd_client_t *cl )
 #if defined( WIN32 ) || defined( UNDER_CE )
         if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
 #else
-        if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
+        if( ( i_len < 0 && errno != EAGAIN ) || ( i_len == 0 ) )
 #endif
         {
             /* error */
@@ -2016,14 +2020,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;
+    int canc = vlc_savecancel ();
 
+retry:
     vlc_object_lock( host );
     evfd = vlc_object_waitpipe( VLC_OBJECT( host ) );
     b_die = !vlc_object_alive( host );
@@ -2035,7 +2042,7 @@ static void httpd_HostThread( httpd_host_t *host )
         {
             /* 0.2s (FIXME: use a condition variable) */
             msleep( 200000 );
-            continue;
+            goto retry;
         }
 
         /* prepare a new TLS session */
@@ -2345,8 +2352,8 @@ static void httpd_HostThread( httpd_host_t *host )
                     }
 
                     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 ) )
                     {
@@ -2452,7 +2459,7 @@ static void httpd_HostThread( httpd_host_t *host )
         {
             b_die = !vlc_object_alive( host );
             if( !b_die )
-                b_die = vlc_object_wait( host );
+                vlc_object_wait( host );
         }
         vlc_object_unlock( host );
 
@@ -2563,6 +2570,8 @@ static void httpd_HostThread( httpd_host_t *host )
         stats_CounterClean( p_total_counter );
     if( p_active_counter )
         stats_CounterClean( p_active_counter );
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 #else /* ENABLE_HTTPD */
@@ -2691,10 +2700,6 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
     return NULL;
 }
 
-void httpd_MsgInit ( httpd_message_t *a )
-{
-}
-
 void httpd_MsgAdd  ( httpd_message_t *a, const char *b, const char *c, ... )
 {
 }
@@ -2704,8 +2709,4 @@ const char *httpd_MsgGet( const httpd_message_t *msg, const char *name )
     return "";
 }
 
-void httpd_MsgClean( httpd_message_t *a )
-{
-}
-
 #endif /* ENABLE_HTTPD */