]> git.sesse.net Git - vlc/commitdiff
* Cleaned up sam's mess with input's pf_open and pf_close (not completely) ;
authorChristophe Massiot <massiot@videolan.org>
Tue, 2 Oct 2001 16:46:59 +0000 (16:46 +0000)
committerChristophe Massiot <massiot@videolan.org>
Tue, 2 Oct 2001 16:46:59 +0000 (16:46 +0000)
* With -vvv modules now show up their scores ;

This afternoon I have been a little bored, so the feature of the day is :
* HTTP input support.

You can test it with :
./vlc http://mysite.com:80/mystream.mpg
It doesn't implement any kind of buffering, so make sure you have enough
bandwidth, otherwise you'll just get nothing.

It is compatible with HTTP proxy, just set http_proxy :
export http_proxy="http://proxy.mycompany.com:3128/"

Enjoy !

include/input_ext-intf.h
plugins/dvd/input_dvd.c
plugins/mpeg/input_es.c
plugins/mpeg/input_ps.c
plugins/mpeg/input_ps.h
plugins/mpeg/input_ts.c
src/input/input.c
src/input/input_programs.c
src/misc/modules.c

index a6fd501c2a68cf31f4eef2e98ac7e00edca8bdbe..11598e13de674e39a55d43a1f26547cc6fd6e242 100644 (file)
@@ -4,7 +4,7 @@
  * control the pace of reading. 
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-intf.h,v 1.43 2001/10/01 16:18:48 massiot Exp $
+ * $Id: input_ext-intf.h,v 1.44 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -284,17 +284,10 @@ typedef struct input_thread_s
                                             * backwards (it's gonna be fun)  */
     void                 (* pf_seek)( struct input_thread_s *, off_t );
 
-    /* Special callback functions */
-    void                 (* pf_file_open )     ( struct input_thread_s * );
-    void                 (* pf_file_close )    ( struct input_thread_s * );
-#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
-    void                 (* pf_network_open )  ( struct input_thread_s * );
-    void                 (* pf_network_close ) ( struct input_thread_s * );
-#endif
-
     char *                  p_source;
 
     int                     i_handle;           /* socket or file descriptor */
+    FILE *                  p_stream;                       /* if applicable */
     int                     i_read_once;        /* number of packet read by
                                                  * pf_read once */
     void *                  p_method_data;     /* data of the packet manager */
index 906eff4656235f93c9fea548ae182cb5ebf0069c..c1b85c834001436c2970e552c231f030174e54e3 100644 (file)
@@ -10,7 +10,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.86 2001/09/30 01:26:44 stef Exp $
+ * $Id: input_dvd.c,v 1.87 2001/10/02 16:46:59 massiot Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -239,9 +239,6 @@ static void DVDInit( input_thread_t * p_input )
     /* Initialize ES structures */
     input_InitStream( p_input, sizeof( stream_ps_data_t ) );
 
-    /* disc input method */
-    p_input->stream.i_method = INPUT_METHOD_DVD;
-
 #define title_inf p_dvd->p_ifo->vmg.title_inf
     intf_WarnMsg( 2, "dvd info: number of titles: %d", title_inf.i_title_nb );
 
index 93d34f43777554bb9feeee9665b18f9a0ef30973..483df70b95d20d51ddbe67e3755df9f742134958 100644 (file)
@@ -2,7 +2,7 @@
  * input_es.c: Elementary Stream demux and packet management
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_es.c,v 1.9 2001/07/30 00:53:05 sam Exp $
+ * $Id: input_es.c,v 1.10 2001/10/02 16:46:59 massiot Exp $
  *
  * Author: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -100,7 +100,7 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #define input p_function_list->functions.input
     p_function_list->pf_probe = ESProbe;
     input.pf_init             = ESInit;
-    input.pf_open             = NULL; /* Set in ESInit */
+    input.pf_open             = NULL;
     input.pf_close            = NULL;
     input.pf_end              = ESEnd;
     input.pf_init_bit_stream  = ESInitBitstream;
@@ -127,8 +127,6 @@ static int ESProbe( probedata_t *p_data )
 {
     input_thread_t * p_input = (input_thread_t *)p_data;
 
-    char * psz_name = p_input->p_source;
-    int i_handle;
     int i_score = 5;
 
     if( TestMethod( INPUT_METHOD_VAR, "es" ) )
@@ -136,13 +134,6 @@ static int ESProbe( probedata_t *p_data )
         return( 999 );
     }
 
-    i_handle = open( psz_name, 0 );
-    if( i_handle == -1 )
-    {
-        return( 0 );
-    }
-    close( i_handle );
-
     return( i_score );
 }
 
@@ -163,9 +154,6 @@ static void ESInit( input_thread_t * p_input )
         return;
     }
 
-    p_input->pf_open  = p_input->pf_file_open;
-    p_input->pf_close = p_input->pf_file_close;
-
     /* FIXME : detect if InitStream failed */
     input_InitStream( p_input, 0 );
     input_AddProgram( p_input, 0, 0 );
@@ -175,7 +163,6 @@ static void ESInit( input_thread_t * p_input )
     p_es->i_type = MPEG1_VIDEO_ES;
     p_es->i_cat = VIDEO_ES;
     input_SelectES( p_input, p_es );
-    p_input->stream.i_method = INPUT_METHOD_FILE;
     p_input->stream.p_selected_area->i_tell = 0;
     p_input->stream.pp_programs[0]->b_is_ok = 1;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
index f7e7bb90534b221245e80f710916fe6d3fb60c94..8b5db02e73f6d2bdbc3e57e75ee4dcef1119e355 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ps.c,v 1.35 2001/10/01 16:18:48 massiot Exp $
+ * $Id: input_ps.c,v 1.36 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
@@ -108,7 +108,7 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #define input p_function_list->functions.input
     p_function_list->pf_probe = PSProbe;
     input.pf_init             = PSInit;
-    input.pf_open             = NULL; /* Set in PSInit */
+    input.pf_open             = NULL;
     input.pf_close            = NULL;
     input.pf_end              = PSEnd;
     input.pf_init_bit_stream  = InitBitstream;
@@ -136,7 +136,6 @@ static int PSProbe( probedata_t *p_data )
     input_thread_t * p_input = (input_thread_t *)p_data;
 
     char * psz_name = p_input->p_source;
-    int i_handle;
     int i_score = 10;
 
     if( TestMethod( INPUT_METHOD_VAR, "ps" ) )
@@ -144,20 +143,15 @@ static int PSProbe( probedata_t *p_data )
         return( 999 );
     }
 
-    if( ( strlen(psz_name) > 5 ) && !strncasecmp( psz_name, "file:", 5 ) )
+    if( ( strlen(psz_name) > 5 ) && (!strncasecmp( psz_name, "file:", 5 )
+                                      || !strncasecmp( psz_name, "http:", 5 )) )
     {
-        /* If the user specified "file:" then it's probably a file */
+        /* If the user specified "file:" or "http:" then it's probably a
+         * PS file */
         i_score = 100;
         psz_name += 5;
     }
 
-    i_handle = open( psz_name, 0 );
-    if( i_handle == -1 )
-    {
-        return( 0 );
-    }
-    close( i_handle );
-
     return( i_score );
 }
 
@@ -166,18 +160,8 @@ static int PSProbe( probedata_t *p_data )
  *****************************************************************************/
 static void PSInit( input_thread_t * p_input )
 {
-    thread_ps_data_t *  p_method;
     packet_cache_t *    p_packet_cache;
 
-    p_method = (thread_ps_data_t *)malloc( sizeof(thread_ps_data_t) );
-    if( p_method == NULL )
-    {
-        intf_ErrMsg( "Out of memory" );
-        p_input->b_error = 1;
-        return;
-    }
-    p_input->p_plugin_data = (void *)p_method;
-    
     /* creates the packet cache structure */
     p_packet_cache = malloc( sizeof(packet_cache_t) );
     if ( p_packet_cache == NULL )
@@ -188,10 +172,6 @@ static void PSInit( input_thread_t * p_input )
     }
     p_input->p_method_data = (void *)p_packet_cache;
 
