changeset 1997:93c59698f5fd trunk

[svn] - NewVFS lives ;)
author nenolod
date Thu, 23 Nov 2006 20:06:19 -0800
parents 1abdcfc557d8
children 1e0503521702
files ChangeLog libaudacious/vfs.c libaudacious/vfs.h libaudacious/vfs_stdio.c
diffstat 4 files changed, 91 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 23 10:38:16 2006 -0800
+++ b/ChangeLog	Thu Nov 23 20:06:19 2006 -0800
@@ -1,3 +1,12 @@
+2006-11-23 18:38:16 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [2981]
+  - fix the %20 in playlist issue. Patch by external contributor Ralf 
+    Ertzinger <ralf@skytale.net>
+  
+  trunk/audacious/widgets/playlist_list.c |    2 ++
+  1 file changed, 2 insertions(+)
+
+
 2006-11-23 17:11:03 +0000  William Pitcock <nenolod@nenolod.net>
   revision [2979]
   - fix handlers
--- a/libaudacious/vfs.c	Thu Nov 23 10:38:16 2006 -0800
+++ b/libaudacious/vfs.c	Thu Nov 23 20:06:19 2006 -0800
@@ -1,4 +1,7 @@
-/*  This program is free software; you can redistribute it and/or modify
+/*  Audacious
+ *  Copyright (c) 2006 William Pitcock
+ *
+ *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
@@ -20,9 +23,23 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+static GList *vfs_transports = NULL;
+
+#define VFS_DEBUG
+
+#ifdef VFS_DEBUG
+# define DBG(x, args...) g_print(x, ## args);
+#else
+# define DBG(x, args...)
+#endif
+
 gboolean
-vfs_init(void)
+vfs_register_transport(VFSConstructor *vtable)
 {
+    DBG("registering transport [%s]\n", vtable->uri_id);
+
+    vfs_transports = g_list_append(vfs_transports, vtable);
+
     return TRUE;
 }
 
@@ -31,19 +48,57 @@
           const gchar * mode)
 {
     VFSFile *file;
+    gchar **vec;
+    VFSConstructor *vtable = NULL;
+    GList *node;
 
     if (!path || !mode)
 	return NULL;
 
-    file = g_new(VFSFile, 1);
+    vec = g_strsplit(path, "://", 2);
+
+    DBG("vec[0]: %s, vec[1]: %s\n", vec[0], vec[1]);
 
-    file->handle = fopen(path, mode);
+    /* special case: no transport specified, look for the "/" transport */
+    if (vec[1] == NULL)
+    {
+        for (node = vfs_transports; node != NULL; node = g_list_next(node))
+        {
+            vtable = (VFSConstructor *) node->data;
+
+            if (*vtable->uri_id == '/')
+                break;
+        }
+    }
+    else
+    {
+        for (node = vfs_transports; node != NULL; node = g_list_next(node))
+        {
+            vtable = (VFSConstructor *) node->data;
 
-    if (file->handle == NULL) {
-        g_free(file);
-        file = NULL;
+            if (!g_strcasecmp(vec[0], vtable->uri_id))
+                break;
+        }
+    }
+
+    /* no transport vtable has been registered, bail. */
+    if (vtable == NULL)
+    {
+        return NULL;
     }
 
+    file = vtable->vfs_fopen_impl(vec[1] ? vec[1] : vec[0], mode);
+
+    if (file == NULL)
+    {
+        return NULL;
+    }
+
+    file->uri = g_strdup(path);
+    file->base = vtable;
+
+    DBG("returning %p", file);
+
     return file;
 }
 
@@ -55,10 +110,8 @@
     if (file == NULL)
         return -1;
 
-    if (file->handle) {
-        if (fclose(file->handle) != 0)
-            ret = -1;
-    }
+    if (file->base->vfs_fclose_impl(file) != 0)
+        ret = -1;
 
     g_free(file);
 
@@ -74,7 +127,7 @@
     if (file == NULL)
         return 0;
 
-    return fread(ptr, size, nmemb, file->handle);
+    return file->base->vfs_fread_impl(ptr, size, nmemb, file);
 }
 
 size_t
@@ -86,19 +139,25 @@
     if (file == NULL)
         return 0;
 
-    return fwrite(ptr, size, nmemb, file->handle);
+    return file->base->vfs_fwrite_impl(ptr, size, nmemb, file);
 }
 
 gint
 vfs_getc(VFSFile *stream)
 {
-  return getc( stream->handle );
+    if (stream == NULL)
+        return -1;
+
+    return stream->base->vfs_getc_impl(stream);
 }
 
 gint
 vfs_ungetc(gint c, VFSFile *stream)
 {
-  return ungetc( c , stream->handle );
+    if (stream == NULL)
+        return -1;
+
+    return stream->base->vfs_ungetc_impl(c, stream);
 }
 
 gint
@@ -109,7 +168,7 @@
     if (file == NULL)
         return 0;
 
-    return fseek(file->handle, offset, whence);
+    return file->base->vfs_fseek_impl(file, offset, whence);
 }
 
 void
@@ -118,7 +177,7 @@
     if (file == NULL)
         return;
 
-    rewind(file->handle);
+    file->base->vfs_rewind_impl(file);
 }
 
 glong
@@ -127,7 +186,7 @@
     if (file == NULL)
         return 0;
 
-    return ftell(file->handle);
+    return file->base->vfs_ftell_impl(file);
 }
 
 gboolean
@@ -136,7 +195,7 @@
     if (file == NULL)
         return FALSE;
 
-    return (gboolean) feof(file->handle);
+    return (gboolean) file->base->vfs_feof_impl(file);
 }
 
 gboolean
@@ -163,5 +222,5 @@
     if (file == NULL)
         return -1;
 
-    return ftruncate(fileno(file->handle), size);
+    return file->base->vfs_truncate_impl(file, size);
 }
--- a/libaudacious/vfs.h	Thu Nov 23 10:38:16 2006 -0800
+++ b/libaudacious/vfs.h	Thu Nov 23 20:06:19 2006 -0800
@@ -92,6 +92,8 @@
 extern int vfs_fprintf(VFSFile *stream, gchar const *format, ...)
     __attribute__ ((__format__ (__printf__, 2, 3)));
 
+extern gboolean vfs_register_transport(VFSConstructor *vtable);
+
 G_END_DECLS
 
 #endif /* VFS_H */
--- a/libaudacious/vfs_stdio.c	Thu Nov 23 10:38:16 2006 -0800
+++ b/libaudacious/vfs_stdio.c	Thu Nov 23 20:06:19 2006 -0800
@@ -54,8 +54,6 @@
             ret = -1;
     }
 
-    g_free(file);
-
     return ret;
 }
 
@@ -172,7 +170,6 @@
 	stdio_vfs_truncate_impl
 };
 
-#if 0
 gboolean
 vfs_init(void)
 {
@@ -180,4 +177,4 @@
     vfs_register_transport(&file_const);
     return TRUE;
 }
-#endif
+