]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add url_dec converter
authorThierry FOURNIER <tfournier@haproxy.com>
Thu, 7 May 2015 13:46:20 +0000 (15:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 May 2015 09:40:36 +0000 (11:40 +0200)
This converter decodes an url-encoded string. It takes a string as
input and returns string as output.

doc/configuration.txt
src/proto_http.c

index 98242d2a6aa989b22034b7bbdd4a1c669104e50e..c5e0e2105d13eef342a6c04baea1aea254552ffd 100644 (file)
@@ -11024,6 +11024,10 @@ upper
   sample fetch function or after a transformation keyword returning a string
   type. The result is of type string.
 
+url_dec
+  Takes an url-encoded string provided as input and returns the decoded
+  version as output. The input and the output are of type string.
+
 utime(<format>[,<offset>])
   Converts an integer supposed to contain a date since epoch to a string
   representing this date in UTC time using a format defined by the <format>
index 957640ecef9a406518da3aa6bf5397fd080c6e9c..cc0c367bf800db2889995ea6ddd452ba0515dfc7 100644 (file)
@@ -11953,6 +11953,28 @@ expect_comma:
        return smp->data.str.len != 0;
 }
 
+/* This fetch url-decode any input string. */
+static int sample_conv_url_dec(struct stream *stream, const struct arg *args,
+                               struct sample *smp, void *private)
+{
+       /* If the constant flag is set or if not size is avalaible at
+        * the end of the buffer, copy the string in other buffer
+         * before decoding.
+        */
+       if (smp->flags & SMP_F_CONST || smp->data.str.size <= smp->data.str.len) {
+               struct chunk *str = get_trash_chunk();
+               memcpy(str->str, smp->data.str.str, smp->data.str.len);
+               smp->data.str.str = str->str;
+               smp->data.str.size = str->size;
+               smp->flags &= ~SMP_F_CONST;
+       }
+
+       /* Add final \0 required by url_decode(), and convert the input string. */
+       smp->data.str.str[smp->data.str.len] = '\0';
+       smp->data.str.len = url_decode(smp->data.str.str);
+       return 1;
+}
+
 /* This function executes one of the set-{method,path,query,uri} actions. It
  * takes the string from the variable 'replace' with length 'len', then modifies
  * the relevant part of the request line accordingly. Then it updates various
@@ -12492,6 +12514,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
 static struct sample_conv_kw_list sample_conv_kws = {ILH, {
        { "http_date", sample_conv_http_date,  ARG1(0,SINT),     NULL, SMP_T_UINT, SMP_T_STR},
        { "language",  sample_conv_q_prefered, ARG2(1,STR,STR),  NULL, SMP_T_STR,  SMP_T_STR},
+       { "url_dec",   sample_conv_url_dec,    0,                NULL, SMP_T_STR,  SMP_T_STR},
        { NULL, NULL, 0, 0, 0 },
 }};