]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
Fixed skipping data until EOF while using block access.
[vlc] / src / input / subtitles.c
index a7814094c30f3199aafe85ce0b17d0bbcc331974..01aeda54fc4b0cfe5deb65ae85f893213ed07d4a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * subtitles.c
+ * subtitles.c : subtitles detection
  *****************************************************************************
- * Copyright (C) 2003-2006 the VideoLAN team
+ * Copyright (C) 2003-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
@@ -32,7 +32,6 @@
 #endif
 
 #include <vlc_common.h>
-#include <vlc_input.h>
 #include <vlc_charset.h>
 #include <vlc_url.h>
 
 #   include <dirent.h>
 #endif
 
-#include <limits.h>
-
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
+
 #include <sys/stat.h>
 
-#include <ctype.h>
+#include <ctype.h> /* isalnum */
+
 #include "input_internal.h"
 
 /**
@@ -55,7 +54,6 @@
  */
 #define MAX_SUBTITLE_FILES 128
 
-
 /**
  * The possible extensions for subtitle files we support
  */
@@ -136,11 +134,11 @@ static int whiteonly( const char *s )
 
 enum
 {
-    SUB_PRIORITY_NONE = 0,
-    SUB_PRIORITY_MATCH_NONE = 1,
+    SUB_PRIORITY_NONE        = 0,
+    SUB_PRIORITY_MATCH_NONE  = 1,
     SUB_PRIORITY_MATCH_RIGHT = 2,
-    SUB_PRIORITY_MATCH_LEFT = 3,
-    SUB_PRIORITY_MATCH_ALL = 4,
+    SUB_PRIORITY_MATCH_LEFT  = 3,
+    SUB_PRIORITY_MATCH_ALL   = 4,
 };
 typedef struct
 {
@@ -173,13 +171,12 @@ static int compare_sub_priority( const void *a, const void *b )
 int subtitles_Filter( const char *psz_dir_content )
 {
     const char *tmp = strrchr( psz_dir_content, '.');
-    int i;
 
     if( !tmp )
         return 0;
     tmp++;
 
-    for( i = 0; sub_exts[i][0]; i++ )
+    for( int i = 0; sub_exts[i][0]; i++ )
         if( strcasecmp( sub_exts[i], tmp ) == 0 )
             return 1;
     return 0;
@@ -262,16 +259,18 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     vlc_subfn_t *result = NULL; /* unsorted results */
     char **result2; /* sorted results */
 
-    if( !psz_fname )
+    if( !psz_name_org )
         return NULL;
 
-    const char *psz_fname = decode_URI( psz_name_org );
-    if( !strncmp( psz_fname, "file://", 7 ) )
+    if( !strncmp( psz_name_org, "file://", 7 ) )
     {
-        psz_fname += 7;
-        if( !strncmp( psz_fname, "localhost", 9 ) )
-            psz_fname += 9;
+        psz_name_org += 7;
+        if( !strncmp( psz_name_org, "localhost", 9 ) )
+            psz_name_org += 9;
     }
+    char *psz_fname = decode_URI_duplicate( psz_name_org );
+    if( !psz_fname )
+        return NULL;
 
     /* extract filename & dirname from psz_fname */
     tmp = strrchr( psz_fname, DIR_SEP_CHAR );
@@ -290,7 +289,10 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         char *psz_cwd = NULL;
 #endif
         if( !psz_cwd )
+        {
+            free( psz_fname );
             return NULL;
+        }
 
         f_fname = strdup( psz_fname );
         if( asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR ) == -1 )
@@ -301,6 +303,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     {
         free( f_fname );
         free( f_dir );
+        free( psz_fname );
         return NULL;
     }
 
@@ -314,6 +317,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         free( f_dir );
         free( f_fname_noext );
         free( f_fname_trim );
+        free( psz_fname );
         return NULL;
     }
 
@@ -329,7 +333,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         const char *psz_dir = j < 0 ? f_dir : subdirs[j];
         char **ppsz_dir_content;
         int i_dir_content;
-        int a;
 
         if( psz_dir == NULL || ( j >= 0 && !strcmp( psz_dir, f_dir ) ) )
             continue;
@@ -341,7 +344,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             continue;
 
         msg_Dbg( p_this, "looking for a subtitle file in %s", psz_dir );
-        for( a = 0; a < i_dir_content && i_sub_count < MAX_SUBTITLE_FILES ; a++ )
+        for( int a = 0; a < i_dir_content && i_sub_count < MAX_SUBTITLE_FILES ; a++ )
         {
             char *psz_name = ppsz_dir_content[a];
             char tmp_fname_noext[strlen( psz_name ) + 1];
@@ -415,7 +418,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         }
         if( ppsz_dir_content )
         {
-            for( a = 0; a < i_dir_content; a++ )
+            for( int a = 0; a < i_dir_content; a++ )
                 free( ppsz_dir_content[a] );
             free( ppsz_dir_content );
         }
@@ -430,6 +433,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     free( f_dir );
     free( f_fname_trim );
     free( f_fname_noext );
+    free( psz_fname );
 
     if( !result )
         return NULL;