Commit d9e1effe authored by Christophe Massiot's avatar Christophe Massiot

* modules/control/http/rpn.c: vlc_var_* now take an extra argument to

   indicate which object we are playing with (for instance 'VLC_OBJECT_INPUT'
   or 'VLC_OBJECT_PLAYLIST'). Espace \ in addslashes.
 * modules/control/http: Factorized and simplified the RealPath() stuff.
   Fixed a few hardcoded '/' as a path separator.
parent 7db33a0a
......@@ -105,6 +105,8 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
int E_(FileLoad)( FILE *f, char **pp_data, int *pi_data );
/** This function creates a suitable URL for a filename */
char *E_(FileToUrl)( char *name, vlc_bool_t *pb_index );
/** This function returns the real path of a file or directory */
char *E_(RealPath)( intf_thread_t *p_intf, const char *psz_src );
/* Locale handling functions */
......
......@@ -861,11 +861,18 @@ void E_(Execute)( httpd_file_sys_t *p_args,
char *p_buffer;
char psz_file[MAX_DIR_SIZE];
char *p;
char sep;
if( m.param1[0] != '/' )
#if defined( WIN32 )
sep = '\\';
#else
sep = '/';
#endif
if( m.param1[0] != sep )
{
strcpy( psz_file, p_args->file );
p = strrchr( psz_file, '/' );
p = strrchr( psz_file, sep );
if( p != NULL )
strcpy( p + 1, m.param1 );
else
......
......@@ -495,10 +495,10 @@ mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
#endif
mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
char *psz_dir )
char *psz_dir )
{
mvar_t *s = mvar_New( name, "set" );
char tmp[MAX_DIR_SIZE], dir[MAX_DIR_SIZE], *p, *src;
char tmp[MAX_DIR_SIZE];
#ifdef HAVE_SYS_STAT_H
struct stat stat_info;
#endif
......@@ -508,91 +508,17 @@ mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
/* convert all / to native separator */
#if defined( WIN32 )
while( (p = strchr( psz_dir, '/' )) )
{
*p = '\\';
}
sep = '\\';
#else
sep = '/';
#endif
/* remove trailling separator */
while( strlen( psz_dir ) > 1 &&
#if defined( WIN32 )
!( strlen(psz_dir)==3 && psz_dir[1]==':' && psz_dir[2]==sep ) &&
#endif
psz_dir[strlen( psz_dir ) -1 ] == sep )
{
psz_dir[strlen( psz_dir ) -1 ] ='\0';
}
/* remove double separator */
for( p = src = psz_dir; *src != '\0'; src++, p++ )
{
if( src[0] == sep && src[1] == sep )
{
src++;
}
*p = *src;
}
*p = '\0';
if( *psz_dir == '\0' )
{
return s;
}
if( psz_dir[0] == '~' && psz_dir[1] == '/' )
{
/* This is incomplete : we should also support the ~cmassiot/ syntax. */
snprintf( dir, sizeof(dir), "%s/%s", p_intf->p_vlc->psz_homedir,
psz_dir + 2 );
psz_dir = dir;
}
/* first fix all .. dir */
p = src = psz_dir;
while( *src )
{
if( src[0] == '.' && src[1] == '.' )
{
src += 2;
if( p <= &psz_dir[1] )
{
continue;
}
p -= 2;
while( p > &psz_dir[1] && *p != sep )
{
p--;
}
}
else if( *src == sep )
{
if( p > psz_dir && p[-1] == sep )
{
src++;
}
else
{
*p++ = *src++;
}
}
else
{
do
{
*p++ = *src++;
} while( *src && *src != sep );
}
}
*p = '\0';
psz_dir = E_(RealPath)( p_intf, psz_dir );
#ifdef HAVE_SYS_STAT_H
if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
{
free( psz_dir );
return s;
}
#endif
......@@ -603,16 +529,10 @@ mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
{
msg_Warn( p_intf, "scandir error on %s (%s)", psz_dir,
strerror(errno) );
free( psz_dir );
return s;
}
/* remove trailing / or \ */
for( p = &psz_dir[strlen( psz_dir) - 1];
p >= psz_dir && ( *p =='/' || *p =='\\' ); p-- )
{
*p = '\0';
}
for( i = 0; i < i_dir_content; i++ )
{
struct dirent *p_dir_content = pp_dir_content[i];
......@@ -625,7 +545,8 @@ mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
continue;
}
snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, p_dir_content->d_name );
snprintf( tmp, sizeof(tmp), "%s%c%s", psz_dir, sep,
p_dir_content->d_name );
#ifdef HAVE_SYS_STAT_H
if( stat( tmp, &stat_info ) == -1 )
......@@ -638,7 +559,7 @@ mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
psz_tmp = vlc_fix_readdir_charset( p_intf, p_dir_content->d_name );
psz_name = E_(FromUTF8)( p_intf, psz_tmp );
free( psz_tmp );
snprintf( tmp, sizeof(tmp), "%s/%s", psz_dir, psz_name );
snprintf( tmp, sizeof(tmp), "%s%c%s", psz_dir, sep, psz_name );
mvar_AppendNewVar( f, "name", tmp );
mvar_AppendNewVar( f, "basename", psz_name );
......@@ -681,6 +602,7 @@ mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
mvar_AppendVar( s, f );
}
free( psz_dir );
return s;
}
......
This diff is collapsed.
......@@ -120,6 +120,14 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
int i_dirlen;
char sep;
#if defined( WIN32 )
sep = '\\';
#else
sep = '/';
#endif
#ifdef HAVE_SYS_STAT_H
if( stat( psz_dir, &stat_info ) == -1 || !S_ISDIR( stat_info.st_mode ) )
{
......@@ -142,7 +150,7 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
msg_Dbg( p_intf, "dir=%s", psz_dir );
sprintf( dir, "%s/.access", psz_dir );
sprintf( dir, "%s%c.access", psz_dir, sep );
if( ( file = fopen( dir, "r" ) ) != NULL )
{
char line[1024];
......@@ -176,7 +184,7 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
fclose( file );
}
sprintf( dir, "%s/.hosts", psz_dir );
sprintf( dir, "%s%c.hosts", psz_dir, sep );
p_acl = ACL_Create( p_intf, VLC_FALSE );
if( ACL_LoadFile( p_acl, dir ) )
{
......@@ -196,7 +204,7 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
|| ( i_dirlen + strlen( p_dir_content->d_name ) > MAX_DIR_SIZE ) )
continue;
sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
sprintf( dir, "%s%c%s", psz_dir, sep, p_dir_content->d_name );
if( E_(ParseDirectory)( p_intf, psz_root, dir ) )
{
httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
......@@ -793,3 +801,92 @@ playlist_item_t *E_(MRLParse)( intf_thread_t *p_intf, char *_psz,
free( psz );
return p_item;
}
/**********************************************************************
* RealPath: parse ../, ~ and path stuff
**********************************************************************/
char *E_(RealPath)( intf_thread_t *p_intf, const char *psz_src )
{
char *psz_dir;
char *p;
int i_len = strlen(psz_src);
char sep;
#if defined( WIN32 )
sep = '\\';
#else
sep = '/';
#endif
psz_dir = malloc( i_len + 2 );
strcpy( psz_dir, psz_src );
/* Add a trailing sep to ease the .. step */
psz_dir[i_len] = sep;
psz_dir[i_len + 1] = '\0';
#ifdef WIN32
/* Convert all / to native separator */
p = psz_dir;
while( (p = strchr( p, '/' )) != NULL )
{
*p = sep;
}
#endif
/* Remove multiple separators and /./ */
p = psz_dir;
while( (p = strchr( p, sep )) != NULL )
{
if( p[1] == sep )
memmove( &p[1], &p[2], strlen(&p[2]) + 1 );
else if( p[1] == '.' && p[2] == sep )
memmove( &p[1], &p[3], strlen(&p[3]) + 1 );
else
p++;
}
if( psz_dir[0] == '~' )
{
char *dir = malloc( strlen(psz_dir)
+ strlen(p_intf->p_vlc->psz_homedir) );
/* This is incomplete : we should also support the ~cmassiot/ syntax. */
sprintf( dir, "%s%s", p_intf->p_vlc->psz_homedir, psz_dir + 1 );
free( psz_dir );
psz_dir = dir;
}
if( strlen(psz_dir) > 2 )
{
/* Fix all .. dir */
p = psz_dir + 3;
while( (p = strchr( p, sep )) != NULL )
{
if( p[-1] == '.' && p[-2] == '.' && p[-3] == sep )
{
char *q;
p[-3] = '\0';
if( (q = strrchr( psz_dir, sep )) != NULL )
{
memmove( q + 1, p + 1, strlen(p + 1) + 1 );
p = q + 1;
}
else
{
memmove( psz_dir, p + 1, strlen(p + 1) + 1 );
p = psz_dir + 3;
}
}
else
p++;
}
}
/* Remove trailing sep if there are at least 2 sep in the string
* (handles the C:\ stuff) */
p = strrchr( psz_dir, sep );
if( p != NULL && p[1] == '\0' && p != strchr( psz_dir, sep ) )
*p = '\0';
return psz_dir;
}
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