-    /* Set callback */
-    p_input->pf_open  = p_input->pf_file_open;
-    p_input->pf_close = p_input->pf_file_close;
-
     /* Initialize packet cache mutex */
     vlc_mutex_init( &p_packet_cache->lock );
     
@@ -239,16 +219,18 @@ static void PSInit( input_thread_t * p_input )
     }
     p_packet_cache->largebuffer.l_index = 0;
     
-    /* Re-open the socket as a buffered FILE stream */
-    p_method->stream = fdopen( p_input->i_handle, "r" );
-
-    if( p_method->stream == NULL )
+    if( p_input->p_stream == NULL )
     {
-        intf_ErrMsg( "Cannot open file (%s)", strerror(errno) );
-        p_input->b_error = 1;
-        return;
+        /* Re-open the socket as a buffered FILE stream */
+        p_input->p_stream = fdopen( p_input->i_handle, "r" );
+
+        if( p_input->p_stream == NULL )
+        {
+            intf_ErrMsg( "Cannot open file (%s)", strerror(errno) );
+            p_input->b_error = 1;
+            return;
+        }
     }
-    rewind( p_method->stream );
 
     /* FIXME : detect if InitStream failed */
     input_InitStream( p_input, sizeof( stream_ps_data_t ) );
@@ -259,6 +241,8 @@ static void PSInit( input_thread_t * p_input )
         stream_ps_data_t * p_demux_data =
              (stream_ps_data_t *)p_input->stream.pp_programs[0]->p_demux_data;
 
+        rewind( p_input->p_stream );
+
         /* Pre-parse the stream to gather stream_descriptor_t. */
         p_input->stream.pp_programs[0]->b_is_ok = 0;
         p_demux_data->i_PSM_version = EMPTY_PSM_VERSION;
@@ -298,10 +282,9 @@ static void PSInit( input_thread_t * p_input )
                 break;
             }
         }
-        rewind( p_method->stream );
+        rewind( p_input->p_stream );
         vlc_mutex_lock( &p_input->stream.stream_lock );
 
-        p_input->stream.i_method = INPUT_METHOD_FILE;
         p_input->stream.p_selected_area->i_tell = 0;
 
         if( p_demux_data->b_has_PSM )
