From: Thierry FOURNIER Date: Thu, 7 May 2015 13:46:20 +0000 (+0200) Subject: MINOR: sample: add url_dec converter X-Git-Tag: v1.6-dev2~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82ff3c9b0584ae2fb56ff0a5433adb4e8acbe1b7;p=thirdparty%2Fhaproxy.git MINOR: sample: add url_dec converter This converter decodes an url-encoded string. It takes a string as input and returns string as output. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 98242d2a6a..c5e0e2105d 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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([,]) 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 diff --git a/src/proto_http.c b/src/proto_http.c index 957640ecef..cc0c367bf8 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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 }, }};