annotate audacious/urldecode.c @ 2014:ae33464ff918 trunk

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