changeset 3161:6dd886b5c72b

revive stdio plugin for now. gio cannot write id3 tags.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 13 Jul 2009 23:53:41 +0900
parents 2fa63d8ef645
children e387614b9be9
files configure.ac src/stdio/Makefile src/stdio/stdio.c
diffstat 3 files changed, 299 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sun May 24 14:40:10 2009 +0900
+++ b/configure.ac	Mon Jul 13 23:53:41 2009 +0900
@@ -129,7 +129,8 @@
 GENERAL_PLUGINS="song_change alarm skins vfstrace"
 VISUALIZATION_PLUGINS="blur_scope spectrum"
 CONTAINER_PLUGINS="m3u pls"
-TRANSPORT_PLUGINS="gio"
+#TRANSPORT_PLUGINS="gio"
+TRANSPORT_PLUGINS="stdio"
 
 dnl Check for Audacious
 
@@ -1756,7 +1757,8 @@
 echo
 echo "  Transport"
 echo "  ---------"
-echo "  gio transport:                          yes"
+echo "  stdio transport:                        yes"
+#echo "  gio transport:                          yes"
 echo "  neon-based http/https:                  $have_neon"
 echo "  libmms-based mms:                       $have_mms"
 echo "  lastfm transport:                       $have_lastfm"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stdio/Makefile	Mon Jul 13 23:53:41 2009 +0900
