changeset 2071:b9c6f1305c99 trunk

[svn] - move urldecode to libaudacious - use urldecode in the VFS layer
author nenolod
date Fri, 08 Dec 2006 15:41:46 -0800
parents 6a2d368a88de
children e4c359265eb0
files ChangeLog audacious/Makefile audacious/urldecode.c audacious/urldecode.h libaudacious/Makefile libaudacious/urldecode.c libaudacious/urldecode.h libaudacious/vfs.c
diffstat 8 files changed, 153 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 08 03:26:45 2006 -0800
+++ b/ChangeLog	Fri Dec 08 15:41:46 2006 -0800
@@ -1,3 +1,11 @@
+2006-12-08 11:26:45 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [3143]
+  - don't free the VFS handle here, just our private handle.
+  
+  trunk/libaudacious/vfs_buffer.c |    2 --
+  1 file changed, 2 deletions(-)
+
+
 2006-12-08 10:26:36 +0000  William Pitcock <nenolod@nenolod.net>
   revision [3141]
   - make sure handle->base is a constpointer.
--- a/audacious/Makefile	Fri Dec 08 03:26:45 2006 -0800
+++ b/audacious/Makefile	Fri Dec 08 15:41:46 2006 -0800
@@ -65,7 +65,6 @@
 	hints.c \
 	about.c credits.c \
 	getopt.c getopt1.c \
-	urldecode.c \
 	iir.c \
 	iir_cfs.c \
 	iir_fpu.c
--- a/audacious/urldecode.c	Fri Dec 08 03:26:45 2006 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-/*  BMP - Cross-platform multimedia player
- *  Copyright (C) 2003-2004  BMP development team.
- *
- *  Based on XMMS:
- *  Copyright (C) 1998-2003  XMMS development team.
- *
- *  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 "urldecode.h"
-
-#include <glib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "util.h"
-
-/* URL-decode a file: URL path, return NULL if it's not what we expect */
-gchar *
-xmms_urldecode_path(const gchar * encoded_path)
-{
-    const gchar *cur, *ext;
-    gchar *path, *tmp;
-    gint realchar;
-
-    if (!encoded_path)
-        return NULL;
-
-    if (!str_has_prefix_nocase(encoded_path, "file:"))
-        return NULL;
-
-    cur = encoded_path + 5;
-
-    if (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;
-}
-
-gchar *
-xmms_urldecode_plain(const gchar * encoded_path)
-{
-    const gchar *cur, *ext;
-    gchar *path, *tmp;
-    gint realchar;
-
-    if (!encoded_path)
-        return NULL;
-
-    cur = encoded_path;
-    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 on
-             * drag and drop.
-             */
-            realchar = '%';
-            cur -= 2;
-        }
-        tmp[strlen(tmp)] = realchar;
-    }
-
-    path = g_strconcat(tmp, cur, NULL);
-    g_free(tmp);
-    return path;
-}
--- a/audacious/urldecode.h	Fri Dec 08 03:26:45 2006 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*  BMP - Cross-platform multimedia player
- *  Copyright (C) 2003-2004  BMP development team.
- *
- *  Based on XMMS:
- *  Copyright (C) 1998-2003  XMMS development team.
- *
- *  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 <glib.h>
-
-gchar *xmms_urldecode_path(const gchar *);
-gchar *xmms_urldecode_plain(const gchar *);
--- a/libaudacious/Makefile	Fri Dec 08 03:26:45 2006 -0800
+++ b/libaudacious/Makefile	Fri Dec 08 15:41:46 2006 -0800
@@ -31,13 +31,14 @@
 	util.c \
 	formatter.c \
 	titlestring.c \
-	xconvert.c
+	xconvert.c \
+	urldecode.c
 
 OBJECTS = ${SOURCES:.c=.o}
 
 HEADERS = \
 	vfs.h vfs_buffer.h rcfile.h configdb.h \
-	beepctrl.h dirbrowser.h \
+	beepctrl.h dirbrowser.h urldecode.h \
 	formatter.h titlestring.h xconvert.h
 
 include ../mk/objective.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libaudacious/urldecode.c	Fri Dec 08 15:41:46 2006 -0800
@@ -0,0 +1,110 @@
+/*  BMP - Cross-platform multimedia player
+ *  Copyright (C) 2003-2004  BMP development team.
+ *
+ *  Based on XMMS:
+ *  Copyright (C) 1998-2003  XMMS development team.
+ *
+ *  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 "urldecode.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "util.h"
+
+/* URL-decode a file: URL path, return NULL if it's not what we expect */
+gchar *
+xmms_urldecode_path(const gchar * encoded_path)
+{
+    const gchar *cur, *ext;
+    gchar *path, *tmp;
+    gint realchar;
+
+    if (!encoded_path)
+        return NULL;
+
+    if (!str_has_prefix_nocase(encoded_path, "file:"))
+        return NULL;
+
+    cur = encoded_path + 5;
+
+    if (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;
+}
+
+gchar *
+xmms_urldecode_plain(const gchar * encoded_path)
+{
+    const gchar *cur, *ext;
+    gchar *path, *tmp;
+    gint realchar;
+
+    if (!encoded_path)
+        return NULL;
+
+    cur = encoded_path;
+    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 on
+             * drag and drop.
+             */
+            realchar = '%';
+            cur -= 2;
+        }
+        tmp[strlen(tmp)] = realchar;
+    }
+
+    path = g_strconcat(tmp, cur, NULL);
+    g_free(tmp);
+    return path;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libaudacious/urldecode.h	Fri Dec 08 15:41:46 2006 -0800
@@ -0,0 +1,25 @@
+/*  BMP - Cross-platform multimedia player
+ *  Copyright (C) 2003-2004  BMP development team.
+ *
+ *  Based on XMMS:
+ *  Copyright (C) 1998-2003  XMMS development team.
+ *
+ *  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 <glib.h>
+
+gchar *xmms_urldecode_path(const gchar *);
+gchar *xmms_urldecode_plain(const gchar *);
--- a/libaudacious/vfs.c	Fri Dec 08 03:26:45 2006 -0800
+++ b/libaudacious/vfs.c	Fri Dec 08 15:41:46 2006 -0800
@@ -23,6 +23,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "urldecode.h"
+
 static GList *vfs_transports = NULL;
 
 #ifdef VFS_DEBUG
@@ -64,11 +66,14 @@
     gchar **vec;
     VFSConstructor *vtable = NULL;
     GList *node;
+    gchar *decpath;
 
     if (!path || !mode)
 	return NULL;
 
-    vec = g_strsplit(path, "://", 2);
+    decpath = xmms_urldecode_plain(path);
+
+    vec = g_strsplit(decpath, "://", 2);
 
     /* special case: no transport specified, look for the "/" transport */
     if (vec[1] == NULL)
@@ -111,6 +116,7 @@
     file->base = vtable;
 
     g_strfreev(vec);
+    g_free(decpath);
 
     return file;
 }