mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MINOR: sample: Add b64dec sample converter
Add "b64dec" as a new converter which can be used to decode a base64 encoded string into its binary representation. It performs the inverse operation of the "base64" converter.
This commit is contained in:
parent
64920538fc
commit
1bfc24ba03
@ -12410,6 +12410,10 @@ and(<value>)
|
|||||||
This prefix is followed by a name. The separator is a '.'. The name may only
|
This prefix is followed by a name. The separator is a '.'. The name may only
|
||||||
contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
|
contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
|
||||||
|
|
||||||
|
b64dec
|
||||||
|
Converts (decodes) a base64 encoded input string to its binary
|
||||||
|
representation. It performs the inverse operation of base64().
|
||||||
|
|
||||||
base64
|
base64
|
||||||
Converts a binary input sample to a base64 string. It is used to log or
|
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:
|
transfer binary content in a way that can be reliably transferred (eg:
|
||||||
|
18
src/sample.c
18
src/sample.c
@ -1464,6 +1464,23 @@ static int sample_conv_debug(const struct arg *arg_p, struct sample *smp, void *
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int sample_conv_base642bin(const struct arg *arg_p, struct sample *smp, void *private)
|
||||||
|
{
|
||||||
|
struct chunk *trash = get_trash_chunk();
|
||||||
|
int bin_len;
|
||||||
|
|
||||||
|
trash->len = 0;
|
||||||
|
bin_len = base64dec(smp->data.u.str.str, smp->data.u.str.len, trash->str, trash->size);
|
||||||
|
if (bin_len < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
trash->len = bin_len;
|
||||||
|
smp->data.u.str = *trash;
|
||||||
|
smp->data.type = SMP_T_BIN;
|
||||||
|
smp->flags &= ~SMP_F_CONST;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp, void *private)
|
static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp, void *private)
|
||||||
{
|
{
|
||||||
struct chunk *trash = get_trash_chunk();
|
struct chunk *trash = get_trash_chunk();
|
||||||
@ -2714,6 +2731,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
|||||||
{ "debug", sample_conv_debug, 0, NULL, SMP_T_ANY, SMP_T_ANY },
|
{ "debug", sample_conv_debug, 0, NULL, SMP_T_ANY, SMP_T_ANY },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
{ "b64dec", sample_conv_base642bin,0, NULL, SMP_T_STR, SMP_T_BIN },
|
||||||
{ "base64", sample_conv_bin2base64,0, NULL, SMP_T_BIN, SMP_T_STR },
|
{ "base64", sample_conv_bin2base64,0, NULL, SMP_T_BIN, SMP_T_STR },
|
||||||
{ "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, 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 },
|
{ "lower", sample_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user