]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / network / httpd.c
index b2b9e7f3510bc82203ec11dd696b6919264072cb..2e95eedc38ffd0d352de06c6e87bc50101db38dc 100644 (file)
@@ -36,6 +36,7 @@
 #include <vlc_tls.h>
 #include <vlc_acl.h>
 #include <vlc_strings.h>
+#include <vlc_rand.h>
 #include "../libvlc.h"
 
 #include <string.h>
 #   include <unistd.h>
 #endif
 
-#ifdef HAVE_FCNTL_H
-#   include <fcntl.h>
-#endif
-
 #ifdef HAVE_POLL
 # include <poll.h>
 #endif
@@ -563,8 +560,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
         {
             p[4] = '\0';
             answer->i_body = strlen((char*)answer->p_body) + 1;
-            uint8_t *p_body = realloc( answer->p_body, answer->i_body );
-            if( p_body ) answer->p_body = p_body;
+            answer->p_body = xrealloc( answer->p_body, answer->i_body );
         }
     }
 
@@ -578,8 +574,8 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
         {
             /* Apache-style */
             i_status = strtol( (char *)&answer->p_body[8], &psz_headers, 0 );
-            if( *psz_headers ) psz_headers++;
-            if( *psz_headers ) psz_headers++;
+            if( *psz_headers == '\r' || *psz_headers == '\n' ) psz_headers++;
+            if( *psz_headers == '\n' ) psz_headers++;
             i_headers = answer->i_body - (psz_headers - (char *)answer->p_body);
         }
         else
@@ -830,7 +826,8 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
                           "application/octet-stream" );
             httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
             httpd_MsgAdd( answer, "Pragma", "no-cache" );
-            httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
+            httpd_MsgAdd( answer, "Pragma", "client-id=%lu",
+                          vlc_mrand48()&0x7fff );
             httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
 
             /* Check if there is a xPlayStrm=1 */
@@ -1084,6 +1081,8 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
     vlc_cond_init( &host->wait );
     host->i_ref = 1;
 
+    vlc_object_attach( host, p_this );
+
     host->fds = net_ListenTCP( p_this, psz_host, i_port );
     if( host->fds == NULL )
     {
@@ -1127,7 +1126,6 @@ error:
     if( httpd->i_host <= 0 )
     {
         libvlc_priv (httpd->p_libvlc)->p_httpd = NULL;
-        vlc_object_detach( httpd );
         vlc_object_release( httpd );
     }
     vlc_mutex_unlock( &httpd_mutex );
@@ -1207,7 +1205,6 @@ void httpd_HostDelete( httpd_host_t *host )
         msg_Dbg( httpd, "no hosts left, stopping httpd" );
 
         libvlc_priv (httpd->p_libvlc)->p_httpd = NULL;
-        vlc_object_detach( httpd );
         vlc_object_release( httpd );
     }
     vlc_mutex_unlock( &httpd_mutex );
@@ -2147,7 +2144,7 @@ static void* httpd_HostThread( void *data )
                     answer->i_body = 0;
                     answer->p_body = NULL;
 
-                    httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING );
+                    httpd_MsgAdd( answer, "Server", "VLC/%s", VERSION );
                     httpd_MsgAdd( answer, "Content-Length", "0" );
 
                     switch( query->i_proto )
@@ -2518,15 +2515,12 @@ static void* httpd_HostThread( void *data )
                 continue;
 
             /* */
-#ifdef HAVE_ACCEPT4
-            fd = accept4 (fd, NULL, NULL, SOCK_CLOEXEC);
-            if (fd == -1 && errno == ENOSYS)
-#endif
-            fd = accept (fd, NULL, NULL);
+            fd = vlc_accept (fd, NULL, NULL, true);
             if (fd == -1)
                 continue;
+            setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
+                        &(int){ 1 }, sizeof(int));
 
-            net_SetupSocket (fd);
             if( p_tls != NULL )
             {
                 switch( tls_ServerSessionHandshake( p_tls, fd ) )