MINOR: checks: add rbinary expect match type
The rbinary match works similarly to the rstring match type, however the
received data is rewritten as hex-string before the match operation is
done.
This allows using regexes on binary content even with the POSIX regex
engine.
[Cf: I slightly updated the patch. mem2hex function was removed and dump_binary
is used instead.]
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 6c1d986..13ce19c 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -3282,7 +3282,8 @@
expect->string = strdup(args[cur_arg + 1]);
expect->length = strlen(expect->string);
}
- else if (strcmp(ptr_arg, "rstring") == 0) {
+ else if (strcmp(ptr_arg, "rstring") == 0 ||
+ strcmp(ptr_arg, "rbinary") == 0) {
if (!*(args[cur_arg + 1])) {
ha_alert("parsing [%s:%d] : '%s %s %s' expects <regex> as an argument.\n",
file, linenum, args[0], args[1], ptr_arg);
@@ -3290,8 +3291,7 @@
goto out;
}
- expect->type = TCPCHK_EXPECT_REGEX;
-
+ expect->type = ((strcmp(ptr_arg, "rbinary") == 0) ? TCPCHK_EXPECT_REGEX_BINARY : TCPCHK_EXPECT_REGEX);
error = NULL;
if (!(expect->regex = regex_comp(args[cur_arg + 1], 1, 1, &error))) {
ha_alert("parsing [%s:%d] : '%s %s %s' : regular expression '%s': %s.\n",
@@ -3302,7 +3302,7 @@
}
}
else {
- ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', found '%s'.\n",
+ ha_alert("parsing [%s:%d] : '%s %s' only supports [!] 'binary', 'string', 'rstring', 'rbinary', found '%s'.\n",
file, linenum, args[0], args[1], ptr_arg);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;