From: Aurelien DARRAGON Date: Thu, 25 Apr 2024 14:20:11 +0000 (+0200) Subject: MINOR: log: postpone conversion for sample expressions in sess_build_logline() X-Git-Tag: v3.0-dev9~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb8b47fed827375c57aa1d53c10e4e47f7ad8c40;p=thirdparty%2Fhaproxy.git MINOR: log: postpone conversion for sample expressions in sess_build_logline() In sess_build_logline(), for sample expression nodes, instead of directly calling sample_fetch_as_type(... SMP_T_STR), let's first process the sample using sample_process(), and then proceed with the conversion to str if required. Doing so will allow us to implement type casting and preserving logic. --- diff --git a/src/log.c b/src/log.c index 5876a773f0..07f4b231bc 100644 --- a/src/log.c +++ b/src/log.c @@ -3218,15 +3218,23 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t break; case LOG_FMT_EXPR: // sample expression, may be request or response + { + int type; + key = NULL; if (ctx.options & LOG_OPT_REQ_CAP) - key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); + key = sample_process(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, NULL); if (!key && (ctx.options & LOG_OPT_RES_CAP)) - key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); + key = sample_process(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, NULL); if (!key && !(ctx.options & (LOG_OPT_REQ_CAP|LOG_OPT_RES_CAP))) // cfg, cli - key = sample_fetch_as_type(be, sess, s, SMP_OPT_FINAL, tmp->expr, SMP_T_STR); + key = sample_process(be, sess, s, SMP_OPT_FINAL, tmp->expr, NULL); + + type = SMP_T_STR; // default + + if (key && !sample_convert(key, type)) + key = NULL; if (ctx.options & LOG_OPT_HTTP) ret = lf_encode_chunk(tmplog, dst + maxsize, @@ -3241,6 +3249,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t goto out; tmplog = ret; break; + } } if (tmp->type != LOG_FMT_TAG)