summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_var.c
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2022-07-28 11:05:04 +0800
committerZhidao HONG <z.hong@f5.com>2022-07-28 11:05:04 +0800
commit3f8cf62c03a55b9767f0c75b3df6a1a40252b19a (patch)
tree38c5c687bb348d888c5fb869d038cc21ea47c5f2 /src/nxt_var.c
parent8761501b4845656a0f2e5c0e7bf98f948c45fb5f (diff)
downloadunit-3f8cf62c03a55b9767f0c75b3df6a1a40252b19a.tar.gz
unit-3f8cf62c03a55b9767f0c75b3df6a1a40252b19a.tar.bz2
Log: customizable access log format.
Diffstat (limited to 'src/nxt_var.c')
-rw-r--r--src/nxt_var.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/nxt_var.c b/src/nxt_var.c
index d3057764..f55a2d30 100644
--- a/src/nxt_var.c
+++ b/src/nxt_var.c
@@ -9,7 +9,7 @@
struct nxt_var_s {
size_t length;
nxt_uint_t vars;
- uint8_t strz; /* 1 bit */
+ nxt_var_flags_t flags;
u_char data[];
/*
@@ -331,11 +331,12 @@ nxt_var_index_init(void)
nxt_var_t *
nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp, nxt_array_t *fields,
- nxt_bool_t strz)
+ nxt_var_flags_t flags)
{
u_char *p, *end, *next, *src;
size_t size;
uint32_t index;
+ nxt_bool_t strz;
nxt_var_t *var;
nxt_str_t part;
nxt_uint_t n;
@@ -343,6 +344,8 @@ nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp, nxt_array_t *fields,
nxt_var_sub_t *subs;
nxt_var_decl_t *decl;
+ strz = (flags & NXT_VAR_STRZ) != 0;
+
n = 0;
p = str->start;
@@ -368,7 +371,7 @@ nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp, nxt_array_t *fields,
var->length = str->length;
var->vars = n;
- var->strz = strz;
+ var->flags = flags;
subs = nxt_var_subs(var);
src = nxt_var_raw_start(var);
@@ -568,6 +571,7 @@ nxt_var_query(nxt_task_t *task, nxt_var_query_t *query, nxt_var_t *var,
size_t length, last, next;
nxt_str_t *value, **part;
nxt_uint_t i;
+ nxt_bool_t strz, logging;
nxt_array_t parts;
nxt_var_sub_t *subs;
@@ -583,6 +587,9 @@ nxt_var_query(nxt_task_t *task, nxt_var_query_t *query, nxt_var_t *var,
nxt_memzero(&parts, sizeof(nxt_array_t));
nxt_array_init(&parts, query->pool, sizeof(nxt_str_t *));
+ strz = (var->flags & NXT_VAR_STRZ) != 0;
+ logging = (var->flags & NXT_VAR_LOGGING) != 0;
+
subs = nxt_var_subs(var);
length = var->length;
@@ -601,9 +608,13 @@ nxt_var_query(nxt_task_t *task, nxt_var_query_t *query, nxt_var_t *var,
*part = value;
length += value->length - subs[i].length;
+
+ if (logging && value->start == NULL) {
+ length += 1;
+ }
}
- p = nxt_mp_nget(query->pool, length + var->strz);
+ p = nxt_mp_nget(query->pool, length + strz);
if (nxt_slow_path(p == NULL)) {
goto fail;
}
@@ -625,6 +636,10 @@ nxt_var_query(nxt_task_t *task, nxt_var_query_t *query, nxt_var_t *var,
p = nxt_cpymem(p, part[i]->start, part[i]->length);
+ if (logging && part[i]->start == NULL) {
+ *p++ = '-';
+ }
+
last = next + subs[i].length;
}
@@ -632,7 +647,7 @@ nxt_var_query(nxt_task_t *task, nxt_var_query_t *query, nxt_var_t *var,
p = nxt_cpymem(p, &src[last], var->length - last);
}
- if (var->strz) {
+ if (strz) {
*p = '\0';
}