Changeset ccf664e20dd3dbf5feb554299c6267c9815da582

Show
Ignore:
Timestamp:
26/01/07 23:37:28 (2 years ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1169851048 +0000
git-parent:

[9c3e6c5367a085e41794efae05eb5c1a20ff1394]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1169851048 +0000
Message:

add new filename_sanitize and path_sanitize functions to remove forbidden charcters from filenames/paths and use where appropriate.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_strings.h

    rfbf4c80 rccf664e  
    3939VLC_EXPORT( char *, convert_xml_special_chars, ( const char *psz_content ) ); 
    4040 
    41 VLC_EXPORT( char *, str_format_time, ( char * ) ); 
     41VLC_EXPORT( char *, str_format_time, ( const char * ) ); 
    4242#define str_format_meta( a, b ) __str_format_meta( VLC_OBJECT( a ), b ) 
    43 VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, char * ) ); 
     43VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) ); 
     44#define str_format( a, b ) __str_format( VLC_OBJECT( a ), b ) 
     45VLC_EXPORT( char *, __str_format, ( vlc_object_t *, const char * ) ); 
     46 
     47VLC_EXPORT( void, filename_sanitize, ( char * ) ); 
     48VLC_EXPORT( void, path_sanitize, ( char * ) ); 
    4449 
    4550/** 
  • modules/access_output/file.c

    rd3fe7f2 rccf664e  
    133133    { 
    134134        int fd; 
    135         char *psz_tmp = str_format_time( p_access->psz_name ); 
    136         char *psz_tmp2 = str_format_meta( p_access, psz_tmp ); 
    137  
     135        char *psz_tmp = str_format( p_access, p_access->psz_name ); 
     136        path_sanitize( psz_tmp ); 
     137 
     138        fd = utf8_open( psz_tmp, i_flags, 0666 ); 
    138139        free( psz_tmp ); 
    139         fd = utf8_open( psz_tmp2, i_flags, 0666 ); 
    140         free( psz_tmp2 ); 
    141140 
    142141        if( fd == -1 ) 
  • modules/video_filter/marq.c

    rdba4eb4 rccf664e  
    252252    video_format_t fmt; 
    253253    time_t t; 
    254     char *buf; 
    255254 
    256255    if( p_sys->last_time == time( NULL ) ) 
     
    290289        p_sys->b_need_update = VLC_FALSE; 
    291290    } 
    292     buf = str_format_time( p_sys->psz_marquee ); 
    293     p_spu->p_region->psz_text = str_format_meta( p_filter, buf ); 
    294     free( buf ); 
     291    p_spu->p_region->psz_text = str_format( p_filter, p_sys->psz_marquee ); 
    295292    p_spu->i_start = date; 
    296293    p_spu->i_stop  = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000; 
  • modules/video_output/image.c

    rd3fe7f2 rccf664e  
    281281 
    282282    if( p_vout->p_sys->b_time ) 
     283    { 
    283284        psz_tmp = str_format_time( p_vout->p_sys->psz_prefix ); 
     285        path_sanitize( psz_tmp ); 
     286    } 
    284287    else 
    285288        psz_tmp = p_vout->p_sys->psz_prefix; 
     
    287290    { 
    288291        psz_prefix = str_format_meta( p_vout, psz_tmp ); 
     292        path_sanitize( psz_prefix ); 
    289293        if( p_vout->p_sys->b_time ) 
    290294            free( psz_tmp ); 
  • src/text/strings.c

    rd3fe7f2 rccf664e  
    332332 * String formating functions 
    333333 ****************************************************************************/ 
    334 char *str_format_time(char *tformat ) 
     334char *str_format_time( const char *tformat ) 
    335335{ 
    336336    char buffer[255]; 
     
    370370                        d++;                                        \ 
    371371                    } 
    372 char *__str_format_meta( vlc_object_t *p_object, char *string ) 
    373 { 
    374     char *s = string; 
     372char *__str_format_meta( vlc_object_t *p_object, const char *string ) 
     373{ 
     374    const char *s = string; 
    375375    char *dst = malloc( 1000 ); 
    376376    char *d = dst; 
     
    647647    return dst; 
    648648} 
     649 
     650/** 
     651 * Apply str format time and str format meta 
     652 */ 
     653char *__str_format( vlc_object_t *p_this, const char *psz_src ) 
     654{ 
     655    char *psz_buf1, *psz_buf2; 
     656    psz_buf1 = str_format_time( psz_src ); 
     657    psz_buf2 = str_format_meta( p_this, psz_buf1 ); 
     658    free( psz_buf1 ); 
     659    return psz_buf2; 
     660} 
     661 
     662/** 
     663 * Remove forbidden characters from filenames (including slashes) 
     664 */ 
     665void filename_sanitize( char *str ) 
     666{ 
     667    while( *str ) 
     668    { 
     669        switch( *str ) 
     670        { 
     671            case '/': 
     672#ifdef WIN32 
     673            case '*': 
     674            case '.': 
     675            case '"': 
     676            case '\\': 
     677            case '[': 
     678            case ']': 
     679            case ':': 
     680            case ';': 
     681            case '|': 
     682            case '=': 
     683#endif 
     684                *str = '_'; 
     685        } 
     686    } 
     687} 
     688 
     689/** 
     690 * Remove forbidden characters from full paths (leaves slashes) 
     691 */ 
     692void path_sanitize( char *str ) 
     693{ 
     694    while( *str ) 
     695    { 
     696        switch( *str ) 
     697        { 
     698#ifdef WIN32 
     699            case '*': 
     700            case '.': 
     701            case '"': 
     702            case '[': 
     703            case ']': 
     704            case ':': 
     705            case ';': 
     706            case '|': 
     707            case '=': 
     708#endif 
     709                *str = '_'; 
     710        } 
     711    } 
     712} 
  • src/video_output/vout_intf.c

    recd201b rccf664e  
    639639        else 
    640640        { 
    641             char *psz_tmp = str_format_time( psz_prefix ); 
     641            char *psz_tmp = str_format( p_vout, psz_prefix ); 
     642            filename_sanitize( psz_tmp ); 
    642643            free( psz_prefix ); 
    643             psz_prefix = str_format_meta( p_vout, psz_tmp ); 
    644             free( psz_tmp ); 
     644            psz_prefix = psz_tmp; 
    645645        } 
    646646 
     
    670670    else // The user specified a full path name (including file name) 
    671671    { 
    672         psz_filename = str_format_meta( p_vout, val.psz_string ); 
     672        psz_filename = str_format( p_vout, val.psz_string ); 
     673        path_sanitize( psz_filename ); 
    673674    } 
    674675