]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
Custom lock for interaction
[vlc] / modules / access / directory.c
index aba105f1487285d1517a92f9017659e98541fa7e..00d792e6e6c1624acb5bf9cc5808846d42148e46 100644 (file)
@@ -78,22 +78,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 ()
 
 
 /*****************************************************************************
@@ -125,8 +125,6 @@ struct access_sys_t
     DIR *handle;
     char *ignored_exts;
     int mode;
-    int i_item_count;
-    char *psz_xspf_extension;
 };
 
 static block_t *Block( access_t * );
@@ -173,8 +171,6 @@ static int Open( vlc_object_t *p_this )
     p_sys->current = NULL;
     p_sys->handle = handle;
     p_sys->ignored_exts = var_CreateGetString (p_access, "ignore-filetypes");
-    p_sys->i_item_count = 0;
-    p_sys->psz_xspf_extension = strdup( "" );
 
     /* Handle mode */
     char *psz = var_CreateGetString( p_access, "recursive" );
@@ -215,7 +211,6 @@ static void Close( vlc_object_t * p_this )
     }
     if (p_sys->handle != NULL)
         closedir (p_sys->handle); /* corner case,:Block() not called ever */
-    free (p_sys->psz_xspf_extension);
     free (p_sys->ignored_exts);
     free (p_sys);
 }
@@ -269,7 +264,7 @@ static block_t *Block (access_t *p_access)
     {   /* Startup: send the XSPF header */
         static const char header[] =
             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-            "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\" xmlns:vlc=\"http://www.videolan.org/vlc/playlist/ns/0/\">\n"
+            "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
             " <trackList>\n";
         block_t *block = block_Alloc (sizeof (header) - 1);
         if (!block)
@@ -310,41 +305,22 @@ static block_t *Block (access_t *p_access)
 
         if (p_sys->current == NULL)
         {   /* End of XSPF playlist */
-            char *footer;
-            int len = asprintf( &footer, " </trackList>\n" \
-                " <extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" \
-                "%s" \
-                " </extension>\n" \
-                "</playlist>\n", p_sys->psz_xspf_extension );
-            if( len < 0 )
-                goto fatal;
+            static const char footer[] =
+                " </trackList>\n"
+                "</playlist>\n";
 
-            block_t *block = block_Alloc ( len );
+            block_t *block = block_Alloc (sizeof (footer) - 1);
             if (!block)
                 goto fatal;
-            memcpy (block->p_buffer, footer, len);
-            free( footer );
+            memcpy (block->p_buffer, footer, sizeof (footer) - 1);
             p_access->info.b_eof = true;
             return block;
         }
-        else
-        {
-            /* This was the end of a "subnode" */
-            /* Write the ID to the extension */
-            char *old_xspf_extension = p_sys->psz_xspf_extension;
-            if (old_xspf_extension == NULL)
-                goto fatal;
-
-            int len2 = asprintf( &p_sys->psz_xspf_extension, "%s  </vlc:node>\n", old_xspf_extension );
-            if (len2 == -1)
-                goto fatal;
-            free( old_xspf_extension );
-        }
         return NULL;
     }
 
-    /* Skip current and parent directories */
-    if (entry[0] == '.' )
+    /* Skip current, parent and hidden directories */
+    if (entry[0] == '.')
         return NULL;
     /* Handle recursion */
     if (p_sys->mode != MODE_COLLAPSE)
@@ -360,7 +336,12 @@ 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)
@@ -372,17 +353,6 @@ static block_t *Block (access_t *p_access)
                 return NULL;
             }
             p_sys->current = sub;
-
-            /* Add node to xspf extension */
-            char *old_xspf_extension = p_sys->psz_xspf_extension;
-            if (old_xspf_extension == NULL)
-                goto fatal;
-
-            int len2 = asprintf( &p_sys->psz_xspf_extension, "%s  <vlc:node title=\"%s\">\n", old_xspf_extension, entry );
-            if (len2 == -1)
-                goto fatal;
-            free( old_xspf_extension );
-
             return NULL;
         }
         else
@@ -418,27 +388,12 @@ static block_t *Block (access_t *p_access)
     if (encoded == NULL)
         goto fatal;
     int len = asprintf (&entry,
-                        "  <track><location>file://%s/%s</location>\n" \
-                        "   <extension application=\"http://www.videolan.org/vlc/playlist/0\">\n" \
-                        "    <vlc:id>%d</vlc:id>\n" \
-                        "   </extension>\n" \
-                        "  </track>\n",
-                        current->uri, encoded, p_sys->i_item_count++);
+                        "  <track><location>file://%s/%s</location></track>\n",
+                        current->uri, encoded);
     free (encoded);
     if (len == -1)
         goto fatal;
 
-    /* Write the ID to the extension */
-    char *old_xspf_extension = p_sys->psz_xspf_extension;
-    if (old_xspf_extension == NULL)
-        goto fatal;
-
-    int len2 = asprintf( &p_sys->psz_xspf_extension, "%s   <vlc:item tid=\"%i\" />\n",
-                            old_xspf_extension, p_sys->i_item_count-1 );
-    if (len2 == -1)
-        goto fatal;
-    free( old_xspf_extension );
-
     /* TODO: new block allocator for malloc()ated data */
     block_t *block = block_Alloc (len);
     if (!block)
@@ -460,9 +415,8 @@ fatal:
  *****************************************************************************/
 static int Control( access_t *p_access, int i_query, va_list args )
 {
-    bool   *pb_bool;
-    int          *pi_int;
-    int64_t      *pi_64;
+    bool    *pb_bool;
+    int64_t *pi_64;
 
     switch( i_query )
     {
@@ -480,11 +434,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
             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;