/*****************************************************************************
* ftp.c:
*****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ftp.c,v 1.3 2002/12/18 14:17:09 sam 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 );
/*****************************************************************************
* 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();
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 ) ) )
{
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: "I64Fd, p_access->i_filesize );
FREE( psz_arg );
/* *** 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;
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
*****************************************************************************/
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;
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;
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", "" ) ) )
{
#else
struct timeval timeout;
fd_set fds;
+ ssize_t i_recv;
int i_ret;
/* Initialize file descriptor set */
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
}