diff src/audacious/vfs.c @ 2579:364714f2d555 trunk

[svn] - urldecode playlist paths
author nenolod
date Mon, 26 Feb 2007 01:14:48 -0800
parents 9713b5a67cba
children 48288757d7c7
line wrap: on
line diff
--- a/src/audacious/vfs.c	Sun Feb 25 22:41:59 2007 -0800
+++ b/src/audacious/vfs.c	Mon Feb 26 01:14:48 2007 -0800
@@ -16,6 +16,7 @@
  */
 
 #include "vfs.h"
+#include "strings.h"
 #include <stdio.h>
 
 #include <unistd.h>
@@ -322,6 +323,49 @@
     return NULL;
 }
 
+static gchar *
+_vfs_urldecode_basic_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;
+}
+
 /**
  * vfs_file_test:
  * @path: A path to test.
@@ -337,10 +381,7 @@
     gchar *path2;
     gboolean ret;
 
-    if (strlen(path) > 5)
-        path2 = xmms_urldecode_plain(path + 5); /* skip file: */
-    else
-        path2 = g_strdup(path);
+    path2 = _vfs_urldecode_basic_path(path);
 
     ret = g_file_test(path2, test);