mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: sample: manage binary to string type convertion in stick-table and samples.
Binary type is converted to a null terminated hexa string.
This commit is contained in:
parent
f6f4f7b9a6
commit
8ac33d99f2
20
src/sample.c
20
src/sample.c
@ -187,6 +187,22 @@ static int c_str2ipv6(struct sample *smp)
|
||||
return inet_pton(AF_INET6, smp->data.str.str, &smp->data.ipv6);
|
||||
}
|
||||
|
||||
static int c_bin2str(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;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int c_int2str(struct sample *smp)
|
||||
{
|
||||
struct chunk *trash = get_trash_chunk();
|
||||
@ -253,9 +269,9 @@ static sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = {
|
||||
/* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_ip2ipv6, c_ip2str, NULL, c_ip2str, NULL },
|
||||
/* IPV6 */ { NULL, NULL, NULL, NULL, c_none, c_ipv62str, NULL, c_ipv62str, NULL },
|
||||
/* STR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_none, c_none, c_none, c_none },
|
||||
/* BIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_none, NULL, c_none },
|
||||
/* BIN */ { NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_bin2str, c_none },
|
||||
/* CSTR */ { c_str2int, c_str2int, c_str2int, c_str2ip, c_str2ipv6, c_datadup, c_datadup, c_none, c_none },
|
||||
/* CBIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_datadup, NULL, c_none },
|
||||
/* CBIN */ { NULL, NULL, NULL, NULL, NULL, c_bin2str, c_datadup, c_bin2str, c_none },
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -504,6 +504,21 @@ static void *k_ip2str(struct sample *smp, union stktable_key_data *kdata, size_t
|
||||
return (void *)kdata->buf;
|
||||
}
|
||||
|
||||
static void *k_bin2str(struct sample *smp, union stktable_key_data *kdata, size_t *len)
|
||||
{
|
||||
unsigned char c;
|
||||
int ptr = 0;
|
||||
|
||||
*len = 0;
|
||||
while (ptr < smp->data.str.len && *len <= sizeof(kdata->buf) - 2) {
|
||||
c = smp->data.str.str[ptr++];
|
||||
kdata->buf[(*len)++] = hextab[(c >> 4) & 0xF];
|
||||
kdata->buf[(*len)++] = hextab[c & 0xF];
|
||||
}
|
||||
|
||||
return (void *)kdata->buf;
|
||||
}
|
||||
|
||||
static void *k_ipv62str(struct sample *smp, union stktable_key_data *kdata, size_t *len)
|
||||
{
|
||||
if (!inet_ntop(AF_INET6, &smp->data.ipv6, kdata->buf, sizeof(kdata->buf)))
|
||||
@ -578,9 +593,9 @@ static sample_to_key_fct sample_to_key[SMP_TYPES][STKTABLE_TYPES] = {
|
||||
/* IPV4 */ { k_ip2ip, k_ip2ipv6, k_ip2int, k_ip2str, NULL },
|
||||
/* IPV6 */ { NULL, k_ipv62ipv6, NULL, k_ipv62str, NULL },
|
||||
/* STR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str },
|
||||
/* BIN */ { NULL, NULL, NULL, NULL, k_str2str },
|
||||
/* BIN */ { NULL, NULL, NULL, k_bin2str, k_str2str },
|
||||
/* CSTR */ { k_str2ip, k_str2ipv6, k_str2int, k_str2str, k_str2str },
|
||||
/* CBIN */ { NULL, NULL, NULL, NULL , k_str2str },
|
||||
/* CBIN */ { NULL, NULL, NULL, k_bin2str, k_str2str },
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user