]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http/tcp: fill the avalaible actions
authorThierry FOURNIER <tfournier@arpalert.org>
Fri, 2 Oct 2015 06:24:51 +0000 (08:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Oct 2015 20:56:11 +0000 (22:56 +0200)
This patch adds a function that generates the list of avalaible actions
for the error message.

include/proto/action.h
src/proto_http.c
src/proto_tcp.c

index 5f71067e9d431e4c6ab40c32049a559ac1747637..fea40cf235c03b55697a7990bcb23958790edca7 100644 (file)
@@ -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 */
index f06975d3a2f516fbb0e09abf6f5524d225d1b7dd..6d4a6b3674450085b996b980709505959e214496 100644 (file)
@@ -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;
        }
 
index 0655b0dff67a3be216cc789ddd9921e68fef1059..df10ccbd9c5defa2cf25511cad1fba34be515358 100644 (file)
@@ -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;
                }