mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: sample: add hex converter
This new filter converts BIN type to its hexadecimal representation in STR type. It is used to keep the compatibility with the original bin2str cast. It will be useful when bin2str changes to copy the string as-is without encoding anymore.
This commit is contained in:
parent
d048d8b891
commit
2f49d6d17b
@ -9343,6 +9343,11 @@ The currently available list of transformation keywords include :
|
|||||||
after a string sample fetch function or after a transformation
|
after a string sample fetch function or after a transformation
|
||||||
keyword returning a string type. The result is of type string.
|
keyword returning a string type. The result is of type string.
|
||||||
|
|
||||||
|
hex Converts a binary input sample to an hex string containing two
|
||||||
|
hex digits per input byte. It is used to log or transfer hex
|
||||||
|
dumps of some binary input data in a way that can be reliably
|
||||||
|
transferred (eg: an SSL ID can be copied in a header).
|
||||||
|
|
||||||
ipmask(<mask>) Apply a mask to an IPv4 address, and use the result for
|
ipmask(<mask>) Apply a mask to an IPv4 address, and use the result for
|
||||||
lookups and storage. This can be used to make all hosts within
|
lookups and storage. This can be used to make all hosts within
|
||||||
a certain mask to share the same table entries and as such use
|
a certain mask to share the same table entries and as such use
|
||||||
|
18
src/sample.c
18
src/sample.c
@ -1089,6 +1089,23 @@ struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l
|
|||||||
/* These functions set the data type on return. */
|
/* These functions set the data type on return. */
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
|
static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp)
|
||||||
|
{
|
||||||
|
struct chunk *trash = get_trash_chunk();
|
||||||
|
unsigned char c;
|
||||||
|
int ptr = 0;
|
||||||
|
|
||||||
|
trash->len = 0;
|
||||||
|
while (ptr < smp->data.str.len && trash->len <= trash->size - 2) {
|
||||||
|
c = smp->data.str.str[ptr++];
|
||||||
|
trash->str[trash->len++] = hextab[(c >> 4) & 0xF];
|
||||||
|
trash->str[trash->len++] = hextab[c & 0xF];
|
||||||
|
}
|
||||||
|
smp->data.str = *trash;
|
||||||
|
smp->type = SMP_T_STR;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp)
|
static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -1225,6 +1242,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
|
|||||||
static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
||||||
{ "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 },
|
||||||
|
{ "hex", sample_conv_bin2hex, 0, NULL, SMP_T_BIN, SMP_T_STR },
|
||||||
{ "ipmask", sample_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 },
|
{ "ipmask", sample_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 },
|
||||||
{ NULL, NULL, 0, 0, 0 },
|
{ NULL, NULL, 0, 0, 0 },
|
||||||
}};
|
}};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user