Stream: log module.

This commit is contained in:
Vladimir Homutov 2016-09-05 17:50:16 +03:00
parent 443b52db59
commit 68a7b9b5a3
6 changed files with 1556 additions and 0 deletions

View File

@ -971,6 +971,7 @@ if [ $STREAM != NO ]; then
ngx_module_name="ngx_stream_module \
ngx_stream_core_module \
ngx_stream_log_module \
ngx_stream_proxy_module \
ngx_stream_upstream_module"
ngx_module_incs="src/stream"
@ -984,6 +985,7 @@ if [ $STREAM != NO ]; then
src/stream/ngx_stream_script.c \
src/stream/ngx_stream_handler.c \
src/stream/ngx_stream_core_module.c \
src/stream/ngx_stream_log_module.c \
src/stream/ngx_stream_proxy_module.c \
src/stream/ngx_stream_upstream.c \
src/stream/ngx_stream_upstream_round_robin.c"

View File

@ -121,6 +121,7 @@ typedef struct {
ngx_stream_access_pt limit_conn_handler;
ngx_stream_access_pt access_handler;
ngx_stream_access_pt access_log_handler;
ngx_hash_t variables_hash;

View File

@ -311,11 +311,19 @@ ngx_stream_ssl_handshake_handler(ngx_connection_t *c)
void
ngx_stream_finalize_session(ngx_stream_session_t *s, ngx_uint_t rc)
{
ngx_stream_core_main_conf_t *cmcf;
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
"finalize stream session: %i", rc);
s->status = rc;
cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module);
if (cmcf->access_log_handler) {
(void) cmcf->access_log_handler(s);
}
ngx_stream_close_connection(s->connection);
}

File diff suppressed because it is too large Load Diff

View File

@ -388,6 +388,73 @@ invalid_variable:
}
u_char *
ngx_stream_script_run(ngx_stream_session_t *s, ngx_str_t *value,
void *code_lengths, size_t len, void *code_values)
{
ngx_uint_t i;
ngx_stream_script_code_pt code;
ngx_stream_script_engine_t e;
ngx_stream_core_main_conf_t *cmcf;
ngx_stream_script_len_code_pt lcode;
cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module);
for (i = 0; i < cmcf->variables.nelts; i++) {
if (s->variables[i].no_cacheable) {
s->variables[i].valid = 0;
s->variables[i].not_found = 0;
}
}
ngx_memzero(&e, sizeof(ngx_stream_script_engine_t));
e.ip = code_lengths;
e.session = s;
e.flushed = 1;
while (*(uintptr_t *) e.ip) {
lcode = *(ngx_stream_script_len_code_pt *) e.ip;
len += lcode(&e);
}
value->len = len;
value->data = ngx_pnalloc(s->connection->pool, len);
if (value->data == NULL) {
return NULL;
}
e.ip = code_values;
e.pos = value->data;
while (*(uintptr_t *) e.ip) {
code = *(ngx_stream_script_code_pt *) e.ip;
code((ngx_stream_script_engine_t *) &e);
}
return e.pos;
}
void
ngx_stream_script_flush_no_cacheable_variables(ngx_stream_session_t *s,
ngx_array_t *indices)
{
ngx_uint_t n, *index;
if (indices) {
index = indices->elts;
for (n = 0; n < indices->nelts; n++) {
if (s->variables[index[n]].no_cacheable) {
s->variables[index[n]].valid = 0;
s->variables[index[n]].not_found = 0;
}
}
}
}
static ngx_int_t
ngx_stream_script_init_arrays(ngx_stream_script_compile_t *sc)
{

View File

@ -110,6 +110,10 @@ char *ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_uint_t ngx_stream_script_variables_count(ngx_str_t *value);
ngx_int_t ngx_stream_script_compile(ngx_stream_script_compile_t *sc);
u_char *ngx_stream_script_run(ngx_stream_session_t *s, ngx_str_t *value,
void *code_lengths, size_t reserved, void *code_values);
void ngx_stream_script_flush_no_cacheable_variables(ngx_stream_session_t *s,
ngx_array_t *indices);
void *ngx_stream_script_add_code(ngx_array_t *codes, size_t size, void *code);