# HG changeset patch # User Igor Sysoev # Date 1164638775 0 # Node ID 3b763d36e055629ae39e1717d1d4494055a5ee76 # Parent 804514cb075829209364a038abbe7e2dc16a2084 axe old % log format diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -270,8 +270,7 @@ HTTP_DEPS="src/http/ngx_http.h \ src/http/ngx_http_variables.h \ src/http/ngx_http_script.h \ src/http/ngx_http_upstream.h \ - src/http/ngx_http_busy_lock.h \ - src/http/modules/ngx_http_log_module.h" + src/http/ngx_http_busy_lock.h" HTTP_SRCS="src/http/ngx_http.c \ src/http/ngx_http_core_module.c \ diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c --- a/src/http/modules/ngx_http_gzip_filter_module.c +++ b/src/http/modules/ngx_http_gzip_filter_module.c @@ -76,9 +76,6 @@ static void *ngx_http_gzip_filter_alloc( static void ngx_http_gzip_filter_free(void *opaque, void *address); static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); -static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); - static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf); static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); @@ -230,14 +227,6 @@ ngx_module_t ngx_http_gzip_filter_modul }; -static ngx_http_log_op_name_t ngx_http_gzip_log_fmt_ops[] = { - { ngx_string("gzip_ratio"), NGX_INT32_LEN + 3, - NULL, NULL, ngx_http_gzip_log_ratio }, - { ngx_null_string, 0, NULL, NULL, NULL } -}; - - - static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 }; #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) @@ -907,39 +896,6 @@ ngx_http_gzip_filter_free(void *opaque, } -static u_char * -ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_uint_t zint, zfrac; - ngx_http_gzip_ctx_t *ctx; - - ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); - - if (ctx == NULL || ctx->zout == 0) { - *buf = '-'; - return buf + 1; - } - - zint = (ngx_uint_t) (ctx->zin / ctx->zout); - zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); - - if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) { - - /* the rounding, e.g., 2.125 to 2.13 */ - - zfrac++; - - if (zfrac > 99) { - zint++; - zfrac = 0; - } - } - - return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); -} - - static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) { @@ -961,8 +917,7 @@ ngx_http_gzip_error(ngx_http_gzip_ctx_t static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf) { - ngx_http_variable_t *var; - ngx_http_log_op_name_t *op; + ngx_http_variable_t *var; var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, NGX_HTTP_VAR_NOHASH); if (var == NULL) { @@ -971,17 +926,6 @@ ngx_http_gzip_add_variables(ngx_conf_t * var->get_handler = ngx_http_gzip_ratio_variable; - for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ } - op->run = NULL; - - for (op = ngx_http_log_fmt_ops; op->run; op++) { - if (op->name.len == 0) { - op = (ngx_http_log_op_name_t *) op->run; - } - } - - op->run = (ngx_http_log_op_run_pt) ngx_http_gzip_log_fmt_ops; - return NGX_OK; } diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c --- a/src/http/modules/ngx_http_log_module.c +++ b/src/http/modules/ngx_http_log_module.c @@ -10,6 +10,22 @@ #include +typedef struct ngx_http_log_op_s ngx_http_log_op_t; + +typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf, + ngx_http_log_op_t *op); + +typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r, + uintptr_t data); + + +struct ngx_http_log_op_s { + size_t len; + ngx_http_log_op_getlen_pt getlen; + ngx_http_log_op_run_pt run; + uintptr_t data; +}; + typedef struct { ngx_str_t name; @@ -43,8 +59,6 @@ typedef struct { } ngx_http_log_var_t; -static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op); static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, @@ -64,41 +78,6 @@ static u_char *ngx_http_log_body_bytes_s static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op); -static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); - -static ngx_int_t ngx_http_log_header_in_compile(ngx_conf_t *cf, - ngx_http_log_op_t *op, ngx_str_t *value); -static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); -static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); - -static ngx_int_t ngx_http_log_header_out_compile(ngx_conf_t *cf, - ngx_http_log_op_t *op, ngx_str_t *value); -static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); -static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); - -static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); -static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); - -static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers, - ngx_str_t *value); - static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, ngx_str_t *value); static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r, @@ -107,7 +86,6 @@ static u_char *ngx_http_log_variable(ngx ngx_http_log_op_t *op); -static ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf); static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, @@ -143,7 +121,7 @@ static ngx_command_t ngx_http_log_comma static ngx_http_module_t ngx_http_log_module_ctx = { - ngx_http_log_set_formats, /* preconfiguration */ + NULL, /* preconfiguration */ ngx_http_log_init, /* postconfiguration */ ngx_http_log_create_main_conf, /* create main configuration */ @@ -202,39 +180,6 @@ static ngx_http_log_var_t ngx_http_log_ }; -ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { - { ngx_string("addr"), INET_ADDRSTRLEN - 1, NULL, NULL, ngx_http_log_addr }, - { ngx_string("conn"), NGX_ATOMIC_T_LEN, NULL, NULL, - ngx_http_log_connection }, - { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, - { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, - NULL, NULL, ngx_http_log_time }, - { ngx_string("msec"), NGX_TIME_T_LEN + 4, NULL, NULL, ngx_http_log_msec }, - { ngx_string("request_time"), NGX_TIME_T_LEN, NULL, NULL, - ngx_http_log_request_time }, - { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, - { ngx_string("length"), NGX_OFF_T_LEN, - NULL, NULL, ngx_http_log_bytes_sent }, - { ngx_string("apache_length"), NGX_OFF_T_LEN, - NULL, NULL, ngx_http_log_body_bytes_sent }, - { ngx_string("request_length"), NGX_SIZE_T_LEN, - NULL, NULL, ngx_http_log_request_length }, - - { ngx_string("request"), 0, NULL, - ngx_http_log_request_getlen, - ngx_http_log_request }, - - { ngx_string("i"), 0, ngx_http_log_header_in_compile, NULL, - ngx_http_log_header_in }, - { ngx_string("o"), 0, ngx_http_log_header_out_compile, NULL, - ngx_http_log_header_out }, - { ngx_string("v"), 0, ngx_http_log_variable_compile, NULL, - ngx_http_log_variable }, - - { ngx_null_string, 0, NULL, NULL, NULL } -}; - - ngx_int_t ngx_http_log_handler(ngx_http_request_t *r) { @@ -367,14 +312,6 @@ ngx_http_log_copy_long(ngx_http_request_ static u_char * -ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) -{ - return ngx_cpymem(buf, r->connection->addr_text.data, - r->connection->addr_text.len); -} - - -static u_char * ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) { @@ -426,20 +363,6 @@ ngx_http_log_request_time(ngx_http_reque } -static size_t -ngx_http_log_request_getlen(ngx_http_request_t *r, uintptr_t data) -{ - return r->request_line.len; -} - - -static u_char * -ngx_http_log_request(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) -{ - return ngx_cpymem(buf, r->request_line.data, r->request_line.len); -} - - static u_char * ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) { @@ -483,363 +406,6 @@ ngx_http_log_request_length(ngx_http_req static ngx_int_t -ngx_http_log_header_in_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, - ngx_str_t *value) -{ - ngx_uint_t i; - - op->len = 0; - - for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) { - - if (ngx_http_headers_in[i].name.len != value->len) { - continue; - } - - /* STUB: "Cookie" speacial handling */ - if (ngx_http_headers_in[i].offset == 0) { - continue; - } - - if (ngx_strncasecmp(ngx_http_headers_in[i].name.data, value->data, - value->len) == 0) - { - op->getlen = ngx_http_log_header_in_getlen; - op->run = ngx_http_log_header_in; - op->data = ngx_http_headers_in[i].offset; - - return NGX_OK; - } - } - - op->getlen = ngx_http_log_unknown_header_in_getlen; - op->run = ngx_http_log_unknown_header_in; - op->data = (uintptr_t) value; - - return NGX_OK; -} - - -static size_t -ngx_http_log_header_in_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_table_elt_t *h; - - h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data); - - if (h) { - return h->value.len; - } - - return 1; -} - - -static u_char * -ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_table_elt_t *h; - - h = *(ngx_table_elt_t **) ((char *) &r->headers_in + op->data); - - if (h) { - return ngx_cpymem(buf, h->value.data, h->value.len); - } - - *buf = '-'; - - return buf + 1; -} - - -static size_t -ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_table_elt_t *h; - - h = ngx_http_log_unknown_header(&r->headers_in.headers, (ngx_str_t *) data); - - if (h) { - return h->value.len; - } - - return 1; -} - - -static u_char * -ngx_http_log_unknown_header_in(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_table_elt_t *h; - - h = ngx_http_log_unknown_header(&r->headers_in.headers, - (ngx_str_t *) op->data); - - if (h) { - return ngx_cpymem(buf, h->value.data, h->value.len); - } - - *buf = '-'; - - return buf + 1; -} - - -static ngx_int_t -ngx_http_log_header_out_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, - ngx_str_t *value) -{ - ngx_uint_t i; - - op->len = 0; - - for (i = 0; ngx_http_headers_out[i].name.len != 0; i++) { - - if (ngx_http_headers_out[i].name.len != value->len) { - continue; - } - - if (ngx_strncasecmp(ngx_http_headers_out[i].name.data, value->data, - value->len) == 0) - { - op->getlen = ngx_http_log_header_out_getlen; - op->run = ngx_http_log_header_out; - op->data = ngx_http_headers_out[i].offset; - - return NGX_OK; - } - } - - if (value->len == sizeof("Connection") - 1 - && ngx_strncasecmp(value->data, "Connection", value->len) == 0) - { - op->len = sizeof("keep-alive") - 1; - op->getlen = NULL; - op->run = ngx_http_log_connection_header_out; - op->data = 0; - return NGX_OK; - } - - if (value->len == sizeof("Transfer-Encoding") - 1 - && ngx_strncasecmp(value->data, "Transfer-Encoding", value->len) == 0) - { - op->len = sizeof("chunked") - 1; - op->getlen = NULL; - op->run = ngx_http_log_transfer_encoding_header_out; - op->data = 0; - return NGX_OK; - } - - op->getlen = ngx_http_log_unknown_header_out_getlen; - op->run = ngx_http_log_unknown_header_out; - op->data = (uintptr_t) value; - - return NGX_OK; -} - - -static size_t -ngx_http_log_header_out_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_table_elt_t *h; - - h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data); - - if (h) { - return h->value.len; - } - - /* - * No header pointer was found. - * However, some headers: "Date", "Server", "Content-Length", - * and "Last-Modified" have a special handling in the header filter, - * but we do not set up their pointers in the filter, - * because they are too seldom needed to be logged. - */ - - if (data == offsetof(ngx_http_headers_out_t, date)) { - return ngx_cached_http_time.len; - } - - if (data == offsetof(ngx_http_headers_out_t, server)) { - return (sizeof(NGINX_VER) - 1); - } - - if (data == offsetof(ngx_http_headers_out_t, content_length)) { - if (r->headers_out.content_length_n == -1) { - return 1; - } - - return NGX_OFF_T_LEN; - } - - if (data == offsetof(ngx_http_headers_out_t, last_modified)) { - if (r->headers_out.last_modified_time == -1) { - return 1; - } - - return sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; - } - - return 1; -} - - -static u_char * -ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_table_elt_t *h; - - h = *(ngx_table_elt_t **) ((char *) &r->headers_out + op->data); - - if (h) { - return ngx_cpymem(buf, h->value.data, h->value.len); - } - - /* - * No header pointer was found. - * However, some headers: "Date", "Server", "Content-Length", - * and "Last-Modified" have a special handling in the header filter, - * but we do not set up their pointers in the filter, - * because they are too seldom needed to be logged. - */ - - if (op->data == offsetof(ngx_http_headers_out_t, date)) { - return ngx_cpymem(buf, ngx_cached_http_time.data, - ngx_cached_http_time.len); - } - - if (op->data == offsetof(ngx_http_headers_out_t, server)) { - return ngx_cpymem(buf, NGINX_VER, sizeof(NGINX_VER) - 1); - } - - if (op->data == offsetof(ngx_http_headers_out_t, content_length)) { - if (r->headers_out.content_length_n == -1) { - *buf = '-'; - - return buf + 1; - } - - return ngx_sprintf(buf, "%O", r->headers_out.content_length_n); - } - - if (op->data == offsetof(ngx_http_headers_out_t, last_modified)) { - if (r->headers_out.last_modified_time == -1) { - *buf = '-'; - - return buf + 1; - } - - return ngx_http_time(buf, r->headers_out.last_modified_time); - } - - *buf = '-'; - - return buf + 1; -} - - -static size_t -ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_table_elt_t *h; - - h = ngx_http_log_unknown_header(&r->headers_out.headers, - (ngx_str_t *) data); - - if (h) { - return h->value.len; - } - - return 1; -} - - -static u_char * -ngx_http_log_unknown_header_out(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_table_elt_t *h; - - h = ngx_http_log_unknown_header(&r->headers_out.headers, - (ngx_str_t *) op->data); - - if (h) { - return ngx_cpymem(buf, h->value.data, h->value.len); - } - - *buf = '-'; - - return buf + 1; -} - - -static ngx_table_elt_t * -ngx_http_log_unknown_header(ngx_list_t *headers, ngx_str_t *value) -{ - ngx_uint_t i; - ngx_list_part_t *part; - ngx_table_elt_t *h; - - part = &headers->part; - h = part->elts; - - for (i = 0; /* void */; i++) { - - if (i >= part->nelts) { - if (part->next == NULL) { - break; - } - - part = part->next; - h = part->elts; - i = 0; - } - - if (h[i].key.len != value->len) { - continue; - } - - if (ngx_strncasecmp(h[i].key.data, value->data, value->len) == 0) { - return &h[i]; - } - } - - return NULL; -} - - -static u_char * -ngx_http_log_connection_header_out(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - if (r->keepalive) { - return ngx_cpymem(buf, "keep-alive", sizeof("keep-alive") - 1); - - } else { - return ngx_cpymem(buf, "close", sizeof("close") - 1); - } -} - - -static u_char * -ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - if (r->chunked) { - return ngx_cpymem(buf, "chunked", sizeof("chunked") - 1); - } - - *buf = '-'; - - return buf + 1; -} - - -static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, ngx_str_t *value) { @@ -890,18 +456,6 @@ ngx_http_log_variable(ngx_http_request_t } -static ngx_int_t -ngx_http_log_set_formats(ngx_conf_t *cf) -{ - ngx_http_log_op_name_t *op; - - for (op = ngx_http_log_fmt_ops; op->name.len; op++) { /* void */ } - op->run = NULL; - - return NGX_OK; -} - - static void * ngx_http_log_create_main_conf(ngx_conf_t *cf) { @@ -1152,20 +706,36 @@ static char * ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) { - u_char *data, *p, *fname, *arg_data, ch; - size_t i, len, fname_len, arg_len; - ngx_str_t *value, var, *a; - ngx_uint_t bracket; - ngx_http_log_op_t *op; - ngx_http_log_var_t *v; - ngx_http_log_op_name_t *name; - static ngx_uint_t warn; + u_char *data, *p, ch; + size_t i, len; + ngx_str_t *value, var; + ngx_uint_t bracket; + ngx_http_log_op_t *op; + ngx_http_log_var_t *v; value = args->elts; - arg_data = NULL; for ( /* void */ ; s < args->nelts; s++) { + for (i = 0; i < value[s].len; i++) { + if (value[s].data[i] != '%') { + continue; + } + + ch = value[s].data[i + 1]; + + if ((ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || ch == '{') + { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "the parameters in the \"%%name\" form are not supported, " + "use the \"$variable\" instead"); + + return NGX_CONF_ERROR; + } + } + i = 0; while (i < value[s].len) { @@ -1177,112 +747,7 @@ ngx_http_log_compile_format(ngx_conf_t * data = &value[s].data[i]; - if (value[s].data[i] == '%') { - i++; - - if (i == value[s].len) { - goto invalid; - } - - if (value[s].data[i] == '{') { - i++; - - arg_data = &value[s].data[i]; - - while (i < value[s].len && value[s].data[i] != '}') { - i++; - } - - arg_len = &value[s].data[i] - arg_data; - - if (i == value[s].len || arg_len == 0) { - goto invalid; - } - - i++; - - } else { - arg_len = 0; - } - - if (warn == 0) { - ngx_conf_log_error(NGX_LOG_WARN, cf, 0, - "the parameters in the \"%%name\" form are deprecated, " - "use the \"$variable\" instead"); - warn = 1; - } - - fname = &value[s].data[i]; - - while (i < value[s].len - && ((value[s].data[i] >= 'a' && value[s].data[i] <= 'z') - || value[s].data[i] == '_')) - { - i++; - } - - fname_len = &value[s].data[i] - fname; - - if (fname_len == 0) { - goto invalid; - } - - for (name = ngx_http_log_fmt_ops; name->run; name++) { - if (name->name.len == 0) { - name = (ngx_http_log_op_name_t *) name->run; - } - - if (name->name.len == fname_len - && ngx_strncmp(name->name.data, fname, fname_len) == 0) - { - if (name->compile == NULL) { - if (arg_len) { - fname[fname_len] = '\0'; - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" must not have argument", - data); - return NGX_CONF_ERROR; - } - - op->len = name->len; - op->getlen = name->getlen; - op->run = name->run; - op->data = 0; - - break; - } - - if (arg_len == 0) { - fname[fname_len] = '\0'; - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" requires argument", - data); - return NGX_CONF_ERROR; - } - - a = ngx_palloc(cf->pool, sizeof(ngx_str_t)); - if (a == NULL) { - return NGX_CONF_ERROR; - } - - a->len = arg_len; - a->data = arg_data; - - if (name->compile(cf, op, a) == NGX_ERROR) { - return NGX_CONF_ERROR; - } - - break; - } - } - - if (name->name.len == 0) { - goto invalid; - } - - continue; - - } else if (value[s].data[i] == '$') { + if (value[s].data[i] == '$') { if (++i == value[s].len) { goto invalid; @@ -1364,10 +829,7 @@ ngx_http_log_compile_format(ngx_conf_t * i++; - while (i < value[s].len - && value[s].data[i] != '$' - && value[s].data[i] != '%') - { + while (i < value[s].len && value[s].data[i] != '$') { i++; } diff --git a/src/http/modules/ngx_http_log_module.h b/src/http/modules/ngx_http_log_module.h deleted file mode 100644 --- a/src/http/modules/ngx_http_log_module.h +++ /dev/null @@ -1,48 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - */ - - -#ifndef _NGX_HTTP_LOG_MODULE_H_INCLUDED_ -#define _NGX_HTTP_LOG_MODULE_H_INCLUDED_ - - -#include -#include -#include - - -typedef struct ngx_http_log_op_s ngx_http_log_op_t; - -typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); - -typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r, - uintptr_t data); - -typedef ngx_int_t (*ngx_http_log_op_compile_pt) (ngx_conf_t *cf, - ngx_http_log_op_t *op, ngx_str_t *value); - - -struct ngx_http_log_op_s { - size_t len; - ngx_http_log_op_getlen_pt getlen; - ngx_http_log_op_run_pt run; - uintptr_t data; -}; - - -typedef struct { - ngx_str_t name; - size_t len; - ngx_http_log_op_compile_pt compile; - ngx_http_log_op_getlen_pt getlen; - ngx_http_log_op_run_pt run; -} ngx_http_log_op_name_t; - - -extern ngx_http_log_op_name_t ngx_http_log_fmt_ops[]; - - -#endif /* _NGX_HTTP_LOG_MODULE_H_INCLUDED_ */ diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c --- a/src/http/modules/ngx_http_userid_filter_module.c +++ b/src/http/modules/ngx_http_userid_filter_module.c @@ -46,15 +46,6 @@ static void ngx_http_userid_get_uid(ngx_ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf); -static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); -static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op); - static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf); static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); @@ -191,17 +182,6 @@ ngx_module_t ngx_http_userid_filter_mod }; -static ngx_http_log_op_name_t ngx_http_userid_log_fmt_ops[] = { - { ngx_string("uid_got"), 0, NULL, - ngx_http_userid_log_uid_got_getlen, - ngx_http_userid_log_uid_got }, - { ngx_string("uid_set"), 0, NULL, - ngx_http_userid_log_uid_set_getlen, - ngx_http_userid_log_uid_set }, - { ngx_null_string, 0, NULL, NULL, NULL } -}; - - static ngx_str_t ngx_http_userid_got = ngx_string("uid_got"); static ngx_str_t ngx_http_userid_set = ngx_string("uid_set"); @@ -462,99 +442,10 @@ ngx_http_userid_set_uid(ngx_http_request } -static size_t -ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_http_userid_ctx_t *ctx; - ngx_http_userid_conf_t *conf; - - ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); - - if (ctx == NULL || ctx->uid_got[3] == 0) { - return 1; - } - - conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - - return conf->name.len + 1 + 32; -} - - -static u_char * -ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_http_userid_ctx_t *ctx; - ngx_http_userid_conf_t *conf; - - ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); - - if (ctx == NULL || ctx->uid_got[3] == 0) { - *buf = '-'; - return buf + 1; - } - - conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - - buf = ngx_copy(buf, conf->name.data, conf->name.len); - - *buf++ = '='; - - return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", - ctx->uid_got[0], ctx->uid_got[1], - ctx->uid_got[2], ctx->uid_got[3]); -} - - -static size_t -ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, uintptr_t data) -{ - ngx_http_userid_ctx_t *ctx; - ngx_http_userid_conf_t *conf; - - ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); - - if (ctx == NULL || ctx->uid_set[3] == 0) { - return 1; - } - - conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - - return conf->name.len + 1 + 32; -} - - -static u_char * -ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_http_userid_ctx_t *ctx; - ngx_http_userid_conf_t *conf; - - ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); - - if (ctx == NULL || ctx->uid_set[3] == 0) { - *buf = '-'; - return buf + 1; - } - - conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - - buf = ngx_copy(buf, conf->name.data, conf->name.len); - - *buf++ = '='; - - return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", - ctx->uid_set[0], ctx->uid_set[1], - ctx->uid_set[2], ctx->uid_set[3]); -} - - static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf) { - ngx_http_variable_t *var; - ngx_http_log_op_name_t *op; + ngx_http_variable_t *var; var = ngx_http_add_variable(cf, &ngx_http_userid_got, NGX_HTTP_VAR_NOHASH); if (var == NULL) { @@ -572,18 +463,6 @@ ngx_http_userid_add_variables(ngx_conf_t var->get_handler = ngx_http_userid_variable; var->data = offsetof(ngx_http_userid_ctx_t, uid_set); - - for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } - op->run = NULL; - - for (op = ngx_http_log_fmt_ops; op->run; op++) { - if (op->name.len == 0) { - op = (ngx_http_log_op_name_t *) op->run; - } - } - - op->run = (ngx_http_log_op_run_pt) ngx_http_userid_log_fmt_ops; - return NGX_OK; } diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -34,7 +34,6 @@ typedef u_char *(*ngx_http_log_handler_p #include #include #include -#include #include #include diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -70,15 +70,6 @@ static ngx_int_t ngx_http_upstream_copy_ ngx_table_elt_t *h, ngx_uint_t offset); #endif -static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); -static size_t ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r, - uintptr_t data); -static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r, - u_char *buf, ngx_http_log_op_t *op); - static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); @@ -265,17 +256,6 @@ ngx_module_t ngx_http_upstream_module = }; -static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = { - { ngx_string("upstream_status"), 0, NULL, - ngx_http_upstream_log_status_getlen, - ngx_http_upstream_log_status }, - { ngx_string("upstream_response_time"), 0, NULL, - ngx_http_upstream_log_response_time_getlen, - ngx_http_upstream_log_response_time }, - { ngx_null_string, 0, NULL, NULL, NULL } -}; - - static ngx_http_variable_t ngx_http_upstream_vars[] = { { ngx_string("upstream_status"), NULL, @@ -2481,108 +2461,10 @@ ngx_http_upstream_copy_content_encoding( #endif -static size_t -ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data) -{ - if (r->upstream) { - return r->upstream->states.nelts * (3 + 2); - } - - return 1; -} - - -static u_char * -ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_uint_t i; - ngx_http_upstream_t *u; - ngx_http_upstream_state_t *state; - - u = r->upstream; - - if (u == NULL || u->states.nelts == 0) { - *buf = '-'; - return buf + 1; - } - - i = 0; - state = u->states.elts; - - for ( ;; ) { - if (state[i].status == 0) { - *buf++ = '-'; - - } else { - buf = ngx_sprintf(buf, "%ui", state[i].status); - } - - if (++i == u->states.nelts) { - return buf; - } - - *buf++ = ','; - *buf++ = ' '; - } -} - - -static size_t -ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r, - uintptr_t data) -{ - if (r->upstream) { - return r->upstream->states.nelts * (NGX_TIME_T_LEN + 4 + 2); - } - - return 1; -} - - -static u_char * -ngx_http_upstream_log_response_time(ngx_http_request_t *r, u_char *buf, - ngx_http_log_op_t *op) -{ - ngx_uint_t i; - ngx_http_upstream_t *u; - ngx_http_upstream_state_t *state; - - u = r->upstream; - - if (u == NULL || u->states.nelts == 0) { - *buf = '-'; - return buf + 1; - } - - i = 0; - state = u->states.elts; - - for ( ;; ) { - if (state[i].status == 0) { - *buf++ = '-'; - - } else { - buf = ngx_sprintf(buf, "%d.%03d", - state[i].response_time / 1000, - state[i].response_time % 1000); - } - - if (++i == u->states.nelts) { - return buf; - } - - *buf++ = ','; - *buf++ = ' '; - } -} - - static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf) { - ngx_http_variable_t *var, *v; - ngx_http_log_op_name_t *op; + ngx_http_variable_t *var, *v; for (v = ngx_http_upstream_vars; v->name.len; v++) { var = ngx_http_add_variable(cf, &v->name, v->flags); @@ -2594,17 +2476,6 @@ ngx_http_upstream_add_variables(ngx_conf var->data = v->data; } - for (op = ngx_http_upstream_log_fmt_ops; op->name.len; op++) { /* void */ } - op->run = NULL; - - for (op = ngx_http_log_fmt_ops; op->run; op++) { - if (op->name.len == 0) { - op = (ngx_http_log_op_name_t *) op->run; - } - } - - op->run = (ngx_http_log_op_run_pt) ngx_http_upstream_log_fmt_ops; - return NGX_OK; }