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.
This commit is contained in:
Thierry FOURNIER 2015-08-19 09:01:53 +02:00 committed by Willy Tarreau
parent 24ff6c6fce
commit 36481b8667
9 changed files with 50 additions and 72 deletions

View File

@ -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);
}

View File

@ -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);

View File

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

View File

@ -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];

View File

@ -29,18 +29,6 @@
#include <types/acl.h>
#include <types/stream.h>
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 */
/*

View File

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

View File

@ -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 }

View File

@ -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;

View File

@ -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 */ }
}};