summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_var.c
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2021-09-28 23:08:26 +0800
committerZhidao HONG <z.hong@f5.com>2021-09-28 23:08:26 +0800
commit37144d68499217d086c26a2030e6e9f6f7342152 (patch)
tree1c32c63469128c19d4f215d5ad56beff89719abc /src/nxt_var.c
parent2fc64c65bcd4bc0d6a46a0e19731fd5038bd1853 (diff)
downloadunit-37144d68499217d086c26a2030e6e9f6f7342152.tar.gz
unit-37144d68499217d086c26a2030e6e9f6f7342152.tar.bz2
Static: variables in the "chroot" option.
Diffstat (limited to 'src/nxt_var.c')
-rw-r--r--src/nxt_var.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/nxt_var.c b/src/nxt_var.c
index d26d4f15..60650ef4 100644
--- a/src/nxt_var.c
+++ b/src/nxt_var.c
@@ -9,6 +9,7 @@
struct nxt_var_s {
size_t length;
nxt_uint_t vars;
+ uint8_t strz; /* 1 bit */
u_char data[];
/*
@@ -229,7 +230,7 @@ nxt_var_index_init(void)
nxt_var_t *
-nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp)
+nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp, nxt_bool_t strz)
{
u_char *p, *end, *next, *src;
size_t size;
@@ -258,19 +259,24 @@ nxt_var_compile(nxt_str_t *str, nxt_mp_t *mp)
size = sizeof(nxt_var_t) + n * sizeof(nxt_var_sub_t) + str->length;
- var = nxt_mp_get(mp, size);
+ var = nxt_mp_get(mp, size + strz);
if (nxt_slow_path(var == NULL)) {
return NULL;
}
var->length = str->length;
var->vars = n;
+ var->strz = strz;
subs = nxt_var_subs(var);
src = nxt_var_raw_start(var);
nxt_memcpy(src, str->start, str->length);
+ if (strz) {
+ src[str->length] = '\0';
+ }
+
n = 0;
p = str->start;
@@ -585,7 +591,7 @@ nxt_var_query_finish(nxt_task_t *task, nxt_var_query_t *query)
length += str->length - subs[j].length;
}
- p = nxt_mp_nget(query->values.mem_pool, length);
+ p = nxt_mp_nget(query->values.mem_pool, length + var->strz);
if (nxt_slow_path(p == NULL)) {
query->failed = 1;
goto done;
@@ -612,10 +618,16 @@ nxt_var_query_finish(nxt_task_t *task, nxt_var_query_t *query)
}
if (last != var->length) {
- nxt_memcpy(p, &src[last], var->length - last);
+ p = nxt_cpymem(p, &src[last], var->length - last);
+ }
+
+ if (var->strz) {
+ *p = '\0';
}
nxt_array_reset(&query->parts);
+
+ nxt_debug(task, "var: \"%*s\" -> \"%V\"", length, src, val[i].value);
}
done: