Mercurial > audlegacy
comparison audacious/urldecode.c @ 0:cb178e5ad177 trunk
[svn] Import audacious source.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 03:06:47 -0700 |
parents | |
children | f12d7e208b43 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb178e5ad177 |
---|---|
1 /* BMP - Cross-platform multimedia player | |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public Licensse as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include "urldecode.h" | |
23 | |
24 #include <glib.h> | |
25 #include <stdio.h> | |
26 #include <string.h> | |
27 | |
28 #include "util.h" | |
29 | |
30 /* URL-decode a file: URL path, return NULL if it's not what we expect */ | |
31 gchar * | |
32 xmms_urldecode_path(const gchar * encoded_path) | |
33 { | |
34 const gchar *cur, *ext; | |
35 gchar *path, *tmp; | |
36 gint realchar; | |
37 | |
38 if (!encoded_path) | |
39 return NULL; | |
40 | |
41 if (!str_has_prefix_nocase(encoded_path, "file:")) | |
42 return NULL; | |
43 | |
44 cur = encoded_path + 5; | |
45 | |
46 if (str_has_prefix_nocase(cur, "//localhost")) | |
47 cur += 11; | |
48 | |
49 if (*cur == '/') | |
50 while (cur[1] == '/') | |
51 cur++; | |
52 | |
53 tmp = g_malloc0(strlen(cur) + 1); | |
54 | |
55 while ((ext = strchr(cur, '%')) != NULL) { | |
56 strncat(tmp, cur, ext - cur); | |
57 ext++; | |
58 cur = ext + 2; | |
59 if (!sscanf(ext, "%2x", &realchar)) { | |
60 /* Assume it is a literal '%'. Several file | |
61 * managers send unencoded file: urls on drag | |
62 * and drop. */ | |
63 realchar = '%'; | |
64 cur -= 2; | |
65 } | |
66 tmp[strlen(tmp)] = realchar; | |
67 } | |
68 | |
69 path = g_strconcat(tmp, cur, NULL); | |
70 g_free(tmp); | |
71 return path; | |
72 } | |
73 | |
74 gchar * | |
75 xmms_urldecode_plain(const gchar * encoded_path) | |
76 { | |
77 const gchar *cur, *ext; | |
78 gchar *path, *tmp; | |
79 gint realchar; | |
80 | |
81 if (!encoded_path) | |
82 return NULL; | |
83 | |
84 cur = encoded_path; | |
85 if (*cur == '/') | |
86 while (cur[1] == '/') | |
87 cur++; | |
88 | |
89 tmp = g_malloc0(strlen(cur) + 1); | |
90 | |
91 while ((ext = strchr(cur, '%')) != NULL) { | |
92 strncat(tmp, cur, ext - cur); | |
93 ext++; | |
94 cur = ext + 2; | |
95 if (!sscanf(ext, "%2x", &realchar)) { | |
96 /* | |
97 * Assume it is a literal '%'. Several file | |
98 * managers send unencoded file: urls on on | |
99 * drag and drop. | |
100 */ | |
101 realchar = '%'; | |
102 cur -= 2; | |
103 } | |
104 tmp[strlen(tmp)] = realchar; | |
105 } | |
106 | |
107 path = g_strconcat(tmp, cur, NULL); | |
108 g_free(tmp); | |
109 return path; | |
110 } |