MINOR: ssl: adds sample converter base64 for binary type.
The new converter encode binary type sample to base64 string.
i.e. : ssl_c_serial,base64
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 8c2c0b0..3d4aee7 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -9535,6 +9535,11 @@
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 7001f36..a1e8012 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -20,6 +20,7 @@
#include <common/chunk.h>
#include <common/standard.h>
#include <common/uri_auth.h>
+#include <common/base64.h>
#include <proto/arg.h>
#include <proto/auth.h>
@@ -1172,6 +1173,23 @@
/* 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 @@
/* Note: must not be declared <const> 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 },