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 * ) );
/**
* @}
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 )
{
subpicture_t *p_spu;
video_format_t fmt;
time_t t;
- char *buf;
if( p_sys->last_time == time( NULL ) )
{
{
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;
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 );
}
/****************************************************************************
* String formating functions
****************************************************************************/
-char *str_format_time(char *tformat )
+char *str_format_time( const char *tformat )
{
char buffer[255];
time_t curtime;
*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;
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 = '_';
+ }
+ }
+}
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 );
}
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 );