@@ -0,0 +1,12 @@
+PLUGIN = stdio${PLUGIN_SUFFIX}
+
+SRCS = stdio.c
+
+include ../../buildsys.mk
+include ../../extra.mk
+
+plugindir := ${plugindir}/${TRANSPORT_PLUGIN_DIR}
+
+CFLAGS += ${PLUGIN_CFLAGS}
+CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS}  ${GTK_CFLAGS} ${GLIB_CFLAGS}  ${ARCH_DEFINES} ${XML_CPPFLAGS} -I../..
+LIBS += ${GTK_LIBS} ${GLIB_LIBS}  ${XML_LIBS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/stdio/stdio.c	Mon Jul 13 23:53:41 2009 +0900
@@ -0,0 +1,283 @@
+/*  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.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include <audlegacy/plugin.h>
+#include <stdio.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <string.h>
+
+static gchar *
+aud_vfs_stdio_urldecode_path(const gchar * encoded_path)
+{
+    const gchar *cur, *ext;
+    gchar *path, *tmp;
+    gint realchar;
+
+    if (!encoded_path)
+        return NULL;
+
+    if (!aud_str_has_prefix_nocase(encoded_path, "file:"))
+        return NULL;
+
+    cur = encoded_path + 5;
+
+    if (aud_str_has_prefix_nocase(cur, "//localhost"))
+        cur += 11;
+
+    if (*cur == '/')
+        while (cur[1] == '/')
+            cur++;
+
+    tmp = g_malloc0(strlen(cur) + 1);
+
+    while ((ext = strchr(cur, '%')) != NULL) {
+        strncat(tmp, cur, ext - cur);
+        ext++;
+        cur = ext + 2;
+        if (!sscanf(ext, "%2x", &realchar)) {
+            /* Assume it is a literal '%'.  Several file
+             * managers send unencoded file: urls on drag
+             * and drop. */
+            realchar = '%';
+            cur -= 2;
+        }
+        tmp[strlen(tmp)] = realchar;
+    }
+
+    path = g_strconcat(tmp, cur, NULL);
+    g_free(tmp);
+    return path;
+}
+
+VFSFile *
+stdio_aud_vfs_fopen_impl(const gchar * path,
+          const gchar * mode)
+{
+    VFSFile *file;
+    gchar *decpath;
+
+    if (!path || !mode)
+	    return NULL;
+
+    decpath = aud_vfs_stdio_urldecode_path(path);
+
+    file = g_new(VFSFile, 1);
+
+    file->handle = fopen(decpath != NULL ? decpath : path, mode);
+
+    g_free(decpath);
+
+    if (file->handle == NULL) {
+        g_free(file);
+        file = NULL;
+    }
+
+    return file;
+}
+
+gint
+stdio_aud_vfs_fclose_impl(VFSFile * file)
+{
+    gint ret = 0;
+
+    if (file == NULL)
+        return -1;
+
+    if (file->handle)
+    {
+        FILE *handle = (FILE *) file->handle;
+
+        if (fclose(handle) != 0)
+            ret = -1;
+        file->handle = NULL;
+    }
+
+    return ret;
+}
+
+size_t
+stdio_aud_vfs_fread_impl(gpointer ptr,
+          size_t size,
+          size_t nmemb,
+          VFSFile * file)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return 0;
+
+    handle = (FILE *) file->handle;
+
+    return fread(ptr, size, nmemb, handle);
+}
+
+size_t
+stdio_aud_vfs_fwrite_impl(gconstpointer ptr,
+           size_t size,
+           size_t nmemb,
+           VFSFile * file)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return 0;
+
+    handle = (FILE *) file->handle;
+
+    return fwrite(ptr, size, nmemb, handle);
+}
+
+gint
+stdio_aud_vfs_getc_impl(VFSFile *stream)
+{
+  FILE *handle = (FILE *) stream->handle;
+
+  return getc( handle );
+}
+
+gint
+stdio_aud_vfs_ungetc_impl(gint c, VFSFile * file)
+{
+    FILE *handle;
+    
+    if (file == NULL)
+        return -1;
+	
+	handle = (FILE *) file->handle;
+	
+    return ungetc(c, handle);
+}
+
+gint
+stdio_aud_vfs_fseek_impl(VFSFile * file,
+          glong offset,
+          gint whence)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return 0;
+
+    handle = (FILE *) file->handle;
+
+    return fseek(handle, offset, whence);
+}
+
+void
+stdio_aud_vfs_rewind_impl(VFSFile * file)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return;
+
+    handle = (FILE *) file->handle;
+
+    rewind(handle);
+}
+
+glong
+stdio_aud_vfs_ftell_impl(VFSFile * file)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return 0;
+
+    handle = (FILE *) file->handle;
+
+    return ftell(handle);
+}
+
+gboolean
+stdio_aud_vfs_feof_impl(VFSFile * file)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return FALSE;
+
+    handle = (FILE *) file->handle;
+
+    return (gboolean) feof(handle);
+}
+
+gint
+stdio_aud_vfs_truncate_impl(VFSFile * file, glong size)
+{
+    FILE *handle;
+
+    if (file == NULL)
+        return -1;
+
+    handle = (FILE *) file->handle;
+
+    return ftruncate(fileno(handle), size);
+}
+
+off_t
+stdio_aud_vfs_fsize_impl(VFSFile * file)
+{
+    FILE *handle;
+    struct stat s;
+
+    if (file == NULL)
+        return -1;
+
+    handle = (FILE *) file->handle;
+
+    if (fstat(fileno(handle), &s) == -1)
+        return -1;
+
+    return s.st_size;
+}
+
+VFSConstructor file_const = {
+	.uri_id = "file://",
+	.vfs_fopen_impl = stdio_aud_vfs_fopen_impl,
+	.vfs_fclose_impl = stdio_aud_vfs_fclose_impl,
+	.vfs_fread_impl = stdio_aud_vfs_fread_impl,
+	.vfs_fwrite_impl = stdio_aud_vfs_fwrite_impl,
+	.vfs_getc_impl = stdio_aud_vfs_getc_impl,
+	.vfs_ungetc_impl = stdio_aud_vfs_ungetc_impl,
+	.vfs_fseek_impl = stdio_aud_vfs_fseek_impl,
+	.vfs_rewind_impl = stdio_aud_vfs_rewind_impl,
+	.vfs_ftell_impl = stdio_aud_vfs_ftell_impl,
+	.vfs_feof_impl = stdio_aud_vfs_feof_impl,
+	.vfs_truncate_impl = stdio_aud_vfs_truncate_impl,
+	.vfs_fsize_impl = stdio_aud_vfs_fsize_impl
+};
+
+static void init(void)
+{
+	aud_vfs_register_transport(&file_const);
+}
+
+static void cleanup(void)
+{
+#if 0
+	aud_vfs_unregister_transport(&file_const);
+#endif
+}
+
+DECLARE_PLUGIN(stdio, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL);