Mercurial > hg > nginx-vendor-0-8
comparison src/http/ngx_http_log_handler.c @ 46:9f3205d496a0 NGINX_0_1_23
nginx 0.1.23
*) Feature: the ngx_http_ssi_filter_module and the ssi,
ssi_silent_errors, and ssi_min_file_chunk directives. The 'echo
var="HTTP_..." default=""' and 'echo var="REMOTE_ADDR"' commands are
supported.
*) Feature: the %request_time log parameter.
*) Feature: if the request has no the "Host" header line, then the
"proxy_preserve_host" directive set this header line to the first
server name of the "server_name" directive.
*) Bugfix: nginx could not be built on platforms different from i386,
amd64, sparc É ppc; bug appeared in 0.1.22.
*) Bugfix: the ngx_http_autoindex_module now shows the information not
about the symlink, but about file or directory it points to.
*) Bugfix: the %apache_length parameter logged the negative length of
the response header if the no response was transferred to a client.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 01 Mar 2005 00:00:00 +0300 |
parents | 41ccba1aba45 |
children | 6cfc63e68377 |
comparison
equal
deleted
inserted
replaced
45:09c688b472a7 | 46:9f3205d496a0 |
---|---|
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 #include <nginx.h> | 10 #include <nginx.h> |
11 | 11 |
12 | 12 |
13 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, | 13 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, |
14 ngx_http_log_op_t *op); | 14 ngx_http_log_op_t *op); |
15 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, | 15 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, |
16 ngx_http_log_op_t *op); | 16 ngx_http_log_op_t *op); |
17 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, | 17 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
18 ngx_http_log_op_t *op); | 18 ngx_http_log_op_t *op); |
19 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, | 19 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
20 ngx_http_log_op_t *op); | 20 ngx_http_log_op_t *op); |
21 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, | 21 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
22 ngx_http_log_op_t *op); | 22 ngx_http_log_op_t *op); |
23 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
24 ngx_http_log_op_t *op); | |
23 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, | 25 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
24 ngx_http_log_op_t *op); | 26 ngx_http_log_op_t *op); |
25 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, | 27 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, |
26 ngx_http_log_op_t *op); | 28 ngx_http_log_op_t *op); |
27 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, | 29 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, |
28 ngx_http_log_op_t *op); | 30 ngx_http_log_op_t *op); |
29 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | 31 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
30 ngx_http_log_op_t *op); | 32 ngx_http_log_op_t *op); |
31 | 33 |
32 static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, | 34 static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, |
33 uintptr_t data); | 35 uintptr_t data); |
34 static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, | 36 static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, |
35 ngx_http_log_op_t *op); | 37 ngx_http_log_op_t *op); |
36 | 38 |
37 static ngx_int_t ngx_http_log_header_in_compile(ngx_http_log_op_t *op, | 39 static ngx_int_t ngx_http_log_header_in_compile(ngx_http_log_op_t *op, |
38 ngx_str_t *value); | 40 ngx_str_t *value); |
39 static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r, | 41 static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r, |
40 uintptr_t data); | 42 uintptr_t data); |
41 static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, | 43 static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, |
42 ngx_http_log_op_t *op); | 44 ngx_http_log_op_t *op); |
43 static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, | 45 static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, |
44 uintptr_t data); | 46 uintptr_t data); |
45 static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, | 47 static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, |
46 u_char *buf, | 48 u_char *buf, ngx_http_log_op_t *op); |
47 ngx_http_log_op_t *op); | |
48 | 49 |
49 static ngx_int_t ngx_http_log_header_out_compile(ngx_http_log_op_t *op, | 50 static ngx_int_t ngx_http_log_header_out_compile(ngx_http_log_op_t *op, |
50 ngx_str_t *value); | 51 ngx_str_t *value); |
51 static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r, | 52 static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r, |
52 uintptr_t data); | 53 uintptr_t data); |
53 static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, | 54 static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, |
54 ngx_http_log_op_t *op); | 55 ngx_http_log_op_t *op); |
55 static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, | 56 static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, |
56 uintptr_t data); | 57 uintptr_t data); |
57 static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, | 58 static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, |
58 u_char *buf, | 59 u_char *buf, ngx_http_log_op_t *op); |
59 ngx_http_log_op_t *op); | |
60 | 60 |
61 static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, | 61 static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, |
62 u_char *buf, | 62 u_char *buf, ngx_http_log_op_t *op); |
63 ngx_http_log_op_t *op); | |
64 static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, | 63 static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, |
65 u_char *buf, | 64 u_char *buf, ngx_http_log_op_t *op); |
66 ngx_http_log_op_t *op); | |
67 | 65 |
68 static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers, | 66 static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers, |
69 ngx_str_t *value); | 67 ngx_str_t *value); |
70 | 68 |
71 static ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf); | 69 static ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf); |
72 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); | 70 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); |
73 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf); | 71 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf); |
74 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, | 72 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, |
75 void *child); | 73 void *child); |
76 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, | 74 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
77 void *conf); | 75 void *conf); |
78 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, | 76 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
79 void *conf); | 77 void *conf); |
80 static ngx_int_t ngx_http_log_parse_format(ngx_conf_t *cf, ngx_array_t *ops, | 78 static ngx_int_t ngx_http_log_parse_format(ngx_conf_t *cf, ngx_array_t *ops, |
81 ngx_str_t *line); | 79 ngx_str_t *line); |
82 | 80 |
83 | 81 |
84 static ngx_command_t ngx_http_log_commands[] = { | 82 static ngx_command_t ngx_http_log_commands[] = { |
85 | 83 |
86 {ngx_string("log_format"), | 84 { ngx_string("log_format"), |
87 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | 85 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, |
88 ngx_http_log_set_format, | 86 ngx_http_log_set_format, |
89 NGX_HTTP_MAIN_CONF_OFFSET, | 87 NGX_HTTP_MAIN_CONF_OFFSET, |
90 0, | 88 0, |
91 NULL}, | 89 NULL }, |
92 | 90 |
93 {ngx_string("access_log"), | 91 { ngx_string("access_log"), |
94 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, | 92 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
95 ngx_http_log_set_log, | 93 ngx_http_log_set_log, |
96 NGX_HTTP_LOC_CONF_OFFSET, | 94 NGX_HTTP_LOC_CONF_OFFSET, |
97 0, | 95 0, |
98 NULL}, | 96 NULL }, |
99 | 97 |
100 ngx_null_command | 98 ngx_null_command |
101 }; | 99 }; |
102 | 100 |
103 | 101 |
104 ngx_http_module_t ngx_http_log_module_ctx = { | 102 ngx_http_module_t ngx_http_log_module_ctx = { |
105 ngx_http_log_set_formats, /* pre conf */ | 103 ngx_http_log_set_formats, /* pre conf */ |
139 ngx_http_log_connection }, | 137 ngx_http_log_connection }, |
140 { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, | 138 { ngx_string("pipe"), 1, NULL, NULL, ngx_http_log_pipe }, |
141 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, | 139 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
142 NULL, NULL, ngx_http_log_time }, | 140 NULL, NULL, ngx_http_log_time }, |
143 { ngx_string("msec"), NGX_TIME_T_LEN + 4, NULL, NULL, ngx_http_log_msec }, | 141 { ngx_string("msec"), NGX_TIME_T_LEN + 4, NULL, NULL, ngx_http_log_msec }, |
142 { ngx_string("request_time"), NGX_TIME_T_LEN, NULL, NULL, | |
143 ngx_http_log_request_time }, | |
144 { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, | 144 { ngx_string("status"), 3, NULL, NULL, ngx_http_log_status }, |
145 { ngx_string("length"), NGX_OFF_T_LEN, NULL, NULL, ngx_http_log_length }, | 145 { ngx_string("length"), NGX_OFF_T_LEN, NULL, NULL, ngx_http_log_length }, |
146 { ngx_string("apache_length"), NGX_OFF_T_LEN, | 146 { ngx_string("apache_length"), NGX_OFF_T_LEN, |
147 NULL, NULL, ngx_http_log_apache_length }, | 147 NULL, NULL, ngx_http_log_apache_length }, |
148 { ngx_string("request_length"), NGX_SIZE_T_LEN, | 148 { ngx_string("request_length"), NGX_SIZE_T_LEN, |
162 | 162 |
163 { ngx_null_string, 0, NULL, NULL, NULL } | 163 { ngx_null_string, 0, NULL, NULL, NULL } |
164 }; | 164 }; |
165 | 165 |
166 | 166 |
167 ngx_int_t ngx_http_log_handler(ngx_http_request_t *r) | 167 ngx_int_t |
168 ngx_http_log_handler(ngx_http_request_t *r) | |
168 { | 169 { |
169 ngx_uint_t i, l; | 170 ngx_uint_t i, l; |
170 u_char *line, *p; | 171 u_char *line, *p; |
171 size_t len; | 172 size_t len; |
172 ngx_http_log_t *log; | 173 ngx_http_log_t *log; |
226 | 227 |
227 return NGX_OK; | 228 return NGX_OK; |
228 } | 229 } |
229 | 230 |
230 | 231 |
231 static u_char *ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | 232 static u_char * |
232 ngx_http_log_op_t *op) | 233 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, |
234 ngx_http_log_op_t *op) | |
233 { | 235 { |
234 size_t len; | 236 size_t len; |
235 uintptr_t data; | 237 uintptr_t data; |
236 | 238 |
237 len = op->len; | 239 len = op->len; |
244 | 246 |
245 return buf; | 247 return buf; |
246 } | 248 } |
247 | 249 |
248 | 250 |
249 static u_char *ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | 251 static u_char * |
250 ngx_http_log_op_t *op) | 252 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, |
253 ngx_http_log_op_t *op) | |
251 { | 254 { |
252 return ngx_cpymem(buf, (u_char *) op->data, op->len); | 255 return ngx_cpymem(buf, (u_char *) op->data, op->len); |
253 } | 256 } |
254 | 257 |
255 | 258 |
256 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, | 259 static u_char * |
257 ngx_http_log_op_t *op) | 260 ngx_http_log_addr(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
258 { | 261 { |
259 return ngx_cpymem(buf, r->connection->addr_text.data, | 262 return ngx_cpymem(buf, r->connection->addr_text.data, |
260 r->connection->addr_text.len); | 263 r->connection->addr_text.len); |
261 } | 264 } |
262 | 265 |
263 | 266 |
264 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, | 267 static u_char * |
265 ngx_http_log_op_t *op) | 268 ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, |
269 ngx_http_log_op_t *op) | |
266 { | 270 { |
267 return ngx_sprintf(buf, "%ui", r->connection->number); | 271 return ngx_sprintf(buf, "%ui", r->connection->number); |
268 } | 272 } |
269 | 273 |
270 | 274 |
271 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, | 275 static u_char * |
272 ngx_http_log_op_t *op) | 276 ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
273 { | 277 { |
274 if (r->pipeline) { | 278 if (r->pipeline) { |
275 *buf = 'p'; | 279 *buf = 'p'; |
276 } else { | 280 } else { |
277 *buf = '.'; | 281 *buf = '.'; |
279 | 283 |
280 return buf + 1; | 284 return buf + 1; |
281 } | 285 } |
282 | 286 |
283 | 287 |
284 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, | 288 static u_char * |
285 ngx_http_log_op_t *op) | 289 ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
286 { | 290 { |
287 return ngx_cpymem(buf, ngx_cached_http_log_time.data, | 291 return ngx_cpymem(buf, ngx_cached_http_log_time.data, |
288 ngx_cached_http_log_time.len); | 292 ngx_cached_http_log_time.len); |
289 } | 293 } |
290 | 294 |
291 | 295 |
292 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, | 296 static u_char * |
293 ngx_http_log_op_t *op) | 297 ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
294 { | 298 { |
295 struct timeval tv; | 299 struct timeval tv; |
296 | 300 |
297 ngx_gettimeofday(&tv); | 301 ngx_gettimeofday(&tv); |
298 | 302 |
299 return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); | 303 return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); |
300 } | 304 } |
301 | 305 |
302 | 306 |
303 static size_t ngx_http_log_request_getlen(ngx_http_request_t *r, | 307 static u_char * |
304 uintptr_t data) | 308 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, |
309 ngx_http_log_op_t *op) | |
310 { | |
311 time_t elapsed; | |
312 | |
313 elapsed = ngx_time() - r->start_time; | |
314 | |
315 return ngx_sprintf(buf, "%T", elapsed); | |
316 } | |
317 | |
318 | |
319 static size_t | |
320 ngx_http_log_request_getlen(ngx_http_request_t *r, uintptr_t data) | |
305 { | 321 { |
306 return r->request_line.len; | 322 return r->request_line.len; |
307 } | 323 } |
308 | 324 |
309 | 325 |
310 static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf, | 326 static u_char * |
311 ngx_http_log_op_t *op) | 327 ngx_http_log_request(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
312 { | 328 { |
313 return ngx_cpymem(buf, r->request_line.data, r->request_line.len); | 329 return ngx_cpymem(buf, r->request_line.data, r->request_line.len); |
314 } | 330 } |
315 | 331 |
316 | 332 |
317 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, | 333 static u_char * |
318 ngx_http_log_op_t *op) | 334 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
319 { | 335 { |
320 return ngx_sprintf(buf, "%ui", | 336 return ngx_sprintf(buf, "%ui", |
321 r->err_status ? r->err_status : r->headers_out.status); | 337 r->err_status ? r->err_status : r->headers_out.status); |
322 } | 338 } |
323 | 339 |
324 | 340 |
325 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf, | 341 static u_char * |
326 ngx_http_log_op_t *op) | 342 ngx_http_log_length(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
327 { | 343 { |
328 return ngx_sprintf(buf, "%O", r->connection->sent); | 344 return ngx_sprintf(buf, "%O", r->connection->sent); |
329 } | 345 } |
330 | 346 |
331 | 347 |
332 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, | 348 static u_char * |
333 ngx_http_log_op_t *op) | 349 ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf, |
334 { | 350 ngx_http_log_op_t *op) |
335 return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size); | 351 { |
336 } | 352 off_t length; |
337 | 353 |
338 | 354 length = r->connection->sent - r->header_size; |
339 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | 355 |
340 ngx_http_log_op_t *op) | 356 if (length > 0) { |
357 return ngx_sprintf(buf, "%O", length); | |
358 } | |
359 | |
360 *buf = '0'; | |
361 | |
362 return buf + 1; | |
363 } | |
364 | |
365 | |
366 static u_char * | |
367 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
368 ngx_http_log_op_t *op) | |
341 { | 369 { |
342 return ngx_sprintf(buf, "%z", r->request_length); | 370 return ngx_sprintf(buf, "%z", r->request_length); |
343 } | 371 } |
344 | 372 |
345 | 373 |
346 static ngx_int_t ngx_http_log_header_in_compile(ngx_http_log_op_t *op, | 374 static ngx_int_t |
347 ngx_str_t *value) | 375 ngx_http_log_header_in_compile(ngx_http_log_op_t *op, ngx_str_t *value) |
348 { | 376 { |
349 ngx_uint_t i; | 377 ngx_uint_t i; |
350 | 378 |
351 op->len = 0; | 379 op->len = 0; |
352 | 380 |
373 | 401 |
374 return NGX_OK; | 402 return NGX_OK; |
375 } | 403 } |
376 | 404 |
377 | 405 |
378 static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r, | 406 static size_t |
379 uintptr_t data) | 407 ngx_http_log_header_in_getlen(ngx_http_request_t *r, uintptr_t data) |
380 { | 408 { |
381 ngx_table_elt_t *h; | 409 ngx_table_elt_t *h; |
382 | 410 |
383 h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data); | 411 h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data); |
384 | 412 |
388 | 416 |
389 return 1; | 417 return 1; |
390 } | 418 } |
391 | 419 |
392 | 420 |
393 static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, | 421 static u_char * |
394 ngx_http_log_op_t *op) | 422 ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf, |
423 ngx_http_log_op_t *op) | |
395 { | 424 { |
396 ngx_table_elt_t *h; | 425 ngx_table_elt_t *h; |
397 | 426 |
398 h = *(ngx_table_elt_t **) ((char *) &r->headers_in + op->data); | 427 h = *(ngx_table_elt_t **) ((char *) &r->headers_in + op->data); |
399 | 428 |
405 | 434 |
406 return buf + 1; | 435 return buf + 1; |
407 } | 436 } |
408 | 437 |
409 | 438 |
410 static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, | 439 static size_t |
411 uintptr_t data) | 440 ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r, uintptr_t data) |
412 { | 441 { |
413 ngx_table_elt_t *h; | 442 ngx_table_elt_t *h; |
414 | 443 |
415 h = ngx_http_log_unknown_header(&r->headers_in.headers, (ngx_str_t *) data); | 444 h = ngx_http_log_unknown_header(&r->headers_in.headers, (ngx_str_t *) data); |
416 | 445 |
420 | 449 |
421 return 1; | 450 return 1; |
422 } | 451 } |
423 | 452 |
424 | 453 |
425 static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, | 454 static u_char * |
426 u_char *buf, | 455 ngx_http_log_unknown_header_in(ngx_http_request_t *r, u_char *buf, |
427 ngx_http_log_op_t *op) | 456 ngx_http_log_op_t *op) |
428 { | 457 { |
429 ngx_table_elt_t *h; | 458 ngx_table_elt_t *h; |
430 | 459 |
431 h = ngx_http_log_unknown_header(&r->headers_in.headers, | 460 h = ngx_http_log_unknown_header(&r->headers_in.headers, |
432 (ngx_str_t *) op->data); | 461 (ngx_str_t *) op->data); |
439 | 468 |
440 return buf + 1; | 469 return buf + 1; |
441 } | 470 } |
442 | 471 |
443 | 472 |
444 static ngx_int_t ngx_http_log_header_out_compile(ngx_http_log_op_t *op, | 473 static ngx_int_t |
445 ngx_str_t *value) | 474 ngx_http_log_header_out_compile(ngx_http_log_op_t *op, ngx_str_t *value) |
446 { | 475 { |
447 ngx_uint_t i; | 476 ngx_uint_t i; |
448 | 477 |
449 op->len = 0; | 478 op->len = 0; |
450 | 479 |
453 if (ngx_http_headers_out[i].name.len != value->len) { | 482 if (ngx_http_headers_out[i].name.len != value->len) { |
454 continue; | 483 continue; |
455 } | 484 } |
456 | 485 |
457 if (ngx_strncasecmp(ngx_http_headers_out[i].name.data, value->data, | 486 if (ngx_strncasecmp(ngx_http_headers_out[i].name.data, value->data, |
458 value->len) == 0) | 487 value->len) == 0) |
459 { | 488 { |
460 op->getlen = ngx_http_log_header_out_getlen; | 489 op->getlen = ngx_http_log_header_out_getlen; |
461 op->run = ngx_http_log_header_out; | 490 op->run = ngx_http_log_header_out; |
462 op->data = ngx_http_headers_out[i].offset; | 491 op->data = ngx_http_headers_out[i].offset; |
463 | 492 |
491 | 520 |
492 return NGX_OK; | 521 return NGX_OK; |
493 } | 522 } |
494 | 523 |
495 | 524 |
496 static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r, | 525 static size_t |
497 uintptr_t data) | 526 ngx_http_log_header_out_getlen(ngx_http_request_t *r, uintptr_t data) |
498 { | 527 { |
499 ngx_table_elt_t *h; | 528 ngx_table_elt_t *h; |
500 | 529 |
501 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data); | 530 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data); |
502 | 531 |
538 | 567 |
539 return 1; | 568 return 1; |
540 } | 569 } |
541 | 570 |
542 | 571 |
543 static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, | 572 static u_char * |
544 ngx_http_log_op_t *op) | 573 ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf, |
574 ngx_http_log_op_t *op) | |
545 { | 575 { |
546 ngx_table_elt_t *h; | 576 ngx_table_elt_t *h; |
547 | 577 |
548 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + op->data); | 578 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + op->data); |
549 | 579 |
592 | 622 |
593 return buf + 1; | 623 return buf + 1; |
594 } | 624 } |
595 | 625 |
596 | 626 |
597 static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, | 627 static size_t |
598 uintptr_t data) | 628 ngx_http_log_unknown_header_out_getlen(ngx_http_request_t *r, uintptr_t data) |
599 { | 629 { |
600 ngx_table_elt_t *h; | 630 ngx_table_elt_t *h; |
601 | 631 |
602 h = ngx_http_log_unknown_header(&r->headers_out.headers, | 632 h = ngx_http_log_unknown_header(&r->headers_out.headers, |
603 (ngx_str_t *) data); | 633 (ngx_str_t *) data); |
608 | 638 |
609 return 1; | 639 return 1; |
610 } | 640 } |
611 | 641 |
612 | 642 |
613 static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, | 643 static u_char * |
614 u_char *buf, | 644 ngx_http_log_unknown_header_out(ngx_http_request_t *r, u_char *buf, |
615 ngx_http_log_op_t *op) | 645 ngx_http_log_op_t *op) |
616 { | 646 { |
617 ngx_table_elt_t *h; | 647 ngx_table_elt_t *h; |
618 | 648 |
619 h = ngx_http_log_unknown_header(&r->headers_out.headers, | 649 h = ngx_http_log_unknown_header(&r->headers_out.headers, |
620 (ngx_str_t *) op->data); | 650 (ngx_str_t *) op->data); |
627 | 657 |
628 return buf + 1; | 658 return buf + 1; |
629 } | 659 } |
630 | 660 |
631 | 661 |
632 static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers, | 662 static ngx_table_elt_t * |
633 ngx_str_t *value) | 663 ngx_http_log_unknown_header(ngx_list_t *headers, ngx_str_t *value) |
634 { | 664 { |
635 ngx_uint_t i; | 665 ngx_uint_t i; |
636 ngx_list_part_t *part; | 666 ngx_list_part_t *part; |
637 ngx_table_elt_t *h; | 667 ngx_table_elt_t *h; |
638 | 668 |
662 | 692 |
663 return NULL; | 693 return NULL; |
664 } | 694 } |
665 | 695 |
666 | 696 |
667 static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r, | 697 static u_char * |
668 u_char *buf, | 698 ngx_http_log_connection_header_out(ngx_http_request_t *r, u_char *buf, |
669 ngx_http_log_op_t *op) | 699 ngx_http_log_op_t *op) |
670 { | 700 { |
671 if (r->keepalive) { | 701 if (r->keepalive) { |
672 return ngx_cpymem(buf, "keep-alive", sizeof("keep-alive") - 1); | 702 return ngx_cpymem(buf, "keep-alive", sizeof("keep-alive") - 1); |
673 | 703 |
674 } else { | 704 } else { |
675 return ngx_cpymem(buf, "close", sizeof("close") - 1); | 705 return ngx_cpymem(buf, "close", sizeof("close") - 1); |
676 } | 706 } |
677 } | 707 } |
678 | 708 |
679 | 709 |
680 static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, | 710 static u_char * |
681 u_char *buf, | 711 ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, u_char *buf, |
682 ngx_http_log_op_t *op) | 712 ngx_http_log_op_t *op) |
683 { | 713 { |
684 if (r->chunked) { | 714 if (r->chunked) { |
685 return ngx_cpymem(buf, "chunked", sizeof("chunked") - 1); | 715 return ngx_cpymem(buf, "chunked", sizeof("chunked") - 1); |
686 } | 716 } |
687 | 717 |
689 | 719 |
690 return buf + 1; | 720 return buf + 1; |
691 } | 721 } |
692 | 722 |
693 | 723 |
694 static ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf) | 724 static ngx_int_t |
725 ngx_http_log_set_formats(ngx_conf_t *cf) | |
695 { | 726 { |
696 ngx_http_log_op_name_t *op; | 727 ngx_http_log_op_name_t *op; |
697 | 728 |
698 for (op = ngx_http_log_fmt_ops; op->name.len; op++) { /* void */ } | 729 for (op = ngx_http_log_fmt_ops; op->name.len; op++) { /* void */ } |
699 op->run = NULL; | 730 op->run = NULL; |
700 | 731 |
701 return NGX_OK; | 732 return NGX_OK; |
702 } | 733 } |
703 | 734 |
704 | 735 |
705 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf) | 736 static void * |
737 ngx_http_log_create_main_conf(ngx_conf_t *cf) | |
706 { | 738 { |
707 ngx_http_log_main_conf_t *conf; | 739 ngx_http_log_main_conf_t *conf; |
708 | 740 |
709 char *rc; | 741 char *rc; |
710 ngx_str_t *value; | 742 ngx_str_t *value; |
711 | 743 |
712 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)))) { | 744 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)))) { |
713 return NGX_CONF_ERROR; | 745 return NGX_CONF_ERROR; |
714 } | 746 } |
715 | 747 |
716 ngx_init_array(conf->formats, cf->pool, 5, sizeof(ngx_http_log_fmt_t), | 748 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
717 NGX_CONF_ERROR); | 749 == NGX_ERROR) |
750 { | |
751 return NGX_CONF_ERROR; | |
752 } | |
718 | 753 |
719 cf->args->nelts = 0; | 754 cf->args->nelts = 0; |
720 | 755 |
721 if (!(value = ngx_push_array(cf->args))) { | 756 if (!(value = ngx_array_push(cf->args))) { |
722 return NGX_CONF_ERROR; | 757 return NGX_CONF_ERROR; |
723 } | 758 } |
724 | 759 |
725 if (!(value = ngx_push_array(cf->args))) { | 760 if (!(value = ngx_array_push(cf->args))) { |
726 return NGX_CONF_ERROR; | 761 return NGX_CONF_ERROR; |
727 } | 762 } |
728 | 763 |
729 value->len = sizeof("combined") - 1; | 764 value->len = sizeof("combined") - 1; |
730 value->data = (u_char *) "combined"; | 765 value->data = (u_char *) "combined"; |
731 | 766 |
732 if (!(value = ngx_push_array(cf->args))) { | 767 if (!(value = ngx_array_push(cf->args))) { |
733 return NGX_CONF_ERROR; | 768 return NGX_CONF_ERROR; |
734 } | 769 } |
735 | 770 |
736 *value = ngx_http_combined_fmt; | 771 *value = ngx_http_combined_fmt; |
737 | 772 |
742 | 777 |
743 return conf; | 778 return conf; |
744 } | 779 } |
745 | 780 |
746 | 781 |
747 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf) | 782 static void * |
783 ngx_http_log_create_loc_conf(ngx_conf_t *cf) | |
748 { | 784 { |
749 ngx_http_log_loc_conf_t *conf; | 785 ngx_http_log_loc_conf_t *conf; |
750 | 786 |
751 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)))) { | 787 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)))) { |
752 return NGX_CONF_ERROR; | 788 return NGX_CONF_ERROR; |
754 | 790 |
755 return conf; | 791 return conf; |
756 } | 792 } |
757 | 793 |
758 | 794 |
759 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, | 795 static char * |
760 void *child) | 796 ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
761 { | 797 { |
762 ngx_http_log_loc_conf_t *prev = parent; | 798 ngx_http_log_loc_conf_t *prev = parent; |
763 ngx_http_log_loc_conf_t *conf = child; | 799 ngx_http_log_loc_conf_t *conf = child; |
764 | 800 |
765 ngx_http_log_t *log; | 801 ngx_http_log_t *log; |
806 | 842 |
807 return NGX_CONF_OK; | 843 return NGX_CONF_OK; |
808 } | 844 } |
809 | 845 |
810 | 846 |
811 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, | 847 static char * |
812 void *conf) | 848 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
813 { | 849 { |
814 ngx_http_log_loc_conf_t *llcf = conf; | 850 ngx_http_log_loc_conf_t *llcf = conf; |
815 | 851 |
816 ngx_uint_t i; | 852 ngx_uint_t i; |
817 ngx_str_t *value, name; | 853 ngx_str_t *value, name; |
865 | 901 |
866 return NGX_CONF_ERROR; | 902 return NGX_CONF_ERROR; |
867 } | 903 } |
868 | 904 |
869 | 905 |
870 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, | 906 static char * |
871 void *conf) | 907 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
872 { | 908 { |
873 ngx_http_log_main_conf_t *lmcf = conf; | 909 ngx_http_log_main_conf_t *lmcf = conf; |
874 | 910 |
875 ngx_uint_t s, f, invalid; | 911 ngx_uint_t s, f, invalid; |
876 u_char *data, *p, *fname; | 912 u_char *data, *p, *fname; |