Commit ccf664e2 authored by Antoine Cellerier's avatar Antoine Cellerier

add new filename_sanitize and path_sanitize functions to remove forbidden...

add new filename_sanitize and path_sanitize functions to remove forbidden charcters from filenames/paths and use where appropriate.
parent 9c3e6c53
......@@ -38,9 +38,14 @@
VLC_EXPORT( void, resolve_xml_special_chars, ( char *psz_value ) );
VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) );
VLC_EXPORT( char *, str_format_time, ( char * ) );
VLC_EXPORT( char *, str_format_time, ( const char * ) );
#define str_format_meta( a, b ) __str_format_meta( VLC_OBJECT( a ), b )
VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, char * ) );
VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) );
#define str_format( a, b ) __str_format( VLC_OBJECT( a ), b )
VLC_EXPORT( char *, __str_format, ( vlc_object_t *, const char * ) );
VLC_EXPORT( void, filename_sanitize, ( char * ) );
VLC_EXPORT( void, path_sanitize, ( char * ) );
/**
* @}
......
......@@ -132,12 +132,11 @@ static int Open( vlc_object_t *p_this )
else
{
int fd;
char *psz_tmp = str_format_time( p_access->psz_name );
char *psz_tmp2 = str_format_meta( p_access, psz_tmp );
char *psz_tmp = str_format( p_access, p_access->psz_name );
path_sanitize( psz_tmp );
fd = utf8_open( psz_tmp, i_flags, 0666 );
free( psz_tmp );
fd = utf8_open( psz_tmp2, i_flags, 0666 );
free( psz_tmp2 );
if( fd == -1 )
{
......
......@@ -251,7 +251,6 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
subpicture_t *p_spu;
video_format_t fmt;
time_t t;
char *buf;
if( p_sys->last_time == time( NULL ) )
{
......@@ -289,9 +288,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
{
p_sys->b_need_update = VLC_FALSE;
}
buf = str_format_time( p_sys->psz_marquee );
p_spu->p_region->psz_text = str_format_meta( p_filter, buf );
free( buf );
p_spu->p_region->psz_text = str_format( p_filter, p_sys->psz_marquee );
p_spu->i_start = date;
p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000;
p_spu->b_ephemer = VLC_TRUE;
......
......@@ -280,12 +280,16 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->render.i_height;
if( p_vout->p_sys->b_time )
{
psz_tmp = str_format_time( p_vout->p_sys->psz_prefix );
path_sanitize( psz_tmp );
}
else
psz_tmp = p_vout->p_sys->psz_prefix;
if( p_vout->p_sys->b_meta )
{
psz_prefix = str_format_meta( p_vout, psz_tmp );
path_sanitize( psz_prefix );
if( p_vout->p_sys->b_time )
free( psz_tmp );
}
......
......@@ -331,7 +331,7 @@ char *convert_xml_special_chars( const char *psz_content )
/****************************************************************************
* String formating functions
****************************************************************************/
char *str_format_time(char *tformat )
char *str_format_time( const char *tformat )
{
char buffer[255];
time_t curtime;
......@@ -369,9 +369,9 @@ char *str_format_time(char *tformat )
*d = '-'; \
d++; \
}
char *__str_format_meta( vlc_object_t *p_object, char *string )
char *__str_format_meta( vlc_object_t *p_object, const char *string )
{
char *s = string;
const char *s = string;
char *dst = malloc( 1000 );
char *d = dst;
int b_is_format = 0;
......@@ -646,3 +646,67 @@ char *__str_format_meta( vlc_object_t *p_object, char *string )
return dst;
}
/**
* Apply str format time and str format meta
*/
char *__str_format( vlc_object_t *p_this, const char *psz_src )
{
char *psz_buf1, *psz_buf2;
psz_buf1 = str_format_time( psz_src );
psz_buf2 = str_format_meta( p_this, psz_buf1 );
free( psz_buf1 );
return psz_buf2;
}
/**
* Remove forbidden characters from filenames (including slashes)
*/
void filename_sanitize( char *str )
{
while( *str )
{
switch( *str )
{
case '/':
#ifdef WIN32
case '*':
case '.':
case '"':
case '\\':
case '[':
case ']':
case ':':
case ';':
case '|':
case '=':
#endif
*str = '_';
}
}
}
/**
* Remove forbidden characters from full paths (leaves slashes)
*/
void path_sanitize( char *str )
{
while( *str )
{
switch( *str )
{
#ifdef WIN32
case '*':
case '.':
case '"':
case '[':
case ']':
case ':':
case ';':
case '|':
case '=':
#endif
*str = '_';
}
}
}
......@@ -638,10 +638,10 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
if( !psz_prefix ) psz_prefix = strdup( "vlcsnap-" );
else
{
char *psz_tmp = str_format_time( psz_prefix );
char *psz_tmp = str_format( p_vout, psz_prefix );
filename_sanitize( psz_tmp );
free( psz_prefix );
psz_prefix = str_format_meta( p_vout, psz_tmp );
free( psz_tmp );
psz_prefix = psz_tmp;
}
closedir( path );
......@@ -669,7 +669,8 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
}
else // The user specified a full path name (including file name)
{
psz_filename = str_format_meta( p_vout, val.psz_string );
psz_filename = str_format( p_vout, val.psz_string );
path_sanitize( psz_filename );
}
free( val.psz_string );
......
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