Introduce a new urldecode_path() helper to resolve percent-encoded URL
portions back into the original binary form.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
return (char *)copy;
}
+
+char *urldecode_path(const char *filename)
+{
+ unsigned char *copy = (unsigned char *)xstrdup(filename);
+ unsigned char *in, *out;
+
+ for (in = copy, out = copy; *in != 0; in++) {
+ if (*in == '%' && isxdigit(in[1]) && isxdigit(in[2])) {
+ *out++ = hex2bin(in[1]) * 16 + hex2bin(in[2]);
+ in += 2;
+ }
+ else {
+ *out++ = *in;
+ }
+ }
+
+ *out = 0;
+
+ return (char *)copy;
+}
char *checksum_hex2bin(const char *src, size_t *len);
char *urlencode_path(const char *filename);
+char *urldecode_path(const char *filename);
#endif