MINOR: sample: manage binary to string type convertion in stick-table and samples.
Binary type is converted to a null terminated hexa string.
diff --git a/src/sample.c b/src/sample.c
index 3eef4c3..b9e3c18 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -187,6 +187,22 @@
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 @@
/* 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 },
};
/*