From: Aurelien DARRAGON Date: Mon, 25 Mar 2024 10:29:58 +0000 (+0100) Subject: MINOR: log: store lf_expr nodes inside substruct X-Git-Tag: v3.0-dev9~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ff4f09e23b9d7427b88360841b27698d7e52413;p=thirdparty%2Fhaproxy.git MINOR: log: store lf_expr nodes inside substruct Add another struct level inside lf_expr struct to allow new information to be stored alongside lf_expr nodes. --- diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index 57cd5f3db0..f2fff26db7 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -175,14 +175,16 @@ enum lf_expr_flags { /* a full logformat expr made of one or multiple logformat nodes */ struct lf_expr { - struct list list; /* to store lf_expr inside a list */ + struct list list; /* to store lf_expr inside a list */ union { - struct list nodes; /* logformat_node list */ - char *str; /* original string prior to parsing (NULL once compiled) */ + struct { + struct list list; /* logformat_node list */ + } nodes; + char *str; /* original string prior to parsing (NULL once compiled) */ }; struct { - char *file; /* file where the lft appears */ - int line; /* line where the lft appears */ + char *file; /* file where the lft appears */ + int line; /* line where the lft appears */ } conf; // parsing hints uint8_t flags; /* LF_FL_* flags */ }; diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 6aa2db6274..fa85cb3107 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -70,7 +70,7 @@ void lf_expr_xfer(struct lf_expr *src, struct lf_expr *dst); void lf_expr_deinit(struct lf_expr *expr); static inline int lf_expr_isempty(const struct lf_expr *expr) { - return !(expr->flags & LF_FL_COMPILED) || LIST_ISEMPTY(&expr->nodes); + return !(expr->flags & LF_FL_COMPILED) || LIST_ISEMPTY(&expr->nodes.list); } int lf_expr_compile(struct lf_expr *lf_expr, struct arg_list *al, int options, int cap, char **err); int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err); diff --git a/src/cfgparse.c b/src/cfgparse.c index a2f7c4a749..6e5055e37e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3164,10 +3164,10 @@ init_proxies_list_stage1: cfgerr++; continue; } - node = LIST_NEXT(&rule->be.expr.nodes, struct logformat_node *, list); + node = LIST_NEXT(&rule->be.expr.nodes.list, struct logformat_node *, list); if (!lf_expr_isempty(&rule->be.expr)) { - if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr.nodes) { + if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr.nodes.list) { rule->dynamic = 1; free(pxname); /* backend is not yet known so we cannot assume its type, @@ -3238,10 +3238,10 @@ init_proxies_list_stage1: cfgerr++; continue; } - node = LIST_NEXT(&srule->expr.nodes, struct logformat_node *, list); + node = LIST_NEXT(&srule->expr.nodes.list, struct logformat_node *, list); if (!lf_expr_isempty(&srule->expr)) { - if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr.nodes) { + if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr.nodes.list) { srule->dynamic = 1; free(server_name); continue; diff --git a/src/log.c b/src/log.c index a9b8f3cab0..ebeddd5d0b 100644 --- a/src/log.c +++ b/src/log.c @@ -407,7 +407,7 @@ static int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len, int *defoptions, char **err) { int j; - struct list *list_format= &lf_expr->nodes; + struct list *list_format= &lf_expr->nodes.list; struct logformat_node *node = NULL; for (j = 0; logformat_tags[j].name; j++) { // search a log type @@ -462,7 +462,7 @@ static int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len, */ int add_to_logformat_list(char *start, char *end, int type, struct lf_expr *lf_expr, char **err) { - struct list *list_format = &lf_expr->nodes; + struct list *list_format = &lf_expr->nodes.list; char *str; if (type == LF_TEXT) { /* type text */ @@ -502,7 +502,7 @@ static int add_sample_to_logformat_list(char *text, char *name, int name_len, in struct arg_list *al, int options, int cap, char **err, char **endptr) { char *cmd[2]; - struct list *list_format = &lf_expr->nodes; + struct list *list_format = &lf_expr->nodes.list; struct sample_expr *expr = NULL; struct logformat_node *node = NULL; int cmd_arg; @@ -608,7 +608,7 @@ int lf_expr_compile(struct lf_expr *lf_expr, * been saved as local 'fmt' string pointer, so we must free it before * returning. */ - LIST_INIT(&lf_expr->nodes); + LIST_INIT(&lf_expr->nodes.list); /* we must set the compiled flag now for proper deinit in case of failure */ lf_expr->flags |= LF_FL_COMPILED; @@ -874,7 +874,7 @@ int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err) if (!(px->flags & PR_FL_CHECKED)) px->to_log |= LW_INIT; - list_for_each_entry(lf, &lf_expr->nodes, list) { + list_for_each_entry(lf, &lf_expr->nodes.list, list) { if (lf->type == LOG_FMT_EXPR) { struct sample_expr *expr = lf->expr; uint8_t http_needed = !!(expr->fetch->use & SMP_USE_HTTP_ANY); @@ -2801,7 +2801,7 @@ void lf_expr_init(struct lf_expr *expr) void lf_expr_deinit(struct lf_expr *expr) { if ((expr->flags & LF_FL_COMPILED)) - free_logformat_list(&expr->nodes); + free_logformat_list(&expr->nodes.list); else logformat_str_free(&expr->str); free(expr->conf.file); @@ -2828,11 +2828,11 @@ void lf_expr_xfer(struct lf_expr *src, struct lf_expr *dst) dst->conf.line = src->conf.line; dst->flags |= LF_FL_COMPILED; - LIST_INIT(&dst->nodes); + LIST_INIT(&dst->nodes.list); - list_for_each_entry_safe(lf, lfb, &src->nodes, list) { + list_for_each_entry_safe(lf, lfb, &src->nodes.list, list) { LIST_DELETE(&lf->list); - LIST_APPEND(&dst->nodes, &lf->list); + LIST_APPEND(&dst->nodes.list, &lf->list); } /* replace with in 's list by first adding @@ -2885,7 +2885,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t struct http_txn *txn; const struct strm_logs *logs; struct connection *fe_conn, *be_conn; - struct list *list_format = &lf_expr->nodes; + struct list *list_format = &lf_expr->nodes.list; unsigned int s_flags; unsigned int uniq_id; struct buffer chunk;