3 * Copyright (C) Igor Sysoev
7 #include <ngx_config.h>
13 static u_char
*ngx_http_log_addr(ngx_http_request_t
*r
, u_char
*buf
,
14 ngx_http_log_op_t
*op
);
15 static u_char
*ngx_http_log_connection(ngx_http_request_t
*r
, u_char
*buf
,
16 ngx_http_log_op_t
*op
);
17 static u_char
*ngx_http_log_pipe(ngx_http_request_t
*r
, u_char
*buf
,
18 ngx_http_log_op_t
*op
);
19 static u_char
*ngx_http_log_time(ngx_http_request_t
*r
, u_char
*buf
,
20 ngx_http_log_op_t
*op
);
21 static u_char
*ngx_http_log_msec(ngx_http_request_t
*r
, u_char
*buf
,
22 ngx_http_log_op_t
*op
);
23 static u_char
*ngx_http_log_status(ngx_http_request_t
*r
, u_char
*buf
,
24 ngx_http_log_op_t
*op
);
25 static u_char
*ngx_http_log_length(ngx_http_request_t
*r
, u_char
*buf
,
26 ngx_http_log_op_t
*op
);
27 static u_char
*ngx_http_log_apache_length(ngx_http_request_t
*r
, u_char
*buf
,
28 ngx_http_log_op_t
*op
);
29 static u_char
*ngx_http_log_request_length(ngx_http_request_t
*r
, u_char
*buf
,
30 ngx_http_log_op_t
*op
);
32 static size_t ngx_http_log_request_getlen(ngx_http_request_t
*r
,
34 static u_char
*ngx_http_log_request(ngx_http_request_t
*r
, u_char
*buf
,
35 ngx_http_log_op_t
*op
);
37 static ngx_int_t
ngx_http_log_header_in_compile(ngx_http_log_op_t
*op
,
39 static size_t ngx_http_log_header_in_getlen(ngx_http_request_t
*r
,
41 static u_char
*ngx_http_log_header_in(ngx_http_request_t
*r
, u_char
*buf
,
42 ngx_http_log_op_t
*op
);
43 static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t
*r
,
45 static u_char
*ngx_http_log_unknown_header_in(ngx_http_request_t
*r
,
47 ngx_http_log_op_t
*op
);
49 static ngx_int_t
ngx_http_log_header_out_compile(ngx_http_log_op_t
*op
,
51 static size_t ngx_http_log_header_out_getlen(ngx_http_request_t
*r
,
53 static u_char
*ngx_http_log_header_out(ngx_http_request_t
*r
, u_char
*buf
,
54 ngx_http_log_op_t
*op
);
55 static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t
*r
,
57 static u_char
*ngx_http_log_unknown_header_out(ngx_http_request_t
*r
,
59 ngx_http_log_op_t
*op
);
61 static u_char
*ngx_http_log_connection_header_out(ngx_http_request_t
*r
,
63 ngx_http_log_op_t
*op
);
64 static u_char
*ngx_http_log_transfer_encoding_header_out(ngx_http_request_t
*r
,
66 ngx_http_log_op_t
*op
);
68 static ngx_table_elt_t
*ngx_http_log_unknown_header(ngx_list_t
*headers
,
71 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
);
73 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
,
76 static char *ngx_http_log_set_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
78 static char *ngx_http_log_set_format(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
80 static ngx_int_t
ngx_http_log_parse_format(ngx_conf_t
*cf
, ngx_array_t
*ops
,
84 static ngx_command_t ngx_http_log_commands
[] = {
86 {ngx_string("log_format"),
87 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_2MORE
,
88 ngx_http_log_set_format
,
89 NGX_HTTP_MAIN_CONF_OFFSET
,
93 {ngx_string("access_log"),
94 NGX_HTTP_MAIN_CONF
|NGX_HTTP_SRV_CONF
|NGX_HTTP_LOC_CONF
|NGX_CONF_TAKE12
,
96 NGX_HTTP_LOC_CONF_OFFSET
,
104 ngx_http_module_t ngx_http_log_module_ctx
= {
105 ngx_http_log_set_formats
, /* pre conf */
107 ngx_http_log_create_main_conf
, /* create main configuration */
108 NULL
, /* init main configuration */
110 NULL
, /* create server configuration */
111 NULL
, /* merge server configuration */
113 ngx_http_log_create_loc_conf
, /* create location configration */
114 ngx_http_log_merge_loc_conf
/* merge location configration */
118 ngx_module_t ngx_http_log_module
= {
120 &ngx_http_log_module_ctx
, /* module context */
121 ngx_http_log_commands
, /* module directives */
122 NGX_HTTP_MODULE
, /* module type */
123 NULL
, /* init module */
124 NULL
/* init child */
128 static ngx_str_t http_access_log
= ngx_string(NGX_HTTP_LOG_PATH
);
131 static ngx_str_t ngx_http_combined_fmt
=
132 ngx_string("%addr - - [%time] \"%request\" %status %apache_length "
133 "\"%{Referer}i\" \"%{User-Agent}i\"");
136 ngx_http_log_op_name_t ngx_http_log_fmt_ops
[] = {
137 { ngx_string("addr"), INET_ADDRSTRLEN
- 1, NULL
, NULL
, ngx_http_log_addr
},
138 { ngx_string("conn"), NGX_INT32_LEN
, NULL
, NULL
, ngx_http_log_connection
},
139 { ngx_string("pipe"), 1, NULL
, NULL
, ngx_http_log_pipe
},
140 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
141 NULL
, NULL
, ngx_http_log_time
},
142 { ngx_string("msec"), NGX_TIME_T_LEN
+ 4, NULL
, NULL
, ngx_http_log_msec
},
143 { ngx_string("status"), 3, NULL
, NULL
, ngx_http_log_status
},
144 { ngx_string("length"), NGX_OFF_T_LEN
, NULL
, NULL
, ngx_http_log_length
},
145 { ngx_string("apache_length"), NGX_OFF_T_LEN
,
146 NULL
, NULL
, ngx_http_log_apache_length
},
147 { ngx_string("request_length"), NGX_SIZE_T_LEN
,
148 NULL
, NULL
, ngx_http_log_request_length
},
150 { ngx_string("request"), 0, NULL
,
151 ngx_http_log_request_getlen
,
152 ngx_http_log_request
},
154 { ngx_string("i"), 0, ngx_http_log_header_in_compile
,
155 ngx_http_log_header_in_getlen
,
156 ngx_http_log_header_in
},
158 { ngx_string("o"), 0, ngx_http_log_header_out_compile
,
159 ngx_http_log_header_out_getlen
,
160 ngx_http_log_header_out
},
162 { ngx_null_string
, 0, NULL
, NULL
, NULL
}
166 ngx_int_t
ngx_http_log_handler(ngx_http_request_t
*r
)
172 ngx_http_log_op_t
*op
;
173 ngx_http_log_loc_conf_t
*lcf
;
178 ngx_log_debug0(NGX_LOG_DEBUG_HTTP
, r
->connection
->log
, 0,
181 lcf
= ngx_http_get_module_loc_conf(r
, ngx_http_log_module
);
187 log
= lcf
->logs
->elts
;
188 for (l
= 0; l
< lcf
->logs
->nelts
; l
++) {
191 op
= log
[l
].ops
->elts
;
192 for (i
= 0; i
< log
[l
].ops
->nelts
; i
++) {
193 if (op
[i
].len
== 0) {
194 len
+= op
[i
].getlen(r
, op
[i
].data
);
207 if (!(line
= ngx_palloc(r
->pool
, len
))) {
213 for (i
= 0; i
< log
[l
].ops
->nelts
; i
++) {
214 p
= op
[i
].run(r
, p
, &op
[i
]);
218 *p
++ = CR
; *p
++ = LF
;
219 WriteFile(log
[l
].file
->fd
, line
, p
- line
, &written
, NULL
);
222 write(log
[l
].file
->fd
, line
, p
- line
);
230 static u_char
*ngx_http_log_copy_short(ngx_http_request_t
*r
, u_char
*buf
,
231 ngx_http_log_op_t
*op
)
240 *buf
++ = (u_char
) (data
& 0xff);
248 static u_char
*ngx_http_log_copy_long(ngx_http_request_t
*r
, u_char
*buf
,
249 ngx_http_log_op_t
*op
)
251 return ngx_cpymem(buf
, (u_char
*) op
->data
, op
->len
);
255 static u_char
*ngx_http_log_addr(ngx_http_request_t
*r
, u_char
*buf
,
256 ngx_http_log_op_t
*op
)
258 return ngx_cpymem(buf
, r
->connection
->addr_text
.data
,
259 r
->connection
->addr_text
.len
);
263 static u_char
*ngx_http_log_connection(ngx_http_request_t
*r
, u_char
*buf
,
264 ngx_http_log_op_t
*op
)
266 return ngx_sprintf(buf
, "%ui", r
->connection
->number
);
270 static u_char
*ngx_http_log_pipe(ngx_http_request_t
*r
, u_char
*buf
,
271 ngx_http_log_op_t
*op
)
283 static u_char
*ngx_http_log_time(ngx_http_request_t
*r
, u_char
*buf
,
284 ngx_http_log_op_t
*op
)
286 return ngx_cpymem(buf
, ngx_cached_http_log_time
.data
,
287 ngx_cached_http_log_time
.len
);
291 static u_char
*ngx_http_log_msec(ngx_http_request_t
*r
, u_char
*buf
,
292 ngx_http_log_op_t
*op
)
296 ngx_gettimeofday(&tv
);
298 return ngx_sprintf(buf
, "%l.%03l", tv
.tv_sec
, tv
.tv_usec
/ 1000);
302 static size_t ngx_http_log_request_getlen(ngx_http_request_t
*r
,
305 return r
->request_line
.len
;
309 static u_char
*ngx_http_log_request(ngx_http_request_t
*r
, u_char
*buf
,
310 ngx_http_log_op_t
*op
)
312 return ngx_cpymem(buf
, r
->request_line
.data
, r
->request_line
.len
);
316 static u_char
*ngx_http_log_status(ngx_http_request_t
*r
, u_char
*buf
,
317 ngx_http_log_op_t
*op
)
319 return ngx_sprintf(buf
, "%ui",
320 r
->err_status
? r
->err_status
: r
->headers_out
.status
);
324 static u_char
*ngx_http_log_length(ngx_http_request_t
*r
, u_char
*buf
,
325 ngx_http_log_op_t
*op
)
327 return ngx_sprintf(buf
, "%O", r
->connection
->sent
);
331 static u_char
*ngx_http_log_apache_length(ngx_http_request_t
*r
, u_char
*buf
,
332 ngx_http_log_op_t
*op
)
334 return ngx_sprintf(buf
, "%O", r
->connection
->sent
- r
->header_size
);
338 static u_char
*ngx_http_log_request_length(ngx_http_request_t
*r
, u_char
*buf
,
339 ngx_http_log_op_t
*op
)
341 return ngx_sprintf(buf
, "%z", r
->request_length
);
345 static ngx_int_t
ngx_http_log_header_in_compile(ngx_http_log_op_t
*op
,
352 for (i
= 0; ngx_http_headers_in
[i
].name
.len
!= 0; i
++) {
354 if (ngx_http_headers_in
[i
].name
.len
!= value
->len
) {
358 if (ngx_strncasecmp(ngx_http_headers_in
[i
].name
.data
, value
->data
,
361 op
->getlen
= ngx_http_log_header_in_getlen
;
362 op
->run
= ngx_http_log_header_in
;
363 op
->data
= ngx_http_headers_in
[i
].offset
;
369 op
->getlen
= ngx_http_log_unknown_header_in_getlen
;
370 op
->run
= ngx_http_log_unknown_header_in
;
371 op
->data
= (uintptr_t) value
;
377 static size_t ngx_http_log_header_in_getlen(ngx_http_request_t
*r
,
382 h
= *(ngx_table_elt_t
**) ((char *) &r
->headers_in
+ data
);
392 static u_char
*ngx_http_log_header_in(ngx_http_request_t
*r
, u_char
*buf
,
393 ngx_http_log_op_t
*op
)
397 h
= *(ngx_table_elt_t
**) ((char *) &r
->headers_in
+ op
->data
);
400 return ngx_cpymem(buf
, h
->value
.data
, h
->value
.len
);
409 static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t
*r
,
414 h
= ngx_http_log_unknown_header(&r
->headers_in
.headers
, (ngx_str_t
*) data
);
424 static u_char
*ngx_http_log_unknown_header_in(ngx_http_request_t
*r
,
426 ngx_http_log_op_t
*op
)
430 h
= ngx_http_log_unknown_header(&r
->headers_in
.headers
,
431 (ngx_str_t
*) op
->data
);
434 return ngx_cpymem(buf
, h
->value
.data
, h
->value
.len
);
443 static ngx_int_t
ngx_http_log_header_out_compile(ngx_http_log_op_t
*op
,
450 for (i
= 0; ngx_http_headers_out
[i
].name
.len
!= 0; i
++) {
452 if (ngx_http_headers_out
[i
].name
.len
!= value
->len
) {
456 if (ngx_strncasecmp(ngx_http_headers_out
[i
].name
.data
, value
->data
,
459 op
->getlen
= ngx_http_log_header_out_getlen
;
460 op
->run
= ngx_http_log_header_out
;
461 op
->data
= ngx_http_headers_out
[i
].offset
;
467 if (value
->len
== sizeof("Connection") - 1
468 && ngx_strncasecmp(value
->data
, "Connection", value
->len
) == 0)
470 op
->len
= sizeof("keep-alive") - 1;
472 op
->run
= ngx_http_log_connection_header_out
;
477 if (value
->len
== sizeof("Transfer-Encoding") - 1
478 && ngx_strncasecmp(value
->data
, "Transfer-Encoding", value
->len
) == 0)
480 op
->len
= sizeof("chunked") - 1;
482 op
->run
= ngx_http_log_transfer_encoding_header_out
;
487 op
->getlen
= ngx_http_log_unknown_header_out_getlen
;
488 op
->run
= ngx_http_log_unknown_header_out
;
489 op
->data
= (uintptr_t) value
;
495 static size_t ngx_http_log_header_out_getlen(ngx_http_request_t
*r
,
500 h
= *(ngx_table_elt_t
**) ((char *) &r
->headers_out
+ data
);
507 * No header pointer was found.
508 * However, some headers: "Date", "Server", "Content-Length",
509 * and "Last-Modified" have a special handling in the header filter
510 * but we do not set up their pointers in the filter because
511 * they are too seldom needed to be logged.
514 if (data
== offsetof(ngx_http_headers_out_t
, date
)) {
515 return ngx_cached_http_time
.len
;
518 if (data
== offsetof(ngx_http_headers_out_t
, server
)) {
519 return (sizeof(NGINX_VER
) - 1);
522 if (data
== offsetof(ngx_http_headers_out_t
, content_length
)) {
523 if (r
->headers_out
.content_length_n
== -1) {
527 return NGX_OFF_T_LEN
;
530 if (data
== offsetof(ngx_http_headers_out_t
, last_modified
)) {
531 if (r
->headers_out
.last_modified_time
== -1) {
535 return sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
542 static u_char
*ngx_http_log_header_out(ngx_http_request_t
*r
, u_char
*buf
,
543 ngx_http_log_op_t
*op
)
547 h
= *(ngx_table_elt_t
**) ((char *) &r
->headers_out
+ op
->data
);
550 return ngx_cpymem(buf
, h
->value
.data
, h
->value
.len
);
554 * No header pointer was found.
555 * However, some headers: "Date", "Server", "Content-Length",
556 * and "Last-Modified" have a special handling in the header filter
557 * but we do not set up their pointers in the filter because
558 * they are too seldom needed to be logged.
561 if (op
->data
== offsetof(ngx_http_headers_out_t
, date
)) {
562 return ngx_cpymem(buf
, ngx_cached_http_time
.data
,
563 ngx_cached_http_time
.len
);
566 if (op
->data
== offsetof(ngx_http_headers_out_t
, server
)) {
567 return ngx_cpymem(buf
, NGINX_VER
, sizeof(NGINX_VER
) - 1);
570 if (op
->data
== offsetof(ngx_http_headers_out_t
, content_length
)) {
571 if (r
->headers_out
.content_length_n
== -1) {
577 return ngx_sprintf(buf
, "%O", r
->headers_out
.content_length_n
);
580 if (op
->data
== offsetof(ngx_http_headers_out_t
, last_modified
)) {
581 if (r
->headers_out
.last_modified_time
== -1) {
587 return ngx_http_time(buf
, r
->headers_out
.last_modified_time
);
596 static size_t ngx_http_log_unknown_header_out_getlen(ngx_http_request_t
*r
,
601 h
= ngx_http_log_unknown_header(&r
->headers_out
.headers
,
612 static u_char
*ngx_http_log_unknown_header_out(ngx_http_request_t
*r
,
614 ngx_http_log_op_t
*op
)
618 h
= ngx_http_log_unknown_header(&r
->headers_out
.headers
,
619 (ngx_str_t
*) op
->data
);
622 return ngx_cpymem(buf
, h
->value
.data
, h
->value
.len
);
631 static ngx_table_elt_t
*ngx_http_log_unknown_header(ngx_list_t
*headers
,
635 ngx_list_part_t
*part
;
638 part
= &headers
->part
;
641 for (i
= 0; /* void */; i
++) {
643 if (i
>= part
->nelts
) {
644 if (part
->next
== NULL
) {
653 if (h
[i
].key
.len
!= value
->len
) {
657 if (ngx_strncasecmp(h
[i
].key
.data
, value
->data
, value
->len
) == 0) {
666 static u_char
*ngx_http_log_connection_header_out(ngx_http_request_t
*r
,
668 ngx_http_log_op_t
*op
)
671 return ngx_cpymem(buf
, "keep-alive", sizeof("keep-alive") - 1);
674 return ngx_cpymem(buf
, "close", sizeof("close") - 1);
679 static u_char
*ngx_http_log_transfer_encoding_header_out(ngx_http_request_t
*r
,
681 ngx_http_log_op_t
*op
)
684 return ngx_cpymem(buf
, "chunked", sizeof("chunked") - 1);
693 static ngx_int_t
ngx_http_log_set_formats(ngx_conf_t
*cf
)
695 ngx_http_log_op_name_t
*op
;
697 for (op
= ngx_http_log_fmt_ops
; op
->name
.len
; op
++) { /* void */ }
704 static void *ngx_http_log_create_main_conf(ngx_conf_t
*cf
)
706 ngx_http_log_main_conf_t
*conf
;
711 if (!(conf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_log_main_conf_t
)))) {
712 return NGX_CONF_ERROR
;
715 ngx_init_array(conf
->formats
, cf
->pool
, 5, sizeof(ngx_http_log_fmt_t
),
720 if (!(value
= ngx_push_array(cf
->args
))) {
721 return NGX_CONF_ERROR
;
724 if (!(value
= ngx_push_array(cf
->args
))) {
725 return NGX_CONF_ERROR
;
728 value
->len
= sizeof("combined") - 1;
729 value
->data
= (u_char
*) "combined";
731 if (!(value
= ngx_push_array(cf
->args
))) {
732 return NGX_CONF_ERROR
;
735 *value
= ngx_http_combined_fmt
;
737 rc
= ngx_http_log_set_format(cf
, NULL
, conf
);
738 if (rc
!= NGX_CONF_OK
) {
746 static void *ngx_http_log_create_loc_conf(ngx_conf_t
*cf
)
748 ngx_http_log_loc_conf_t
*conf
;
750 if (!(conf
= ngx_pcalloc(cf
->pool
, sizeof(ngx_http_log_loc_conf_t
)))) {
751 return NGX_CONF_ERROR
;
758 static char *ngx_http_log_merge_loc_conf(ngx_conf_t
*cf
, void *parent
,
761 ngx_http_log_loc_conf_t
*prev
= parent
;
762 ngx_http_log_loc_conf_t
*conf
= child
;
765 ngx_http_log_fmt_t
*fmt
;
766 ngx_http_log_main_conf_t
*lmcf
;
768 if (conf
->logs
== NULL
) {
775 conf
->logs
= prev
->logs
;
780 conf
->off
= prev
->off
;
784 conf
->logs
= ngx_array_create(cf
->pool
, 2, sizeof(ngx_http_log_t
));
785 if (conf
->logs
== NULL
) {
786 return NGX_CONF_ERROR
;
789 if (!(log
= ngx_array_push(conf
->logs
))) {
790 return NGX_CONF_ERROR
;
793 log
->file
= ngx_conf_open_file(cf
->cycle
, &http_access_log
);
794 if (log
->file
== NULL
) {
795 return NGX_CONF_ERROR
;
798 lmcf
= ngx_http_conf_get_module_main_conf(cf
, ngx_http_log_module
);
799 fmt
= lmcf
->formats
.elts
;
801 /* the default "combined" format */
802 log
->ops
= fmt
[0].ops
;
810 static char *ngx_http_log_set_log(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
813 ngx_http_log_loc_conf_t
*llcf
= conf
;
816 ngx_str_t
*value
, name
;
818 ngx_http_log_fmt_t
*fmt
;
819 ngx_http_log_main_conf_t
*lmcf
;
821 value
= cf
->args
->elts
;
823 if (ngx_strcmp(value
[1].data
, "off") == 0) {
828 if (llcf
->logs
== NULL
) {
829 llcf
->logs
= ngx_array_create(cf
->pool
, 2, sizeof(ngx_http_log_t
));
830 if (llcf
->logs
== NULL
) {
831 return NGX_CONF_ERROR
;
835 lmcf
= ngx_http_conf_get_module_main_conf(cf
, ngx_http_log_module
);
837 if (!(log
= ngx_array_push(llcf
->logs
))) {
838 return NGX_CONF_ERROR
;
841 if (!(log
->file
= ngx_conf_open_file(cf
->cycle
, &value
[1]))) {
842 return NGX_CONF_ERROR
;
845 if (cf
->args
->nelts
== 3) {
848 name
.len
= sizeof("combined") - 1;
849 name
.data
= (u_char
*) "combined";
852 fmt
= lmcf
->formats
.elts
;
853 for (i
= 0; i
< lmcf
->formats
.nelts
; i
++) {
854 if (fmt
[i
].name
.len
== name
.len
855 && ngx_strcasecmp(fmt
[i
].name
.data
, name
.data
) == 0)
857 log
->ops
= fmt
[i
].ops
;
862 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
863 "unknown log format \"%V\"", &name
);
865 return NGX_CONF_ERROR
;
869 static char *ngx_http_log_set_format(ngx_conf_t
*cf
, ngx_command_t
*cmd
,
872 ngx_http_log_main_conf_t
*lmcf
= conf
;
874 ngx_uint_t s
, f
, invalid
;
875 u_char
*data
, *p
, *fname
;
876 size_t i
, len
, fname_len
;
877 ngx_str_t
*value
, arg
, *a
;
878 ngx_http_log_op_t
*op
;
879 ngx_http_log_fmt_t
*fmt
;
880 ngx_http_log_op_name_t
*name
;
882 value
= cf
->args
->elts
;
884 fmt
= lmcf
->formats
.elts
;
885 for (f
= 0; f
< lmcf
->formats
.nelts
; f
++) {
886 if (fmt
[f
].name
.len
== value
[1].len
887 && ngx_strcmp(fmt
->name
.data
, value
[1].data
) == 0)
889 return "duplicate \"log_format\" name";
893 if (!(fmt
= ngx_push_array(&lmcf
->formats
))) {
894 return NGX_CONF_ERROR
;
897 fmt
->name
= value
[1];
899 if (!(fmt
->ops
= ngx_array_create(cf
->pool
, 20, sizeof(ngx_http_log_op_t
))))
901 return NGX_CONF_ERROR
;
907 for (s
= 2; s
< cf
->args
->nelts
&& !invalid
; s
++) {
911 while (i
< value
[s
].len
) {
913 if (!(op
= ngx_push_array(fmt
->ops
))) {
914 return NGX_CONF_ERROR
;
917 data
= &value
[s
].data
[i
];
919 if (value
[s
].data
[i
] == '%') {
922 if (i
== value
[s
].len
) {
927 if (value
[s
].data
[i
] == '{') {
930 arg
.data
= &value
[s
].data
[i
];
932 while (i
< value
[s
].len
&& value
[s
].data
[i
] != '}') {
936 arg
.len
= &value
[s
].data
[i
] - arg
.data
;
938 if (i
== value
[s
].len
|| arg
.len
== 0) {
949 fname
= &value
[s
].data
[i
];
951 while (i
< value
[s
].len
952 && ((value
[s
].data
[i
] >= 'a' && value
[s
].data
[i
] <= 'z')
953 || value
[s
].data
[i
] == '_'))
958 fname_len
= &value
[s
].data
[i
] - fname
;
960 if (fname_len
== 0) {
965 for (name
= ngx_http_log_fmt_ops
; name
->run
; name
++) {
966 if (name
->name
.len
== 0) {
967 name
= (ngx_http_log_op_name_t
*) name
->run
;
970 if (name
->name
.len
== fname_len
971 && ngx_strncmp(name
->name
.data
, fname
, fname_len
) == 0)
973 if (name
->compile
== NULL
) {
975 fname
[fname_len
] = '\0';
976 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
977 "\"%s\" must not have argument",
979 return NGX_CONF_ERROR
;
983 op
->getlen
= name
->getlen
;
991 fname
[fname_len
] = '\0';
992 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
993 "\"%s\" requires argument",
995 return NGX_CONF_ERROR
;
998 if (!(a
= ngx_palloc(cf
->pool
, sizeof(ngx_str_t
)))) {
999 return NGX_CONF_ERROR
;
1003 if (name
->compile(op
, a
) == NGX_ERROR
) {
1004 return NGX_CONF_ERROR
;
1011 if (name
->name
.len
== 0) {
1019 while (i
< value
[s
].len
&& value
[s
].data
[i
] != '%') {
1023 len
= &value
[s
].data
[i
] - data
;
1030 if (len
<= sizeof(uintptr_t)) {
1031 op
->run
= ngx_http_log_copy_short
;
1036 op
->data
|= data
[len
];
1040 op
->run
= ngx_http_log_copy_long
;
1042 if (!(p
= ngx_palloc(cf
->pool
, len
))) {
1043 return NGX_CONF_ERROR
;
1046 ngx_memcpy(p
, data
, len
);
1047 op
->data
= (uintptr_t) p
;
1055 ngx_conf_log_error(NGX_LOG_EMERG
, cf
, 0,
1056 "invalid parameter \"%s\"", data
);
1057 return NGX_CONF_ERROR
;