diff --git a/doc/configuration.txt b/doc/configuration.txt index 8c2c0b035..3d4aee702 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -9535,6 +9535,11 @@ support some arguments (eg: a netmask) which must be passed in parenthesis. The currently available list of transformation keywords include : +base64 + Converts a binary input sample to a base64 string. It is used to log or + transfer binary content in a way that can be reliably transferred (eg: + an SSL ID can be copied in a header). + lower Convert a string sample to lower case. This can only be placed after a string sample fetch function or after a transformation keyword returning a string diff --git a/src/sample.c b/src/sample.c index 7001f36ab..a1e80124f 100644 --- a/src/sample.c +++ b/src/sample.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1172,6 +1173,23 @@ struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l /* These functions set the data type on return. */ /*****************************************************************/ +static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp) +{ + struct chunk *trash = get_trash_chunk(); + int b64_len; + + trash->len = 0; + b64_len = a2base64(smp->data.str.str, smp->data.str.len, trash->str, trash->size); + if (b64_len < 0) + return 0; + + trash->len = b64_len; + smp->data.str = *trash; + smp->type = SMP_T_STR; + smp->flags &= ~SMP_F_CONST; + return 1; +} + static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp) { struct chunk *trash = get_trash_chunk(); @@ -1329,6 +1347,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { /* Note: must not be declared as its list will be overwritten */ static struct sample_conv_kw_list sample_conv_kws = {ILH, { + { "base64", sample_conv_bin2base64,0, NULL, SMP_T_BIN, SMP_T_STR }, { "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, { "lower", sample_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR }, { "hex", sample_conv_bin2hex, 0, NULL, SMP_T_BIN, SMP_T_STR },