]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
* ALL: using "%ll" in printf format strings is not portable (notably on win32) so
[vlc] / modules / access / http.c
index 3d87884df1e9490aa6dccf840ad6566cd86a6238..a7d2c102a7a0c669f8779fa61ac9701c9c30d77a 100644 (file)
@@ -2,7 +2,7 @@
  * http.c: HTTP access plug-in
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: http.c,v 1.3 2002/08/08 00:35:10 sam Exp $
+ * $Id: http.c,v 1.7 2002/11/08 10:26:52 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -67,6 +67,7 @@ static void Seek       ( input_thread_t *, off_t );
 vlc_module_begin();
     set_description( _("HTTP access module") );
     set_capability( "access", 0 );
+    add_shortcut( "http" );
     add_shortcut( "http4" );
     add_shortcut( "http6" );
     set_callbacks( Open, Close );
@@ -95,7 +96,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
     module_t *          p_network;
     char                psz_buffer[256];
     byte_t *            psz_parser;
-    int                 i_returncode, i;
+    int                 i_returncode, i, i_size;
     char *              psz_return_alpha;
 
     /* Find an appropriate network module */
@@ -117,10 +118,9 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
     {
          snprintf( psz_buffer, sizeof(psz_buffer),
                    "%s"
-                   "Range: bytes=%d%d-\r\n"
+                   "Range: bytes="I64Fd"-\r\n"
                    HTTP_USERAGENT HTTP_END,
-                   p_access_data->psz_buffer,
-                   (u32)(i_tell>>32), (u32)i_tell );
+                   p_access_data->psz_buffer, i_tell );
     }
     else
     {
@@ -160,24 +160,33 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
 #define MAX_LINE 1024
 
     /* get the returncode */
-    if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 )
+    if( (i_size = input_Peek( p_input, &psz_parser, MAX_LINE )) <= 0 )
     {
         msg_Err( p_input, "not enough data" );
         input_FDNetworkClose( p_input );
         return( -1 );
     }
 
-    if( !strncmp( psz_parser, "HTTP/1.",
-                  strlen("HTTP/1.") ) )
+    if( (i_size >= sizeof("HTTP/1.") + 1 ) &&
+       !strncmp( psz_parser, "HTTP/1.", sizeof("HTTP/1.") - 1 ) )
     {
-        psz_parser += strlen("HTTP 1.") + 2;
+        psz_parser += sizeof("HTTP/1.") + 1;
         i_returncode = atoi( (char*)psz_parser );
         msg_Dbg( p_input, "HTTP server replied: %i", i_returncode );
         psz_parser += 4;
-        for ( i = 0; psz_parser[i] != '\r' || psz_parser[i+1] != '\n'; i++ )
+       i_size -= (sizeof("HTTP/1.") + 5);
+        for ( i = 0; (i < i_size -1) && ((psz_parser[i] != '\r') ||
+             (psz_parser[i+1] != '\n')); i++ )
         {
             ;
         }
+        /* check we actually parsed something */
+        if ( (i == i_size - 1) && (psz_parser[i+1] != '\n') )
+        {
+            msg_Err( p_input, "stream not compliant with HTTP/1.x" );
+            return -1;
+        }
+
         psz_return_alpha = malloc( i + 1 );
         memcpy( psz_return_alpha, psz_parser, i );
         psz_return_alpha[i] = '\0';
@@ -187,7 +196,7 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
         msg_Err( p_input, "invalid http reply" );
         return -1;
     }
-    
+
     if ( i_returncode >= 400 ) /* something is wrong */
     {
         msg_Err( p_input, "%i %s", i_returncode,
@@ -497,7 +506,7 @@ static void Seek( input_thread_t * p_input, off_t i_pos )
 {
     _input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data;
     close( p_access_data->_socket.i_handle );
-    msg_Dbg( p_input, "seeking to position %lld", i_pos );
+    msg_Dbg( p_input, "seeking to position "I64Fd, i_pos );
     HTTPConnect( p_input, i_pos );
 }