]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
spatializer: convert to audio filter2
[vlc] / modules / access / directory.c
index cb724dc87797e6cbabec296b0373201af3e45d80..73f65dbafe76ae6f2054ddcabacd3a831a5427e9 100644 (file)
 #ifdef HAVE_DIRENT_H
 #   include <dirent.h>
 #endif
+#ifdef __sun__
+static inline int dirfd (DIR *dir)
+{
+    return dir->dd_fd;
+}
+#endif
 
 #include <vlc_charset.h>
 #include <vlc_url.h>
+#include <vlc_strings.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -78,22 +85,22 @@ static const char *const psz_recursive_list_text[] = {
         "This is useful if you add directories that contain playlist files " \
         "for instance. Use a comma-separated list of extensions." )
 
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_shortname( N_("Directory" ) );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
-    set_description( N_("Standard filesystem directory input") );
-    set_capability( "access", 55 );
-    add_shortcut( "directory" );
-    add_shortcut( "dir" );
-    add_shortcut( "file" );
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_shortname( N_("Directory" ) )
+    set_subcategory( SUBCAT_INPUT_ACCESS )
+    set_description( N_("Standard filesystem directory input") )
+    set_capability( "access", 55 )
+    add_shortcut( "directory" )
+    add_shortcut( "dir" )
+    add_shortcut( "file" )
     add_string( "recursive", "expand" , NULL, RECURSIVE_TEXT,
-                RECURSIVE_LONGTEXT, false );
-      change_string_list( psz_recursive_list, psz_recursive_list_text, 0 );
-    add_string( "ignore-filetypes", "m3u,db,nfo,jpg,gif,sfv,txt,sub,idx,srt,cue",
-                NULL, IGNORE_TEXT, IGNORE_LONGTEXT, false );
-    set_callbacks( Open, Close );
-vlc_module_end();
+                RECURSIVE_LONGTEXT, false )
+      change_string_list( psz_recursive_list, psz_recursive_list_text, 0 )
+    add_string( "ignore-filetypes", "m3u,db,nfo,ini,jpg,jpeg,ljpg,gif,png,pgm,pgmyuv,pbm,pam,tga,bmp,pnm,xpm,xcf,pcx,tif,tiff,lbm,sfv,txt,sub,idx,srt,cue,ssa",
+                NULL, IGNORE_TEXT, IGNORE_LONGTEXT, false )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 
 /*****************************************************************************
@@ -143,7 +150,22 @@ static int Open( vlc_object_t *p_this )
     if( !p_access->psz_path )
         return VLC_EGENERIC;
 
-    DIR *handle = utf8_opendir (p_access->psz_path);
+    DIR *handle;
+    if (strcmp (p_access->psz_path, "-"))
+        handle = utf8_opendir (p_access->psz_path);
+    else
+    {
+#if 0   /* This won't work yet, it generates paths like "-/music.ogg".
+         * We'd need to use openat() here and in the file access... */
+        int fd = dup (0);
+        handle = fdopendir (fd);
+        if (handle == NULL)
+            close (fd);
+#else
+        return VLC_EGENERIC;
+#endif
+    }
+
     if (handle == NULL)
         return VLC_EGENERIC;
 
@@ -205,27 +227,6 @@ static void Close( vlc_object_t * p_this )
     free (p_sys);
 }
 
-/**
- * URI-encodes a file path. The only reserved characters is slash.
- */
-static char *encode_path (const char *path)
-{
-    static const char sep[]= "%2F";
-    char *enc = encode_URI_component (path), *ptr = enc;
-
-    if (enc == NULL)
-        return NULL;
-
-    /* Replace '%2F' with '/'. TODO: extend encode_URI*() */
-    /* (On Windows, both ':' and '\\' will be encoded) */
-    while ((ptr = strstr (ptr, sep)) != NULL)
-    {
-        *ptr++ = '/';
-        memmove (ptr, ptr + 2, strlen (ptr) - 1);
-    }
-    return enc;
-}
-
 /* Detect directories that recurse into themselves. */
 static bool has_inode_loop (const directory_t *dir)
 {
@@ -238,6 +239,7 @@ static bool has_inode_loop (const directory_t *dir)
             return true;
 #else
 # define fstat( fd, st ) (0)
+    VLC_UNUSED( dir );
 #endif
     return false;
 }
@@ -271,7 +273,7 @@ static block_t *Block (access_t *p_access)
         current->parent = NULL;
         current->handle = p_sys->handle;
         strcpy (current->path, p_access->psz_path);