@@ -427,18 +410,16 @@ static void PSEnd( input_thread_t * p_input )
 static __inline__ int SafeRead( input_thread_t * p_input, byte_t * p_buffer,
                                 size_t i_len )
 {
-    thread_ps_data_t *  p_method;
     int                 i_error;
 
-    p_method = (thread_ps_data_t *)p_input->p_plugin_data;
-    while( fread( p_buffer, i_len, 1, p_method->stream ) != 1 )
+    while( fread( p_buffer, i_len, 1, p_input->p_stream ) != 1 )
     {
-        if( feof( p_method->stream ) )
+        if( feof( p_input->p_stream ) )
         {
             return( 1 );
         }
 
-        if( (i_error = ferror( p_method->stream )) )
+        if( (i_error = ferror( p_input->p_stream )) )
         {
             intf_ErrMsg( "Read failed (%s)", strerror(i_error) );
             return( -1 );
@@ -463,9 +444,6 @@ static int PSRead( input_thread_t * p_input,
     data_packet_t *     p_data;
     size_t              i_packet_size;
     int                 i_packet, i_error;
-    thread_ps_data_t *  p_method;
-
-    p_method = (thread_ps_data_t *)p_input->p_plugin_data;
 
     memset( pp_packets, 0, INPUT_READ_ONCE * sizeof(data_packet_t *) );
     for( i_packet = 0; i_packet < INPUT_READ_ONCE; i_packet++ )
@@ -494,7 +472,7 @@ static int PSRead( input_thread_t * p_input,
             while( (i_startcode & 0xFFFFFF00) != 0x100L )
             {
                 i_startcode <<= 8;
-                if( (i_dummy = getc( p_method->stream )) != EOF )
+                if( (i_dummy = getc( p_input->p_stream )) != EOF )
                 {
                     i_startcode |= i_dummy;
                 }
@@ -600,15 +578,11 @@ static int PSRead( input_thread_t * p_input,
  *****************************************************************************/
 static void PSSeek( input_thread_t * p_input, off_t i_position )
 {
-    thread_ps_data_t *  p_method;
-
-    p_method = (thread_ps_data_t *)p_input->p_plugin_data;
-
     /* A little bourrin but should work for a while --Meuuh */
 #if defined( WIN32 ) || defined( SYS_GNU0_2 )
-    fseek( p_method->stream, (long)i_position, SEEK_SET );
+    fseek( p_input->p_stream, (long)i_position, SEEK_SET );
 #else
-    fseeko( p_method->stream, i_position, SEEK_SET );
+    fseeko( p_input->p_stream, i_position, SEEK_SET );
 #endif
 
     p_input->stream.p_selected_area->i_tell = i_position;
index 0656472922fdb078cb9017bae7cc681e98eaa73b..4d72ade2a88843fe12bd4e2d0e3f1e4dae4f4190 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.h: thread structure of the PS plugin
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ps.h,v 1.8 2001/05/31 03:12:49 sam Exp $
+ * $Id: input_ps.h,v 1.9 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-/*****************************************************************************
- * thread_ps_data_t: extension of input_thread_t
- *****************************************************************************/
-typedef struct thread_ps_data_s
-{
-    /* We're necessarily reading a file. */
-    FILE *                  stream;
-} thread_ps_data_t;
-
-
 #define DATA_CACHE_SIZE 150
 #define PES_CACHE_SIZE 150
 #define SMALL_CACHE_SIZE 150
index 403cd4de6736b8c4c8c521f496d5a4a1706cda01..1bb1a8c73bfba68594a12baa58810a197c55e34e 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ts.c,v 1.33 2001/09/06 18:21:02 henri Exp $
+ * $Id: input_ts.c,v 1.34 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -89,7 +89,6 @@
  *****************************************************************************/
 static int  TSProbe     ( probedata_t * );
 static void TSInit      ( struct input_thread_s * );
-static void TSFakeOpen  ( struct input_thread_s * );
 static void TSEnd       ( struct input_thread_s * );
 static int  TSRead      ( struct input_thread_s *,
                           data_packet_t * p_packets[INPUT_READ_ONCE] );
@@ -103,8 +102,8 @@ void _M( input_getfunctions )( function_list_t * p_function_list )
 #define input p_function_list->functions.input
     p_function_list->pf_probe = TSProbe;
     input.pf_init             = TSInit;
-    input.pf_open             = TSFakeOpen;
-    input.pf_close            = NULL;              /* Will be set by pf_open */
+    input.pf_open             = NULL;
+    input.pf_close            = NULL;
     input.pf_end              = TSEnd;
     input.pf_init_bit_stream  = InitBitstream;
     input.pf_set_area         = NULL;
@@ -127,8 +126,7 @@ static int TSProbe( probedata_t * p_data )
     input_thread_t * p_input = (input_thread_t *)p_data;
 
     char * psz_name = p_input->p_source;
-    int i_handle;
-    int i_score = 1;
+    int i_score = 2;
 
     if( TestMethod( INPUT_METHOD_VAR, "ts" ) )
     {
@@ -154,13 +152,6 @@ static int TSProbe( probedata_t * p_data )
         return( 900 );
     }
 
-    i_handle = open( psz_name, 0 );
-    if( i_handle == -1 )
-    {
-        return( 0 );
-    }
-    close( i_handle );
-
     return( i_score );
 }
 
@@ -204,9 +195,6 @@ static void TSInit( input_thread_t * p_input )
     /* Initialize the stream */
     input_InitStream( p_input, sizeof( stream_ts_data_t ) );
 
-    /* input method type */
-    /* FIXME: should test if you have network or file here */
-    p_input->stream.i_method = INPUT_METHOD_NETWORK;
     p_input->stream.p_selected_area->i_tell = 0;
 
     /* Init */
@@ -226,30 +214,6 @@ static void TSInit( input_thread_t * p_input )
 
 }
 
-/*****************************************************************************
- * TSFakeOpen: open the stream and set pf_close
- *****************************************************************************/
-void TSFakeOpen( input_thread_t * p_input )
-{
-#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
-    char *psz_name = p_input->p_source;
-
-    if( ( strlen(psz_name) > 3 ) && !strncasecmp( psz_name, "ts:", 3 ) )
-    {
-        /* If the user specified "ts:" he wants a network stream */
-        p_input->pf_open  = p_input->pf_network_open;
-        p_input->pf_close = p_input->pf_network_close;
-    }
-    else
-#endif
-    {
-        p_input->pf_open  = p_input->pf_file_open;
-        p_input->pf_close = p_input->pf_file_close;
-    }
-
-    p_input->pf_open( p_input );
-}
-
 /*****************************************************************************
  * TSEnd: frees unused data
  *****************************************************************************/
index c30edb5eda0097f7e6b56851d31d8d04bad2d698..d8ba850b4fc978d917ca03cab2d7b6de6301c8a3 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.132 2001/10/01 16:18:48 massiot Exp $
+ * $Id: input.c,v 1.133 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -91,6 +91,7 @@ static void FileOpen        ( input_thread_t *p_input );
 static void FileClose       ( input_thread_t *p_input );
 #if !defined( SYS_BEOS ) && !defined( SYS_NTO )
 static void NetworkOpen     ( input_thread_t *p_input );
+static void HTTPOpen        ( input_thread_t *p_input );
 static void NetworkClose    ( input_thread_t *p_input );
 #endif
 
@@ -158,14 +159,6 @@ input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
     p_input->stream.control.i_smp = main_GetIntVariable(
                             VDEC_SMP_VAR, VDEC_SMP_DEFAULT );
 
-    /* Setup callbacks */
-    p_input->pf_file_open     = FileOpen;
-    p_input->pf_file_close    = FileClose;
-#if !defined( SYS_BEOS ) && !defined( SYS_NTO )
-    p_input->pf_network_open  = NetworkOpen;
-    p_input->pf_network_close = NetworkClose;
-#endif
-
     intf_WarnMsg( 1, "input: playlist item `%s'", p_input->p_source );
 
     /* Create thread. */
@@ -387,16 +380,14 @@ static int InitThread( input_thread_t * p_input )
     p_input->c_loops                    = 0;
     p_input->stream.c_packets_read      = 0;
     p_input->stream.c_packets_trashed   = 0;
+    p_input->p_stream                   = NULL;
 
     /* Set locks. */
     vlc_mutex_init( &p_input->stream.stream_lock );
     vlc_cond_init( &p_input->stream.stream_wait );
     vlc_mutex_init( &p_input->stream.control.control_lock );
 
-    /* Default, might get overwritten */
-    p_input->pf_open = p_input->pf_file_open;
-    p_input->pf_close = p_input->pf_file_close;
-
+    /* Find appropriate module. */
     p_input->p_input_module = module_Need( MODULE_CAPABILITY_INPUT,
                                            (probedata_t *)p_input );
 
@@ -409,14 +400,6 @@ static int InitThread( input_thread_t * p_input )
 
 #define f p_input->p_input_module->p_functions->input.functions.input
     p_input->pf_init          = f.pf_init;
-    if( f.pf_open != NULL )
-    {
-        p_input->pf_open      = f.pf_open;
-    }
-    if( f.pf_close != NULL )
-    {
-        p_input->pf_close     = f.pf_close;
-    }
     p_input->pf_end           = f.pf_end;
     p_input->pf_init_bit_stream= f.pf_init_bit_stream;
     p_input->pf_read          = f.pf_read;
@@ -430,8 +413,31 @@ static int InitThread( input_thread_t * p_input )
     p_input->pf_seek          = f.pf_seek;
 #undef f
 
-    /* We found the appropriate plugin, open the target */
-    p_input->pf_open( p_input );
+    /* FIXME : this is waaaay too kludgy */
+    if( (strlen( p_input->p_source ) > 3) && !strncasecmp( p_input->p_source, "ts:", 3 ) )
+    {
+        /* Network stream */
+        NetworkOpen( p_input );
+        p_input->stream.i_method = INPUT_METHOD_NETWORK;
+    }
+    else if( ( strlen( p_input->p_source ) > 5 ) && !strncasecmp( p_input->p_source, "http:", 5 ) )
+    {
+        /* HTTP stream */
+        HTTPOpen( p_input );
+        p_input->stream.i_method = INPUT_METHOD_NETWORK;
+    }
+    else if( ( strlen( p_input->p_source ) > 4 ) && !strncasecmp( p_input->p_source, "dvd:", 4 ) )
+    {
+        /* DVD - this is THE kludge */
+        p_input->p_input_module->p_functions->input.functions.input.pf_open( p_input );
+        p_input->stream.i_method = INPUT_METHOD_DVD;
+    }
+    else
+    {
+        /* File input */
+        FileOpen( p_input );
+        p_input->stream.i_method = INPUT_METHOD_FILE;
+    }
 
     if( p_input->b_error )
     {
@@ -500,7 +506,22 @@ static void EndThread( input_thread_t * p_input )
     p_input->pf_end( p_input );
 
     /* Close stream */
-    p_input->pf_close( p_input );
+    if( (strlen( p_input->p_source ) > 3) && !strncasecmp( p_input->p_source, "ts:", 3 ) )
+    {
+        NetworkClose( p_input );
+    }
+    else if( ( strlen( p_input->p_source ) > 5 ) && !strncasecmp( p_input->p_source, "http:", 5 ) )
+    {
+        NetworkClose( p_input );
+    }
+    else if( ( strlen( p_input->p_source ) > 4 ) && !strncasecmp( p_input->p_source, "dvd:", 4 ) )
+    {
+        p_input->p_input_module->p_functions->input.functions.input.pf_close( p_input );
+    }
+    else
+    {
+        FileClose( p_input );
+    }
 
     /* Release modules */
     module_Unneed( p_input->p_input_module );
@@ -538,8 +559,6 @@ static void FileOpen( input_thread_t * p_input )
 
     char *psz_name = p_input->p_source;
 
-    /* FIXME: this code ought to be in the plugin so that code can
-     * be shared with the *_Probe function */
     if( ( i_stat = stat( psz_name, &stat_info ) ) == (-1) )
     {
         int i_size = strlen( psz_name );
@@ -709,7 +728,7 @@ static void NetworkOpen( input_thread_t * p_input )
                 }
 
                 /* port before broadcast address */
-                if( *psz_port != ':' )
+                if( *psz_port != '\0' )
                 {
                     i_port = atoi( psz_port );
                 }
@@ -894,7 +913,286 @@ static void NetworkClose( input_thread_t * p_input )
 #ifdef WIN32 
     WSACleanup();
 #endif
-
 }
+
+/*****************************************************************************
+ * HTTPOpen : make an HTTP request
+ *****************************************************************************/
+static void HTTPOpen( input_thread_t * p_input )
+{
+    char                *psz_server = NULL;
+    char                *psz_path = NULL;
+    char                *psz_proxy;
+    int                 i_port = 0;
+    int                 i_opt;
+    struct sockaddr_in  sock;
+    char                psz_buffer[256];
+
+#ifdef WIN32
+    WSADATA Data;
+    int i_err;
+#endif
+    
+#ifdef WIN32
+    /* WinSock Library Init. */
+    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
+
+    if( i_err )
+    {
+        intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
+        return ;
+    }
 #endif
+    
+    /* Get the remote server */
+    if( p_input->p_source != NULL )
+    {
+        psz_server = p_input->p_source;
+
+        /* Skip the protocol name */
+        while( *psz_server && *psz_server != ':' )
+        {
+            psz_server++;
+        }
+
+        /* Skip the "://" part */
+        while( *psz_server && (*psz_server == ':' || *psz_server == '/') )
+        {
+            psz_server++;
+        }
+
+        /* Found a server name */
+        if( *psz_server )
+        {
+            char *psz_port = psz_server;
+
+            /* Skip the hostname part */
+            while( *psz_port && *psz_port != ':' && *psz_port != '/' )
+            {
+                psz_port++;
+            }
+
+            /* Found a port name */
+            if( *psz_port )
+            {
+                if( *psz_port == ':' )
+                {
+                    /* Replace ':' with '\0' */
+                    *psz_port = '\0';
+                    psz_port++;
+                }
+
+                psz_path = psz_port;
+                while( *psz_path && *psz_path != '/' )
+                {
+                    psz_path++;
+                }
+
+                if( *psz_path )
+                {
+                    *psz_path = '\0';
+                    psz_path++;
+                }
+                else
+                {
+                    psz_path = NULL;
+                }
+
+                if( *psz_port != '\0' )
+                {
+                    i_port = atoi( psz_port );
+                }
+            }
+        }
+        else
+        {
+            psz_server = NULL;
+        }
+    }
+
+    /* Check that we got a valid server */
+    if( psz_server == NULL )
+    {
+        intf_ErrMsg( "input error: No server given" );
+        p_input->b_error = 1;
+        return;
+    }
+
+    /* Check that we got a valid port */
+    if( i_port == 0 )
+    {
+        i_port = 80; /* FIXME */
+    }
+
+    intf_WarnMsg( 2, "input: server=%s port=%d path=%s", psz_server,
+                  i_port, psz_path );
+
+    /* Open a SOCK_STREAM (TCP) socket, in the AF_INET domain, automatic (0)
+     *      * protocol */
+    p_input->i_handle = socket( AF_INET, SOCK_STREAM, 0 );
+    if( p_input->i_handle == -1 )
+    {
+        intf_ErrMsg( "input error: can't create socket (%s)", strerror(errno) );        p_input->b_error = 1;
+        return;
+    }
+
+    /* We may want to reuse an already used socket */
+    i_opt = 1;
+    if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_REUSEADDR,
+                    (void *) &i_opt, sizeof( i_opt ) ) == -1 )
+    {
+        intf_ErrMsg( "input error: can't configure socket (SO_REUSEADDR: %s)",
+                     strerror(errno));
+        close( p_input->i_handle );
+        p_input->b_error = 1;
+        return;
+    }
+
+    /* Check proxy */
+    if( (psz_proxy = main_GetPszVariable( "http_proxy", NULL )) != NULL )
+    {
+        /* http://myproxy.mydomain:myport/ */
+        int                 i_proxy_port = 0;
+
+        /* Skip the protocol name */
+        while( *psz_proxy && *psz_proxy != ':' )
+        {
+            psz_proxy++;
+        }
+
+        /* Skip the "://" part */
+        while( *psz_proxy && (*psz_proxy == ':' || *psz_proxy == '/') )
+        {
+            psz_proxy++;
+        }
+
+        /* Found a proxy name */
+        if( *psz_proxy )
+        {
+            char *psz_port = psz_proxy;
+
+            /* Skip the hostname part */
+            while( *psz_port && *psz_port != ':' && *psz_port != '/' )
+            {
+                psz_port++;
+            }
+
+            /* Found a port name */
+            if( *psz_port )
+            {
+                char * psz_junk;
+
+                /* Replace ':' with '\0' */
+                *psz_port = '\0';
+                psz_port++;
+
+                psz_junk = psz_port;
+                while( *psz_junk && *psz_junk != '/' )
+                {
+                    psz_junk++;
+                }
+
+                if( *psz_junk )
+                {
+                    *psz_junk = '\0';
+                }
+
+                if( *psz_port != '\0' )
+                {
+                    i_proxy_port = atoi( psz_port );
+                }
+            }
+        }
+        else
+        {
+            intf_ErrMsg( "input error: http_proxy environment variable is invalid !" );
+            close( p_input->i_handle );
+            p_input->b_error = 1;
+            return;
+        }
+
+        /* Build socket for proxy connection */
+        if ( network_BuildRemoteAddr( &sock, psz_proxy ) == -1 )
+        {
+            intf_ErrMsg( "input error: can't build remote address" );
+            close( p_input->i_handle );
+            p_input->b_error = 1;
+            return;
+        }
+        sock.sin_port = htons( i_proxy_port );
+    }
+    else
+    {
+        /* No proxy, direct connection */
+        if ( network_BuildRemoteAddr( &sock, psz_server ) == -1 )
+        {
+            intf_ErrMsg( "input error: can't build remote address" );
+            close( p_input->i_handle );
+            p_input->b_error = 1;
+            return;
+        }
+        sock.sin_port = htons( i_port );
+    }
+
+    /* Connect the socket */
+    if( connect( p_input->i_handle, (struct sockaddr *) &sock,
+                 sizeof( sock ) ) == (-1) )
+    {
+        intf_ErrMsg( "input error: can't connect socket (%s)",
+                     strerror(errno) );
+        close( p_input->i_handle );
+        p_input->b_error = 1;
+        return;
+    }
+
+    p_input->stream.b_seekable = 0;
+    p_input->stream.b_pace_control = 1; /* TCP/IP... */
+
+    /* Prepare GET ... */
+    if( psz_proxy != NULL )
+    {
+        snprintf( psz_buffer, sizeof(psz_buffer),
+                  "GET http://%s:%d/%s HTTP/1.0\r\n\r\n", psz_server,
+                  i_port, psz_path );
+    }
+    else
+    {
+        snprintf( psz_buffer, sizeof(psz_buffer), "GET /%s HTTP/1.0\r\n\r\n",
+                  psz_path );
+    }
+    psz_buffer[sizeof(psz_buffer) - 1] = '\0';
+
+    /* Send GET ... */
+    if( write( p_input->i_handle, psz_buffer, strlen( psz_buffer ) ) == (-1) )
+    {
+        intf_ErrMsg( "input error: can't send request (%s)", strerror(errno) );
+        close( p_input->i_handle );
+        p_input->b_error = 1;
+        return;
+    }
+
+    /* Read HTTP header - this is gonna be fun with plug-ins which do not
+     * use p_input->p_stream :-( */
+    if( (p_input->p_stream = fdopen( p_input->i_handle, "r+" )) == NULL )
+    {
+        intf_ErrMsg( "input error: can't reopen socket (%s)", strerror(errno) );
+        close( p_input->i_handle );
+        p_input->b_error = 1;
+        return;
+    }
+
+    while( !feof( p_input->p_stream ) && !ferror( p_input->p_stream ) )
+    {
+        if( fgets( psz_buffer, sizeof(psz_buffer), p_input->p_stream ) == NULL
+             || *psz_buffer == '\r' || *psz_buffer == '\0' )
+        {
+            break;
+        }
+        /* FIXME : check Content-Type one day */
+    }
+
+    intf_WarnMsg( 3, "input: successfully opened HTTP mode" );
+}
+
+#endif /* !defined( SYS_BEOS ) && !defined( SYS_NTO ) */
 
index 56eb1930b17fce8e17d5c0b630541a629b60083f..501b51709ad0e215226991e3abeaf43a4a6c2da3 100644 (file)
@@ -2,7 +2,7 @@
  * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_programs.c,v 1.61 2001/08/09 20:16:17 jlj Exp $
+ * $Id: input_programs.c,v 1.62 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -56,7 +56,6 @@
 int input_InitStream( input_thread_t * p_input, size_t i_data_len )
 {
 
-    p_input->stream.i_method = INPUT_METHOD_NONE;
     p_input->stream.i_stream_id = 0;
 
     /* initialized to 0 since we don't give the signal to the interface
index 05b7d39ea5631125dd9c03cb3642f907e4ca1822..28edb137a2af5da752918f4487df91e8f8118e5d 100644 (file)
@@ -2,7 +2,7 @@
  * modules.c : Built-in and plugin modules management functions
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules.c,v 1.40 2001/07/17 09:48:08 massiot Exp $
+ * $Id: modules.c,v 1.41 2001/10/02 16:46:59 massiot Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Ethan C. Baldridge <BaldridgeE@cadmus.com>
@@ -365,6 +365,8 @@ module_t * module_Need( int i_capabilities, void *p_data )
                     }
                 }
             }
+            intf_WarnMsg( 3, "module: %s has score %d",
+                          p_module->psz_name, i_totalscore );
 
             /* If the high score was broken, we have a new champion */
             if( i_totalscore > i_bestscore )