]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
Fixed sanetizing of file name in input_CreateFilename.
[vlc] / src / input / subtitles.c
index a20bcabf2ec43231efe08cabd5bf1f17d52d7813..c721a7958ef3cdbd0f695d973620c3702638fcb3 100644 (file)
  *  This file contains functions to dectect subtitle files.
  */
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 #include <vlc_input.h>
 #include <vlc_charset.h>
 
@@ -35,9 +39,7 @@
 #   include <dirent.h>
 #endif
 
-#ifdef HAVE_LIMITS_H
-#   include <limits.h>
-#endif
+#include <limits.h>
 
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
  * The possible extensions for subtitle files we support
  */
 static const char const sub_exts[][6] = {
+    "idx", "sub",  "srt",
+    "ssa", "ass",  "smi",
     "utf", "utf8", "utf-8",
-    "sub", "srt", "smi",
-    "txt", "ssa", "idx",
-
-    "cdg",
-
+    "txt", "rt",   "aqt",
+    "usf", "jss",  "cdg",
+    "psb", "mpsub","mpl2",
+    "pjs", "dks",
     ""
 };
 
-/* extensions from unsupported types */
-/* rt, aqt, jss, js, ass */
-
 static void strcpy_trim( char *d, const char *s )
 {
     /* skip leading whitespace */
@@ -220,10 +220,12 @@ static char **paths_to_list( const char *psz_dir, char *psz_path )
         if( *psz_subdir == '\0' )
             continue;
 
-        asprintf( &subdirs[i++], "%s%s%c",
+        if( asprintf( &subdirs[i++], "%s%s%c",
                   psz_subdir[0] == '.' ? psz_dir : "",
                   psz_subdir,
-                  psz_subdir[strlen(psz_subdir) - 1] == DIR_SEP_CHAR ? '\0' : DIR_SEP_CHAR );
+                  psz_subdir[strlen(psz_subdir) - 1] == DIR_SEP_CHAR ?
+                                           '\0' : DIR_SEP_CHAR ) == -1 )
+            break;
     }
     subdirs[i] = NULL;
 
@@ -249,7 +251,7 @@ static char **paths_to_list( const char *psz_dir, char *psz_path )
 char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                          const char *psz_name_org )
 {
-    vlc_value_t fuzzy;
+    int i_fuzzy;
     int j, i_result2, i_sub_count, i_fname_len;
     char *f_dir = NULL, *f_fname = NULL, *f_fname_noext = NULL, *f_fname_trim = NULL;
     char *tmp = NULL;
@@ -276,7 +278,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     }
     else
     {
-#ifdef HAVE_UNISTD_H
+#if defined (HAVE_UNISTD_H) && !defined (UNDER_CE)
         /* Get the current working directory */
         char *psz_cwd = getcwd( NULL, 0 );
 #else
@@ -286,7 +288,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             return NULL;
 
         f_fname = strdup( psz_fname );
-        asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR );
+        if( asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR ) == -1 )
+            f_dir = NULL; /* Assure that function will return in next test */
         free( psz_cwd );
     }
     if( !f_fname || !f_dir )
@@ -312,7 +315,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     strcpy_strip_ext( f_fname_noext, f_fname );
     strcpy_trim( f_fname_trim, f_fname_noext );
 
-    var_Get( p_this, "sub-autodetect-fuzzy", &fuzzy );
+    i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
 
     result = calloc( MAX_SUBTITLE_FILES+1, sizeof(vlc_subfn_t) ); /* We check it later (simplify code) */
     subdirs = paths_to_list( f_dir, psz_path );
@@ -342,7 +345,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 
             int i_prio;
 
-            if( psz_name == NULL )
+            if( psz_name == NULL || psz_name[0] == '.' )
                 continue;
 
             /* retrieve various parts of the filename */
@@ -379,7 +382,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                 /* doesn't contain the movie name, prefer files in f_dir over subdirs */
                 i_prio = SUB_PRIORITY_MATCH_NONE;
             }
-            if( i_prio >= fuzzy.i_int )
+            if( i_prio >= i_fuzzy )
             {
                 char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1];
                 struct stat st;
@@ -432,7 +435,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 
     for( j = 0, i_result2 = 0; j < i_sub_count && result2 != NULL; j++ )
     {
-        vlc_bool_t b_reject = VLC_FALSE;
+        bool b_reject = false;
 
         if( !result[j].psz_fname || !result[j].psz_ext ) /* memory out */
             break;
@@ -449,12 +452,12 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                     break;
             }
             if( i < i_sub_count )
-                b_reject = VLC_TRUE;
+                b_reject = true;
         }
         else if( !strcasecmp( result[j].psz_ext, "cdg" ) )
         {
             if( result[j].priority < SUB_PRIORITY_MATCH_ALL )
-                b_reject = VLC_TRUE;
+                b_reject = true;
         }
 
         /* */