diff options
author | Zhidao HONG <z.hong@f5.com> | 2024-10-14 15:10:06 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2024-10-22 13:40:50 +0800 |
commit | de430edae585d40dacec20dcf4324d7c0ee8fba1 (patch) | |
tree | f8f87e2a5c456b9608c81cadf61dd04cf72e2e6e /src | |
parent | f6036bbc7c798133e95d107ef99f289281366b0d (diff) | |
download | unit-de430edae585d40dacec20dcf4324d7c0ee8fba1.tar.gz unit-de430edae585d40dacec20dcf4324d7c0ee8fba1.tar.bz2 |
Add flag for newline control in access log entries
This commit introduces a new flag to control the addition of newline
characters in access log entries. This is prepared for fixing the issue
where log entries lack newlines when using JS configuration.
Diffstat (limited to 'src')
-rw-r--r-- | src/nxt_js.c | 18 | ||||
-rw-r--r-- | src/nxt_js.h | 2 | ||||
-rw-r--r-- | src/nxt_tstr.c | 11 | ||||
-rw-r--r-- | src/nxt_tstr.h | 1 |
4 files changed, 24 insertions, 8 deletions
diff --git a/src/nxt_js.c b/src/nxt_js.c index d46231bd..0482482a 100644 --- a/src/nxt_js.c +++ b/src/nxt_js.c @@ -230,7 +230,7 @@ nxt_js_add_module(nxt_js_conf_t *jcf, nxt_str_t *name, nxt_str_t *text) nxt_js_t * -nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz) +nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_uint_t flags) { size_t size; u_char *p, *start; @@ -243,13 +243,19 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz) " return "); /* - * Appending a terminating null character if strz is true. + * Append a newline character if newline is true. + * Append a terminating null character if strz is true. */ + static const nxt_str_t newline_str = nxt_string(" + '\\x0A'"); static const nxt_str_t strz_str = nxt_string(" + '\\x00'"); size = func_str.length + str->length + 1; - if (strz) { + if (flags & NXT_TSTR_NEWLINE) { + size += newline_str.length; + } + + if (flags & NXT_TSTR_STRZ) { size += strz_str.length; } @@ -263,7 +269,11 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz) p = nxt_cpymem(p, func_str.start, func_str.length); p = nxt_cpymem(p, str->start, str->length); - if (strz) { + if (flags & NXT_TSTR_NEWLINE) { + p = nxt_cpymem(p, newline_str.start, newline_str.length); + } + + if (flags & NXT_TSTR_STRZ) { p = nxt_cpymem(p, strz_str.start, strz_str.length); } diff --git a/src/nxt_js.h b/src/nxt_js.h index 48f036b8..53262563 100644 --- a/src/nxt_js.h +++ b/src/nxt_js.h @@ -28,7 +28,7 @@ void nxt_js_conf_release(nxt_js_conf_t *jcf); void nxt_js_set_proto(nxt_js_conf_t *jcf, njs_external_t *proto, nxt_uint_t n); nxt_int_t nxt_js_add_module(nxt_js_conf_t *jcf, nxt_str_t *name, nxt_str_t *text); -nxt_js_t *nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz); +nxt_js_t *nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_uint_t flags); nxt_int_t nxt_js_compile(nxt_js_conf_t *jcf); nxt_int_t nxt_js_test(nxt_js_conf_t *jcf, nxt_str_t *str, u_char *error); nxt_int_t nxt_js_call(nxt_task_t *task, nxt_js_conf_t *jcf, diff --git a/src/nxt_tstr.c b/src/nxt_tstr.c index 50df4c47..36d77e69 100644 --- a/src/nxt_tstr.c +++ b/src/nxt_tstr.c @@ -80,16 +80,17 @@ nxt_tstr_compile(nxt_tstr_state_t *state, const nxt_str_t *str, { u_char *p; nxt_tstr_t *tstr; - nxt_bool_t strz; + nxt_bool_t strz, newline; strz = (flags & NXT_TSTR_STRZ) != 0; + newline = (flags & NXT_TSTR_NEWLINE) != 0; tstr = nxt_mp_get(state->pool, sizeof(nxt_tstr_t)); if (nxt_slow_path(tstr == NULL)) { return NULL; } - tstr->str.length = str->length + strz; + tstr->str.length = str->length + newline + strz; tstr->str.start = nxt_mp_nget(state->pool, tstr->str.length); if (nxt_slow_path(tstr->str.start == NULL)) { @@ -98,6 +99,10 @@ nxt_tstr_compile(nxt_tstr_state_t *state, const nxt_str_t *str, p = nxt_cpymem(tstr->str.start, str->start, str->length); + if (newline) { + *p++ = '\n'; + } + if (strz) { *p = '\0'; } @@ -114,7 +119,7 @@ nxt_tstr_compile(nxt_tstr_state_t *state, const nxt_str_t *str, nxt_tstr_str(tstr, &tpl); - tstr->u.js = nxt_js_add_tpl(state->jcf, &tpl, strz); + tstr->u.js = nxt_js_add_tpl(state->jcf, &tpl, flags); if (nxt_slow_path(tstr->u.js == NULL)) { return NULL; } diff --git a/src/nxt_tstr.h b/src/nxt_tstr.h index aca74e20..8e3cdb93 100644 --- a/src/nxt_tstr.h +++ b/src/nxt_tstr.h @@ -34,6 +34,7 @@ typedef struct { typedef enum { NXT_TSTR_STRZ = 1 << 0, NXT_TSTR_LOGGING = 1 << 1, + NXT_TSTR_NEWLINE = 1 << 2, } nxt_tstr_flags_t; |