]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
Encode non-ASCII characters outside comments
[vlc] / modules / access / directory.c
index 07decfc71e28a6a2e7ff0fe0dfb260690342a484..f600040d67e26fcdf0ad2eecadae03e4f506aa54 100644 (file)
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -94,10 +94,8 @@ vlc_module_begin();
     add_string( "recursive", "expand" , NULL, RECURSIVE_TEXT,
                 RECURSIVE_LONGTEXT, VLC_FALSE );
       change_string_list( psz_recursive_list, psz_recursive_list_text, 0 );
-#ifdef HAVE_STRSEP
     add_string( "ignore-filetypes", "m3u,db,nfo,jpg,gif,sfv,txt,sub,idx,srt,cue",
                 NULL, IGNORE_TEXT, IGNORE_LONGTEXT, VLC_FALSE );
-#endif
     set_callbacks( Open, Close );
 
     add_submodule();
@@ -124,7 +122,7 @@ static int Demux( demux_t *p_demux );
 static int DemuxControl( demux_t *p_demux, int i_query, va_list args );
 
 
-static int ReadDir( playlist_t *, char *psz_name, int i_mode, int *pi_pos,
+static int ReadDir( playlist_t *, const char *psz_name, int i_mode,
                     playlist_item_t * );
 
 /*****************************************************************************
@@ -282,8 +280,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
     }
 
     p_item->input.i_type = ITEM_TYPE_DIRECTORY;
-    if( ReadDir( p_playlist, psz_name , i_mode, &i_pos,
-                 p_item ) != VLC_SUCCESS )
+    if( ReadDir( p_playlist, psz_name , i_mode, p_item ) != VLC_SUCCESS )
     {
     }
 end:
@@ -371,6 +368,7 @@ static int Demux( demux_t *p_demux )
 {
     return 0;
 }
+
 /*****************************************************************************
  * DemuxControl:
  *****************************************************************************/
@@ -383,12 +381,12 @@ static int Filter( const struct dirent *foo )
 {
     return VLC_TRUE;
 }
+
 /*****************************************************************************
  * ReadDir: read a directory and add its content to the list
  *****************************************************************************/
-static int ReadDir( playlist_t *p_playlist,
-                    char *psz_name, int i_mode, int *pi_position,
-                    playlist_item_t *p_parent )
+static int ReadDir( playlist_t *p_playlist, const char *psz_name,
+                    int i_mode, playlist_item_t *p_parent )
 {
     struct dirent   **pp_dir_content;
     int             i_dir_content, i;
@@ -414,7 +412,7 @@ static int ReadDir( playlist_t *p_playlist,
         {
             int b;
             char *tmp;
-            
+
             while( psz_parser[0] != '\0' && psz_parser[0] == ' ' ) psz_parser++;
             for( b = 0; psz_parser[b] != '\0'; b++ )
             {
@@ -471,6 +469,21 @@ static int ReadDir( playlist_t *p_playlist,
             if( 0 )
 #endif
             {
+#if defined( S_ISLNK )
+/*
+ * FIXME: there is a ToCToU race condition here; but it is rather tricky
+ * impossible to fix while keeping some kind of portable code, and maybe even
+ * in a non-portable way.
+ */
+                if( lstat( psz_uri, &stat_data )
+                 || S_ISLNK(stat_data.st_mode) )
+                {
+                    msg_Dbg( p_playlist, "Skipping directory symlink %s",
+                             psz_uri );
+                    free( psz_uri );
+                    continue;
+                }
+#endif
                 if( i_mode == MODE_NONE )
                 {
                     msg_Dbg( p_playlist, "Skipping subdirectory %s", psz_uri );
@@ -496,7 +509,7 @@ static int ReadDir( playlist_t *p_playlist,
                     p_node->input.i_type = ITEM_TYPE_DIRECTORY;
 
                     if( ReadDir( p_playlist, psz_uri , MODE_EXPAND,
-                                 pi_position, p_node ) != VLC_SUCCESS )
+                                 p_node ) != VLC_SUCCESS )
                     {
                         return VLC_EGENERIC;
                     }
@@ -545,7 +558,8 @@ static int ReadDir( playlist_t *p_playlist,
                 playlist_NodeAddItem( p_playlist,p_item,
                                       p_parent->pp_parents[0]->i_view,
                                       p_parent,
-                                      PLAYLIST_APPEND, PLAYLIST_END );
+                                      PLAYLIST_APPEND | PLAYLIST_PREPARSE,
+                                      PLAYLIST_END );
 
                 playlist_CopyParents( p_parent, p_item );
             }
@@ -561,6 +575,8 @@ static int ReadDir( playlist_t *p_playlist,
     if( ppsz_extensions ) free( ppsz_extensions );
     if( psz_ignore ) free( psz_ignore );
 
-    free( pp_dir_content );
+    for( i = 0; i < i_dir_content; i++ )
+        if( pp_dir_content[i] ) free( pp_dir_content[i] );
+    if( pp_dir_content ) free( pp_dir_content );
     return VLC_SUCCESS;
 }