From: Thierry FOURNIER Date: Wed, 19 Aug 2015 07:01:53 +0000 (+0200) Subject: MEDIUM: actions: Merge (http|tcp)-(request|reponse) keywords structs X-Git-Tag: v1.6-dev4~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36481b86675f74c1ddc817cfbc1bc38682f78d1c;p=thirdparty%2Fhaproxy.git MEDIUM: actions: Merge (http|tcp)-(request|reponse) keywords structs This patch merges the conguration keyword struct. Each declared configuration keyword struct are similar with the others. This patch simplify the code. --- diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h index a3a261fa09..0ebc612196 100644 --- a/include/proto/proto_http.h +++ b/include/proto/proto_http.h @@ -129,16 +129,16 @@ int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, enum http_meth_t find_http_meth(const char *str, const int len); -struct http_req_action_kw *action_http_req_custom(const char *kw); -struct http_res_action_kw *action_http_res_custom(const char *kw); +struct action_kw *action_http_req_custom(const char *kw); +struct action_kw *action_http_res_custom(const char *kw); int val_hdr(struct arg *arg, char **err_msg); -static inline void http_req_keywords_register(struct http_req_action_kw_list *kw_list) +static inline void http_req_keywords_register(struct action_kw_list *kw_list) { LIST_ADDQ(&http_req_keywords.list, &kw_list->list); } -static inline void http_res_keywords_register(struct http_res_action_kw_list *kw_list) +static inline void http_res_keywords_register(struct action_kw_list *kw_list) { LIST_ADDQ(&http_res_keywords.list, &kw_list->list); } diff --git a/include/proto/proto_tcp.h b/include/proto/proto_tcp.h index 312762538b..5f589eac56 100644 --- a/include/proto/proto_tcp.h +++ b/include/proto/proto_tcp.h @@ -41,9 +41,9 @@ int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit); int tcp_exec_req_rules(struct session *sess); /* TCP keywords. */ -void tcp_req_conn_keywords_register(struct tcp_action_kw_list *kw_list); -void tcp_req_cont_keywords_register(struct tcp_action_kw_list *kw_list); -void tcp_res_cont_keywords_register(struct tcp_action_kw_list *kw_list); +void tcp_req_conn_keywords_register(struct action_kw_list *kw_list); +void tcp_req_cont_keywords_register(struct action_kw_list *kw_list); +void tcp_res_cont_keywords_register(struct action_kw_list *kw_list); /* Export some samples. */ int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private); diff --git a/include/types/action.h b/include/types/action.h index 713631ed06..9fb087889d 100644 --- a/include/types/action.h +++ b/include/types/action.h @@ -132,4 +132,16 @@ struct act_rule { } arg; /* arguments used by some actions */ }; +struct action_kw { + const char *kw; + int (*parse)(const char **args, int *cur_arg, struct proxy *px, + struct act_rule *rule, char **err); + int match_pfx; +}; + +struct action_kw_list { + struct list list; + struct action_kw kw[VAR_ARRAY]; +}; + #endif /* _TYPES_ACTION_H */ diff --git a/include/types/proto_http.h b/include/types/proto_http.h index 16be842df4..3f827b873c 100644 --- a/include/types/proto_http.h +++ b/include/types/proto_http.h @@ -397,30 +397,8 @@ struct http_method_name { int len; }; -struct http_req_action_kw { - const char *kw; - int (*parse)(const char **args, int *cur_arg, struct proxy *px, struct act_rule *rule, char **err); - int match_pfx; -}; - -struct http_res_action_kw { - const char *kw; - int (*parse)(const char **args, int *cur_arg, struct proxy *px, struct act_rule *rule, char **err); - int match_pfx; -}; - -struct http_req_action_kw_list { - struct list list; - struct http_req_action_kw kw[VAR_ARRAY]; -}; - -struct http_res_action_kw_list { - struct list list; - struct http_res_action_kw kw[VAR_ARRAY]; -}; - -extern struct http_req_action_kw_list http_req_keywords; -extern struct http_res_action_kw_list http_res_keywords; +extern struct action_kw_list http_req_keywords; +extern struct action_kw_list http_res_keywords; extern const struct http_method_name http_known_methods[HTTP_METH_OTHER]; diff --git a/include/types/proto_tcp.h b/include/types/proto_tcp.h index df969a145b..9d888a7a20 100644 --- a/include/types/proto_tcp.h +++ b/include/types/proto_tcp.h @@ -29,18 +29,6 @@ #include #include -struct tcp_action_kw { - const char *kw; - int (*parse)(const char **args, int *cur_arg, struct proxy *px, - struct act_rule *rule, char **err); - int match_pfx; -}; - -struct tcp_action_kw_list { - struct list list; - struct tcp_action_kw kw[VAR_ARRAY]; -}; - #endif /* _TYPES_PROTO_TCP_H */ /* diff --git a/src/hlua.c b/src/hlua.c index 5395b6d303..32f8df412c 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -4584,22 +4584,22 @@ static struct cfg_kw_list cfg_kws = {{ },{ { 0, NULL, NULL }, }}; -static struct http_req_action_kw_list http_req_kws = { { }, { +static struct action_kw_list http_req_kws = { { }, { { "lua", http_req_action_register_lua }, { NULL, NULL } }}; -static struct http_res_action_kw_list http_res_kws = { { }, { +static struct action_kw_list http_res_kws = { { }, { { "lua", http_res_action_register_lua }, { NULL, NULL } }}; -static struct tcp_action_kw_list tcp_req_cont_kws = { { }, { +static struct action_kw_list tcp_req_cont_kws = { { }, { { "lua", tcp_req_action_register_lua }, { NULL, NULL } }}; -static struct tcp_action_kw_list tcp_res_cont_kws = { { }, { +static struct action_kw_list tcp_res_cont_kws = { { }, { { "lua", tcp_res_action_register_lua }, { NULL, NULL } }}; diff --git a/src/proto_http.c b/src/proto_http.c index ce43ec5991..69a1052d10 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -236,12 +236,12 @@ const char *stat_status_codes[STAT_STATUS_SIZE] = { /* List head of all known action keywords for "http-request" */ -struct http_req_action_kw_list http_req_keywords = { +struct action_kw_list http_req_keywords = { .list = LIST_HEAD_INIT(http_req_keywords.list) }; /* List head of all known action keywords for "http-response" */ -struct http_res_action_kw_list http_res_keywords = { +struct action_kw_list http_res_keywords = { .list = LIST_HEAD_INIT(http_res_keywords.list) }; @@ -8934,7 +8934,7 @@ void free_http_req_rules(struct list *r) struct act_rule *parse_http_req_cond(const char **args, const char *file, int linenum, struct proxy *proxy) { struct act_rule *rule; - struct http_req_action_kw *custom = NULL; + struct action_kw *custom = NULL; int cur_arg; char *error; @@ -9408,7 +9408,7 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li struct act_rule *parse_http_res_cond(const char **args, const char *file, int linenum, struct proxy *proxy) { struct act_rule *rule; - struct http_res_action_kw *custom = NULL; + struct action_kw *custom = NULL; int cur_arg; char *error; @@ -12645,10 +12645,10 @@ int parse_http_res_capture(const char **args, int *orig_arg, struct proxy *px, s /* * Return the struct http_req_action_kw associated to a keyword. */ -struct http_req_action_kw *action_http_req_custom(const char *kw) +struct action_kw *action_http_req_custom(const char *kw) { if (!LIST_ISEMPTY(&http_req_keywords.list)) { - struct http_req_action_kw_list *kw_list; + struct action_kw_list *kw_list; int i; list_for_each_entry(kw_list, &http_req_keywords.list, list) { @@ -12667,10 +12667,10 @@ struct http_req_action_kw *action_http_req_custom(const char *kw) /* * Return the struct http_res_action_kw associated to a keyword. */ -struct http_res_action_kw *action_http_res_custom(const char *kw) +struct action_kw *action_http_res_custom(const char *kw) { if (!LIST_ISEMPTY(&http_res_keywords.list)) { - struct http_res_action_kw_list *kw_list; + struct action_kw_list *kw_list; int i; list_for_each_entry(kw_list, &http_res_keywords.list, list) { @@ -12911,7 +12911,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, { /************************************************************************/ /* All supported http-request action keywords must be declared here. */ /************************************************************************/ -struct http_req_action_kw_list http_req_actions = { +struct action_kw_list http_req_actions = { .kw = { { "capture", parse_http_req_capture }, { "set-method", parse_set_req_line }, @@ -12922,7 +12922,7 @@ struct http_req_action_kw_list http_req_actions = { } }; -struct http_res_action_kw_list http_res_actions = { +struct action_kw_list http_res_actions = { .kw = { { "capture", parse_http_res_capture }, { NULL, NULL } diff --git a/src/proto_tcp.c b/src/proto_tcp.c index f797042fdc..8dd95fd2d7 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -117,17 +117,17 @@ static struct protocol proto_tcpv6 = { /* * Register keywords. */ -void tcp_req_conn_keywords_register(struct tcp_action_kw_list *kw_list) +void tcp_req_conn_keywords_register(struct action_kw_list *kw_list) { LIST_ADDQ(&tcp_req_conn_keywords, &kw_list->list); } -void tcp_req_cont_keywords_register(struct tcp_action_kw_list *kw_list) +void tcp_req_cont_keywords_register(struct action_kw_list *kw_list) { LIST_ADDQ(&tcp_req_cont_keywords, &kw_list->list); } -void tcp_res_cont_keywords_register(struct tcp_action_kw_list *kw_list) +void tcp_res_cont_keywords_register(struct action_kw_list *kw_list) { LIST_ADDQ(&tcp_res_cont_keywords, &kw_list->list); } @@ -135,9 +135,9 @@ void tcp_res_cont_keywords_register(struct tcp_action_kw_list *kw_list) /* * Return the struct http_req_action_kw associated to a keyword. */ -static struct tcp_action_kw *tcp_req_conn_action(const char *kw) +static struct action_kw *tcp_req_conn_action(const char *kw) { - struct tcp_action_kw_list *kw_list; + struct action_kw_list *kw_list; int i; if (LIST_ISEMPTY(&tcp_req_conn_keywords)) @@ -155,9 +155,9 @@ static struct tcp_action_kw *tcp_req_conn_action(const char *kw) return NULL; } -static struct tcp_action_kw *tcp_req_cont_action(const char *kw) +static struct action_kw *tcp_req_cont_action(const char *kw) { - struct tcp_action_kw_list *kw_list; + struct action_kw_list *kw_list; int i; if (LIST_ISEMPTY(&tcp_req_cont_keywords)) @@ -175,9 +175,9 @@ static struct tcp_action_kw *tcp_req_cont_action(const char *kw) return NULL; } -static struct tcp_action_kw *tcp_res_cont_action(const char *kw) +static struct action_kw *tcp_res_cont_action(const char *kw) { - struct tcp_action_kw_list *kw_list; + struct action_kw_list *kw_list; int i; if (LIST_ISEMPTY(&tcp_res_cont_keywords)) @@ -1504,7 +1504,7 @@ static int tcp_parse_response_rule(char **args, int arg, int section_type, rule->action = ACT_TCP_CLOSE; } else { - struct tcp_action_kw *kw; + struct action_kw *kw; kw = tcp_res_cont_action(args[arg]); if (kw) { arg++; @@ -1707,7 +1707,7 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type, rule->action = ACT_TCP_EXPECT_PX; } else { - struct tcp_action_kw *kw; + struct action_kw *kw; if (where & SMP_VAL_FE_CON_ACC) { kw = tcp_req_conn_action(args[arg]); rule->from = ACT_F_TCP_REQ_CON; diff --git a/src/vars.c b/src/vars.c index 430801232c..88e31a8ac9 100644 --- a/src/vars.c +++ b/src/vars.c @@ -710,22 +710,22 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, { { /* END */ }, }}; -static struct tcp_action_kw_list tcp_req_kws = { { }, { +static struct action_kw_list tcp_req_kws = { { }, { { "set-var", parse_tcp_req_store, 1 }, { /* END */ } }}; -static struct tcp_action_kw_list tcp_res_kws = { { }, { +static struct action_kw_list tcp_res_kws = { { }, { { "set-var", parse_tcp_res_store, 1 }, { /* END */ } }}; -static struct http_req_action_kw_list http_req_kws = { { }, { +static struct action_kw_list http_req_kws = { { }, { { "set-var", parse_http_req_store, 1 }, { /* END */ } }}; -static struct http_res_action_kw_list http_res_kws = { { }, { +static struct action_kw_list http_res_kws = { { }, { { "set-var", parse_http_res_store, 1 }, { /* END */ } }};