]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: store lf_expr nodes inside substruct
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 25 Mar 2024 10:29:58 +0000 (11:29 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 26 Apr 2024 16:39:31 +0000 (18:39 +0200)
Add another struct level inside lf_expr struct to allow new information
to be stored alongside lf_expr nodes.

include/haproxy/log-t.h
include/haproxy/log.h
src/cfgparse.c
src/log.c

index 57cd5f3db052c4bf5d2b37815320a562b6a5c67a..f2fff26db7e4517c20181ea7a504b880aed6aef8 100644 (file)
@@ -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 */
 };
index 6aa2db627490abc00c56b25396b8628c6f74303a..fa85cb3107984009d6ec3f913d2bb2a999bb9293 100644 (file)
@@ -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);
index a2f7c4a749f71860c4d51a1cc171660def17173a..6e5055e37e24b35f25e5955065e699260ccc32c8 100644 (file)
@@ -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;
index a9b8f3cab0a6711d0e0259fbb920c373e4776729..ebeddd5d0b4d7dbc71037e1ec8b0fd87cdeaa519 100644 (file)
--- 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 <src> with <dst> in <src>'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;