Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/filesystems/curlftpfs/files/patch-path__utils.c
16464 views
1
--- path_utils.c.orig 2007-11-20 19:27:58 UTC
2
+++ path_utils.c
3
@@ -92,3 +92,72 @@ char* get_dir_path(const char* path) {
4
5
return ret;
6
}
7
+
8
+/*
9
+ * the chars not needed to be escaped:
10
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
11
+ */
12
+static inline int is_unreserved_rfc3986(char c)
13
+{
14
+ int is_locase_alpha = (c >= 'a' && c <= 'z');
15
+ int is_upcase_alpha = (c >= 'A' && c <= 'Z');
16
+ int is_digit = (c >= '0' && c <= '9');
17
+ int is_special = c == '-'
18
+ || c == '.'
19
+ || c == '_'
20
+ || c == '~';
21
+ int is_unreserved = is_locase_alpha
22
+ || is_upcase_alpha
23
+ || is_digit
24
+ || is_special;
25
+
26
+ return is_unreserved;
27
+}
28
+
29
+static inline int is_unreserved(char c)
30
+{
31
+ return is_unreserved_rfc3986(c) || c == '/';
32
+}
33
+
34
+char* path_to_uri(const char* path)
35
+{
36
+ static const char hex[] = "0123456789ABCDEF";
37
+ size_t path_len = strlen(path);
38
+ size_t host_len = strlen(ftpfs.host);
39
+ /* at worst: c -> %XX */
40
+ char * encoded_path = malloc (3 * path_len + 1);
41
+ const char * s = path;
42
+ char * d = encoded_path;
43
+
44
+ /*
45
+ * 'path' is always prefixed with 'ftpfs.host'
46
+ */
47
+ memcpy (d, ftpfs.host, host_len);
48
+ s += host_len;
49
+ d += host_len;
50
+
51
+ for (; *s; ++s)
52
+ {
53
+ char c = *s;
54
+ if (is_unreserved (c))
55
+ {
56
+ *d++ = c;
57
+ }
58
+ else
59
+ {
60
+ unsigned int hi = ((unsigned)c >> 4) & 0xF;
61
+ unsigned int lo = ((unsigned)c >> 0) & 0xF;
62
+ *d++ = '%';
63
+ *d++ = hex[hi];
64
+ *d++ = hex[lo];
65
+ }
66
+ }
67
+ *d = '\0';
68
+
69
+ return encoded_path;
70
+}
71
+
72
+void free_uri(char* path)
73
+{
74
+ free(path);
75
+}
76
77