]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
SAP can now listen for IPv6 announces
[vlc] / modules / access / http.c
index 9c83c6a4800391cd1c8d52fa6990280923541b01..5129660936851b9c8660936db48b839cd4881a5e 100644 (file)
@@ -2,7 +2,7 @@
  * http.c: HTTP access plug-in
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: http.c,v 1.27 2003/03/22 23:03:02 sigmunau Exp $
+ * $Id: http.c,v 1.36 2003/06/02 16:01:21 sigmunau Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 static int  Open       ( vlc_object_t * );
 static void Close      ( vlc_object_t * );
 
-static int  SetProgram ( input_thread_t *, pgrm_descriptor_t * );
 static void Seek       ( input_thread_t *, off_t );
 static ssize_t Read    ( input_thread_t *, byte_t *, size_t );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define PROXY_TEXT N_("specify an HTTP proxy")
+#define PROXY_TEXT N_("Specify an HTTP proxy")
 #define PROXY_LONGTEXT N_( \
     "Specify an HTTP proxy to use. It must be in the form " \
     "http://myproxy.mydomain:myport. If none is specified, the HTTP_PROXY " \
     "environment variable will be tried." )
 
-#define CACHING_TEXT N_("caching value in ms")
+#define CACHING_TEXT N_("Caching value in ms")
 #define CACHING_LONGTEXT N_( \
     "Allows you to modify the default caching value for http streams. This " \
     "value should be set in miliseconds units." )
@@ -87,7 +86,7 @@ vlc_module_begin();
     add_category_hint( N_("http"), NULL, VLC_FALSE );
     add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT, VLC_FALSE );
     add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
-    set_description( _("HTTP access module") );
+    set_description( _("HTTP input") );
     set_capability( "access", 0 );
     add_shortcut( "http" );
     add_shortcut( "http4" );
@@ -307,13 +306,14 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
 #ifdef HAVE_ATOLL
             i_size = i_tell + atoll( psz_value );
 #else
-            psz_parser = psz_value;
-            while( psz_parser[0] >= '0' && psz_parser[0] <= '9' )
+            int sign = 1;
+
+            if( *psz_value == '-' ) sign = -1;
+            while( *psz_value >= '0' && *psz_value <= '9' )
             {
-                i_size *= 10;
-                i_size += psz_parser[0] - '0';
+                i_size = i_size * 10 + *psz_value++ - '0';
             }
-            i_size += i_tell;
+            i_size = i_tell + ( i_size * sign );
 #endif
             msg_Dbg( p_input, "stream size is "I64Fd, i_size );
 
@@ -377,6 +377,10 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
     {
         p_input->stream.b_seekable = VLC_FALSE;
     }
+    if( i_code != 206 )
+    {
+        p_input->stream.b_seekable = VLC_FALSE;
+    }
     p_input->stream.b_changed = VLC_TRUE;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
@@ -604,14 +608,13 @@ static int Open( vlc_object_t *p_this )
                       psz_server_addr, i_server_port, psz_path );
 
     p_input->pf_read = Read;
-    p_input->pf_set_program = SetProgram;
+    p_input->pf_set_program = input_SetProgram;
     p_input->pf_set_area = NULL;
     p_input->pf_seek = Seek;
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
     p_input->stream.b_pace_control = VLC_TRUE;
     p_input->stream.b_seekable = VLC_TRUE;
-    p_input->stream.b_connected = VLC_TRUE;
     p_input->stream.p_selected_area->i_tell = 0;
     p_input->stream.p_selected_area->i_size = 0;
     p_input->stream.i_method = INPUT_METHOD_NETWORK;
@@ -667,15 +670,6 @@ static void Close( vlc_object_t *p_this )
     free( p_access_data );
 }
 
-/*****************************************************************************
- * SetProgram: do nothing
- *****************************************************************************/
-static int SetProgram( input_thread_t * p_input,
-                       pgrm_descriptor_t * p_program )
-{
-    return VLC_SUCCESS;
-}
-
 /*****************************************************************************
  * Seek: close and re-open a connection at the right place
  *****************************************************************************/
@@ -700,6 +694,7 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
     struct timeval  timeout;
     fd_set          fds;
+    ssize_t         i_recv;
     int             i_ret;
 
     /* Initialize file descriptor set */
@@ -711,35 +706,40 @@ static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
     timeout.tv_usec = 500000;
 
     /* Find if some data is available */
-    i_ret = select( p_access_data->i_handle + 1, &fds,
-                    NULL, NULL, &timeout );
-
+    while( (i_ret = select( p_access_data->i_handle + 1, &fds,
+                            NULL, NULL, &timeout )) == 0
 #ifdef HAVE_ERRNO_H
-    if( i_ret == -1 && errno != EINTR )
+           || (i_ret < 0 && errno == EINTR)
+#endif
+           )
     {
-        msg_Err( p_input, "network select error (%s)", strerror(errno) );
+        FD_ZERO( &fds );
+        FD_SET( p_access_data->i_handle, &fds );
+        timeout.tv_sec = 0;
+        timeout.tv_usec = 500000;
+
+        if( p_input->b_die || p_input->b_error )
+        {
+            return 0;
+        }
     }
-#else
-    if( i_ret == -1 )
+
+    if( i_ret < 0 )
     {
         msg_Err( p_input, "network select error" );
+        return -1;
     }
-#endif
-    else if( i_ret > 0 )
-    {
-        ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
 
-        if( i_recv < 0 )
-        {
+    i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
+
+    if( i_recv < 0 )
+    {
 #ifdef HAVE_ERRNO_H
-            msg_Err( p_input, "recv failed (%s)", strerror(errno) );
+        msg_Err( p_input, "recv failed (%s)", strerror(errno) );
 #else
-            msg_Err( p_input, "recv failed" );
+        msg_Err( p_input, "recv failed" );
 #endif
-        }
-
-        return i_recv;
     }
 
-    return 0;
+    return i_recv;
 }