Mercurial > hg > nginx-vendor-1-0
comparison src/http/modules/ngx_http_log_module.c @ 122:d25a1d6034f1 NGINX_0_3_8
nginx 0.3.8
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; bug appeared
in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 09 Nov 2005 00:00:00 +0300 |
parents | e85dca77c46a |
children | df17fbafec8f |
comparison
equal
deleted
inserted
replaced
121:737953b238a4 | 122:d25a1d6034f1 |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 #include <nginx.h> | 10 #include <nginx.h> |
11 | |
12 | |
13 | |
14 typedef struct { | |
15 ngx_str_t name; | |
16 ngx_array_t *ops; /* array of ngx_http_log_op_t */ | |
17 } ngx_http_log_fmt_t; | |
18 | |
19 typedef struct { | |
20 ngx_array_t formats; /* array of ngx_http_log_fmt_t */ | |
21 ngx_uint_t combined_used; /* unsigned combined_used:1 */ | |
22 } ngx_http_log_main_conf_t; | |
23 | |
24 typedef struct { | |
25 ngx_open_file_t *file; | |
26 ngx_array_t *ops; /* array of ngx_http_log_op_t */ | |
27 } ngx_http_log_t; | |
28 | |
29 typedef struct { | |
30 ngx_array_t *logs; /* array of ngx_http_log_t */ | |
31 ngx_uint_t off; /* unsigned off:1 */ | |
32 } ngx_http_log_loc_conf_t; | |
33 | |
34 | |
35 typedef struct { | |
36 ngx_str_t name; | |
37 size_t len; | |
38 ngx_http_log_op_run_pt run; | |
39 } ngx_http_log_var_t; | |
11 | 40 |
12 | 41 |
13 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, | 42 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, |
14 ngx_http_log_op_t *op); | 43 ngx_http_log_op_t *op); |
15 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, | 44 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, |
22 ngx_http_log_op_t *op); | 51 ngx_http_log_op_t *op); |
23 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | 52 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, |
24 ngx_http_log_op_t *op); | 53 ngx_http_log_op_t *op); |
25 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, | 54 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
26 ngx_http_log_op_t *op); | 55 ngx_http_log_op_t *op); |
27 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, | 56 static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
28 ngx_http_log_op_t *op); | 57 ngx_http_log_op_t *op); |
29 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, | 58 static u_char *ngx_http_log_apache_bytes_sent(ngx_http_request_t *r, |
30 ngx_http_log_op_t *op); | 59 u_char *buf, ngx_http_log_op_t *op); |
31 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | 60 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
32 ngx_http_log_op_t *op); | 61 ngx_http_log_op_t *op); |
33 | 62 |
34 static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, | 63 static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, |
35 uintptr_t data); | 64 uintptr_t data); |
81 void *child); | 110 void *child); |
82 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, | 111 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
83 void *conf); | 112 void *conf); |
84 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, | 113 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
85 void *conf); | 114 void *conf); |
86 static ngx_int_t ngx_http_log_init(ngx_cycle_t *cycle); | 115 static char *ngx_http_log_compile_format(ngx_conf_t *cf, |
116 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); | |
117 static ngx_int_t ngx_http_log_init(ngx_conf_t *cf); | |
87 | 118 |
88 | 119 |
89 static ngx_command_t ngx_http_log_commands[] = { | 120 static ngx_command_t ngx_http_log_commands[] = { |
90 | 121 |
91 { ngx_string("log_format"), | 122 { ngx_string("log_format"), |
106 }; | 137 }; |
107 | 138 |
108 | 139 |
109 ngx_http_module_t ngx_http_log_module_ctx = { | 140 ngx_http_module_t ngx_http_log_module_ctx = { |
110 ngx_http_log_set_formats, /* preconfiguration */ | 141 ngx_http_log_set_formats, /* preconfiguration */ |
111 NULL, /* postconfiguration */ | 142 ngx_http_log_init, /* postconfiguration */ |
112 | 143 |
113 ngx_http_log_create_main_conf, /* create main configuration */ | 144 ngx_http_log_create_main_conf, /* create main configuration */ |
114 NULL, /* init main configuration */ | 145 NULL, /* init main configuration */ |
115 | 146 |
116 NULL, /* create server configuration */ | 147 NULL, /* create server configuration */ |
125 NGX_MODULE_V1, | 156 NGX_MODULE_V1, |
126 &ngx_http_log_module_ctx, /* module context */ | 157 &ngx_http_log_module_ctx, /* module context */ |
127 ngx_http_log_commands, /* module directives */ | 158 ngx_http_log_commands, /* module directives */ |
128 NGX_HTTP_MODULE, /* module type */ | 159 NGX_HTTP_MODULE, /* module type */ |
129 NULL, /* init master */ | 160 NULL, /* init master */ |
130 ngx_http_log_init, /* init module */ | 161 NULL, /* init module */ |
131 NULL, /* init process */ | 162 NULL, /* init process */ |
132 NULL, /* init thread */ | 163 NULL, /* init thread */ |
133 NULL, /* exit thread */ | 164 NULL, /* exit thread */ |
134 NULL, /* exit process */ | 165 NULL, /* exit process */ |
135 NULL, /* exit master */ | 166 NULL, /* exit master */ |
136 NGX_MODULE_V1_PADDING | 167 NGX_MODULE_V1_PADDING |
137 }; | 168 }; |
138 | 169 |
139 | 170 |
140 static ngx_str_t http_access_log = ngx_string(NGX_HTTP_LOG_PATH); | 171 static ngx_str_t http_access_log = ngx_string(NGX_HTTP_LOG_PATH); |
141 | 172 |
142 | 173 |
143 static ngx_str_t ngx_http_combined_fmt = | 174 static ngx_str_t ngx_http_combined_fmt = |
144 #if 0 | 175 ngx_string("$remote_addr - $remote_user [$time_gmt] " |
145 ngx_string("$remote_addr - $remote_user [%time] " | 176 "\"$request\" $status $apache_bytes_sent " |
146 "\"$request\" %status %apache_length " | |
147 "\"$http_referer\" \"$http_user_agent\""); | 177 "\"$http_referer\" \"$http_user_agent\""); |
148 #endif | 178 |
149 ngx_string("%addr - - [%time] " | 179 |
150 "\"%request\" %status %apache_length " | 180 static ngx_http_log_var_t ngx_http_log_vars[] = { |
151 "\"%{referer}i\" \"%{user-agent}i\""); | 181 { ngx_string("connection"), NGX_ATOMIC_T_LEN, ngx_http_log_connection }, |
152 | 182 { ngx_string("pipe"), 1, ngx_http_log_pipe }, |
153 | 183 { ngx_string("time_gmt"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
154 ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { | 184 ngx_http_log_time }, |
185 { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, | |
186 { ngx_string("request_time"), NGX_TIME_T_LEN, ngx_http_log_request_time }, | |
187 { ngx_string("status"), 3, ngx_http_log_status }, | |
188 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, | |
189 { ngx_string("apache_bytes_sent"), NGX_OFF_T_LEN, | |
190 ngx_http_log_apache_bytes_sent }, | |
191 { ngx_string("request_length"), NGX_SIZE_T_LEN, | |
192 ngx_http_log_request_length }, | |
193 | |
194 { ngx_null_string, 0, NULL } | |
195 }; | |
196 | |
197 | |
198 ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = { | |
155 { ngx_string("addr"), INET_ADDRSTRLEN - 1, NULL, NULL, ngx_http_log_addr }, | 199 { ngx_string("addr"), INET_ADDRSTRLEN - 1, NULL, NULL, ngx_http_log_addr }, |
156 { ngx_string("conn"), NGX_ATOMIC_T_LEN, NULL, NULL, | 200 { ngx_string("conn"), NGX_ATOMIC_T_LEN, NULL, NULL, |
157 ngx_http_log_connection }, | 201 ngx_http_log_connection }, |
158 { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, | 202 { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, |
159 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, | 203 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
160 NULL, NULL, ngx_http_log_time }, | 204 NULL, NULL, ngx_http_log_time }, |
161 { ngx_string("msec"), NGX_TIME_T_LEN + 4, NULL, NULL, ngx_http_log_msec }, | 205 { ngx_string("msec"), NGX_TIME_T_LEN + 4, NULL, NULL, ngx_http_log_msec }, |
162 { ngx_string("request_time"), NGX_TIME_T_LEN, NULL, NULL, | 206 { ngx_string("request_time"), NGX_TIME_T_LEN, NULL, NULL, |
163 ngx_http_log_request_time }, | 207 ngx_http_log_request_time }, |
164 { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, | 208 { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, |
165 { ngx_string("length"), NGX_OFF_T_LEN, NULL, NULL, ngx_http_log_length }, | 209 { ngx_string("length"), NGX_OFF_T_LEN, |
210 NULL, NULL, ngx_http_log_bytes_sent }, | |
166 { ngx_string("apache_length"), NGX_OFF_T_LEN, | 211 { ngx_string("apache_length"), NGX_OFF_T_LEN, |
167 NULL, NULL, ngx_http_log_apache_length }, | 212 NULL, NULL, ngx_http_log_apache_bytes_sent }, |
168 { ngx_string("request_length"), NGX_SIZE_T_LEN, | 213 { ngx_string("request_length"), NGX_SIZE_T_LEN, |
169 NULL, NULL, ngx_http_log_request_length }, | 214 NULL, NULL, ngx_http_log_request_length }, |
170 | 215 |
171 { ngx_string("request"), 0, NULL, | 216 { ngx_string("request"), 0, NULL, |
172 ngx_http_log_request_getlen, | 217 ngx_http_log_request_getlen, |
374 r->err_status ? r->err_status : r->headers_out.status); | 419 r->err_status ? r->err_status : r->headers_out.status); |
375 } | 420 } |
376 | 421 |
377 | 422 |
378 static u_char * | 423 static u_char * |
379 ngx_http_log_length(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | 424 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
425 ngx_http_log_op_t *op) | |
380 { | 426 { |
381 return ngx_sprintf(buf, "%O", r->connection->sent); | 427 return ngx_sprintf(buf, "%O", r->connection->sent); |
382 } | 428 } |
383 | 429 |
384 | 430 |
385 static u_char * | 431 static u_char * |
386 ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, | 432 ngx_http_log_apache_bytes_sent(ngx_http_request_t *r, u_char *buf, |
387 ngx_http_log_op_t *op) | 433 ngx_http_log_op_t *op) |
388 { | 434 { |
389 off_t length; | 435 off_t length; |
390 | 436 |
391 length = r->connection->sent - r->header_size; | 437 length = r->connection->sent - r->header_size; |
790 { | 836 { |
791 ngx_http_variable_value_t *value; | 837 ngx_http_variable_value_t *value; |
792 | 838 |
793 value = ngx_http_get_indexed_variable(r, data); | 839 value = ngx_http_get_indexed_variable(r, data); |
794 | 840 |
795 if (value == NULL | 841 if (value == NULL || value->not_found) { |
796 || value == NGX_HTTP_VAR_NOT_FOUND | |
797 || value->text.len == 0) | |
798 { | |
799 return 1; | 842 return 1; |
800 } | 843 } |
801 | 844 |
802 return value->text.len; | 845 return value->len; |
803 } | 846 } |
804 | 847 |
805 | 848 |
806 static u_char * | 849 static u_char * |
807 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | 850 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
808 { | 851 { |
809 ngx_http_variable_value_t *value; | 852 ngx_http_variable_value_t *value; |
810 | 853 |
811 value = ngx_http_get_indexed_variable(r, op->data); | 854 value = ngx_http_get_indexed_variable(r, op->data); |
812 | 855 |
813 if (value == NULL | 856 if (value == NULL || value->not_found) { |
814 || value == NGX_HTTP_VAR_NOT_FOUND | |
815 || value->text.len == 0) | |
816 { | |
817 *buf = '-'; | 857 *buf = '-'; |
818 return buf + 1; | 858 return buf + 1; |
819 } | 859 } |
820 | 860 |
821 return ngx_cpymem(buf, value->text.data, value->text.len); | 861 return ngx_cpymem(buf, value->data, value->len); |
822 } | 862 } |
823 | 863 |
824 | 864 |
825 static ngx_int_t | 865 static ngx_int_t |
826 ngx_http_log_set_formats(ngx_conf_t *cf) | 866 ngx_http_log_set_formats(ngx_conf_t *cf) |
837 static void * | 877 static void * |
838 ngx_http_log_create_main_conf(ngx_conf_t *cf) | 878 ngx_http_log_create_main_conf(ngx_conf_t *cf) |
839 { | 879 { |
840 ngx_http_log_main_conf_t *conf; | 880 ngx_http_log_main_conf_t *conf; |
841 | 881 |
842 char *rc; | 882 ngx_http_log_fmt_t *fmt; |
843 ngx_str_t *value; | |
844 | 883 |
845 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); | 884 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
846 if (conf == NULL) { | 885 if (conf == NULL) { |
847 return NGX_CONF_ERROR; | 886 return NGX_CONF_ERROR; |
848 } | 887 } |
849 | 888 |
850 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) | 889 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
851 == NGX_ERROR) | 890 != NGX_OK) |
852 { | 891 { |
853 return NGX_CONF_ERROR; | 892 return NGX_CONF_ERROR; |
854 } | 893 } |
855 | 894 |
856 cf->args->nelts = 0; | 895 fmt = ngx_array_push(&conf->formats); |
857 | 896 if (fmt == NULL) { |
858 value = ngx_array_push(cf->args); | |
859 if (value == NULL) { | |
860 return NGX_CONF_ERROR; | 897 return NGX_CONF_ERROR; |
861 } | 898 } |
862 | 899 |
863 value->len = 0; | 900 fmt->name.len = sizeof("combined") - 1; |
864 value->data = NULL; | 901 fmt->name.data = (u_char *) "combined"; |
865 | 902 |
866 value = ngx_array_push(cf->args); | 903 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
867 if (value == NULL) { | 904 if (fmt->ops == NULL) { |
868 return NGX_CONF_ERROR; | |
869 } | |
870 | |
871 value->len = sizeof("combined") - 1; | |
872 value->data = (u_char *) "combined"; | |
873 | |
874 value = ngx_array_push(cf->args); | |
875 if (value == NULL) { | |
876 return NGX_CONF_ERROR; | |
877 } | |
878 | |
879 *value = ngx_http_combined_fmt; | |
880 | |
881 rc = ngx_http_log_set_format(cf, NULL, conf); | |
882 if (rc != NGX_CONF_OK) { | |
883 return NGX_CONF_ERROR; | 905 return NGX_CONF_ERROR; |
884 } | 906 } |
885 | 907 |
886 return conf; | 908 return conf; |
887 } | 909 } |
945 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); | 967 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
946 fmt = lmcf->formats.elts; | 968 fmt = lmcf->formats.elts; |
947 | 969 |
948 /* the default "combined" format */ | 970 /* the default "combined" format */ |
949 log->ops = fmt[0].ops; | 971 log->ops = fmt[0].ops; |
972 lmcf->combined_used = 1; | |
950 } | 973 } |
951 } | 974 } |
952 | 975 |
953 return NGX_CONF_OK; | 976 return NGX_CONF_OK; |
954 } | 977 } |
995 if (cf->args->nelts >= 3) { | 1018 if (cf->args->nelts >= 3) { |
996 name = value[2]; | 1019 name = value[2]; |
997 } else { | 1020 } else { |
998 name.len = sizeof("combined") - 1; | 1021 name.len = sizeof("combined") - 1; |
999 name.data = (u_char *) "combined"; | 1022 name.data = (u_char *) "combined"; |
1023 lmcf->combined_used = 1; | |
1000 } | 1024 } |
1001 | 1025 |
1002 fmt = lmcf->formats.elts; | 1026 fmt = lmcf->formats.elts; |
1003 for (i = 0; i < lmcf->formats.nelts; i++) { | 1027 for (i = 0; i < lmcf->formats.nelts; i++) { |
1004 if (fmt[i].name.len == name.len | 1028 if (fmt[i].name.len == name.len |
1056 static char * | 1080 static char * |
1057 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1081 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1058 { | 1082 { |
1059 ngx_http_log_main_conf_t *lmcf = conf; | 1083 ngx_http_log_main_conf_t *lmcf = conf; |
1060 | 1084 |
1061 u_char *data, *p, *fname, ch; | 1085 ngx_str_t *value; |
1062 size_t i, len, fname_len; | 1086 ngx_uint_t i; |
1063 ngx_str_t *value, var, arg, *a; | 1087 ngx_http_log_fmt_t *fmt; |
1064 ngx_uint_t s, f, bracket; | |
1065 ngx_http_log_op_t *op; | |
1066 ngx_http_log_fmt_t *fmt; | |
1067 ngx_http_log_op_name_t *name; | |
1068 | 1088 |
1069 value = cf->args->elts; | 1089 value = cf->args->elts; |
1070 | 1090 |
1071 fmt = lmcf->formats.elts; | 1091 fmt = lmcf->formats.elts; |
1072 for (f = 0; f < lmcf->formats.nelts; f++) { | 1092 for (i = 0; i < lmcf->formats.nelts; i++) { |
1073 if (fmt[f].name.len == value[1].len | 1093 if (fmt[i].name.len == value[1].len |
1074 && ngx_strcmp(fmt->name.data, value[1].data) == 0) | 1094 && ngx_strcmp(fmt[i].name.data, value[1].data) == 0) |
1075 { | 1095 { |
1076 return "duplicate \"log_format\" name"; | 1096 return "duplicate \"log_format\" name"; |
1077 } | 1097 } |
1078 } | 1098 } |
1079 | 1099 |
1082 return NGX_CONF_ERROR; | 1102 return NGX_CONF_ERROR; |
1083 } | 1103 } |
1084 | 1104 |
1085 fmt->name = value[1]; | 1105 fmt->name = value[1]; |
1086 | 1106 |
1087 fmt->ops = ngx_array_create(cf->pool, 20, sizeof(ngx_http_log_op_t)); | 1107 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
1088 if (fmt->ops == NULL) { | 1108 if (fmt->ops == NULL) { |
1089 return NGX_CONF_ERROR; | 1109 return NGX_CONF_ERROR; |
1090 } | 1110 } |
1091 | 1111 |
1092 arg.data = NULL; | 1112 return ngx_http_log_compile_format(cf, fmt->ops, cf->args, 2); |
1093 | 1113 } |
1094 for (s = 2; s < cf->args->nelts; s++) { | 1114 |
1115 | |
1116 static char * | |
1117 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops, | |
1118 ngx_array_t *args, ngx_uint_t s) | |
1119 { | |
1120 u_char *data, *p, *fname, *arg_data, ch; | |
1121 size_t i, len, fname_len, arg_len; | |
1122 ngx_str_t *value, var, *a; | |
1123 ngx_uint_t bracket; | |
1124 ngx_http_log_op_t *op; | |
1125 ngx_http_log_var_t *v; | |
1126 ngx_http_log_op_name_t *name; | |
1127 static ngx_uint_t warn; | |
1128 | |
1129 value = args->elts; | |
1130 arg_data = NULL; | |
1131 | |
1132 for ( /* void */ ; s < args->nelts; s++) { | |
1095 | 1133 |
1096 i = 0; | 1134 i = 0; |
1097 | 1135 |
1098 while (i < value[s].len) { | 1136 while (i < value[s].len) { |
1099 | 1137 |
1100 op = ngx_array_push(fmt->ops); | 1138 op = ngx_array_push(ops); |
1101 if (op == NULL) { | 1139 if (op == NULL) { |
1102 return NGX_CONF_ERROR; | 1140 return NGX_CONF_ERROR; |
1103 } | 1141 } |
1104 | 1142 |
1105 data = &value[s].data[i]; | 1143 data = &value[s].data[i]; |
1112 } | 1150 } |
1113 | 1151 |
1114 if (value[s].data[i] == '{') { | 1152 if (value[s].data[i] == '{') { |
1115 i++; | 1153 i++; |
1116 | 1154 |
1117 arg.data = &value[s].data[i]; | 1155 arg_data = &value[s].data[i]; |
1118 | 1156 |
1119 while (i < value[s].len && value[s].data[i] != '}') { | 1157 while (i < value[s].len && value[s].data[i] != '}') { |
1120 i++; | 1158 i++; |
1121 } | 1159 } |
1122 | 1160 |
1123 arg.len = &value[s].data[i] - arg.data; | 1161 arg_len = &value[s].data[i] - arg_data; |
1124 | 1162 |
1125 if (i == value[s].len || arg.len == 0) { | 1163 if (i == value[s].len || arg_len == 0) { |
1126 goto invalid; | 1164 goto invalid; |
1127 } | 1165 } |
1128 | 1166 |
1129 i++; | 1167 i++; |
1130 | 1168 |
1131 } else { | 1169 } else { |
1132 arg.len = 0; | 1170 arg_len = 0; |
1171 } | |
1172 | |
1173 if (warn == 0) { | |
1174 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
1175 "the parameters in the \"%%name\" form are deprecated, " | |
1176 "use the \"$variable\" instead"); | |
1177 warn = 1; | |
1133 } | 1178 } |
1134 | 1179 |
1135 fname = &value[s].data[i]; | 1180 fname = &value[s].data[i]; |
1136 | 1181 |
1137 while (i < value[s].len | 1182 while (i < value[s].len |
1154 | 1199 |
1155 if (name->name.len == fname_len | 1200 if (name->name.len == fname_len |
1156 && ngx_strncmp(name->name.data, fname, fname_len) == 0) | 1201 && ngx_strncmp(name->name.data, fname, fname_len) == 0) |
1157 { | 1202 { |
1158 if (name->compile == NULL) { | 1203 if (name->compile == NULL) { |
1159 if (arg.len) { | 1204 if (arg_len) { |
1160 fname[fname_len] = '\0'; | 1205 fname[fname_len] = '\0'; |
1161 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1206 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1162 "\"%s\" must not have argument", | 1207 "\"%s\" must not have argument", |
1163 data); | 1208 data); |
1164 return NGX_CONF_ERROR; | 1209 return NGX_CONF_ERROR; |
1170 op->data = 0; | 1215 op->data = 0; |
1171 | 1216 |
1172 break; | 1217 break; |
1173 } | 1218 } |
1174 | 1219 |
1175 if (arg.len == 0) { | 1220 if (arg_len == 0) { |
1176 fname[fname_len] = '\0'; | 1221 fname[fname_len] = '\0'; |
1177 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1222 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1178 "\"%s\" requires argument", | 1223 "\"%s\" requires argument", |
1179 data); | 1224 data); |
1180 return NGX_CONF_ERROR; | 1225 return NGX_CONF_ERROR; |
1183 a = ngx_palloc(cf->pool, sizeof(ngx_str_t)); | 1228 a = ngx_palloc(cf->pool, sizeof(ngx_str_t)); |
1184 if (a == NULL) { | 1229 if (a == NULL) { |
1185 return NGX_CONF_ERROR; | 1230 return NGX_CONF_ERROR; |
1186 } | 1231 } |
1187 | 1232 |
1188 *a = arg; | 1233 a->len = arg_len; |
1234 a->data = arg_data; | |
1235 | |
1189 if (name->compile(cf, op, a) == NGX_ERROR) { | 1236 if (name->compile(cf, op, a) == NGX_ERROR) { |
1190 return NGX_CONF_ERROR; | 1237 return NGX_CONF_ERROR; |
1191 } | 1238 } |
1192 | 1239 |
1193 break; | 1240 break; |
1195 } | 1242 } |
1196 | 1243 |
1197 if (name->name.len == 0) { | 1244 if (name->name.len == 0) { |
1198 goto invalid; | 1245 goto invalid; |
1199 } | 1246 } |
1247 | |
1248 continue; | |
1200 | 1249 |
1201 } else if (value[s].data[i] == '$') { | 1250 } else if (value[s].data[i] == '$') { |
1202 | 1251 |
1203 if (++i == value[s].len) { | 1252 if (++i == value[s].len) { |
1204 goto invalid; | 1253 goto invalid; |
1247 | 1296 |
1248 if (var.len == 0) { | 1297 if (var.len == 0) { |
1249 goto invalid; | 1298 goto invalid; |
1250 } | 1299 } |
1251 | 1300 |
1301 for (v = ngx_http_log_vars; v->name.len; v++) { | |
1302 | |
1303 if (v->name.len == var.len | |
1304 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1305 { | |
1306 op->len = v->len; | |
1307 op->getlen = NULL; | |
1308 op->run = v->run; | |
1309 op->data = 0; | |
1310 | |
1311 goto found; | |
1312 } | |
1313 } | |
1314 | |
1252 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) { | 1315 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) { |
1253 return NGX_CONF_ERROR; | 1316 return NGX_CONF_ERROR; |
1254 } | 1317 } |
1255 | 1318 |
1256 } else { | 1319 found: |
1320 | |
1321 continue; | |
1322 } | |
1323 | |
1324 i++; | |
1325 | |
1326 while (i < value[s].len | |
1327 && value[s].data[i] != '$' | |
1328 && value[s].data[i] != '%') | |
1329 { | |
1257 i++; | 1330 i++; |
1258 | 1331 } |
1259 while (i < value[s].len | 1332 |
1260 && value[s].data[i] != '$' | 1333 len = &value[s].data[i] - data; |
1261 && value[s].data[i] != '%') | 1334 |
1262 { | 1335 if (len) { |
1263 i++; | 1336 |
1264 } | 1337 op->len = len; |
1265 | 1338 op->getlen = NULL; |
1266 len = &value[s].data[i] - data; | 1339 |
1267 | 1340 if (len <= sizeof(uintptr_t)) { |
1268 if (len) { | 1341 op->run = ngx_http_log_copy_short; |
1269 | 1342 op->data = 0; |
1270 op->len = len; | 1343 |
1271 op->getlen = NULL; | 1344 while (len--) { |
1272 | 1345 op->data <<= 8; |
1273 if (len <= sizeof(uintptr_t)) { | 1346 op->data |= data[len]; |
1274 op->run = ngx_http_log_copy_short; | |
1275 op->data = 0; | |
1276 | |
1277 while (len--) { | |
1278 op->data <<= 8; | |
1279 op->data |= data[len]; | |
1280 } | |
1281 | |
1282 } else { | |
1283 op->run = ngx_http_log_copy_long; | |
1284 | |
1285 p = ngx_palloc(cf->pool, len); | |
1286 if (p == NULL) { | |
1287 return NGX_CONF_ERROR; | |
1288 } | |
1289 | |
1290 ngx_memcpy(p, data, len); | |
1291 op->data = (uintptr_t) p; | |
1292 } | 1347 } |
1348 | |
1349 } else { | |
1350 op->run = ngx_http_log_copy_long; | |
1351 | |
1352 p = ngx_palloc(cf->pool, len); | |
1353 if (p == NULL) { | |
1354 return NGX_CONF_ERROR; | |
1355 } | |
1356 | |
1357 ngx_memcpy(p, data, len); | |
1358 op->data = (uintptr_t) p; | |
1293 } | 1359 } |
1294 } | 1360 } |
1295 } | 1361 } |
1296 } | 1362 } |
1297 | 1363 |
1304 return NGX_CONF_ERROR; | 1370 return NGX_CONF_ERROR; |
1305 } | 1371 } |
1306 | 1372 |
1307 | 1373 |
1308 static ngx_int_t | 1374 static ngx_int_t |
1309 ngx_http_log_init(ngx_cycle_t *cycle) | 1375 ngx_http_log_init(ngx_conf_t *cf) |
1310 { | 1376 { |
1377 ngx_str_t *value; | |
1378 ngx_array_t a; | |
1379 ngx_http_log_fmt_t *fmt; | |
1380 ngx_http_log_main_conf_t *lmcf; | |
1311 ngx_http_core_main_conf_t *cmcf; | 1381 ngx_http_core_main_conf_t *cmcf; |
1312 | 1382 |
1313 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module); | 1383 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1384 | |
1385 if (lmcf->combined_used) { | |
1386 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1387 return NGX_ERROR; | |
1388 } | |
1389 | |
1390 value = ngx_array_push(&a); | |
1391 if (value == NULL) { | |
1392 return NGX_ERROR; | |
1393 } | |
1394 | |
1395 *value = ngx_http_combined_fmt; | |
1396 fmt = lmcf->formats.elts; | |
1397 | |
1398 if (ngx_http_log_compile_format(cf, fmt->ops, &a, 0) | |
1399 != NGX_CONF_OK) | |
1400 { | |
1401 return NGX_ERROR; | |
1402 } | |
1403 } | |
1404 | |
1405 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
1314 | 1406 |
1315 cmcf->log_handler = ngx_http_log_handler; | 1407 cmcf->log_handler = ngx_http_log_handler; |
1316 | 1408 |
1317 return NGX_OK; | 1409 return NGX_OK; |
1318 } | 1410 } |