This patch replaces the ad-hoc generation of stream's `unique_id` values
by calls to `stream_generate_unique_id`.
---
src/http_ana.c | 14 ++++++--------
src/http_fetch.c | 17 ++++++++---------
src/log.c | 3 +--
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/src/http_ana.c b/src/http_ana.c
index 20c7b6e50..d6f41b428 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -788,20 +788,18 @@ int http_process_request(struct stream *s, struct channel
*req, int an_bit)
http_manage_client_side_cookies(s, req);
/* add unique-id if "header-unique-id" is specified */
+ if (sess->fe->header_unique_id &&
!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
+ struct ist n, v;
+ 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));
+ 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;
diff --git a/src/http_fetch.c b/src/http_fetch.c
index d288e841d..dbbb5ecfd 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -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;
}
diff --git a/src/log.c b/src/log.c
index 60b1a5a4d..b46605b8d 100644
--- 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)) {
--
2.25.1