mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: action: replace match_pfx by a keyword flags field
Define a new keyword flag KWF_MATCH_PREFIX. This is used to replace the match_pfx field of action struct. This has the benefit to have more explicit action declaration, and now it is possible to quickly implement experimental actions.
This commit is contained in:
parent
d2e53cd47e
commit
e4a617c931
@ -187,7 +187,7 @@ struct action_kw {
|
||||
const char *kw;
|
||||
enum act_parse_ret (*parse)(const char **args, int *cur_arg, struct proxy *px,
|
||||
struct act_rule *rule, char **err);
|
||||
int match_pfx;
|
||||
int flags;
|
||||
void *private;
|
||||
};
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <haproxy/action-t.h>
|
||||
#include <haproxy/cfgparse.h>
|
||||
#include <haproxy/list.h>
|
||||
#include <haproxy/sample.h>
|
||||
|
||||
@ -41,7 +42,7 @@ static inline struct action_kw *action_lookup(struct list *keywords, const char
|
||||
|
||||
list_for_each_entry(kw_list, keywords, list) {
|
||||
for (i = 0; kw_list->kw[i].kw != NULL; i++) {
|
||||
if (kw_list->kw[i].match_pfx &&
|
||||
if ((kw_list->kw[i].flags & KWF_MATCH_PREFIX) &&
|
||||
strncmp(kw, kw_list->kw[i].kw, strlen(kw_list->kw[i].kw)) == 0)
|
||||
return &kw_list->kw[i];
|
||||
if (strcmp(kw, kw_list->kw[i].kw) == 0)
|
||||
@ -64,7 +65,7 @@ static inline void action_build_list(struct list *keywords,
|
||||
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 ? "(*)" : "");
|
||||
l = snprintf(p, end - p, "'%s%s', ", kw_list->kw[i].kw, (kw_list->kw[i].flags & KWF_MATCH_PREFIX) ? "(*)" : "");
|
||||
if (l > end - p)
|
||||
continue;
|
||||
p += l;
|
||||
|
@ -44,6 +44,7 @@ enum kw_mod {
|
||||
|
||||
enum cfg_keyword_flags {
|
||||
KWF_EXPERIMENTAL = 0x1,
|
||||
KWF_MATCH_PREFIX = 0x2,
|
||||
};
|
||||
|
||||
struct cfg_keyword {
|
||||
|
@ -277,8 +277,8 @@ const char *action_suggest(const char *word, const struct list *keywords, const
|
||||
* when they're known to exist (not from extra list).
|
||||
*/
|
||||
if (best_ptr &&
|
||||
(best_dist > (2 + (best_kw && best_kw->match_pfx)) * strlen(word) ||
|
||||
best_dist > (2 + (best_kw && best_kw->match_pfx)) * strlen(best_ptr)))
|
||||
(best_dist > (2 + (best_kw && (best_kw->flags & KWF_MATCH_PREFIX))) * strlen(word) ||
|
||||
best_dist > (2 + (best_kw && (best_kw->flags & KWF_MATCH_PREFIX))) * strlen(best_ptr)))
|
||||
best_ptr = NULL;
|
||||
|
||||
return best_ptr;
|
||||
|
@ -7741,7 +7741,7 @@ __LJMP static int hlua_register_action(lua_State *L)
|
||||
|
||||
snprintf((char *)akl->kw[0].kw, len, "lua.%s", name);
|
||||
|
||||
akl->kw[0].match_pfx = 0;
|
||||
akl->kw[0].flags = 0;
|
||||
akl->kw[0].private = fcn;
|
||||
akl->kw[0].parse = action_register_lua;
|
||||
|
||||
@ -7895,7 +7895,7 @@ __LJMP static int hlua_register_service(lua_State *L)
|
||||
"'tcp' or 'http' are expected.", env));
|
||||
}
|
||||
|
||||
akl->kw[0].match_pfx = 0;
|
||||
akl->kw[0].flags = 0;
|
||||
akl->kw[0].private = fcn;
|
||||
|
||||
/* End of array. */
|
||||
|
@ -2438,14 +2438,14 @@ static enum act_parse_ret parse_http_wait_for_body(const char **args, int *orig_
|
||||
|
||||
static struct action_kw_list http_req_actions = {
|
||||
.kw = {
|
||||
{ "add-acl", parse_http_set_map, 1 },
|
||||
{ "add-acl", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "add-header", parse_http_set_header, 0 },
|
||||
{ "allow", parse_http_allow, 0 },
|
||||
{ "auth", parse_http_auth, 0 },
|
||||
{ "capture", parse_http_req_capture, 0 },
|
||||
{ "del-acl", parse_http_set_map, 1 },
|
||||
{ "del-acl", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "del-header", parse_http_del_header, 0 },
|
||||
{ "del-map", parse_http_set_map, 1 },
|
||||
{ "del-map", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "deny", parse_http_deny, 0 },
|
||||
{ "disable-l7-retry", parse_http_req_disable_l7_retry, 0 },
|
||||
{ "early-hint", parse_http_set_header, 0 },
|
||||
@ -2460,7 +2460,7 @@ static struct action_kw_list http_req_actions = {
|
||||
{ "return", parse_http_return, 0 },
|
||||
{ "set-header", parse_http_set_header, 0 },
|
||||
{ "set-log-level", parse_http_set_log_level, 0 },
|
||||
{ "set-map", parse_http_set_map, 1 },
|
||||
{ "set-map", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "set-method", parse_set_req_line, 0 },
|
||||
{ "set-mark", parse_http_set_mark, 0 },
|
||||
{ "set-nice", parse_http_set_nice, 0 },
|
||||
@ -2471,7 +2471,7 @@ static struct action_kw_list http_req_actions = {
|
||||
{ "set-uri", parse_set_req_line, 0 },
|
||||
{ "strict-mode", parse_http_strict_mode, 0 },
|
||||
{ "tarpit", parse_http_deny, 0 },
|
||||
{ "track-sc", parse_http_track_sc, 1 },
|
||||
{ "track-sc", parse_http_track_sc, KWF_MATCH_PREFIX },
|
||||
{ "set-timeout", parse_http_set_timeout, 0 },
|
||||
{ "wait-for-body", parse_http_wait_for_body, 0 },
|
||||
{ NULL, NULL }
|
||||
@ -2482,13 +2482,13 @@ INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_actions);
|
||||
|
||||
static struct action_kw_list http_res_actions = {
|
||||
.kw = {
|
||||
{ "add-acl", parse_http_set_map, 1 },
|
||||
{ "add-acl", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "add-header", parse_http_set_header, 0 },
|
||||
{ "allow", parse_http_allow, 0 },
|
||||
{ "capture", parse_http_res_capture, 0 },
|
||||
{ "del-acl", parse_http_set_map, 1 },
|
||||
{ "del-acl", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "del-header", parse_http_del_header, 0 },
|
||||
{ "del-map", parse_http_set_map, 1 },
|
||||
{ "del-map", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "deny", parse_http_deny, 0 },
|
||||
{ "redirect", parse_http_redirect, 0 },
|
||||
{ "replace-header", parse_http_replace_header, 0 },
|
||||
@ -2496,13 +2496,13 @@ static struct action_kw_list http_res_actions = {
|
||||
{ "return", parse_http_return, 0 },
|
||||
{ "set-header", parse_http_set_header, 0 },
|
||||
{ "set-log-level", parse_http_set_log_level, 0 },
|
||||
{ "set-map", parse_http_set_map, 1 },
|
||||
{ "set-map", parse_http_set_map, KWF_MATCH_PREFIX },
|
||||
{ "set-mark", parse_http_set_mark, 0 },
|
||||
{ "set-nice", parse_http_set_nice, 0 },
|
||||
{ "set-status", parse_http_set_status, 0 },
|
||||
{ "set-tos", parse_http_set_tos, 0 },
|
||||
{ "strict-mode", parse_http_strict_mode, 0 },
|
||||
{ "track-sc", parse_http_track_sc, 1 },
|
||||
{ "track-sc", parse_http_track_sc, KWF_MATCH_PREFIX },
|
||||
{ "wait-for-body", parse_http_wait_for_body, 0 },
|
||||
{ NULL, NULL }
|
||||
}
|
||||
|
@ -2829,14 +2829,14 @@ enum act_parse_ret resolv_parse_do_resolve(const char **args, int *orig_arg, str
|
||||
}
|
||||
|
||||
static struct action_kw_list http_req_kws = { { }, {
|
||||
{ "do-resolve", resolv_parse_do_resolve, 1 },
|
||||
{ "do-resolve", resolv_parse_do_resolve, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
|
||||
|
||||
static struct action_kw_list tcp_req_cont_actions = {ILH, {
|
||||
{ "do-resolve", resolv_parse_do_resolve, 1 },
|
||||
{ "do-resolve", resolv_parse_do_resolve, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
|
@ -4068,54 +4068,54 @@ static struct cli_kw_list cli_kws = {{ },{
|
||||
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
|
||||
|
||||
static struct action_kw_list tcp_conn_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_req_conn_keywords_register, &tcp_conn_kws);
|
||||
|
||||
static struct action_kw_list tcp_sess_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_sess_kws);
|
||||
|
||||
static struct action_kw_list tcp_req_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_kws);
|
||||
|
||||
static struct action_kw_list tcp_res_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws);
|
||||
|
||||
static struct action_kw_list http_req_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
|
||||
|
||||
static struct action_kw_list http_res_kws = { { }, {
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, 1 },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, 1 },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, 1 },
|
||||
{ "sc-inc-gpc0", parse_inc_gpc0, KWF_MATCH_PREFIX },
|
||||
{ "sc-inc-gpc1", parse_inc_gpc1, KWF_MATCH_PREFIX },
|
||||
{ "sc-set-gpt0", parse_set_gpt0, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
|
28
src/vars.c
28
src/vars.c
@ -1056,56 +1056,56 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
||||
INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);
|
||||
|
||||
static struct action_kw_list tcp_req_sess_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_req_sess_keywords_register, &tcp_req_sess_kws);
|
||||
|
||||
static struct action_kw_list tcp_req_cont_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_req_cont_kws);
|
||||
|
||||
static struct action_kw_list tcp_res_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_res_cont_keywords_register, &tcp_res_kws);
|
||||
|
||||
static struct action_kw_list tcp_check_kws = {ILH, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, tcp_check_keywords_register, &tcp_check_kws);
|
||||
|
||||
static struct action_kw_list http_req_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
|
||||
|
||||
static struct action_kw_list http_res_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_kws);
|
||||
|
||||
static struct action_kw_list http_after_res_kws = { { }, {
|
||||
{ "set-var", parse_store, 1 },
|
||||
{ "unset-var", parse_store, 1 },
|
||||
{ "set-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ "unset-var", parse_store, KWF_MATCH_PREFIX },
|
||||
{ /* END */ }
|
||||
}};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user