From: Stephan Bosch Date: Thu, 25 Oct 2018 11:34:52 +0000 (+0200) Subject: lib: uri-util: Add functions for escaping (almost) all reserved URI characters. X-Git-Tag: 2.3.4~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cc8d26ae57ef45b08d0c1a6add7047a076c8b6a5;p=thirdparty%2Fdovecot%2Fcore.git lib: uri-util: Add functions for escaping (almost) all reserved URI characters. --- diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index 4699e081ec..4da0e47be9 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -102,6 +102,7 @@ #define CHAR_MASK_PFCHAR ((1<<0)|(1<<1)|(1<<3)|(1<<5)) #define CHAR_MASK_UCHAR ((1<<0)|(1<<1)|(1<<4)) #define CHAR_MASK_QCHAR ((1<<0)|(1<<1)|(1<<3)|(1<<5)|(1<<6)) +#define CHAR_MASK_UNRESERVED_PATH ((1<<0)|(1<<5)) static unsigned const char _uri_char_lookup[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00 @@ -1318,3 +1319,15 @@ void uri_append_fragment(string_t *out, const char *fragment) if (*fragment != '\0') uri_append_fragment_data(out, NULL, fragment); } + +void uri_append_unreserved(string_t *out, const char *data) +{ + uri_data_encode(out, _uri_char_lookup, CHAR_MASK_UNRESERVED, + NULL, data); +} + +void uri_append_unreserved_path(string_t *out, const char *data) +{ + uri_data_encode(out, _uri_char_lookup, CHAR_MASK_UNRESERVED_PATH, + NULL, data); +} diff --git a/src/lib/uri-util.h b/src/lib/uri-util.h index 1546fd5232..837e54c987 100644 --- a/src/lib/uri-util.h +++ b/src/lib/uri-util.h @@ -290,4 +290,9 @@ void uri_append_fragment_data(string_t *out, produced. Characters are percent-encoded when necessary. */ void uri_append_fragment(string_t *out, const char *fragment); +/* append data to the out buffer and escape any reserved character */ +void uri_append_unreserved(string_t *out, const char *data); +/* append data to the out buffer and escape any reserved character except '/' */ +void uri_append_unreserved_path(string_t *out, const char *data); + #endif