MINOR: http/tcp: fill the avalaible actions

This patch adds a function that generates the list of avalaible actions
for the error message.
This commit is contained in:
Thierry FOURNIER 2015-10-02 08:24:51 +02:00 committed by Willy Tarreau
parent a2d02253cf
commit ab95e656ea
3 changed files with 46 additions and 9 deletions

View 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 */

View 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;
}

View 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;
}