]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: expose logformat_tag struct
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 22 Feb 2024 18:28:40 +0000 (19:28 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 4 Apr 2024 17:10:01 +0000 (19:10 +0200)
rename logformat_type internal struct to logformat_tag to to make it less
confusing, then expose logformat_tag struct through header file so that it
can be referenced in other structs.

also rename logformat_keywords[] to logformat_tags[] for better
consistency.

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

index ac222049b7ac1a2e0384ea1b70e9f762da37b343..5f77c2b5d67286b0c53d26fce64ca67d496d43a2 100644 (file)
@@ -210,6 +210,17 @@ enum {
        LF_END,        // \0 found
 };
 
+/* log_format tags (ie: %tag), see logformat_tags table in log.c for
+ * available tags definitions
+ */
+struct logformat_node; // forward-declaration
+struct logformat_tag {
+       char *name;
+       int type;
+       int mode;
+       int lw; /* logwait bitsfield */
+       int (*config_callback)(struct logformat_node *node, struct proxy *curproxy);
+};
 
 struct logformat_node {
        struct list list;
index 75fb21101776e5755c60a49a3944cefebe69df33..ecb475f1e7534e384b0562c439d80141bd4d4eb8 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -119,19 +119,10 @@ const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, Cli
 const char sess_fin_state[8]  = "-RCHDLQT";    /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
 
 
-/* log_format   */
-struct logformat_type {
-       char *name;
-       int type;
-       int mode;
-       int lw; /* logwait bitsfield */
-       int (*config_callback)(struct logformat_node *node, struct proxy *curproxy);
-};
-
 int prepare_addrsource(struct logformat_node *node, struct proxy *curproxy);
 
 /* log_format tag names */
-static const struct logformat_type logformat_keywords[] = {
+static const struct logformat_tag logformat_tags[] = {
        { "o", LOG_FMT_GLOBAL, PR_MODE_TCP, 0, NULL },  /* global option */
 
        /* please keep these lines sorted ! */
@@ -316,16 +307,16 @@ int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len, int ty
        int j;
        struct logformat_node *node = NULL;
 
-       for (j = 0; logformat_keywords[j].name; j++) { // search a log type
-               if (strlen(logformat_keywords[j].name) == tag_len &&
-                   strncmp(tag, logformat_keywords[j].name, tag_len) == 0) {
-                       if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
+       for (j = 0; logformat_tags[j].name; j++) { // search a log type
+               if (strlen(logformat_tags[j].name) == tag_len &&
+                   strncmp(tag, logformat_tags[j].name, tag_len) == 0) {
+                       if (logformat_tags[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
                                node = calloc(1, sizeof(*node));
                                if (!node) {
                                        memprintf(err, "out of memory error");
                                        goto error_free;
                                }
-                               node->type = logformat_keywords[j].type;
+                               node->type = logformat_tags[j].type;
                                node->typecast = typecast;
                                if (name)
                                        node->name = my_strndup(name, name_len);
@@ -339,17 +330,17 @@ int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len, int ty
                                        *defoptions = node->options;
                                        free_logformat_node(node);
                                } else {
-                                       if (logformat_keywords[j].config_callback &&
-                                           logformat_keywords[j].config_callback(node, curproxy) != 0) {
+                                       if (logformat_tags[j].config_callback &&
+                                           logformat_tags[j].config_callback(node, curproxy) != 0) {
                                                goto error_free;
                                        }
-                                       curproxy->to_log |= logformat_keywords[j].lw;
+                                       curproxy->to_log |= logformat_tags[j].lw;
                                        LIST_APPEND(list_format, &node->list);
                                }
                                return 1;
                        } else {
                                memprintf(err, "format tag '%s' is reserved for HTTP mode",
-                                         logformat_keywords[j].name);
+                                         logformat_tags[j].name);
                                goto error_free;
                        }
                }