summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_string.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2019-09-16 20:17:42 +0300
committerValentin Bartenev <vbart@nginx.com>2019-09-16 20:17:42 +0300
commit64be8717bdc2f0f8f11cbb8d18a0f96d2c24c6d3 (patch)
tree1539675a0756c9356719fd6b679eabea840983dc /src/nxt_string.c
parentb5394c39568d9895d5c84862e7a209b76f98bea9 (diff)
downloadunit-64be8717bdc2f0f8f11cbb8d18a0f96d2c24c6d3.tar.gz
unit-64be8717bdc2f0f8f11cbb8d18a0f96d2c24c6d3.tar.bz2
Configuration: added ability to access object members with slashes.
Now URI encoding can be used to escape "/" in the request path: GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/
Diffstat (limited to 'src/nxt_string.c')
-rw-r--r--src/nxt_string.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/nxt_string.c b/src/nxt_string.c
index 7d8c1ce3..4d3b3954 100644
--- a/src/nxt_string.c
+++ b/src/nxt_string.c
@@ -451,3 +451,59 @@ nxt_strvers_match(u_char *version, u_char *prefix, size_t length)
return 0;
}
+
+
+u_char *
+nxt_decode_uri(u_char *dst, u_char *src, size_t length)
+{
+ u_char *end, ch;
+ uint8_t d0, d1;
+
+ static const uint8_t hex[256]
+ nxt_aligned(32) =
+ {
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 16, 16, 16, 16, 16,
+ 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ };
+
+ nxt_prefetch(&hex['0']);
+
+ end = src + length;
+
+ while (src < end) {
+ ch = *src++;
+
+ if (ch == '%') {
+ if (nxt_slow_path(end - src < 2)) {
+ return NULL;
+ }
+
+ d0 = hex[*src++];
+ d1 = hex[*src++];
+
+ if (nxt_slow_path((d0 | d1) >= 16)) {
+ return NULL;
+ }
+
+ ch = (d0 << 4) + d1;
+ }
+
+ *dst++ = ch;
+ }
+
+ return dst;
+}