From: Aurelien DARRAGON Date: Thu, 22 Feb 2024 18:28:40 +0000 (+0100) Subject: MINOR: log: expose logformat_tag struct X-Git-Tag: v3.0-dev7~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cf5c3d7f0ad83c2fab48a5d482b038b1cbe4efc;p=thirdparty%2Fhaproxy.git MINOR: log: expose logformat_tag struct 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. --- diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index ac222049b7..5f77c2b5d6 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -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; diff --git a/src/log.c b/src/log.c index 75fb211017..ecb475f1e7 100644 --- 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; } }