Mercurial > audlegacy
diff audacious/util.c @ 2074:c725daec3849 trunk
[svn] - move xmms_urldecode_path() back into main binary
author | nenolod |
---|---|
date | Sat, 09 Dec 2006 02:01:53 -0800 |
parents | d3a62e1075e2 |
children | bc47a2129067 |
line wrap: on
line diff
--- a/audacious/util.c Sat Dec 09 01:55:27 2006 -0800 +++ b/audacious/util.c Sat Dec 09 02:01:53 2006 -0800 @@ -1926,3 +1926,48 @@ } return dblimg; } + +/* 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; +} +