]> git.sesse.net Git - vlc/blobdiff - src/misc/httpd.c
- Simplify check for getnameinfo
[vlc] / src / misc / httpd.c
index 354631617657e40434ad72061544adf308ea91ba..fb15d64ad4bd0711159e0fd51cb94849e638dd81 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * httpd.c
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004-2005 VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
- *          Remi Denis-Courmont <courmisch@via.ecp.fr>
+ *          Remi Denis-Courmont <rem # videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #   endif
 #endif
 
-#if defined(WIN32)
+#if defined(WIN32) && !defined(UNDER_CE)
 static const struct in6_addr in6addr_any = {{IN6ADDR_ANY_INIT}};
+#elif defined(UNDER_CE) && defined(AF_INET6)
+#   undef AF_INET6
 #endif
 
 #ifndef PF_INET
@@ -877,15 +879,6 @@ void httpd_StreamDelete( httpd_stream_t *stream )
  *****************************************************************************/
 #define LISTEN_BACKLOG          100
 
-#if defined(HAVE_GETNAMEINFO) && !defined(HAVE_GETADDRINFO)
-/* 
- * For now, VLC's configure script does not check for getaddrinfo(),
- * but it should be present if getnameinfo() is (the opposite is untrue, with
- * Debian potato as an example)
- */
-# define HAVE_GETADDRINFO 1
-#endif
-
 static void httpd_HostThread( httpd_host_t * );
 static int GetAddrPort( const struct sockaddr_storage *p_ss );
 
@@ -929,25 +922,16 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, char *psz_host,
         vlc_value_t val;
         char psz_port[6];
         struct addrinfo hints;
+        int check;
 
         memset( &hints, 0, sizeof( hints ) );
 
-#if 0
-        /* 
-         * For now, keep IPv4 by default. That said, it should be safe to use
-         * IPv6 by default *on the server side*, as, apart from NetBSD, most
-         * systems accept IPv4 clients on IPv6 listening sockets.
-         */
-        hints.ai_family = PF_INET;
-#else
-        hints.ai_family = 0;
-
         /* Check if ipv4 or ipv6 were forced */
         var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
         var_Get( p_this, "ipv4", &val );
         if( val.b_bool )
             hints.ai_family = PF_INET;
-#endif
+
         var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
         var_Get( p_this, "ipv6", &val );
         if( val.b_bool )
@@ -962,9 +946,15 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, char *psz_host,
         snprintf( psz_port, sizeof( psz_port ), "%d", i_port );
         psz_port[sizeof( psz_port ) - 1] = '\0';
         
-        if( getaddrinfo( psz_host, psz_port, &hints, &res ) )
+        check = getaddrinfo( psz_host, psz_port, &hints, &res );
+        if( check != 0 )
         {
+#ifdef HAVE_GAI_STRERROR
+            msg_Err( p_this, "cannot resolve %s:%d : %s", psz_host, i_port,
+                     gai_strerror( check ) );
+#else
             msg_Err( p_this, "cannot resolve %s:%d", psz_host, i_port );
+#endif
             return NULL;
         }
     }
@@ -1537,7 +1527,7 @@ static void httpd_ClientClean( httpd_client_t *cl )
     if( cl->fd >= 0 )
     {
         if( cl->p_tls != NULL )
-            tls_SessionClose( cl->p_tls );
+            tls_ServerSessionClose( cl->p_tls );
         net_Close( cl->fd );
         cl->fd = -1;
     }
@@ -2476,15 +2466,15 @@ static void httpd_HostThread( httpd_host_t *host )
                 fcntl( fd, F_SETFL, O_NONBLOCK );
 #endif
 
-                /* FIXME: that MUST be non-blocking */
                 if( p_tls != NULL)
                 {
-                    switch ( tls_SessionHandshake( p_tls, fd ) )
+                    switch ( tls_ServerSessionHandshake( p_tls, fd ) )
                     {
                         case -1:
                             msg_Err( host, "Rejecting TLS connection" );
                             net_Close( fd );
                             fd = -1;
+                            p_tls = NULL;
                             break;
 
                         case 1: /* missing input - most likely */
@@ -2551,6 +2541,9 @@ static void httpd_HostThread( httpd_host_t *host )
         }
         vlc_mutex_unlock( &host->lock );
     }
+
+    if( p_tls != NULL )
+        tls_ServerSessionClose( p_tls );
 }
 
 #ifndef HAVE_GETADDRINFO