]> git.sesse.net Git - vlc/blobdiff - modules/access/ftp.c
New spanish translation, by Antonio Javier Varela.
[vlc] / modules / access / ftp.c
index e43c42495cd62cedefa5258a33320985c325326f..ec99402eafd8a16f2fc04d1a79b4e222c8e388d8 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * ftp.c:
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ftp.c,v 1.1 2002/12/15 23:39:41 fenrir Exp $
+ * Copyright (C) 2001-2003 VideoLAN
+ * $Id: ftp.c,v 1.21 2003/09/10 21:09:05 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  *****************************************************************************/
 #include <stdlib.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <sys/stat.h>
-#include <string.h>
 #include <errno.h>
 #include <fcntl.h>
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 
+#ifdef HAVE_SYS_TIME_H
+#    include <sys/time.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
-#elif defined( _MSC_VER ) && defined( _WIN32 )
-#   include <io.h>
 #endif
 
 #ifdef WIN32
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  Open        ( vlc_object_t * );
-static void Close       ( vlc_object_t * );
+static int     Open     ( vlc_object_t * );
+static void    Close    ( vlc_object_t * );
 
-static int  Read        ( input_thread_t * p_input, byte_t * p_buffer,
+static ssize_t Read     ( input_thread_t * p_input, byte_t * p_buffer,
                           size_t i_len );
-static void Seek        ( input_thread_t *, off_t );
-static int  SetProgram  ( input_thread_t *, pgrm_descriptor_t * );
+static void    Seek     ( input_thread_t *, off_t );
 
 
 static ssize_t NetRead ( input_thread_t *, input_socket_t *, byte_t *, size_t );
@@ -81,20 +82,20 @@ static int  ftp_StopStream ( input_thread_t *);
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#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 ftp streams. This " \
     "value should be set in miliseconds units." )
 
 vlc_module_begin();
-    set_description( _("ftp access module") );
+    set_description( _("FTP input") );
     set_capability( "access", 0 );
-    add_category_hint( "stream", NULL );
+    add_category_hint( "stream", NULL, VLC_FALSE );
         add_integer( "ftp-caching", 2 * DEFAULT_PTS_DELAY / 1000, NULL,
-                     CACHING_TEXT, CACHING_LONGTEXT );
-        add_string( "ftp-user", "anonymous", NULL, "ftp user name", "ftp user name" );
-        add_string( "ftp-pwd", "anonymous@dummy.org", NULL, "ftp password", "ftp password, be careful with that option..." );
-        add_string( "ftp-account", "anonymous", NULL, "ftp account", "ftp account" );
+                     CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
+        add_string( "ftp-user", "anonymous", NULL, "ftp user name", "ftp user name", VLC_FALSE );
+        add_string( "ftp-pwd", "anonymous@dummy.org", NULL, "ftp password", "ftp password, be careful with that option...", VLC_FALSE );
+        add_string( "ftp-account", "anonymous", NULL, "ftp account", "ftp account", VLC_FALSE );
     add_shortcut( "ftp" );
     set_callbacks( Open, Close );
 vlc_module_end();
@@ -198,6 +199,7 @@ static int Open( vlc_object_t *p_this )
     socket_desc.i_server_port   = p_url->i_server_port;
     socket_desc.psz_bind_addr   = "";
     socket_desc.i_bind_port     = 0;
+    socket_desc.i_ttl           = 0;
     p_input->p_private = (void*)&socket_desc;
     if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
     {
@@ -332,25 +334,9 @@ static int Open( vlc_object_t *p_this )
         goto exit_error;
     }
 
-#ifdef HAVE_ATOLL
     p_access->i_filesize = atoll( psz_arg + 4 );
-#else
-    {
-        int64_t i_size;
-        char    *psz_parser = psz_arg + 4;
 
-        while( *psz_parser == ' ' ) psz_parser++;
-
-        while( psz_parser[0] >= '0' && psz_parser[0] <= '9' )
-        {
-            i_size *= 10;
-            i_size += psz_parser[0] - '0';
-        }
-        p_access->i_filesize = i_size;
-    }
-#endif
-
-    msg_Dbg( p_input, "file size:%d", p_access->i_filesize );
+    msg_Dbg( p_input, "file size: "I64Fd, p_access->i_filesize );
     FREE( psz_arg );
 
     if( ftp_StartStream( p_input, 0 ) < 0 )
