]>
Commit | Line | Data |
---|---|---|
517e249f | 1 | commit 167f7fc08fc8f6aedf864f3fc3c77b4c96a86f84 |
2 | Author: Marcin Banasiak <megabajt@pld-linux.org> | |
3 | Date: Sat May 30 12:13:31 2009 +0200 | |
4 | ||
5 | Decode strings that may be urlencoded before displaying. | |
6 | ||
7 | diff --git a/vfile/fetch.c b/vfile/fetch.c | |
8 | index 0a4ee5a..88d98dd 100644 | |
9 | --- a/vfile/fetch.c | |
10 | +++ b/vfile/fetch.c | |
11 | @@ -828,6 +828,39 @@ const char *vf_url_slim_s(const char *url, int maxl) | |
12 | return vf_url_slim(buf, sizeof(buf), url, maxl > 50 ? maxl : 60); | |
13 | } | |
14 | ||
15 | +char *vf_url_unescape(const char *url) | |
16 | +{ | |
17 | + char *unescaped = NULL; | |
18 | + int unesclen = 0; | |
19 | + | |
20 | + if (!url) | |
21 | + return NULL; | |
22 | + | |
23 | + unescaped = n_malloc(strlen(url) + 1); | |
24 | + | |
25 | + while (*url) { | |
26 | + char ch = *url; | |
27 | + | |
28 | + if (*url == '%' && isxdigit(url[1]) && isxdigit(url[2])) { | |
29 | + char str[3]; | |
30 | + | |
31 | + str[0] = url[1]; | |
32 | + str[1] = url[2]; | |
33 | + str[2] = '\0'; | |
34 | + | |
35 | + ch = (char)strtol(str, NULL, 16); | |
36 | + | |
37 | + url += 2; | |
38 | + } | |
39 | + | |
40 | + unescaped[unesclen++] = ch; | |
41 | + url++; | |
42 | + } | |
43 | + | |
44 | + unescaped[unesclen] = '\0'; | |
45 | + | |
46 | + return unescaped; | |
47 | +} | |
48 | ||
49 | int vf_find_external_command(char *cmdpath, int size, const char *cmd, | |
50 | const char *PATH) | |
51 | diff --git a/vfile/libvfile.sym b/vfile/libvfile.sym | |
52 | index c283fcb..d96d3a5 100644 | |
53 | --- a/vfile/libvfile.sym | |
54 | +++ b/vfile/libvfile.sym | |
55 | @@ -41,6 +41,7 @@ vf_url_proto | |
56 | vf_url_slim | |
57 | vf_url_slim_s | |
58 | vf_url_type | |
59 | +vf_url_unescape | |
60 | vf_userathost | |
61 | vf_valid_path | |
62 | vf_vlog | |
63 | diff --git a/vfile/vfetch.c b/vfile/vfetch.c | |
64 | index 7f23244..cb46dd1 100644 | |
65 | --- a/vfile/vfetch.c | |
66 | +++ b/vfile/vfetch.c | |
67 | @@ -219,8 +219,8 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags, | |
68 | struct vflock *vflock = NULL; | |
69 | struct vf_request *req = NULL; | |
70 | char destpath[PATH_MAX]; | |
71 | + char *url_unescaped = NULL; | |
72 | int rc = 0; | |
73 | - | |
74 | ||
75 | if (*vfile_verbose <= 0) | |
76 | flags |= VF_FETCH_NOLABEL|VF_FETCH_NOPROGRESS; | |
77 | @@ -239,11 +239,15 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags, | |
78 | ||
79 | if ((mod = select_vf_module(url)) == NULL) { /* no internal module found */ | |
80 | if ((flags & VF_FETCH_NOLABEL) == 0) { | |
81 | + url_unescaped = vf_url_unescape(url); | |
82 | + | |
83 | if (urlabel) | |
84 | vf_loginfo(_("Retrieving %s::%s...\n"), urlabel, | |
85 | - n_basenam(url)); | |
86 | + n_basenam(url_unescaped)); | |
87 | else | |
88 | - vf_loginfo(_("Retrieving %s...\n"), PR_URL(url)); | |
89 | + vf_loginfo(_("Retrieving %s...\n"), PR_URL(url_unescaped)); | |
90 | + | |
91 | + free(url_unescaped); | |
92 | } | |
93 | ||
94 | rc = vf_fetch_ext(url, destdir); | |
95 | @@ -298,11 +302,15 @@ int vfile__vf_fetch(const char *url, const char *dest_dir, unsigned flags, | |
96 | } | |
97 | ||
98 | if ((flags & VF_FETCH_NOLABEL) == 0) { | |
99 | + url_unescaped = vf_url_unescape(req->url); | |
100 | + | |
101 | if (urlabel) | |
102 | vf_loginfo(_("Retrieving %s::%s...\n"), urlabel, | |
103 | - n_basenam(req->url)); | |
104 | + n_basenam(url_unescaped)); | |
105 | else | |
106 | - vf_loginfo(_("Retrieving %s...\n"), PR_URL(req->url)); | |
107 | + vf_loginfo(_("Retrieving %s...\n"), PR_URL(url_unescaped)); | |
108 | + | |
109 | + free(url_unescaped); | |
110 | } | |
111 | ||
112 | if ((rc = do_vfile_req(REQTYPE_FETCH, mod, req, flags)) == 0) { | |
113 | diff --git a/vfile/vfile.h b/vfile/vfile.h | |
114 | index 0125a68..13501eb 100644 | |
115 | --- a/vfile/vfile.h | |
116 | +++ b/vfile/vfile.h | |
117 | @@ -182,6 +182,7 @@ const char *vf_url_hidepasswd_s(const char *url); | |
118 | const char *vf_url_slim(char *buf, int size, const char *url, int maxl); | |
119 | const char *vf_url_slim_s(const char *url, int maxl); | |
120 | ||
121 | +char *vf_url_unescape(const char *url); | |
122 | ||
123 | int vf_valid_path(const char *path); | |
124 | int vf_mkdir(const char *path); |