nginx 0.1.11
[nginx-catap.git] / src / http / ngx_http_log_handler.c
blobfd373444e4265fe2c43bd25aadc2c0804d5db282
2 /*
3 * Copyright (C) Igor Sysoev
4 */
7 #include <ngx_config.h>
8 #include <ngx_core.h>
9 #include <ngx_http.h>
10 #include <nginx.h>
13 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf,
14 uintptr_t data);
15 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf,
16 uintptr_t data);
17 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
18 uintptr_t data);
19 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
20 uintptr_t data);
21 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
22 uintptr_t data);
23 static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf,
24 uintptr_t data);
25 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf,
26 uintptr_t data);
27 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf,
28 uintptr_t data);
29 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf,
30 uintptr_t data);
31 static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf,
32 uintptr_t data);
33 static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r,
34 u_char *buf, uintptr_t data);
35 static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r,
36 u_char *buf,
37 uintptr_t data);
38 static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r,
39 u_char *buf, uintptr_t data);
40 static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf,
41 uintptr_t data);
42 static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r, u_char *buf,
43 uintptr_t data);
45 static ngx_int_t ngx_http_log_pre_conf(ngx_conf_t *cf);
46 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
47 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
48 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent,
49 void *child);
50 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
51 void *conf);
52 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
53 void *conf);
54 static ngx_int_t ngx_http_log_parse_format(ngx_conf_t *cf, ngx_array_t *ops,
55 ngx_str_t *line);
58 static ngx_command_t ngx_http_log_commands[] = {
60 {ngx_string("log_format"),
61 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
62 ngx_http_log_set_format,
63 NGX_HTTP_MAIN_CONF_OFFSET,
65 NULL},
67 {ngx_string("access_log"),
68 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
69 ngx_http_log_set_log,
70 NGX_HTTP_LOC_CONF_OFFSET,
72 NULL},
74 ngx_null_command
78 ngx_http_module_t ngx_http_log_module_ctx = {
79 ngx_http_log_pre_conf, /* pre conf */
81 ngx_http_log_create_main_conf, /* create main configuration */
82 NULL, /* init main configuration */
84 NULL, /* create server configuration */
85 NULL, /* merge server configuration */
87 ngx_http_log_create_loc_conf, /* create location configration */
88 ngx_http_log_merge_loc_conf /* merge location configration */
92 ngx_module_t ngx_http_log_module = {
93 NGX_MODULE,
94 &ngx_http_log_module_ctx, /* module context */
95 ngx_http_log_commands, /* module directives */
96 NGX_HTTP_MODULE, /* module type */
97 NULL, /* init module */
98 NULL /* init child */
102 static ngx_str_t http_access_log = ngx_string(NGX_HTTP_LOG_PATH);
105 static ngx_str_t ngx_http_combined_fmt =
106 ngx_string("%addr - - [%time] \"%request\" %status %apache_length "
107 "\"%{Referer}i\" \"%{User-Agent}i\"");
110 ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
111 { ngx_string("addr"), INET_ADDRSTRLEN - 1, ngx_http_log_addr },
112 { ngx_string("conn"), NGX_INT32_LEN, ngx_http_log_connection },
113 { ngx_string("pipe"), 1, ngx_http_log_pipe },
114 { ngx_string("time"), sizeof("28/Sep/1970:12:00:00") - 1,
115 ngx_http_log_time },
116 { ngx_string("msec"), TIME_T_LEN + 4, ngx_http_log_msec },
117 { ngx_string("request"), 0, ngx_http_log_request },
118 { ngx_string("status"), 3, ngx_http_log_status },
119 { ngx_string("length"), NGX_OFF_T_LEN, ngx_http_log_length },
120 { ngx_string("apache_length"), NGX_OFF_T_LEN, ngx_http_log_apache_length },
121 { ngx_string("i"), NGX_HTTP_LOG_ARG, ngx_http_log_header_in },
122 { ngx_string("o"), NGX_HTTP_LOG_ARG, ngx_http_log_header_out },
123 { ngx_null_string, 0, NULL }
127 ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
129 ngx_uint_t i, l;
130 uintptr_t data;
131 u_char *line, *p;
132 size_t len;
133 ngx_http_log_t *log;
134 ngx_http_log_op_t *op;
135 ngx_http_log_loc_conf_t *lcf;
136 #if (NGX_WIN32)
137 u_long written;
138 #endif
140 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
141 "http log handler");
143 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module);
145 if (lcf->off) {
146 return NGX_OK;
149 log = lcf->logs->elts;
150 for (l = 0; l < lcf->logs->nelts; l++) {
152 len = 0;
153 op = log[l].ops->elts;
154 for (i = 0; i < log[l].ops->nelts; i++) {
155 if (op[i].len == 0) {
156 len += (size_t) op[i].op(r, NULL, op[i].data);
158 } else {
159 len += op[i].len;
163 #if (NGX_WIN32)
164 len += 2;
165 #else
166 len++;
167 #endif
169 if (!(line = ngx_palloc(r->pool, len))) {
170 return NGX_ERROR;
173 p = line;
175 for (i = 0; i < log[l].ops->nelts; i++) {
176 if (op[i].op == NGX_HTTP_LOG_COPY_SHORT) {
177 len = op[i].len;
178 data = op[i].data;
179 while (len--) {
180 *p++ = (char) (data & 0xff);
181 data >>= 8;
184 } else if (op[i].op == NGX_HTTP_LOG_COPY_LONG) {
185 p = ngx_cpymem(p, (void *) op[i].data, op[i].len);
187 } else {
188 p = op[i].op(r, p, op[i].data);
192 #if (NGX_WIN32)
193 *p++ = CR; *p++ = LF;
194 WriteFile(log[l].file->fd, line, p - line, &written, NULL);
195 #else
196 *p++ = LF;
197 write(log[l].file->fd, line, p - line);
198 #endif
201 return NGX_OK;
205 static u_char *ngx_http_log_addr(ngx_http_request_t *r, u_char *buf,
206 uintptr_t data)
208 return ngx_cpymem(buf, r->connection->addr_text.data,
209 r->connection->addr_text.len);
213 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf,
214 uintptr_t data)
216 return ngx_sprintf(buf, "%ui", r->connection->number);
220 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
221 uintptr_t data)
223 if (r->pipeline) {
224 *buf = 'p';
225 } else {
226 *buf = '.';
229 return buf + 1;
233 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
234 uintptr_t data)
236 return ngx_cpymem(buf, ngx_cached_http_log_time.data,
237 ngx_cached_http_log_time.len);
241 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
242 uintptr_t data)
244 struct timeval tv;
246 ngx_gettimeofday(&tv);
248 return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000);
252 static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf,
253 uintptr_t data)
255 if (buf == NULL) {
256 /* find the request line length */
257 return (u_char *) r->request_line.len;
260 return ngx_cpymem(buf, r->request_line.data, r->request_line.len);
264 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf,
265 uintptr_t data)
267 return ngx_sprintf(buf, "%ui",
268 r->err_status ? r->err_status : r->headers_out.status);
272 static u_char *ngx_http_log_length(ngx_http_request_t *r, u_char *buf,
273 uintptr_t data)
275 return ngx_sprintf(buf, "%O", r->connection->sent);
279 static u_char *ngx_http_log_apache_length(ngx_http_request_t *r, u_char *buf,
280 uintptr_t data)
282 return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size);
286 static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf,
287 uintptr_t data)
289 ngx_uint_t i;
290 ngx_str_t *s;
291 ngx_table_elt_t *h;
292 ngx_http_log_op_t *op;
294 if (r) {
295 h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data);
297 if (h == NULL) {
299 /* no header */
301 if (buf) {
302 *buf = '-';
305 return buf + 1;
308 if (buf == NULL) {
309 /* find the header length */
310 return (u_char *) h->value.len;
313 return ngx_cpymem(buf, h->value.data, h->value.len);
316 /* find an offset while a format string compilation */
318 op = (ngx_http_log_op_t *) buf;
319 s = (ngx_str_t *) data;
321 op->len = 0;
323 for (i = 0; ngx_http_headers_in[i].name.len != 0; i++) {
324 if (ngx_http_headers_in[i].name.len != s->len) {
325 continue;
328 if (ngx_strncasecmp(ngx_http_headers_in[i].name.data, s->data, s->len)
329 == 0)
331 op->op = ngx_http_log_header_in;
332 op->data = ngx_http_headers_in[i].offset;
333 return NULL;
337 op->op = ngx_http_log_unknown_header_in;
338 op->data = (uintptr_t) s;
340 return NULL;
344 static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r,
345 u_char *buf, uintptr_t data)
347 ngx_uint_t i;
348 ngx_str_t *s;
349 ngx_list_part_t *part;
350 ngx_table_elt_t *h;
352 s = (ngx_str_t *) data;
354 part = &r->headers_in.headers.part;
355 h = part->elts;
357 for (i = 0; /* void */; i++) {
359 if (i >= part->nelts) {
360 if (part->next == NULL) {
361 break;
364 part = part->next;
365 h = part->elts;
366 i = 0;
369 if (h[i].key.len != s->len) {
370 continue;
373 if (ngx_strncasecmp(h[i].key.data, s->data, s->len) == 0) {
374 if (buf == NULL) {
375 /* find the header length */
376 return (u_char *) h[i].value.len;
379 return ngx_cpymem(buf, h[i].value.data, h[i].value.len);
383 /* no header */
385 if (buf) {
386 *buf = '-';
389 return buf + 1;
393 static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf,
394 uintptr_t data)
396 ngx_uint_t i;
397 ngx_str_t *s;
398 ngx_table_elt_t *h;
399 ngx_http_log_op_t *op;
401 if (r) {
403 /* run-time execution */
405 if (r->http_version < NGX_HTTP_VERSION_10) {
406 if (buf) {
407 *buf = '-';
410 return buf + 1;
413 h = *(ngx_table_elt_t **) ((char *) &r->headers_out + data);
415 if (h == NULL) {
418 * No header pointer was found.
419 * However, some headers: "Date", "Server", "Content-Length",
420 * and "Last-Modified" have a special handling in the header filter
421 * but we do not set up their pointers in the filter because
422 * they are too seldom needed to be logged.
425 if (data == offsetof(ngx_http_headers_out_t, date)) {
426 if (buf == NULL) {
427 return (u_char *) ngx_cached_http_time.len;
429 return ngx_cpymem(buf, ngx_cached_http_time.data,
430 ngx_cached_http_time.len);
433 if (data == offsetof(ngx_http_headers_out_t, server)) {
434 if (buf == NULL) {
435 return (u_char *) (sizeof(NGINX_VER) - 1);
437 return ngx_cpymem(buf, NGINX_VER, sizeof(NGINX_VER) - 1);
440 if (data == offsetof(ngx_http_headers_out_t, content_length)) {
441 if (r->headers_out.content_length_n == -1) {
442 if (buf) {
443 *buf = '-';
445 return buf + 1;
448 if (buf == NULL) {
449 return (u_char *) NGX_OFF_T_LEN;
451 return ngx_sprintf(buf, "%O", r->headers_out.content_length_n);
454 if (data == offsetof(ngx_http_headers_out_t, last_modified)) {
455 if (r->headers_out.last_modified_time == -1) {
456 if (buf) {
457 *buf = '-';
459 return buf + 1;
462 if (buf == NULL) {
463 return (u_char *)
464 sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
466 return ngx_http_time(buf, r->headers_out.last_modified_time);
469 if (buf) {
470 *buf = '-';
473 return buf + 1;
476 if (buf == NULL) {
477 /* find the header length */
478 return (u_char *) h->value.len;
481 return ngx_cpymem(buf, h->value.data, h->value.len);
484 /* find an offset while a format string compilation */
486 op = (ngx_http_log_op_t *) buf;
487 s = (ngx_str_t *) data;
489 op->len = 0;
491 for (i = 0; ngx_http_headers_out[i].name.len != 0; i++) {
492 if (ngx_http_headers_out[i].name.len != s->len) {
493 continue;
496 if (ngx_strncasecmp(ngx_http_headers_out[i].name.data, s->data, s->len)
497 == 0)
499 op->op = ngx_http_log_header_out;
500 op->data = ngx_http_headers_out[i].offset;
501 return NULL;
505 if (s->len == sizeof("Connection") - 1
506 && ngx_strncasecmp(s->data, "Connection", s->len) == 0)
508 op->op = ngx_http_log_connection_header_out;
509 op->data = (uintptr_t) NULL;
510 return NULL;
513 if (s->len == sizeof("Transfer-Encoding") - 1
514 && ngx_strncasecmp(s->data, "Transfer-Encoding", s->len) == 0) {
515 op->op = ngx_http_log_transfer_encoding_header_out;
516 op->data = (uintptr_t) NULL;
517 return NULL;
520 op->op = ngx_http_log_unknown_header_out;
521 op->data = (uintptr_t) s;
523 return NULL;
527 static u_char *ngx_http_log_connection_header_out(ngx_http_request_t *r,
528 u_char *buf, uintptr_t data)
530 if (buf == NULL) {
531 return (u_char *) ((r->keepalive) ? sizeof("keep-alive") - 1:
532 sizeof("close") - 1);
535 if (r->keepalive) {
536 return ngx_cpymem(buf, "keep-alive", sizeof("keep-alive") - 1);
538 } else {
539 return ngx_cpymem(buf, "close", sizeof("close") - 1);
544 static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r,
545 u_char *buf,
546 uintptr_t data)
548 if (buf == NULL) {
549 return (u_char *) ((r->chunked) ? sizeof("chunked") - 1 : 1);
552 if (r->chunked) {
553 return ngx_cpymem(buf, "chunked", sizeof("chunked") - 1);
556 *buf = '-';
558 return buf + 1;
562 static u_char *ngx_http_log_unknown_header_out(ngx_http_request_t *r,
563 u_char *buf,
564 uintptr_t data)
566 ngx_uint_t i;
567 ngx_str_t *s;
568 ngx_list_part_t *part;
569 ngx_table_elt_t *h;
571 s = (ngx_str_t *) data;
573 part = &r->headers_out.headers.part;
574 h = part->elts;
576 for (i = 0; /* void */; i++) {
578 if (i >= part->nelts) {
579 if (part->next == NULL) {
580 break;
583 part = part->next;
584 h = part->elts;
585 i = 0;
588 if (h[i].key.len != s->len) {
589 continue;
592 if (ngx_strncasecmp(h[i].key.data, s->data, s->len) == 0) {
593 if (buf == NULL) {
594 /* find the header length */
595 return (u_char *) h[i].value.len;
598 return ngx_cpymem(buf, h[i].value.data, h[i].value.len);
602 /* no header */
604 if (buf) {
605 *buf = '-';
608 return buf + 1;
612 static ngx_int_t ngx_http_log_pre_conf(ngx_conf_t *cf)
614 ngx_http_log_op_name_t *op;
616 for (op = ngx_http_log_fmt_ops; op->name.len; op++) { /* void */ }
617 op->op = NULL;
619 return NGX_OK;
623 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf)
625 ngx_http_log_main_conf_t *conf;
627 char *rc;
628 ngx_str_t *value;
630 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)))) {
631 return NGX_CONF_ERROR;
634 ngx_init_array(conf->formats, cf->pool, 5, sizeof(ngx_http_log_fmt_t),
635 NGX_CONF_ERROR);
637 cf->args->nelts = 0;
639 if (!(value = ngx_push_array(cf->args))) {
640 return NGX_CONF_ERROR;
643 if (!(value = ngx_push_array(cf->args))) {
644 return NGX_CONF_ERROR;
647 value->len = sizeof("combined") - 1;
648 value->data = (u_char *) "combined";
650 if (!(value = ngx_push_array(cf->args))) {
651 return NGX_CONF_ERROR;
654 *value = ngx_http_combined_fmt;
656 rc = ngx_http_log_set_format(cf, NULL, conf);
657 if (rc != NGX_CONF_OK) {
658 return NULL;
661 return conf;
665 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf)
667 ngx_http_log_loc_conf_t *conf;
669 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)))) {
670 return NGX_CONF_ERROR;
673 return conf;
677 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent,
678 void *child)
680 ngx_http_log_loc_conf_t *prev = parent;
681 ngx_http_log_loc_conf_t *conf = child;
683 ngx_http_log_t *log;
684 ngx_http_log_fmt_t *fmt;
685 ngx_http_log_main_conf_t *lmcf;
687 if (conf->logs == NULL) {
689 if (conf->off) {
690 return NGX_CONF_OK;
693 if (prev->logs) {
694 conf->logs = prev->logs;
696 } else {
698 if (prev->off) {
699 conf->off = prev->off;
700 return NGX_CONF_OK;
703 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
704 if (conf->logs == NULL) {
705 return NGX_CONF_ERROR;
708 if (!(log = ngx_array_push(conf->logs))) {
709 return NGX_CONF_ERROR;
712 log->file = ngx_conf_open_file(cf->cycle, &http_access_log);
713 if (log->file == NULL) {
714 return NGX_CONF_ERROR;
717 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
718 fmt = lmcf->formats.elts;
720 /* the default "combined" format */
721 log->ops = fmt[0].ops;
725 return NGX_CONF_OK;
729 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
730 void *conf)
732 ngx_http_log_loc_conf_t *llcf = conf;
734 ngx_uint_t i;
735 ngx_str_t *value, name;
736 ngx_http_log_t *log;
737 ngx_http_log_fmt_t *fmt;
738 ngx_http_log_main_conf_t *lmcf;
740 value = cf->args->elts;
742 if (ngx_strcmp(value[1].data, "off") == 0) {
743 llcf->off = 1;
744 return NGX_CONF_OK;
747 if (llcf->logs == NULL) {
748 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
749 if (llcf->logs == NULL) {
750 return NGX_CONF_ERROR;
754 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
756 if (!(log = ngx_array_push(llcf->logs))) {
757 return NGX_CONF_ERROR;
760 if (!(log->file = ngx_conf_open_file(cf->cycle, &value[1]))) {
761 return NGX_CONF_ERROR;
764 if (cf->args->nelts == 3) {
765 name = value[2];
766 } else {
767 name.len = sizeof("combined") - 1;
768 name.data = (u_char *) "combined";
771 fmt = lmcf->formats.elts;
772 for (i = 0; i < lmcf->formats.nelts; i++) {
773 if (fmt[i].name.len == name.len
774 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
776 log->ops = fmt[i].ops;
777 return NGX_CONF_OK;
781 return NGX_CONF_OK;
785 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
786 void *conf)
788 ngx_http_log_main_conf_t *lmcf = conf;
790 ngx_uint_t s, f, invalid;
791 u_char *data, *p, *fname;
792 size_t i, len, fname_len;
793 ngx_str_t *value, arg, *a;
794 ngx_http_log_op_t *op;
795 ngx_http_log_fmt_t *fmt;
796 ngx_http_log_op_name_t *name;
798 value = cf->args->elts;
800 fmt = lmcf->formats.elts;
801 for (f = 0; f < lmcf->formats.nelts; f++) {
802 if (fmt[f].name.len == value[1].len
803 && ngx_strcmp(fmt->name.data, value[1].data) == 0)
805 return "duplicate \"log_format\" name";
809 if (!(fmt = ngx_push_array(&lmcf->formats))) {
810 return NGX_CONF_ERROR;
813 fmt->name = value[1];
815 if (!(fmt->ops = ngx_create_array(cf->pool, 20,
816 sizeof(ngx_http_log_op_t)))) {
817 return NGX_CONF_ERROR;
820 invalid = 0;
821 data = NULL;
823 for (s = 2; s < cf->args->nelts && !invalid; s++) {
825 i = 0;
827 while (i < value[s].len) {
829 if (!(op = ngx_push_array(fmt->ops))) {
830 return NGX_CONF_ERROR;
833 data = &value[s].data[i];
835 if (value[s].data[i] == '%') {
836 i++;
838 if (i == value[s].len) {
839 invalid = 1;
840 break;
843 if (value[s].data[i] == '{') {
844 i++;
846 arg.data = &value[s].data[i];
848 while (i < value[s].len && value[s].data[i] != '}') {
849 i++;
852 arg.len = &value[s].data[i] - arg.data;
854 if (i == value[s].len || arg.len == 0) {
855 invalid = 1;
856 break;
859 i++;
861 } else {
862 arg.len = 0;
865 fname = &value[s].data[i];
867 while (i < value[s].len
868 && ((value[s].data[i] >= 'a' && value[s].data[i] <= 'z')
869 || value[s].data[i] == '_'))
871 i++;
874 fname_len = &value[s].data[i] - fname;
876 if (fname_len == 0) {
877 invalid = 1;
878 break;
881 for (name = ngx_http_log_fmt_ops; name->op; name++) {
882 if (name->name.len == 0) {
883 name = (ngx_http_log_op_name_t *) name->op;
886 if (name->name.len == fname_len
887 && ngx_strncmp(name->name.data, fname, fname_len) == 0)
889 if (name->len != NGX_HTTP_LOG_ARG) {
890 if (arg.len) {
891 fname[fname_len] = '\0';
892 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
893 "\"%s\" must not have argument",
894 data);
895 return NGX_CONF_ERROR;
898 op->len = name->len;
899 op->op = name->op;
900 op->data = 0;
902 break;
905 if (arg.len == 0) {
906 fname[fname_len] = '\0';
907 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
908 "\"%s\" requires argument",
909 data);
910 return NGX_CONF_ERROR;
913 if (!(a = ngx_palloc(cf->pool, sizeof(ngx_str_t)))) {
914 return NGX_CONF_ERROR;
917 *a = arg;
918 name->op(NULL, (u_char *) op, (uintptr_t) a);
920 break;
924 if (name->name.len == 0) {
925 invalid = 1;
926 break;
929 } else {
930 i++;
932 while (i < value[s].len && value[s].data[i] != '%') {
933 i++;
936 len = &value[s].data[i] - data;
938 if (len) {
940 op->len = len;
942 if (len <= sizeof(uintptr_t)) {
943 op->op = NGX_HTTP_LOG_COPY_SHORT;
944 op->data = 0;
946 while (len--) {
947 op->data <<= 8;
948 op->data |= data[len];
951 } else {
952 op->op = NGX_HTTP_LOG_COPY_LONG;
954 if (!(p = ngx_palloc(cf->pool, len))) {
955 return NGX_CONF_ERROR;
958 ngx_memcpy(p, data, len);
959 op->data = (uintptr_t) p;
966 if (invalid) {
967 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
968 "invalid parameter \"%s\"", data);
969 return NGX_CONF_ERROR;
972 return NGX_CONF_OK;