]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / network / httpd.c
index 4b505683ce22ee33e6e31464ad566e323a8309e4..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
@@ -829,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 */
@@ -1083,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 )
     {
@@ -1126,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 );
@@ -1206,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 );
@@ -2146,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 )
@@ -2517,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 ) )