]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: postpone conversion for sample expressions in sess_build_logline()
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 25 Apr 2024 14:20:11 +0000 (16:20 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 26 Apr 2024 16:39:31 +0000 (18:39 +0200)
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.

src/log.c

index 5876a773f0ebde8db63881eb8e89fee022a55e9a..07f4b231bc4cb5ce77d29bc04c2a9cfd8be0e975 100644 (file)
--- 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)