-        current->uri = encode_path (current->path);
+        current->uri = make_URI (current->path);
         if ((current->uri == NULL)
          || fstat (dirfd (current->handle), &current->st))
         {
@@ -291,6 +293,7 @@ static block_t *Block (access_t *p_access)
     {   /* End of directory, go back to parent */
         closedir (current->handle);
         p_sys->current = current->parent;
+        free (current->uri);
         free (current);
 
         if (p_sys->current == NULL)
@@ -328,16 +331,22 @@ static block_t *Block (access_t *p_access)
         return NULL;
     }
 
-    /* Skip current and parent directories */
-    if (entry[0] == '.' )
+    /* Skip current, parent and hidden directories */
+    if (entry[0] == '.')
+    {
+        free (entry);
         return NULL;
+    }
     /* Handle recursion */
     if (p_sys->mode != MODE_COLLAPSE)
     {
         directory_t *sub = malloc (sizeof (*sub) + strlen (current->path) + 1
                                                  + strlen (entry));
         if (sub == NULL)
+        {
+            free (entry);
             return NULL;
+        }
         sprintf (sub->path, "%s/%s", current->path, entry);
 
         DIR *handle = utf8_opendir (sub->path);
@@ -345,14 +354,21 @@ static block_t *Block (access_t *p_access)
         {
             sub->parent = current;
             sub->handle = handle;
-            sub->uri = encode_path (sub->path);
+
+            char *encoded = encode_URI_component (entry);
+            if ((encoded == NULL)
+             || (asprintf (&sub->uri, "%s/%s", current->uri, encoded) == -1))
+                 sub->uri = NULL;
+            free (encoded);
 
             if ((p_sys->mode == MODE_NONE)
              || fstat (dirfd (handle), &sub->st)
              || has_inode_loop (sub)
              || (sub->uri == NULL))
             {
+                free (entry);
                 closedir (handle);
+                free (sub->uri);
                 free (sub);
                 return NULL;
             }
@@ -361,13 +377,23 @@ static block_t *Block (access_t *p_access)
             /* Add node to xspf extension */
             char *old_xspf_extension = p_sys->psz_xspf_extension;
             if (old_xspf_extension == NULL)
+            {
+                free (entry);
                 goto fatal;
+            }
 
-            int len2 = asprintf( &p_sys->psz_xspf_extension, "%s  <vlc:node title=\"%s\">\n", old_xspf_extension, entry );
-            if (len2 == -1)
+            char *title = convert_xml_special_chars (entry);
+            free (entry);
+            if (title == NULL
+             || asprintf (&p_sys->psz_xspf_extension, "%s"
+                          "  <vlc:node title=\"%s\">\n", old_xspf_extension,
+                          title) == -1)
+            {
+                free (title);
                 goto fatal;
-            free( old_xspf_extension );
-
+            }
+            free (title);
+            free (old_xspf_extension);
             return NULL;
         }
         else
@@ -390,7 +416,10 @@ static block_t *Block (access_t *p_access)
 
                 if (type + extlen == end
                  && !strncasecmp (ext, type, extlen))
+                {
+                    free (entry);
                     return NULL;
+                }
 
                 if (*end == '\0')
                     break;
@@ -403,7 +432,7 @@ static block_t *Block (access_t *p_access)
     if (encoded == NULL)
         goto fatal;
     int len = asprintf (&entry,
-                        "  <track><location>file://%s/%s</location>\n" \
+                        "  <track><location>%s/%s</location>\n" \
                         "   <extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" \
                         "    <vlc:id>%d</vlc:id>\n" \
                         "   </extension>\n" \
@@ -445,34 +474,22 @@ fatal:
  *****************************************************************************/
 static int Control( access_t *p_access, int i_query, va_list args )
 {
-    bool   *pb_bool;
-    int          *pi_int;
-    int64_t      *pi_64;
-
     switch( i_query )
     {
         /* */
         case ACCESS_CAN_SEEK:
         case ACCESS_CAN_FASTSEEK:
-            pb_bool = (bool*)va_arg( args, bool* );
-            *pb_bool = false;
+            *va_arg( args, bool* ) = false;
             break;
 
         case ACCESS_CAN_PAUSE:
         case ACCESS_CAN_CONTROL_PACE:
-            pb_bool = (bool*)va_arg( args, bool* );
-            *pb_bool = true;
+            *va_arg( args, bool* ) = true;
             break;
 
         /* */
-        case ACCESS_GET_MTU:
-            pi_int = (int*)va_arg( args, int * );
-            *pi_int = 0;
-            break;
-
         case ACCESS_GET_PTS_DELAY:
-            pi_64 = (int64_t*)va_arg( args, int64_t * );
-            *pi_64 = DEFAULT_PTS_DELAY * 1000;
+            *va_arg( args, int64_t * ) = DEFAULT_PTS_DELAY * 1000;
             break;
 
         /* */