Mercurial > hg > nginx
comparison src/http/ngx_http_log_handler.c @ 208:0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 08 Dec 2003 20:48:12 +0000 |
parents | 8dee38ea9117 |
children | 00cafae0bdf1 |
comparison
equal
deleted
inserted
replaced
207:6e0fef527732 | 208:0b67be7d4489 |
---|---|
19 uintptr_t data); | 19 uintptr_t data); |
20 static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, | 20 static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, |
21 uintptr_t data); | 21 uintptr_t data); |
22 static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, | 22 static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, |
23 uintptr_t data); | 23 uintptr_t data); |
24 static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, | |
25 char *buf, uintptr_t data); | |
26 static char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, | |
27 char *buf, | |
28 uintptr_t data); | |
24 static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, | 29 static char *ngx_http_log_unknown_header_in(ngx_http_request_t *r, char *buf, |
25 uintptr_t data); | 30 uintptr_t data); |
26 static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, | 31 static char *ngx_http_log_header_out(ngx_http_request_t *r, char *buf, |
27 uintptr_t data); | 32 uintptr_t data); |
28 static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, | 33 static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, |
29 uintptr_t data); | 34 uintptr_t data); |
30 | 35 |
31 static int ngx_http_log_pre_conf(ngx_conf_t *cf); | 36 static int ngx_http_log_pre_conf(ngx_conf_t *cf); |
32 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); | 37 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); |
102 { ngx_string("pipe"), 1, ngx_http_log_pipe }, | 107 { ngx_string("pipe"), 1, ngx_http_log_pipe }, |
103 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00") - 1, | 108 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00") - 1, |
104 ngx_http_log_time }, | 109 ngx_http_log_time }, |
105 { ngx_string("request"), 0, ngx_http_log_request }, | 110 { ngx_string("request"), 0, ngx_http_log_request }, |
106 { ngx_string("status"), 3, ngx_http_log_status }, | 111 { ngx_string("status"), 3, ngx_http_log_status }, |
107 { ngx_string("length"), NGX_OFF_LEN, ngx_http_log_length }, | 112 { ngx_string("length"), NGX_OFF_T_LEN, ngx_http_log_length }, |
108 { ngx_string("i"), NGX_HTTP_LOG_ARG, ngx_http_log_header_in }, | 113 { ngx_string("i"), NGX_HTTP_LOG_ARG, ngx_http_log_header_in }, |
109 { ngx_string("o"), NGX_HTTP_LOG_ARG, ngx_http_log_header_out }, | 114 { ngx_string("o"), NGX_HTTP_LOG_ARG, ngx_http_log_header_out }, |
110 { ngx_null_string, 0, NULL } | 115 { ngx_null_string, 0, NULL } |
111 }; | 116 }; |
112 | 117 |
210 | 215 |
211 static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data) | 216 static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data) |
212 { | 217 { |
213 return ngx_cpymem(buf, ngx_cached_http_log_time.data, | 218 return ngx_cpymem(buf, ngx_cached_http_log_time.data, |
214 ngx_cached_http_log_time.len); | 219 ngx_cached_http_log_time.len); |
215 | |
216 #if 0 | |
217 ngx_tm_t tm; | |
218 | |
219 ngx_localtime(&tm); | |
220 | |
221 return buf + ngx_snprintf(buf, sizeof("28/Sep/1970:12:00:00"), | |
222 "%02d/%s/%d:%02d:%02d:%02d", | |
223 tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1], | |
224 tm.ngx_tm_year, | |
225 tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); | |
226 #endif | |
227 } | 220 } |
228 | 221 |
229 | 222 |
230 static char *ngx_http_log_request(ngx_http_request_t *r, char *buf, | 223 static char *ngx_http_log_request(ngx_http_request_t *r, char *buf, |
231 uintptr_t data) | 224 uintptr_t data) |
248 | 241 |
249 | 242 |
250 static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, | 243 static char *ngx_http_log_length(ngx_http_request_t *r, char *buf, |
251 uintptr_t data) | 244 uintptr_t data) |
252 { | 245 { |
253 return buf + ngx_snprintf(buf, NGX_OFF_LEN + 1, OFF_T_FMT, | 246 return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, |
254 r->connection->sent); | 247 r->connection->sent); |
255 } | 248 } |
256 | 249 |
257 | 250 |
258 static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, | 251 static char *ngx_http_log_header_in(ngx_http_request_t *r, char *buf, |
355 ngx_str_t *s; | 348 ngx_str_t *s; |
356 ngx_table_elt_t *h; | 349 ngx_table_elt_t *h; |
357 ngx_http_log_op_t *op; | 350 ngx_http_log_op_t *op; |
358 | 351 |
359 if (r) { | 352 if (r) { |
353 | |
354 /* run-time execution */ | |
355 | |
356 if (r->http_version < NGX_HTTP_VERSION_10) { | |
357 if (buf) { | |
358 *buf = '-'; | |
359 } | |
360 | |
361 return buf + 1; | |
362 } | |
363 | |
360 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data); | 364 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data); |
361 | 365 |
362 if (h == NULL) { | 366 if (h == NULL) { |
363 | 367 |
364 /* no header */ | 368 /* |
369 * No header pointer was found. | |
370 * However, some headers: "Date", "Server", "Content-Length", | |
371 * and "Last-Modified" have a special handling in the header filter | |
372 * but we do not set up their pointers in the filter because | |
373 * they are too seldom needed to be logged. | |
374 */ | |
375 | |
376 if (data == offsetof(ngx_http_headers_out_t, date)) { | |
377 if (buf == NULL) { | |
378 return (char *) ngx_cached_http_time.len; | |
379 } | |
380 return ngx_cpymem(buf, ngx_cached_http_time.data, | |
381 ngx_cached_http_time.len); | |
382 } | |
365 | 383 |
366 if (data == offsetof(ngx_http_headers_out_t, server)) { | 384 if (data == offsetof(ngx_http_headers_out_t, server)) { |
367 if (buf == NULL) { | 385 if (buf == NULL) { |
368 return (char *) (sizeof(NGINX_VER) - 1); | 386 return (char *) (sizeof(NGINX_VER) - 1); |
369 } | 387 } |
370 return ngx_cpymem(buf, NGINX_VER, sizeof(NGINX_VER) - 1); | 388 return ngx_cpymem(buf, NGINX_VER, sizeof(NGINX_VER) - 1); |
389 } | |
390 | |
391 if (data == offsetof(ngx_http_headers_out_t, content_length)) { | |
392 if (r->headers_out.content_length_n == -1) { | |
393 if (buf) { | |
394 *buf = '-'; | |
395 } | |
396 return buf + 1; | |
397 } | |
398 | |
399 if (buf == NULL) { | |
400 return (char *) NGX_OFF_T_LEN; | |
401 } | |
402 return buf + ngx_snprintf(buf, NGX_OFF_T_LEN + 2, OFF_T_FMT, | |
403 r->headers_out.content_length_n); | |
404 } | |
405 | |
406 if (data == offsetof(ngx_http_headers_out_t, last_modified)) { | |
407 if (r->headers_out.last_modified_time == -1) { | |
408 if (buf) { | |
409 *buf = '-'; | |
410 } | |
411 return buf + 1; | |
412 } | |
413 | |
414 if (buf == NULL) { | |
415 return (char *) sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; | |
416 } | |
417 return buf + ngx_http_time(buf, | |
418 r->headers_out.last_modified_time); | |
371 } | 419 } |
372 | 420 |
373 if (buf) { | 421 if (buf) { |
374 *buf = '-'; | 422 *buf = '-'; |
375 } | 423 } |
404 op->data = ngx_http_headers_out[i].offset; | 452 op->data = ngx_http_headers_out[i].offset; |
405 return NULL; | 453 return NULL; |
406 } | 454 } |
407 } | 455 } |
408 | 456 |
457 if (s->len == sizeof("Connection") - 1 | |
458 && ngx_strncasecmp(s->data, "Connection", s->len) == 0) | |
459 { | |
460 op->op = ngx_http_log_connection_header_out; | |
461 op->data = NULL; | |
462 return NULL; | |
463 } | |
464 | |
465 if (s->len == sizeof("Transfer-Encoding") - 1 | |
466 && ngx_strncasecmp(s->data, "Transfer-Encoding", s->len) == 0) { | |
467 op->op = ngx_http_log_transfer_encoding_header_out; | |
468 op->data = NULL; | |
469 return NULL; | |
470 } | |
471 | |
409 op->op = ngx_http_log_unknown_header_out; | 472 op->op = ngx_http_log_unknown_header_out; |
410 op->data = (uintptr_t) s; | 473 op->data = (uintptr_t) s; |
411 | 474 |
412 return NULL; | 475 return NULL; |
476 } | |
477 | |
478 | |
479 static char *ngx_http_log_connection_header_out(ngx_http_request_t *r, | |
480 char *buf, uintptr_t data) | |
481 { | |
482 if (buf == NULL) { | |
483 return (char *) ((r->keepalive) ? sizeof("keep-alive") - 1: | |
484 sizeof("close") - 1); | |
485 } | |
486 | |
487 if (r->keepalive) { | |
488 return ngx_cpymem(buf, "keep-alive", sizeof("keep-alive") - 1); | |
489 | |
490 } else { | |
491 return ngx_cpymem(buf, "close", sizeof("close") - 1); | |
492 } | |
493 } | |
494 | |
495 | |
496 static char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, | |
497 char *buf, | |
498 uintptr_t data) | |
499 { | |
500 if (buf == NULL) { | |
501 return (char *) ((r->chunked) ? sizeof("chunked") - 1 : 1); | |
502 } | |
503 | |
504 if (r->chunked) { | |
505 return ngx_cpymem(buf, "chunked", sizeof("chunked") - 1); | |
506 } | |
507 | |
508 *buf = '-'; | |
509 | |
510 return buf + 1; | |
413 } | 511 } |
414 | 512 |
415 | 513 |
416 static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, | 514 static char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, char *buf, |
417 uintptr_t data) | 515 uintptr_t data) |