@@ -361,7 +347,7 @@ static int Open( vlc_object_t *p_this )
     /* *** set exported functions *** */
     p_input->pf_read = Read;
     p_input->pf_seek = Seek;
-    p_input->pf_set_program = SetProgram;
+    p_input->pf_set_program = input_SetProgram;
     p_input->pf_set_area = NULL;
 
     p_input->p_private = NULL;
@@ -414,15 +400,6 @@ static void Close( vlc_object_t *p_this )
     FREE( p_access->url.psz_private );
 }
 
-/*****************************************************************************
- * SetProgram: do nothing
- *****************************************************************************/
-static int SetProgram( input_thread_t * p_input,
-                       pgrm_descriptor_t * p_program )
-{
-    return( 0 );
-}
-
 /*****************************************************************************
  * Seek: try to go at the right place
  *****************************************************************************/
@@ -444,7 +421,7 @@ static void Seek( input_thread_t * p_input, off_t i_pos )
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 }
 
-static int  Read        ( input_thread_t * p_input, byte_t * p_buffer,
+static ssize_t Read     ( input_thread_t * p_input, byte_t * p_buffer,
                           size_t i_len )
 {
     access_t    *p_access = (access_t*)p_input->p_access_data;
@@ -460,17 +437,17 @@ static int  ftp_SendCommand( input_thread_t *p_input, char *psz_fmt, ... )
     access_t        *p_access = (access_t*)p_input->p_access_data;
     va_list args;
     char    *psz_buffer;
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN)
+#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
         size_t  i_size;
 #endif
 
     va_start( args, psz_fmt );
 
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN)
+#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
     vasprintf( &psz_buffer, psz_fmt, args );
 #else
     i_size = strlen( psz_fmt ) + 2048;
-    psz_path = calloc( i_size, sizeof( char ) );
+    psz_buffer = calloc( i_size, sizeof( char ) );
     vsnprintf( psz_buffer, i_size, psz_fmt, args );
     psz_buffer[i_size - 1] = 0;
 #endif
@@ -650,6 +627,7 @@ static int  ftp_StartStream( input_thread_t *p_input, off_t i_start )
     socket_desc.i_server_port   = i_port;
     socket_desc.psz_bind_addr   = "";
     socket_desc.i_bind_port     = 0;
+    socket_desc.i_ttl           = 0;
     p_input->p_private = (void*)&socket_desc;
     if( !( p_network = module_Need( p_input, "network", "" ) ) )
     {
@@ -813,6 +791,7 @@ static ssize_t NetRead( input_thread_t *p_input,
 #else
     struct timeval  timeout;
     fd_set          fds;
+    ssize_t         i_recv;
     int             i_ret;
 
     /* Initialize file descriptor set */
@@ -820,30 +799,39 @@ static ssize_t NetRead( input_thread_t *p_input,
     FD_SET( p_socket->i_handle, &fds );
 
     /* We'll wait 1 second if nothing happens */
-    timeout.tv_sec  = 0;
-    timeout.tv_usec = 1000000;
+    timeout.tv_sec  = 1;
+    timeout.tv_usec = 0;
 
     /* Find if some data is available */
-    i_ret = select( p_socket->i_handle + 1, &fds,
-                    NULL, NULL, &timeout );
+    while( (i_ret = select( p_socket->i_handle + 1, &fds,
+                            NULL, NULL, &timeout )) == 0
+           || (i_ret < 0 && errno == EINTR) )
+    {
+        FD_ZERO( &fds );
+        FD_SET( p_socket->i_handle, &fds );
+        timeout.tv_sec  = 1;
+        timeout.tv_usec = 0;
+
+        if( p_input->b_die || p_input->b_error )
+        {
+            return 0;
+        }
+    }
 
-    if( i_ret == -1 && errno != EINTR )
+    if( i_ret < 0 )
     {
         msg_Err( p_input, "network select error (%s)", strerror(errno) );
+        return -1;
     }
-    else if( i_ret > 0 )
-    {
-        ssize_t i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 );
 
-        if( i_recv < 0 )
-        {
-            msg_Err( p_input, "recv failed (%s)", strerror(errno) );
-        }
+    i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 );
 
-        return i_recv;
+    if( i_recv < 0 )
+    {
+        msg_Err( p_input, "recv failed (%s)", strerror(errno) );
     }
 
-    return 0;
+    return i_recv;
 
 #endif
 }