]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: uri-util: Add functions for escaping (almost) all reserved URI characters.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 25 Oct 2018 11:34:52 +0000 (13:34 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 14 Nov 2018 12:37:19 +0000 (14:37 +0200)
src/lib/uri-util.c
src/lib/uri-util.h

index 4699e081ec3630eec0f7b1c62100627ae91ef2cd..4da0e47be955a9f83eaf945913f3f537d03b5951 100644 (file)
 #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);
+}
index 1546fd5232f4fdce1fa088b0e7cc8415f215f738..837e54c98736a9d40f3781c704ede964377611a4 100644 (file)
@@ -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