From db67b0ed799c3b0d460925f3ddb40bf945dc9456 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 12 Mar 2021 13:46:10 +0100 Subject: [PATCH] MINOR: tcp-rules: suggest approaching action names on mismatch This adds support for action_suggest() in tcp-request and tcp-response rules so as to propose the closest match in case of misspelling. --- src/tcp_rules.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/tcp_rules.c b/src/tcp_rules.c index de99cff64..21a7c0fd8 100644 --- a/src/tcp_rules.c +++ b/src/tcp_rules.c @@ -603,11 +603,17 @@ static int tcp_parse_response_rule(char **args, int arg, int section_type, if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR) return -1; } else { + const char *extra[] = { "accept", "reject", "close", NULL }; + const char *best = action_suggest(args[arg], &tcp_res_cont_keywords, extra); + action_build_list(&tcp_res_cont_keywords, &trash); memprintf(err, - "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s')", + "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s').%s%s%s", args[0], args[1], trash.area, - proxy_type_str(curpx), curpx->id, args[arg]); + proxy_type_str(curpx), curpx->id, args[arg], + best ? " Did you mean '" : "", + best ? best : "", + best ? "' maybe ?" : ""); return -1; } } @@ -949,18 +955,32 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type, if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR) return -1; } else { - if (where & SMP_VAL_FE_CON_ACC) + const char *extra[] = { "accept", "reject", "capture", "track-sc", "expect-proxy", "expect-netscaler-ip", NULL }; + const char *best = NULL; + + + if (where & SMP_VAL_FE_CON_ACC) { action_build_list(&tcp_req_conn_keywords, &trash); - else if (where & SMP_VAL_FE_SES_ACC) + best = action_suggest(args[arg], &tcp_req_conn_keywords, extra); + } + else if (where & SMP_VAL_FE_SES_ACC) { action_build_list(&tcp_req_sess_keywords, &trash); - else + best = action_suggest(args[arg], &tcp_req_sess_keywords, extra); + } + else { action_build_list(&tcp_req_cont_keywords, &trash); + best = action_suggest(args[arg], &tcp_req_cont_keywords, extra); + } + memprintf(err, "'%s %s' expects 'accept', 'reject', 'capture', 'expect-proxy', 'expect-netscaler-ip', 'track-sc0' ... 'track-sc%d', %s " - "in %s '%s' (got '%s').\n", + "in %s '%s' (got '%s').%s%s%s\n", args[0], args[1], MAX_SESS_STKCTR-1, trash.area, proxy_type_str(curpx), - curpx->id, args[arg]); + curpx->id, args[arg], + best ? " Did you mean '" : "", + best ? best : "", + best ? "' maybe ?" : ""); return -1; } }