]> git.sesse.net Git - vlc/commitdiff
plugins/access/http.c: backported my last commit on request from sam
authorSigmund Augdal Helberg <sigmunau@videolan.org>
Thu, 25 Jul 2002 20:22:17 +0000 (20:22 +0000)
committerSigmund Augdal Helberg <sigmunau@videolan.org>
Thu, 25 Jul 2002 20:22:17 +0000 (20:22 +0000)
plugins/access/http.c

index befbc2c19c6e415970ae8da003db8bd9eec6ba9c..8408010a90c002b94887c8772fe849e33ee53153 100644 (file)
@@ -2,7 +2,7 @@
  * http.c: HTTP access plug-in
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: http.c,v 1.10.2.2 2002/07/23 20:32:21 massiot Exp $
+ * $Id: http.c,v 1.10.2.3 2002/07/25 20:22:17 sigmunau Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -125,6 +125,8 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
     struct module_s *   p_network;
     char                psz_buffer[256];
     byte_t *            psz_parser;
+    int                 i_returncode, i;
+    char *              psz_return_alpha;
 
     /* Find an appropriate network module */
     p_network = module_Need( MODULE_CAPABILITY_NETWORK,
@@ -184,6 +186,41 @@ static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
 
     /* Parse HTTP header. */
 #define MAX_LINE 1024
+    /* get the returncode */
+    if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 )
+    {
+        intf_ErrMsg( "not enough data" );
+        input_FDNetworkClose( p_input );
+        return( -1 );
+    }
+
+    if( !strncmp( psz_parser, "HTTP/1.",
+                  strlen("HTTP/1.") ) )
+    {
+        psz_parser += strlen("HTTP 1.") + 2;
+        i_returncode = atoi( psz_parser );
+        intf_WarnMsg( 3, "HTTP server replied: %i", i_returncode );
+        psz_parser += 4;
+        for ( i = 0; psz_parser[i] != '\r' || psz_parser[i+1] != '\n'; i++ )
+        {
+            ;
+        }
+        psz_return_alpha = malloc( i + 1 );
+        memcpy( psz_return_alpha, psz_parser, i );
+        psz_return_alpha[i] = '\0';
+    }
+    else
+    {
+        intf_ErrMsg( "http error: invalid http reply" );
+        return -1;
+    }
+    
+    if ( i_returncode >= 400 ) /* something is wrong */
+    {
+        intf_ErrMsg( "http error: %i %s", i_returncode, psz_return_alpha );
+        return -1;
+    }
+
     for( ; ; ) 
     {
         if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 )