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.
This commit is contained in:
Willy Tarreau 2021-07-16 16:38:58 +02:00
parent 379ceeaaeb
commit c8194c30df
2 changed files with 14 additions and 13 deletions

View File

@ -1889,13 +1889,11 @@ next_line:
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 @@ next_line:
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);

View File

@ -1807,6 +1807,7 @@ static void init(int argc, char **argv)
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 @@ static void init(int argc, char **argv)
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 @@ static void init(int argc, char **argv)
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) {