From ee88c4418fdb8f8be4e7d083dba86abd1e27621a Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Wed, 31 Jan 2024 14:37:07 +0100 Subject: [PATCH] MINOR: log: automate string array construction in sess_build_logline() make it so string array construction is performed by dedicated macro helpers instead of manual char insertion between string members. The goal is to easily be able to support multiple forms of array construction depending on the data encoding format (raw, json..). Only %hrl and %hsl logformats are concerned. --- src/log.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index c211fe520..b0c112a1a 100644 --- a/src/log.c +++ b/src/log.c @@ -2544,6 +2544,19 @@ const char sess_set_cookie[8] = "NPDIRU67"; /* No set-cookie, Set-cookie found a LOGCHAR(chr); \ } while (0) +/* indicate the start of a string array */ +#define LOG_STRARRAY_START() do { \ + } while (0) + +/* indicate that a new element is added to the string array */ +#define LOG_STRARRAY_NEXT() do { \ + LOGCHAR(' '); \ + } while (0) + +/* indicate the end of a string array */ +#define LOG_STRARRAY_END() do { \ + } while (0) + /* Initializes some log data at boot */ static void init_log() { @@ -3335,9 +3348,10 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_HDRREQUESTLIST: // %hrl /* request header list */ if (fe->nb_req_cap && s && s->req_cap) { + LOG_STRARRAY_START(); for (hdr = 0; hdr < fe->nb_req_cap; hdr++) { if (hdr > 0) - LOGCHAR(' '); + LOG_STRARRAY_NEXT(); LOGQUOTE_START(); if (s->req_cap[hdr] != NULL) { ret = lf_encode_string(tmplog, dst + maxsize, @@ -3352,6 +3366,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t */ LOGQUOTE_END(); } + LOG_STRARRAY_END(); } break; @@ -3379,9 +3394,10 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t case LOG_FMT_HDRRESPONSLIST: // %hsl /* response header list */ if (fe->nb_rsp_cap && s && s->res_cap) { + LOG_STRARRAY_START(); for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) { if (hdr > 0) - LOGCHAR(' '); + LOG_STRARRAY_NEXT(); LOGQUOTE_START(); if (s->res_cap[hdr] != NULL) { ret = lf_encode_string(tmplog, dst + maxsize, @@ -3396,6 +3412,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t */ LOGQUOTE_END(); } + LOG_STRARRAY_END(); } break;