Commit eb0eac06 authored by Gildas Bazin's avatar Gildas Bazin

* modules/access/directory.c: fixed the directory access plugin.
* configure.ac.in, modules/access/Modules.am: enabled the directory access plugin.
parent ed521849
......@@ -803,7 +803,7 @@ dnl
dnl default modules
dnl
BUILTINS="${BUILTINS} mpeg_video idct idctclassic motion"
PLUGINS="${PLUGINS} dummy rc logger gestures access_file memcpy"
PLUGINS="${PLUGINS} dummy rc logger gestures memcpy"
PLUGINS="${PLUGINS} es audio m4v mpeg_system ps ts avi asf aac mp4 rawdv"
PLUGINS="${PLUGINS} spudec mpeg_audio lpcm a52 dts cinepak"
PLUGINS="${PLUGINS} deinterlace invert adjust wall transform distort clone crop motionblur"
......@@ -816,8 +816,8 @@ PLUGINS="${PLUGINS} aout_file"
PLUGINS="${PLUGINS} i420_rgb i420_yuy2 i422_yuy2 i420_ymga"
PLUGINS="${PLUGINS} id3 m3u"
PLUGINS="${PLUGINS} wav araw demuxdump demuxsub adpcm a52sys au"
PLUGINS="${PLUGINS} access_udp access_http ipv4 access_mms access_ftp"
PLUGINS="${PLUGINS} sap httpd"
PLUGINS="${PLUGINS} access_file access_udp access_http ipv4 access_mms"
PLUGINS="${PLUGINS} access_ftp access_directory sap httpd"
dnl
dnl Some plugins aren't useful on some platforms
......
SOURCES_access_file = modules/access/file.c
SOURCES_access_directory = modules/access/directory.c
SOURCES_access_udp = modules/access/udp.c
SOURCES_access_http = modules/access/http.c
SOURCES_access_ftp = modules/access/ftp.c
......
......@@ -2,7 +2,7 @@
* directory.c: expands a directory (directory: access plug-in)
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: directory.c,v 1.1 2003/03/24 00:12:51 hartman Exp $
* $Id: directory.c,v 1.2 2003/03/24 01:39:58 gbazin Exp $
*
* Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
*
......@@ -58,12 +58,12 @@
*****************************************************************************/
#define MAX_DIR_SIZE 50000
typedef struct _input_directory_s
typedef struct input_directory_s
{
char p_dir_buffer[MAX_DIR_SIZE];
int i_buf_pos;
int i_buf_length;
} _input_directory_t;
char p_dir_buffer[MAX_DIR_SIZE];
int i_buf_pos;
int i_buf_length;
} input_directory_t;
/*****************************************************************************
......@@ -92,16 +92,15 @@ vlc_module_end();
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
char * psz_name = p_input->psz_name;
_input_directory_t * p_access_data;
input_thread_t * p_input = (input_thread_t *)p_this;
char * psz_name;
input_directory_t * p_access_data;
#ifdef HAVE_SYS_STAT_H
int i_stat;
struct stat stat_info;
struct stat stat_info;
#endif
DIR * p_current_dir;
struct dirent * p_dir_content;
int i_pos=0;
DIR * p_current_dir;
struct dirent * p_dir_content;
int i_pos=0;
/* Initialize access plug-in structures. */
if( p_input->i_mtu == 0 )
......@@ -114,38 +113,43 @@ static int Open( vlc_object_t *p_this )
p_input->pf_set_program = NULL;
p_input->pf_set_area = NULL;
p_input->pf_seek = NULL;
p_input->psz_demux = "m3u";
#ifdef HAVE_SYS_STAT_H
if( ( i_stat = stat( psz_name, &stat_info )) == (-1) || !S_ISDIR( stat_info.st_mode ) )
{
# ifdef HAVE_ERRNO_H
msg_Warn( p_input, "cannot stat() directory `%s' (%s)",
psz_name, strerror(errno));
# else
msg_Warn( p_input, "cannot stat() directory `%s'", psz_name );
# endif
/* Remove the ending '/' char */
psz_name = strdup( p_input->psz_name );
if( psz_name == NULL )
return VLC_EGENERIC;
if( (psz_name[strlen(psz_name)-1] == '/') ||
(psz_name[strlen(psz_name)-1] == '\\') )
{
psz_name[strlen(psz_name)-1] = '\0';
}
#endif
if( psz_name[strlen(psz_name)-1] != '/' )
#ifdef HAVE_SYS_STAT_H
if( ( stat( psz_name, &stat_info ) == -1 ) ||
!S_ISDIR( stat_info.st_mode ) )
#else
if( !p_input->psz_access || strcmp(p_input->psz_access, "dir") )
#endif
{
/* add the / char */
free( psz_name );
return VLC_EGENERIC;
}
msg_Dbg( p_input, "opening directory `%s'", psz_name );
p_access_data = malloc( sizeof(_input_directory_t) );
p_access_data = malloc( sizeof(input_directory_t) );
p_input->p_access_data = (void *)p_access_data;
if( p_access_data == NULL )
{
msg_Err( p_input, "out of memory" );
free( psz_name );
return VLC_ENOMEM;
}
/* have to cd into this dir */
p_current_dir = opendir( psz_name );
if( p_current_dir == NULL )
{
/* something went bad, get out of here ! */
......@@ -156,6 +160,7 @@ static int Open( vlc_object_t *p_this )
msg_Warn( p_input, "cannot open directory `%s'", psz_name );
# endif
free( p_access_data );
free( psz_name );
return VLC_EGENERIC;
}
......@@ -164,13 +169,18 @@ static int Open( vlc_object_t *p_this )
/* while we still have entries in the directory */
while( p_dir_content != NULL && i_pos < MAX_DIR_SIZE )
{
int i_size_entry = strlen( psz_name ) +
strlen( p_dir_content->d_name ) + 2;
/* if it is "." or "..", forget it */
if( ( strcmp( p_dir_content->d_name, "." ) != 0 ) &&
( strcmp( p_dir_content->d_name, ".." ) != 0 ) )
if( strcmp( p_dir_content->d_name, "." ) &&
strcmp( p_dir_content->d_name, ".." ) &&
i_pos + i_size_entry < MAX_DIR_SIZE )
{
msg_Dbg( p_input, "%s", p_dir_content->d_name );
memcpy( &p_access_data->p_dir_buffer[i_pos], p_dir_content->d_name, strlen( p_dir_content->d_name ) );
i_pos += strlen( p_dir_content->d_name );
sprintf( &p_access_data->p_dir_buffer[i_pos], "%s/%s",
psz_name, p_dir_content->d_name );
msg_Dbg( p_input, "%s", &p_access_data->p_dir_buffer[i_pos] );
i_pos += i_size_entry - 1;
p_access_data->p_dir_buffer[i_pos] = '\n';
i_pos++;
}
......@@ -181,7 +191,14 @@ static int Open( vlc_object_t *p_this )
p_access_data->i_buf_length = i_pos;
p_access_data->i_buf_pos = 0;
msg_Dbg( p_input, "%s", p_access_data->p_dir_buffer );
closedir( p_current_dir );
free( psz_name );
/* Force m3u demuxer */
p_input->psz_demux = "m3u";
return VLC_SUCCESS;
}
......@@ -191,7 +208,8 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t * p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
_input_directory_t * p_access_data = (_input_directory_t *)p_input->p_access_data;
input_directory_t * p_access_data =
(input_directory_t *)p_input->p_access_data;
msg_Info( p_input, "closing `%s/%s://%s'",
p_input->psz_access, p_input->psz_demux, p_input->psz_name );
......@@ -204,14 +222,19 @@ static void Close( vlc_object_t * p_this )
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
{
_input_directory_t * p_access_data = (_input_directory_t *)p_input->p_access_data;
int i_ret = 0;
unsigned int i_remaining = p_access_data->i_buf_length - p_access_data->i_buf_pos +1;
input_directory_t * p_access_data =
(input_directory_t *)p_input->p_access_data;
unsigned int i_remaining = p_access_data->i_buf_length -
p_access_data->i_buf_pos;
if( i_remaining > 0 )
{
i_ret = (i_len > i_remaining) ? i_remaining : i_len;
memcpy( p_buffer, &p_access_data->p_dir_buffer[p_access_data->i_buf_pos], i_ret );
int i_ret;
i_ret = __MIN( i_len, i_remaining );
memcpy( p_buffer,
&p_access_data->p_dir_buffer[p_access_data->i_buf_pos],
i_ret );
p_access_data->i_buf_pos += i_ret;
return (ssize_t) i_ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment