The `unique_id` member of `struct stream` now is a `struct ist`.
---
include/proto/stream.h | 2 +-
include/types/stream.h | 2 +-
src/http_ana.c | 16 ++++++----------
src/http_fetch.c | 10 +++++-----
src/log.c | 8 +++++---
src/stream.c | 37 ++++++++++++++++++++++---------------
6 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/include/proto/stream.h b/include/proto/stream.h
index e54ac60cc..69153df5d 100644
--- a/include/proto/stream.h
+++ b/include/proto/stream.h
@@ -66,7 +66,7 @@ void stream_shutdown(struct stream *stream, int why);
void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx,
char eol);
void stream_dump_and_crash(enum obj_type *obj, int rate);
-int stream_generate_unique_id(struct stream *strm, struct list *format);
+struct ist stream_generate_unique_id(struct stream *strm, struct list *format);
void stream_process_counters(struct stream *s);
void sess_change_server(struct stream *sess, struct server *newsrv);
diff --git a/include/types/stream.h b/include/types/stream.h
index 90819e66d..39a68557e 100644
--- a/include/types/stream.h
+++ b/include/types/stream.h
@@ -177,7 +177,7 @@ struct stream {
int pcli_next_pid; /* next target PID to use for
the CLI proxy */
int pcli_flags; /* flags for CLI proxy */
- char *unique_id; /* custom unique ID */
+ struct ist unique_id; /* custom unique ID */
/* These two pointers are used to resume the execution of the rule
lists. */
struct list *current_rule_list; /* this is used to store the
current executed rule list. */
diff --git a/src/http_ana.c b/src/http_ana.c
index 549d61090..8e651f343 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -793,22 +793,18 @@ int http_process_request(struct stream *s, struct channel
*req, int an_bit)
* fetches only available in the HTTP request processing stage.
*/
if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
- int length;
+ struct ist unique_id = stream_generate_unique_id(s,
&sess->fe->format_unique_id);
- if ((length = stream_generate_unique_id(s,
&sess->fe->format_unique_id)) < 0) {
+ if (unique_id.ptr == NULL) {
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;
goto return_int_err;
}
/* send unique ID if a "unique-id-header" is defined */
- if (sess->fe->header_unique_id.ptr) {
- struct ist n, v;
- v = ist2(s->unique_id, length);
-
- if (unlikely(!http_add_header(htx,
sess->fe->header_unique_id, v)))
+ if (sess->fe->header_unique_id.ptr
+ && unlikely(!http_add_header(htx,
sess->fe->header_unique_id, s->unique_id)))
goto return_int_err;
- }
}
/*
@@ -5082,9 +5078,9 @@ void http_end_txn(struct stream *s)
pool_free(pool_head_requri, txn->uri);
pool_free(pool_head_capture, txn->cli_cookie);
pool_free(pool_head_capture, txn->srv_cookie);
- pool_free(pool_head_uniqueid, s->unique_id);
+ pool_free(pool_head_uniqueid, s->unique_id.ptr);
- s->unique_id = NULL;
+ s->unique_id = ist_NULL();
txn->uri = NULL;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;
diff --git a/src/http_fetch.c b/src/http_fetch.c
index dbbb5ecfd..67fac6df0 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -409,17 +409,17 @@ 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;
+ struct ist unique_id;
if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
return 0;
- length = stream_generate_unique_id(smp->strm,
&smp->sess->fe->format_unique_id);
- if (length < 0)
+ unique_id = stream_generate_unique_id(smp->strm,
&smp->sess->fe->format_unique_id);
+ if (unique_id.ptr == NULL)
return 0;
- smp->data.u.str.area = smp->strm->unique_id;
- smp->data.u.str.data = length;
+ smp->data.u.str.area = smp->strm->unique_id.ptr;
+ smp->data.u.str.data = smp->strm->unique_id.len;
smp->data.type = SMP_T_STR;
smp->flags = SMP_F_CONST;
return 1;
diff --git a/src/log.c b/src/log.c
index b46605b8d..9a99a6082 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2927,8 +2927,10 @@ int sess_build_logline(struct session *sess, struct
stream *s, char *dst, size_t
case LOG_FMT_UNIQUEID: // %ID
ret = NULL;
- src = s ? s->unique_id : NULL;
- ret = lf_text(tmplog, src, maxsize - (tmplog -
dst), tmp);
+ if (s)
+ ret = lf_text_len(tmplog,
s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), tmp);
+ else
+ ret = lf_text_len(tmplog, NULL, 0,
maxsize - (tmplog - dst), tmp);
if (ret == NULL)
goto out;
tmplog = ret;
@@ -2982,7 +2984,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.ptr == NULL &&
!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
stream_generate_unique_id(s, &sess->fe->format_unique_id);
}
diff --git a/src/stream.c b/src/stream.c
index 306444e89..f266cc816 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -170,8 +170,11 @@ static void strm_trace(enum trace_level level, uint64_t
mask, const struct trace
/* General info about the stream (htx/tcp, id...) */
chunk_appendf(&trace_buf, " : [%u,%s]",
s->uniq_id, ((s->flags & SF_HTX) ? "HTX" : "TCP"));
- if (s->unique_id)
- chunk_appendf(&trace_buf, " id=%s", s->unique_id);
+ if (s->unique_id.ptr != NULL) {
+ chunk_appendf(&trace_buf, " id=");
+ for (size_t i = 0; i < s->unique_id.len; i++)
+ b_putchr(&trace_buf, s->unique_id.ptr[i]);
+ }
/* Front and back stream-int state */
chunk_appendf(&trace_buf, " SI=(%s,%s)",
@@ -399,7 +402,7 @@ struct stream *stream_new(struct session *sess, enum
obj_type *origin)
s->call_rate.curr_sec = s->call_rate.curr_ctr = s->call_rate.prev_ctr =
0;
s->pcli_next_pid = 0;
s->pcli_flags = 0;
- s->unique_id = NULL;
+ s->unique_id = ist_NULL();
if ((t = task_new(tid_bit)) == NULL)
goto out_fail_alloc;
@@ -605,8 +608,8 @@ static void stream_free(struct stream *s)
offer_buffers(NULL, tasks_run_queue);
}
- pool_free(pool_head_uniqueid, s->unique_id);
- s->unique_id = NULL;
+ pool_free(pool_head_uniqueid, s->unique_id.ptr);
+ s->unique_id = ist_NULL();
hlua_ctx_destroy(s->hlua);
s->hlua = NULL;
@@ -2659,25 +2662,29 @@ void stream_dump_and_crash(enum obj_type *obj, int rate)
}
/* Generates a unique ID based on the given <format>, stores it in the given
<strm> and
- * returns the length of the ID. -1 is returned on memory allocation failure.
+ * returns the unique ID.
+
+ * If this function fails to allocate memory an `ist` with `.ptr = NULL` and
`.len = 0`
+ * is returned.
*
- * If an ID is already stored within the stream nothing happens and length of
the stored
- * ID is returned.
+ * If an ID is already stored within the stream nothing happens existing
unique ID i
+ * returned.
*/
-int stream_generate_unique_id(struct stream *strm, struct list *format)
+struct ist stream_generate_unique_id(struct stream *strm, struct list *format)
{
- if (strm->unique_id != NULL) {
- return strlen(strm->unique_id);
+ if (strm->unique_id.ptr != NULL) {
+ return strm->unique_id;
}
else {
char *unique_id;
+ int length;
if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
- return -1;
+ return ist_NULL();
- strm->unique_id = unique_id;
- strm->unique_id[0] = 0;
+ length = build_logline(strm, unique_id, UNIQUEID_LEN, format);
+ strm->unique_id = ist2(unique_id, length);
- return build_logline(strm, strm->unique_id, UNIQUEID_LEN,
format);
+ return strm->unique_id;
}
}
--
2.25.1