]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Use stream_generate_unique_id
authorTim Duesterhus <tim@bastelstu.be>
Fri, 28 Feb 2020 14:13:34 +0000 (15:13 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2020 06:23:00 +0000 (07:23 +0100)
This patch replaces the ad-hoc generation of stream's `unique_id` values
by calls to `stream_generate_unique_id`.

src/http_ana.c
src/http_fetch.c
src/log.c

index 20c7b6e502ad6cd734162c59a044857563f5e78d..094208d631866c5469dbbfa8e4f9f6ef9c79dd96 100644 (file)
@@ -787,24 +787,29 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
        if (s->be->cookie_name || sess->fe->capture_name)
                http_manage_client_side_cookies(s, req);
 
-       /* add unique-id if "header-unique-id" is specified */
+       /* 8: Generate unique ID if a "unique-id-format" is defined.
+        *
+        * A unique ID is generated even when it is not sent to ensure that the ID can make use of
+        * fetches only available in the HTTP request processing stage.
+        */
+       if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
+               int length;
 
-       if (!LIST_ISEMPTY(&sess->fe->format_unique_id) && !s->unique_id) {
-               if ((s->unique_id = pool_alloc(pool_head_uniqueid)) == NULL) {
+               if ((length = stream_generate_unique_id(s, &sess->fe->format_unique_id)) < 0) {
                        if (!(s->flags & SF_ERR_MASK))
                                s->flags |= SF_ERR_RESOURCE;
                        goto return_int_err;
                }
-               s->unique_id[0] = '\0';
-               build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id);
-       }
 
-       if (sess->fe->header_unique_id && s->unique_id) {
-               struct ist n = ist2(sess->fe->header_unique_id, strlen(sess->fe->header_unique_id));
-               struct ist v = ist2(s->unique_id, strlen(s->unique_id));
+               /* send unique ID if a "unique-id-header" is defined */
+               if (sess->fe->header_unique_id) {
+                       struct ist n, v;
+                       n = ist2(sess->fe->header_unique_id, strlen(sess->fe->header_unique_id));
+                       v = ist2(s->unique_id, length);
 
-               if (unlikely(!http_add_header(htx, n, v)))
-                       goto return_int_err;
+                       if (unlikely(!http_add_header(htx, n, v)))
+                               goto return_int_err;
+               }
        }
 
        /*
index d288e841dad3dfdbf152eaa6cb43041254c9c9b0..dbbb5ecfd2e9884ea83369d10217584ac0e30cc6 100644 (file)
@@ -409,19 +409,18 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch
 
 static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
+       int length;
+
        if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
                return 0;
 
-       if (!smp->strm->unique_id) {
-               if ((smp->strm->unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
-                       return 0;
-               smp->strm->unique_id[0] = '\0';
-               build_logline(smp->strm, smp->strm->unique_id,
-                             UNIQUEID_LEN, &smp->sess->fe->format_unique_id);
-       }
-       smp->data.u.str.data = strlen(smp->strm->unique_id);
-       smp->data.type = SMP_T_STR;
+       length = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id);
+       if (length < 0)
+               return 0;
+
        smp->data.u.str.area = smp->strm->unique_id;
+       smp->data.u.str.data = length;
+       smp->data.type = SMP_T_STR;
        smp->flags = SMP_F_CONST;
        return 1;
 }
index 60b1a5a4d786c2d0918ef35fba9639f0c205a143..b46605b8de3b558a06eb30e4df9d119d2dfe0faf 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2983,8 +2983,7 @@ void strm_log(struct stream *s)
 
        /* if unique-id was not generated */
        if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) {
-               if ((s->unique_id = pool_alloc(pool_head_uniqueid)) != NULL)
-                       build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id);
+               stream_generate_unique_id(s, &sess->fe->format_unique_id);
        }
 
        if (!LIST_ISEMPTY(&sess->fe->logformat_sd)) {