MINOR: cfgcond: remerge all arguments into a single line
Till now we were dealing with single-word expressions but in order to
extend the configuration condition language a bit more, we'll need to
support slightly more complex expressions involving operators, and we
must absolutely support spaces around them to keep them readable.
As all arguments are pointers to the same line with spaces replaced by
zeroes, we can trivially rebuild the whole line before calling the
condition evaluator, and remove the test for extraneous argument. This
is what this patch does.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 4cee8a7..fed8f7e 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -1889,13 +1889,11 @@
const char *errptr = NULL;
char *errmsg = NULL;
int cond;
+ char *w;
- if (*args[2]) {
- ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n",
- file, linenum, args[2], args[0]);
- err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT;
- break;
- }
+ /* remerge all words into a single expression */
+ for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ')
+ ;
nested_cond_lvl++;
if (nested_cond_lvl >= MAXNESTEDCONDS) {
@@ -1938,13 +1936,11 @@
const char *errptr = NULL;
char *errmsg = NULL;
int cond;
+ char *w;
- if (*args[2]) {
- ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n",
- file, linenum, args[2], args[0]);
- err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT;
- break;
- }
+ /* remerge all words into a single expression */
+ for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ')
+ ;
if (!nested_cond_lvl) {
ha_alert("parsing [%s:%d]: lone '.elif' with no matching '.if'.\n", file, linenum);
diff --git a/src/haproxy.c b/src/haproxy.c
index c863e13..a4cbce5 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1807,6 +1807,7 @@
char *args[MAX_LINE_ARGS+1];
int arg = sizeof(args) / sizeof(*args);
size_t outlen = strlen(check_condition) + 1;
+ char *w;
err = parse_line(check_condition, check_condition, &outlen, args, &arg,
PARSE_OPT_ENV | PARSE_OPT_WORD_EXPAND | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE | PARSE_OPT_BKSLASH,
@@ -1827,7 +1828,7 @@
exit(2);
}
- if ((err & PARSE_ERR_TOOMANY) || *args[1]) {
+ if (err & PARSE_ERR_TOOMANY) {
ha_alert("Error in condition: Too many words.\n");
exit(2);
}
@@ -1837,6 +1838,10 @@
exit(2);
}
+ /* remerge all words into a single expression */
+ for (w = *args; (w += strlen(w)) < check_condition + outlen - 1; *w = ' ')
+ ;
+
result = cfg_eval_condition(args, &errmsg, &errptr);
if (result < 0) {