From: Thierry FOURNIER Date: Fri, 2 Oct 2015 06:24:51 +0000 (+0200) Subject: MINOR: http/tcp: fill the avalaible actions X-Git-Tag: v1.6-dev7~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab95e656ea0cb0bcf628c7368713841ea9cb8c4f;p=thirdparty%2Fhaproxy.git MINOR: http/tcp: fill the avalaible actions This patch adds a function that generates the list of avalaible actions for the error message. --- diff --git a/include/proto/action.h b/include/proto/action.h index 5f71067e9d..fea40cf235 100644 --- a/include/proto/action.h +++ b/include/proto/action.h @@ -44,4 +44,28 @@ static inline struct action_kw *action_lookup(struct list *keywords, const char return NULL; } +static inline void action_build_list(struct list *keywords, struct chunk *chk) +{ + struct action_kw_list *kw_list; + int i; + char *p; + char *end; + int l; + + p = chk->str; + end = p + chk->size - 1; + list_for_each_entry(kw_list, keywords, list) { + for (i = 0; kw_list->kw[i].kw != NULL; i++) { + l = snprintf(p, end - p, "'%s%s', ", kw_list->kw[i].kw, kw_list->kw[i].match_pfx ? "(*)" : ""); + if (l > end - p) + continue; + p += l; + } + } + if (p > chk->str) + *(p-2) = '\0'; + else + *p = '\0'; +} + #endif /* _PROTO_ACTION_H */ diff --git a/src/proto_http.c b/src/proto_http.c index f06975d3a2..6d4a6b3674 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -9470,8 +9470,12 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li goto out_err; } } else { - Alert("parsing [%s:%d]: 'http-request' expects 'allow', 'deny', 'auth', 'redirect', 'tarpit', 'add-header', 'set-header', 'replace-header', 'replace-value', 'set-nice', 'set-tos', 'set-mark', 'set-log-level', 'add-acl', 'del-acl', 'del-map', 'set-map', 'set-var', 'set-src', but got '%s'%s.\n", - file, linenum, args[0], *args[0] ? "" : " (missing argument)"); + action_build_list(&http_req_keywords.list, &trash); + Alert("parsing [%s:%d]: 'http-request' expects 'allow', 'deny', 'auth', 'redirect', " + "'tarpit', 'add-header', 'set-header', 'replace-header', 'replace-value', 'set-nice', " + "'set-tos', 'set-mark', 'set-log-level', 'add-acl', 'del-acl', 'del-map', 'set-map', " + "'set-src'%s%s, but got '%s'%s.\n", + file, linenum, *trash.str ? ", " : "", trash.str, args[0], *args[0] ? "" : " (missing argument)"); goto out_err; } @@ -9827,8 +9831,12 @@ struct act_rule *parse_http_res_cond(const char **args, const char *file, int li goto out_err; } } else { - Alert("parsing [%s:%d]: 'http-response' expects 'allow', 'deny', 'redirect', 'add-header', 'del-header', 'set-header', 'replace-header', 'replace-value', 'set-nice', 'set-tos', 'set-mark', 'set-log-level', 'del-acl', 'add-acl', 'del-map', 'set-map', 'set-var' but got '%s'%s.\n", - file, linenum, args[0], *args[0] ? "" : " (missing argument)"); + action_build_list(&http_res_keywords.list, &trash); + Alert("parsing [%s:%d]: 'http-response' expects 'allow', 'deny', 'redirect', " + "'add-header', 'del-header', 'set-header', 'replace-header', 'replace-value', 'set-nice', " + "'set-tos', 'set-mark', 'set-log-level', 'add-acl', 'del-acl', 'del-map', 'set-map', " + "'set-src'%s%s, but got '%s'%s.\n", + file, linenum, *trash.str ? ", " : "", trash.str, args[0], *args[0] ? "" : " (missing argument)"); goto out_err; } diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 0655b0dff6..df10ccbd9c 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -1521,9 +1521,10 @@ 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 { + action_build_list(&tcp_res_cont_keywords, &trash); memprintf(err, - "'%s %s' expects 'accept', 'close', 'reject' or 'set-var' in %s '%s' (got '%s')", - args[0], args[1], proxy_type_str(curpx), curpx->id, args[arg]); + "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s')", + args[0], args[1], trash.str, proxy_type_str(curpx), curpx->id, args[arg]); return -1; } } @@ -1731,10 +1732,14 @@ 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) + action_build_list(&tcp_req_conn_keywords, &trash); + else + action_build_list(&tcp_req_cont_keywords, &trash); memprintf(err, - "'%s %s' expects 'accept', 'reject', 'track-sc0' ... 'track-sc%d', " - " or 'set-var' in %s '%s' (got '%s')", - args[0], args[1], MAX_SESS_STKCTR-1, proxy_type_str(curpx), + "'%s %s' expects 'accept', 'reject', 'track-sc0' ... 'track-sc%d', %s " + "in %s '%s' (got '%s').\n", + args[0], args[1], MAX_SESS_STKCTR-1, trash.str, proxy_type_str(curpx), curpx->id, args[arg]); return -1; }