Bug Summary

File:http/modules/ngx_http_log_module.c
Location:line 405, column 16
Description:Dereference of null pointer

Annotated Source Code

1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#include <ngx_config.h>
9#include <ngx_core.h>
10#include <ngx_http.h>
11
12#if (NGX_ZLIB1)
13#include <zlib.h>
14#endif
15
16
17typedef struct ngx_http_log_op_s ngx_http_log_op_t;
18
19typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf,
20 ngx_http_log_op_t *op);
21
22typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r,
23 uintptr_t data);
24
25
26struct ngx_http_log_op_s {
27 size_t len;
28 ngx_http_log_op_getlen_pt getlen;
29 ngx_http_log_op_run_pt run;
30 uintptr_t data;
31};
32
33
34typedef struct {
35 ngx_str_t name;
36 ngx_array_t *flushes;
37 ngx_array_t *ops; /* array of ngx_http_log_op_t */
38} ngx_http_log_fmt_t;
39
40
41typedef struct {
42 ngx_array_t formats; /* array of ngx_http_log_fmt_t */
43 ngx_uint_t combined_used; /* unsigned combined_used:1 */
44} ngx_http_log_main_conf_t;
45
46
47typedef struct {
48 u_char *start;
49 u_char *pos;
50 u_char *last;
51
52 ngx_event_t *event;
53 ngx_msec_t flush;
54 ngx_int_t gzip;
55} ngx_http_log_buf_t;
56
57
58typedef struct {
59 ngx_array_t *lengths;
60 ngx_array_t *values;
61} ngx_http_log_script_t;
62
63
64typedef struct {
65 ngx_open_file_t *file;
66 ngx_http_log_script_t *script;
67 time_t disk_full_time;
68 time_t error_log_time;
69 ngx_syslog_peer_t *syslog_peer;
70 ngx_http_log_fmt_t *format;
71 ngx_http_complex_value_t *filter;
72} ngx_http_log_t;
73
74
75typedef struct {
76 ngx_array_t *logs; /* array of ngx_http_log_t */
77
78 ngx_open_file_cache_t *open_file_cache;
79 time_t open_file_cache_valid;
80 ngx_uint_t open_file_cache_min_uses;
81
82 ngx_uint_t off; /* unsigned off:1 */
83} ngx_http_log_loc_conf_t;
84
85
86typedef struct {
87 ngx_str_t name;
88 size_t len;
89 ngx_http_log_op_run_pt run;
90} ngx_http_log_var_t;
91
92
93static void ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log,
94 u_char *buf, size_t len);
95static ssize_t ngx_http_log_script_write(ngx_http_request_t *r,
96 ngx_http_log_script_t *script, u_char **name, u_char *buf, size_t len);
97
98#if (NGX_ZLIB1)
99static ssize_t ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len,
100 ngx_int_t level, ngx_log_t *log);
101
102static void *ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size);
103static void ngx_http_log_gzip_free(void *opaque, void *address);
104#endif
105
106static void ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log);
107static void ngx_http_log_flush_handler(ngx_event_t *ev);
108
109static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
110 ngx_http_log_op_t *op);
111static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
112 ngx_http_log_op_t *op);
113static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf,
114 ngx_http_log_op_t *op);
115static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
116 ngx_http_log_op_t *op);
117static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
118 ngx_http_log_op_t *op);
119static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf,
120 ngx_http_log_op_t *op);
121static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf,
122 ngx_http_log_op_t *op);
123static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r,
124 u_char *buf, ngx_http_log_op_t *op);
125static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
126 ngx_http_log_op_t *op);
127
128static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf,
129 ngx_http_log_op_t *op, ngx_str_t *value);
130static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r,
131 uintptr_t data);
132static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf,
133 ngx_http_log_op_t *op);
134static uintptr_t ngx_http_log_escape(u_char *dst, u_char *src, size_t size);
135
136
137static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
138static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
139static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent,
140 void *child);
141static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
142 void *conf);
143static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
144 void *conf);
145static char *ngx_http_log_compile_format(ngx_conf_t *cf,
146 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s);
147static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
148 void *conf);
149static ngx_int_t ngx_http_log_init(ngx_conf_t *cf);
150
151
152static ngx_command_t ngx_http_log_commands[] = {
153
154 { ngx_string("log_format"){ sizeof("log_format") - 1, (u_char *) "log_format" },
155 NGX_HTTP_MAIN_CONF0x02000000|NGX_CONF_2MORE0x00001000,
156 ngx_http_log_set_format,
157 NGX_HTTP_MAIN_CONF_OFFSET__builtin_offsetof(ngx_http_conf_ctx_t, main_conf),
158 0,
159 NULL((void*)0) },
160
161 { ngx_string("access_log"){ sizeof("access_log") - 1, (u_char *) "access_log" },
162 NGX_HTTP_MAIN_CONF0x02000000|NGX_HTTP_SRV_CONF0x04000000|NGX_HTTP_LOC_CONF0x08000000|NGX_HTTP_LIF_CONF0x40000000
163 |NGX_HTTP_LMT_CONF0x80000000|NGX_CONF_1MORE0x00000800,
164 ngx_http_log_set_log,
165 NGX_HTTP_LOC_CONF_OFFSET__builtin_offsetof(ngx_http_conf_ctx_t, loc_conf),
166 0,
167 NULL((void*)0) },
168
169 { ngx_string("open_log_file_cache"){ sizeof("open_log_file_cache") - 1, (u_char *) "open_log_file_cache"
}
,
170 NGX_HTTP_MAIN_CONF0x02000000|NGX_HTTP_SRV_CONF0x04000000|NGX_HTTP_LOC_CONF0x08000000|NGX_CONF_TAKE1234(0x00000002|0x00000004|0x00000008 |0x00000010),
171 ngx_http_log_open_file_cache,
172 NGX_HTTP_LOC_CONF_OFFSET__builtin_offsetof(ngx_http_conf_ctx_t, loc_conf),
173 0,
174 NULL((void*)0) },
175
176 ngx_null_command{ { 0, ((void*)0) }, 0, ((void*)0), 0, 0, ((void*)0) }
177};
178
179
180static ngx_http_module_t ngx_http_log_module_ctx = {
181 NULL((void*)0), /* preconfiguration */
182 ngx_http_log_init, /* postconfiguration */
183
184 ngx_http_log_create_main_conf, /* create main configuration */
185 NULL((void*)0), /* init main configuration */
186
187 NULL((void*)0), /* create server configuration */
188 NULL((void*)0), /* merge server configuration */
189
190 ngx_http_log_create_loc_conf, /* create location configuration */
191 ngx_http_log_merge_loc_conf /* merge location configuration */
192};
193
194
195ngx_module_t ngx_http_log_module = {
196 NGX_MODULE_V1(ngx_uint_t) -1, (ngx_uint_t) -1, ((void*)0), 0, 0, 1011001, "8"
"," "4" "," "8" "," "0" "0" "0" "0" "1" "1" "1" "0" "0" "1" "0"
"1" "0" "1" "1" "1" "1" "1" "1" "1" "1" "0" "1" "0" "0" "1" "0"
"1" "0" "0" "0" "1" "1"
,
197 &ngx_http_log_module_ctx, /* module context */
198 ngx_http_log_commands, /* module directives */
199 NGX_HTTP_MODULE0x50545448, /* module type */
200 NULL((void*)0), /* init master */
201 NULL((void*)0), /* init module */
202 NULL((void*)0), /* init process */
203 NULL((void*)0), /* init thread */
204 NULL((void*)0), /* exit thread */
205 NULL((void*)0), /* exit process */
206 NULL((void*)0), /* exit master */
207 NGX_MODULE_V1_PADDING0, 0, 0, 0, 0, 0, 0, 0
208};
209
210
211static ngx_str_t ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH){ sizeof("logs/access.log") - 1, (u_char *) "logs/access.log"
}
;
212
213
214static ngx_str_t ngx_http_combined_fmt =
215 ngx_string("$remote_addr - $remote_user [$time_local] "{ sizeof("$remote_addr - $remote_user [$time_local] " "\"$request\" $status $body_bytes_sent "
"\"$http_referer\" \"$http_user_agent\"") - 1, (u_char *) "$remote_addr - $remote_user [$time_local] "
"\"$request\" $status $body_bytes_sent " "\"$http_referer\" \"$http_user_agent\""
}
216 "\"$request\" $status $body_bytes_sent "{ sizeof("$remote_addr - $remote_user [$time_local] " "\"$request\" $status $body_bytes_sent "
"\"$http_referer\" \"$http_user_agent\"") - 1, (u_char *) "$remote_addr - $remote_user [$time_local] "
"\"$request\" $status $body_bytes_sent " "\"$http_referer\" \"$http_user_agent\""
}
217 "\"$http_referer\" \"$http_user_agent\""){ sizeof("$remote_addr - $remote_user [$time_local] " "\"$request\" $status $body_bytes_sent "
"\"$http_referer\" \"$http_user_agent\"") - 1, (u_char *) "$remote_addr - $remote_user [$time_local] "
"\"$request\" $status $body_bytes_sent " "\"$http_referer\" \"$http_user_agent\""
}
;
218
219
220static ngx_http_log_var_t ngx_http_log_vars[] = {
221 { ngx_string("pipe"){ sizeof("pipe") - 1, (u_char *) "pipe" }, 1, ngx_http_log_pipe },
222 { ngx_string("time_local"){ sizeof("time_local") - 1, (u_char *) "time_local" }, sizeof("28/Sep/1970:12:00:00 +0600") - 1,
223 ngx_http_log_time },
224 { ngx_string("time_iso8601"){ sizeof("time_iso8601") - 1, (u_char *) "time_iso8601" }, sizeof("1970-09-28T12:00:00+06:00") - 1,
225 ngx_http_log_iso8601 },
226 { ngx_string("msec"){ sizeof("msec") - 1, (u_char *) "msec" }, NGX_TIME_T_LEN(sizeof("-9223372036854775808") - 1) + 4, ngx_http_log_msec },
227 { ngx_string("request_time"){ sizeof("request_time") - 1, (u_char *) "request_time" }, NGX_TIME_T_LEN(sizeof("-9223372036854775808") - 1) + 4,
228 ngx_http_log_request_time },
229 { ngx_string("status"){ sizeof("status") - 1, (u_char *) "status" }, NGX_INT_T_LEN(sizeof("-9223372036854775808") - 1), ngx_http_log_status },
230 { ngx_string("bytes_sent"){ sizeof("bytes_sent") - 1, (u_char *) "bytes_sent" }, NGX_OFF_T_LEN(sizeof("-9223372036854775808") - 1), ngx_http_log_bytes_sent },
231 { ngx_string("body_bytes_sent"){ sizeof("body_bytes_sent") - 1, (u_char *) "body_bytes_sent"
}
, NGX_OFF_T_LEN(sizeof("-9223372036854775808") - 1),
232 ngx_http_log_body_bytes_sent },
233 { ngx_string("request_length"){ sizeof("request_length") - 1, (u_char *) "request_length" }, NGX_SIZE_T_LEN(sizeof("-9223372036854775808") - 1),
234 ngx_http_log_request_length },
235
236 { ngx_null_string{ 0, ((void*)0) }, 0, NULL((void*)0) }
237};
238
239
240static ngx_int_t
241ngx_http_log_handler(ngx_http_request_t *r)
242{
243 u_char *line, *p;
244 size_t len, size;
245 ssize_t n;
246 ngx_str_t val;
247 ngx_uint_t i, l;
248 ngx_http_log_t *log;
249 ngx_http_log_op_t *op;
250 ngx_http_log_buf_t *buffer;
251 ngx_http_log_loc_conf_t *lcf;
252
253 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
254 "http log handler");
255
256 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module)(r)->loc_conf[ngx_http_log_module.ctx_index];
257
258 if (lcf->off) {
1
Taking false branch
259 return NGX_OK0;
260 }
261
262 log = lcf->logs->elts;
263 for (l = 0; l < lcf->logs->nelts; l++) {
2
Loop condition is true. Entering loop body
14
Loop condition is true. Entering loop body
26
Loop condition is true. Entering loop body
264
265 if (log[l].filter) {
3
Taking false branch
15
Taking false branch
27
Taking false branch
266 if (ngx_http_complex_value(r, log[l].filter, &val) != NGX_OK0) {
267 return NGX_ERROR-1;
268 }
269
270 if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) {
271 continue;
272 }
273 }
274
275 if (ngx_time()ngx_cached_time->sec == log[l].disk_full_time) {
4
Taking false branch
16
Taking false branch
28
Taking false branch
276
277 /*
278 * on FreeBSD writing to a full filesystem with enabled softupdates
279 * may block process for much longer time than writing to non-full
280 * filesystem, so we skip writing to a log for one second
281 */
282
283 continue;
284 }
285
286 ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes);
287
288 len = 0;
289 op = log[l].format->ops->elts;
290 for (i = 0; i < log[l].format->ops->nelts; i++) {
5
Loop condition is false. Execution continues on line 299
17
Loop condition is false. Execution continues on line 299
29
Loop condition is false. Execution continues on line 299
291 if (op[i].len == 0) {
292 len += op[i].getlen(r, op[i].data);
293
294 } else {
295 len += op[i].len;
296 }
297 }
298
299 if (log[l].syslog_peer) {
6
Taking false branch
18
Taking false branch
30
Taking false branch
300
301 /* length of syslog's PRI and HEADER message parts */
302 len += sizeof("<255>Jan 01 00:00:00 ") - 1
303 + ngx_cycle->hostname.len + 1
304 + log[l].syslog_peer->tag.len + 2;
305
306 goto alloc_line;
307 }
308
309 len += NGX_LINEFEED_SIZE1;
310
311 buffer = log[l].file ? log[l].file->data : NULL((void*)0);
7
'?' condition is false
19
'?' condition is false
31
Assuming pointer value is null
32
'?' condition is false
312
313 if (buffer) {
8
Taking false branch
20
Taking false branch
33
Taking false branch
314
315 if (len > (size_t) (buffer->last - buffer->pos)) {
316
317 ngx_http_log_write(r, &log[l], buffer->start,
318 buffer->pos - buffer->start);
319
320 buffer->pos = buffer->start;
321 }
322
323 if (len <= (size_t) (buffer->last - buffer->pos)) {
324
325 p = buffer->pos;
326
327 if (buffer->event && p == buffer->start) {
328 ngx_add_timerngx_event_add_timer(buffer->event, buffer->flush);
329 }
330
331 for (i = 0; i < log[l].format->ops->nelts; i++) {
332 p = op[i].run(r, p, &op[i]);
333 }
334
335 ngx_linefeed(p)*p++ = (u_char) '\n';;
336
337 buffer->pos = p;
338
339 continue;
340 }
341
342 if (buffer->event && buffer->event->timer_set) {
343 ngx_del_timerngx_event_del_timer(buffer->event);
344 }
345 }
346
347 alloc_line:
348
349 line = ngx_pnalloc(r->pool, len);
350 if (line == NULL((void*)0)) {
9
Assuming 'line' is not equal to null
10
Taking false branch
21
Assuming 'line' is not equal to null
22
Taking false branch
34
Assuming 'line' is not equal to null
35
Taking false branch
351 return NGX_ERROR-1;
352 }
353
354 p = line;
355
356 if (log[l].syslog_peer) {
11
Taking false branch
23
Taking false branch
36
Taking false branch
357 p = ngx_syslog_add_header(log[l].syslog_peer, line);
358 }
359
360 for (i = 0; i < log[l].format->ops->nelts; i++) {
12
Loop condition is false. Execution continues on line 364
24
Loop condition is false. Execution continues on line 364
37
Loop condition is false. Execution continues on line 364
361 p = op[i].run(r, p, &op[i]);
362 }
363
364 if (log[l].syslog_peer) {
13
Taking false branch
25
Taking false branch
38
Taking false branch
365
366 size = p - line;
367
368 n = ngx_syslog_send(log[l].syslog_peer, line, size);
369
370 if (n < 0) {
371 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,if ((r->connection->log)->log_level >= 5) ngx_log_error_core
(5, r->connection->log, 0, "send() to syslog failed")
372 "send() to syslog failed")if ((r->connection->log)->log_level >= 5) ngx_log_error_core
(5, r->connection->log, 0, "send() to syslog failed")
;
373
374 } else if ((size_t) n != size) {
375 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,if ((r->connection->log)->log_level >= 5) ngx_log_error_core
(5, r->connection->log, 0, "send() to syslog has written only %z of %uz"
, n, size)
376 "send() to syslog has written only %z of %uz",if ((r->connection->log)->log_level >= 5) ngx_log_error_core
(5, r->connection->log, 0, "send() to syslog has written only %z of %uz"
, n, size)
377 n, size)if ((r->connection->log)->log_level >= 5) ngx_log_error_core
(5, r->connection->log, 0, "send() to syslog has written only %z of %uz"
, n, size)
;
378 }
379
380 continue;
381 }
382
383 ngx_linefeed(p)*p++ = (u_char) '\n';;
384
385 ngx_http_log_write(r, &log[l], line, p - line);
39
Calling 'ngx_http_log_write'
386 }
387
388 return NGX_OK0;
389}
390
391
392static void
393ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
394 size_t len)
395{
396 u_char *name;
397 time_t now;
398 ssize_t n;
399 ngx_err_t err;
400#if (NGX_ZLIB1)
401 ngx_http_log_buf_t *buffer;
402#endif
403
404 if (log->script == NULL((void*)0)) {
40
Taking true branch
405 name = log->file->name.data;
41
Dereference of null pointer
406
407#if (NGX_ZLIB1)
408 buffer = log->file->data;
409
410 if (buffer && buffer->gzip) {
411 n = ngx_http_log_gzip(log->file->fd, buf, len, buffer->gzip,
412 r->connection->log);
413 } else {
414 n = ngx_write_fd(log->file->fd, buf, len);
415 }
416#else
417 n = ngx_write_fd(log->file->fd, buf, len);
418#endif
419
420 } else {
421 name = NULL((void*)0);
422 n = ngx_http_log_script_write(r, log->script, &name, buf, len);
423 }
424
425 if (n == (ssize_t) len) {
426 return;
427 }
428
429 now = ngx_time()ngx_cached_time->sec;
430
431 if (n == -1) {
432 err = ngx_errno(*__errno_location ());
433
434 if (err == NGX_ENOSPC28) {
435 log->disk_full_time = now;
436 }
437
438 if (now - log->error_log_time > 59) {
439 ngx_log_error(NGX_LOG_ALERT, r->connection->log, err,if ((r->connection->log)->log_level >= 2) ngx_log_error_core
(2, r->connection->log, err, "write()" " to \"%s\" failed"
, name)
440 ngx_write_fd_n " to \"%s\" failed", name)if ((r->connection->log)->log_level >= 2) ngx_log_error_core
(2, r->connection->log, err, "write()" " to \"%s\" failed"
, name)
;
441
442 log->error_log_time = now;
443 }
444
445 return;
446 }
447
448 if (now - log->error_log_time > 59) {
449 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,if ((r->connection->log)->log_level >= 2) ngx_log_error_core
(2, r->connection->log, 0, "write()" " to \"%s\" was incomplete: %z of %uz"
, name, n, len)
450 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",if ((r->connection->log)->log_level >= 2) ngx_log_error_core
(2, r->connection->log, 0, "write()" " to \"%s\" was incomplete: %z of %uz"
, name, n, len)
451 name, n, len)if ((r->connection->log)->log_level >= 2) ngx_log_error_core
(2, r->connection->log, 0, "write()" " to \"%s\" was incomplete: %z of %uz"
, name, n, len)
;
452
453 log->error_log_time = now;
454 }
455}
456
457
458static ssize_t
459ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script,
460 u_char **name, u_char *buf, size_t len)
461{
462 size_t root;
463 ssize_t n;
464 ngx_str_t log, path;
465 ngx_open_file_info_t of;
466 ngx_http_log_loc_conf_t *llcf;
467 ngx_http_core_loc_conf_t *clcf;
468
469 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module)(r)->loc_conf[ngx_http_core_module.ctx_index];
470
471 if (!r->root_tested) {
472
473 /* test root directory existence */
474
475 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL((void*)0)) {
476 /* simulate successful logging */
477 return len;
478 }
479
480 path.data[root] = '\0';
481
482 ngx_memzero(&of, sizeof(ngx_open_file_info_t))(void) memset(&of, 0, sizeof(ngx_open_file_info_t));
483
484 of.valid = clcf->open_file_cache_valid;
485 of.min_uses = clcf->open_file_cache_min_uses;
486 of.test_dir = 1;
487 of.test_only = 1;
488 of.errors = clcf->open_file_cache_errors;
489 of.events = clcf->open_file_cache_events;
490
491 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK0) {
492 /* simulate successful logging */
493 return len;
494 }
495
496 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
497 != NGX_OK0)
498 {
499 if (of.err == 0) {
500 /* simulate successful logging */
501 return len;
502 }
503
504 ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err,if ((r->connection->log)->log_level >= 4) ngx_log_error_core
(4, r->connection->log, of.err, "testing \"%s\" existence failed"
, path.data)
505 "testing \"%s\" existence failed", path.data)if ((r->connection->log)->log_level >= 4) ngx_log_error_core
(4, r->connection->log, of.err, "testing \"%s\" existence failed"
, path.data)
;
506
507 /* simulate successful logging */
508 return len;
509 }
510
511 if (!of.is_dir) {
512 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ENOTDIR,if ((r->connection->log)->log_level >= 4) ngx_log_error_core
(4, r->connection->log, 20, "testing \"%s\" existence failed"
, path.data)
513 "testing \"%s\" existence failed", path.data)if ((r->connection->log)->log_level >= 4) ngx_log_error_core
(4, r->connection->log, 20, "testing \"%s\" existence failed"
, path.data)
;
514
515 /* simulate successful logging */
516 return len;
517 }
518 }
519
520 if (ngx_http_script_run(r, &log, script->lengths->elts, 1,
521 script->values->elts)
522 == NULL((void*)0))
523 {
524 /* simulate successful logging */
525 return len;
526 }
527
528 log.data[log.len - 1] = '\0';
529 *name = log.data;
530
531 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
532 "http log \"%s\"", log.data);
533
534 llcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module)(r)->loc_conf[ngx_http_log_module.ctx_index];
535
536 ngx_memzero(&of, sizeof(ngx_open_file_info_t))(void) memset(&of, 0, sizeof(ngx_open_file_info_t));
537
538 of.log = 1;
539 of.valid = llcf->open_file_cache_valid;
540 of.min_uses = llcf->open_file_cache_min_uses;
541 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF9223372036854775807LL;
542
543 if (ngx_http_set_disable_symlinks(r, clcf, &log, &of) != NGX_OK0) {
544 /* simulate successful logging */
545 return len;
546 }
547
548 if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool)
549 != NGX_OK0)
550 {
551 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,if ((r->connection->log)->log_level >= 3) ngx_log_error_core
(3, r->connection->log, (*__errno_location ()), "%s \"%s\" failed"
, of.failed, log.data)
552 "%s \"%s\" failed", of.failed, log.data)if ((r->connection->log)->log_level >= 3) ngx_log_error_core
(3, r->connection->log, (*__errno_location ()), "%s \"%s\" failed"
, of.failed, log.data)
;
553 /* simulate successful logging */
554 return len;
555 }
556
557 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
558 "http log #%d", of.fd);
559
560 n = ngx_write_fd(of.fd, buf, len);
561
562 return n;
563}
564
565
566#if (NGX_ZLIB1)
567
568static ssize_t
569ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, ngx_int_t level,
570 ngx_log_t *log)
571{
572 int rc, wbits, memlevel;
573 u_char *out;
574 size_t size;
575 ssize_t n;
576 z_stream zstream;
577 ngx_err_t err;
578 ngx_pool_t *pool;
579
580 wbits = MAX_WBITS15;
581 memlevel = MAX_MEM_LEVEL9 - 1;
582
583 while ((ssize_t) len < ((1 << (wbits - 1)) - 262)) {
584 wbits--;
585 memlevel--;
586 }
587
588 /*
589 * This is a formula from deflateBound() for conservative upper bound of
590 * compressed data plus 18 bytes of gzip wrapper.
591 */
592
593 size = len + ((len + 7) >> 3) + ((len + 63) >> 6) + 5 + 18;
594
595 ngx_memzero(&zstream, sizeof(z_stream))(void) memset(&zstream, 0, sizeof(z_stream));
596
597 pool = ngx_create_pool(256, log);
598 if (pool == NULL((void*)0)) {
599 /* simulate successful logging */
600 return len;
601 }
602
603 pool->log = log;
604
605 zstream.zalloc = ngx_http_log_gzip_alloc;
606 zstream.zfree = ngx_http_log_gzip_free;
607 zstream.opaque = pool;
608
609 out = ngx_pnalloc(pool, size);
610 if (out == NULL((void*)0)) {
611 goto done;
612 }
613
614 zstream.next_in = buf;
615 zstream.avail_in = len;
616 zstream.next_out = out;
617 zstream.avail_out = size;
618
619 rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel,deflateInit2_((&zstream),((int) level),(8),(wbits + 16),(
memlevel), (0), "1.2.8", (int)sizeof(z_stream))
620 Z_DEFAULT_STRATEGY)deflateInit2_((&zstream),((int) level),(8),(wbits + 16),(
memlevel), (0), "1.2.8", (int)sizeof(z_stream))
;
621
622 if (rc != Z_OK0) {
623 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateInit2() failed: %d", rc)if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "deflateInit2() failed: %d", rc)
;
624 goto done;
625 }
626
627 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0,
628 "deflate in: ni:%p no:%p ai:%ud ao:%ud",
629 zstream.next_in, zstream.next_out,
630 zstream.avail_in, zstream.avail_out);
631
632 rc = deflate(&zstream, Z_FINISH4);
633
634 if (rc != Z_STREAM_END1) {
635 ngx_log_error(NGX_LOG_ALERT, log, 0,if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "deflate(Z_FINISH) failed: %d", rc)
636 "deflate(Z_FINISH) failed: %d", rc)if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "deflate(Z_FINISH) failed: %d", rc)
;
637 goto done;
638 }
639
640 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, log, 0,
641 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
642 zstream.next_in, zstream.next_out,
643 zstream.avail_in, zstream.avail_out,
644 rc);
645
646 size -= zstream.avail_out;
647
648 rc = deflateEnd(&zstream);
649
650 if (rc != Z_OK0) {
651 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc)if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "deflateEnd() failed: %d", rc)
;
652 goto done;
653 }
654
655 n = ngx_write_fd(fd, out, size);
656
657 if (n != (ssize_t) size) {
658 err = (n == -1) ? ngx_errno(*__errno_location ()) : 0;
659
660 ngx_destroy_pool(pool);
661
662 ngx_set_errno(err)(*__errno_location ()) = err;
663 return -1;
664 }
665
666done:
667
668 ngx_destroy_pool(pool);
669
670 /* simulate successful logging */
671 return len;
672}
673
674
675static void *
676ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size)
677{
678 ngx_pool_t *pool = opaque;
679
680 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pool->log, 0,
681 "gzip alloc: n:%ud s:%ud", items, size);
682
683 return ngx_palloc(pool, items * size);
684}
685
686
687static void
688ngx_http_log_gzip_free(void *opaque, void *address)
689{
690#if 0
691 ngx_pool_t *pool = opaque;
692
693 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pool->log, 0, "gzip free: %p", address);
694#endif
695}
696
697#endif
698
699
700static void
701ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
702{
703 size_t len;
704 ssize_t n;
705 ngx_http_log_buf_t *buffer;
706
707 buffer = file->data;
708
709 len = buffer->pos - buffer->start;
710
711 if (len == 0) {
712 return;
713 }
714
715#if (NGX_ZLIB1)
716 if (buffer->gzip) {
717 n = ngx_http_log_gzip(file->fd, buffer->start, len, buffer->gzip, log);
718 } else {
719 n = ngx_write_fd(file->fd, buffer->start, len);
720 }
721#else
722 n = ngx_write_fd(file->fd, buffer->start, len);
723#endif
724
725 if (n == -1) {
726 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,if ((log)->log_level >= 2) ngx_log_error_core(2, log, (
*__errno_location ()), "write()" " to \"%s\" failed", file->
name.data)
727 ngx_write_fd_n " to \"%s\" failed",if ((log)->log_level >= 2) ngx_log_error_core(2, log, (
*__errno_location ()), "write()" " to \"%s\" failed", file->
name.data)
728 file->name.data)if ((log)->log_level >= 2) ngx_log_error_core(2, log, (
*__errno_location ()), "write()" " to \"%s\" failed", file->
name.data)
;
729
730 } else if ((size_t) n != len) {
731 ngx_log_error(NGX_LOG_ALERT, log, 0,if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "write()" " to \"%s\" was incomplete: %z of %uz", file->
name.data, n, len)
732 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "write()" " to \"%s\" was incomplete: %z of %uz", file->
name.data, n, len)
733 file->name.data, n, len)if ((log)->log_level >= 2) ngx_log_error_core(2, log, 0
, "write()" " to \"%s\" was incomplete: %z of %uz", file->
name.data, n, len)
;
734 }
735
736 buffer->pos = buffer->start;
737
738 if (buffer->event && buffer->event->timer_set) {
739 ngx_del_timerngx_event_del_timer(buffer->event);
740 }
741}
742
743
744static void
745ngx_http_log_flush_handler(ngx_event_t *ev)
746{
747 ngx_open_file_t *file;
748 ngx_http_log_buf_t *buffer;
749
750 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0,
751 "http log buffer flush handler");
752
753 if (ev->timedout) {
754 ngx_http_log_flush(ev->data, ev->log);
755 return;
756 }
757
758 /* cancel the flush timer for graceful shutdown */
759
760 file = ev->data;
761 buffer = file->data;
762
763 buffer->event = NULL((void*)0);
764}
765
766
767static u_char *
768ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf,
769 ngx_http_log_op_t *op)
770{
771 size_t len;
772 uintptr_t data;
773
774 len = op->len;
775 data = op->data;
776
777 while (len--) {
778 *buf++ = (u_char) (data & 0xff);
779 data >>= 8;
780 }
781
782 return buf;
783}
784
785
786static u_char *
787ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf,
788 ngx_http_log_op_t *op)
789{
790 return ngx_cpymem(buf, (u_char *) op->data, op->len)(((u_char *) memcpy(buf, (u_char *) op->data, op->len))
+ (op->len))
;
791}
792
793
794static u_char *
795ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
796{
797 if (r->pipeline) {
798 *buf = 'p';
799 } else {
800 *buf = '.';
801 }
802
803 return buf + 1;
804}
805
806
807static u_char *
808ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
809{
810 return ngx_cpymem(buf, ngx_cached_http_log_time.data,(((u_char *) memcpy(buf, ngx_cached_http_log_time.data, ngx_cached_http_log_time
.len)) + (ngx_cached_http_log_time.len))
811 ngx_cached_http_log_time.len)(((u_char *) memcpy(buf, ngx_cached_http_log_time.data, ngx_cached_http_log_time
.len)) + (ngx_cached_http_log_time.len))
;
812}
813
814static u_char *
815ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
816{
817 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data,(((u_char *) memcpy(buf, ngx_cached_http_log_iso8601.data, ngx_cached_http_log_iso8601
.len)) + (ngx_cached_http_log_iso8601.len))
818 ngx_cached_http_log_iso8601.len)(((u_char *) memcpy(buf, ngx_cached_http_log_iso8601.data, ngx_cached_http_log_iso8601
.len)) + (ngx_cached_http_log_iso8601.len))
;
819}
820
821static u_char *
822ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
823{
824 ngx_time_t *tp;
825
826 tp = ngx_timeofday()(ngx_time_t *) ngx_cached_time;
827
828 return ngx_sprintf(buf, "%T.%03M", tp->sec, tp->msec);
829}
830
831
832static u_char *
833ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
834 ngx_http_log_op_t *op)
835{
836 ngx_time_t *tp;
837 ngx_msec_int_t ms;
838
839 tp = ngx_timeofday()(ngx_time_t *) ngx_cached_time;
840
841 ms = (ngx_msec_int_t)
842 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
843 ms = ngx_max(ms, 0)((ms < 0) ? (0) : (ms));
844
845 return ngx_sprintf(buf, "%T.%03M", (time_t) ms / 1000, ms % 1000);
846}
847
848
849static u_char *
850ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
851{
852 ngx_uint_t status;
853
854 if (r->err_status) {
855 status = r->err_status;
856
857 } else if (r->headers_out.status) {
858 status = r->headers_out.status;
859
860 } else if (r->http_version == NGX_HTTP_VERSION_99) {
861 status = 9;
862
863 } else {
864 status = 0;
865 }
866
867 return ngx_sprintf(buf, "%03ui", status);
868}
869
870
871static u_char *
872ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf,
873 ngx_http_log_op_t *op)
874{
875 return ngx_sprintf(buf, "%O", r->connection->sent);
876}
877
878
879/*
880 * although there is a real $body_bytes_sent variable,
881 * this log operation code function is more optimized for logging
882 */
883
884static u_char *
885ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf,
886 ngx_http_log_op_t *op)
887{
888 off_t length;
889
890 length = r->connection->sent - r->header_size;
891
892 if (length > 0) {
893 return ngx_sprintf(buf, "%O", length);
894 }
895
896 *buf = '0';
897
898 return buf + 1;
899}
900
901
902static u_char *
903ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
904 ngx_http_log_op_t *op)
905{
906 return ngx_sprintf(buf, "%O", r->request_length);
907}
908
909
910static ngx_int_t
911ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
912 ngx_str_t *value)
913{
914 ngx_int_t index;
915
916 index = ngx_http_get_variable_index(cf, value);
917 if (index == NGX_ERROR-1) {
918 return NGX_ERROR-1;
919 }
920
921 op->len = 0;
922 op->getlen = ngx_http_log_variable_getlen;
923 op->run = ngx_http_log_variable;
924 op->data = index;
925
926 return NGX_OK0;
927}
928
929
930static size_t
931ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data)
932{
933 uintptr_t len;
934 ngx_http_variable_value_t *value;
935
936 value = ngx_http_get_indexed_variable(r, data);
937
938 if (value == NULL((void*)0) || value->not_found) {
939 return 1;
940 }
941
942 len = ngx_http_log_escape(NULL((void*)0), value->data, value->len);
943
944 value->escape = len ? 1 : 0;
945
946 return value->len + len * 3;
947}
948
949
950static u_char *
951ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
952{
953 ngx_http_variable_value_t *value;
954
955 value = ngx_http_get_indexed_variable(r, op->data);
956
957 if (value == NULL((void*)0) || value->not_found) {
958 *buf = '-';
959 return buf + 1;
960 }
961
962 if (value->escape == 0) {
963 return ngx_cpymem(buf, value->data, value->len)(((u_char *) memcpy(buf, value->data, value->len)) + (value
->len))
;
964
965 } else {
966 return (u_char *) ngx_http_log_escape(buf, value->data, value->len);
967 }
968}
969
970
971static uintptr_t
972ngx_http_log_escape(u_char *dst, u_char *src, size_t size)
973{
974 ngx_uint_t n;
975 static u_char hex[] = "0123456789ABCDEF";
976
977 static uint32_t escape[] = {
978 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
979
980 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
981 0x00000004, /* 0000 0000 0000 0000 0000 0000 0000 0100 */
982
983 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
984 0x10000000, /* 0001 0000 0000 0000 0000 0000 0000 0000 */
985
986 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
987 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
988
989 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
990 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
991 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
992 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
993 };
994
995
996 if (dst == NULL((void*)0)) {
997
998 /* find the number of the characters to be escaped */
999
1000 n = 0;
1001
1002 while (size) {
1003 if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1004 n++;
1005 }
1006 src++;
1007 size--;
1008 }
1009
1010 return (uintptr_t) n;
1011 }
1012
1013 while (size) {
1014 if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1015 *dst++ = '\\';
1016 *dst++ = 'x';
1017 *dst++ = hex[*src >> 4];
1018 *dst++ = hex[*src & 0xf];
1019 src++;
1020
1021 } else {
1022 *dst++ = *src++;
1023 }
1024 size--;
1025 }
1026
1027 return (uintptr_t) dst;
1028}
1029
1030
1031static void *
1032ngx_http_log_create_main_conf(ngx_conf_t *cf)
1033{
1034 ngx_http_log_main_conf_t *conf;
1035
1036 ngx_http_log_fmt_t *fmt;
1037
1038 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t));
1039 if (conf == NULL((void*)0)) {
1040 return NULL((void*)0);
1041 }
1042
1043 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t))
1044 != NGX_OK0)
1045 {
1046 return NULL((void*)0);
1047 }
1048
1049 fmt = ngx_array_push(&conf->formats);
1050 if (fmt == NULL((void*)0)) {
1051 return NULL((void*)0);
1052 }
1053
1054 ngx_str_set(&fmt->name, "combined")(&fmt->name)->len = sizeof("combined") - 1; (&fmt
->name)->data = (u_char *) "combined"
;
1055
1056 fmt->flushes = NULL((void*)0);
1057
1058 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
1059 if (fmt->ops == NULL((void*)0)) {
1060 return NULL((void*)0);
1061 }
1062
1063 return conf;
1064}
1065
1066
1067static void *
1068ngx_http_log_create_loc_conf(ngx_conf_t *cf)
1069{
1070 ngx_http_log_loc_conf_t *conf;
1071
1072 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t));
1073 if (conf == NULL((void*)0)) {
1074 return NULL((void*)0);
1075 }
1076
1077 conf->open_file_cache = NGX_CONF_UNSET_PTR(void *) -1;
1078
1079 return conf;
1080}
1081
1082
1083static char *
1084ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
1085{
1086 ngx_http_log_loc_conf_t *prev = parent;
1087 ngx_http_log_loc_conf_t *conf = child;
1088
1089 ngx_http_log_t *log;
1090 ngx_http_log_fmt_t *fmt;
1091 ngx_http_log_main_conf_t *lmcf;
1092
1093 if (conf->open_file_cache == NGX_CONF_UNSET_PTR(void *) -1) {
1094
1095 conf->open_file_cache = prev->open_file_cache;
1096 conf->open_file_cache_valid = prev->open_file_cache_valid;
1097 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses;
1098
1099 if (conf->open_file_cache == NGX_CONF_UNSET_PTR(void *) -1) {
1100 conf->open_file_cache = NULL((void*)0);
1101 }
1102 }
1103
1104 if (conf->logs || conf->off) {
1105 return NGX_CONF_OK((void*)0);
1106 }
1107
1108 conf->logs = prev->logs;
1109 conf->off = prev->off;
1110
1111 if (conf->logs || conf->off) {
1112 return NGX_CONF_OK((void*)0);
1113 }
1114
1115 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
1116 if (conf->logs == NULL((void*)0)) {
1117 return NGX_CONF_ERROR(void *) -1;
1118 }
1119
1120 log = ngx_array_push(conf->logs);
1121 if (log == NULL((void*)0)) {
1122 return NGX_CONF_ERROR(void *) -1;
1123 }
1124
1125 ngx_memzero(log, sizeof(ngx_http_log_t))(void) memset(log, 0, sizeof(ngx_http_log_t));
1126
1127 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
1128 if (log->file == NULL((void*)0)) {
1129 return NGX_CONF_ERROR(void *) -1;
1130 }
1131
1132 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module)((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[ngx_http_log_module
.ctx_index]
;
1133 fmt = lmcf->formats.elts;
1134
1135 /* the default "combined" format */
1136 log->format = &fmt[0];
1137 lmcf->combined_used = 1;
1138
1139 return NGX_CONF_OK((void*)0);
1140}
1141
1142
1143static char *
1144ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1145{
1146 ngx_http_log_loc_conf_t *llcf = conf;
1147
1148 ssize_t size;
1149 ngx_int_t gzip;
1150 ngx_uint_t i, n;
1151 ngx_msec_t flush;
1152 ngx_str_t *value, name, s;
1153 ngx_http_log_t *log;
1154 ngx_syslog_peer_t *peer;
1155 ngx_http_log_buf_t *buffer;
1156 ngx_http_log_fmt_t *fmt;
1157 ngx_http_log_main_conf_t *lmcf;
1158 ngx_http_script_compile_t sc;
1159 ngx_http_compile_complex_value_t ccv;
1160
1161 value = cf->args->elts;
1162
1163 if (ngx_strcmp(value[1].data, "off")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) value[1].data) && __builtin_constant_p
((const char *) "off") && (__s1_len = strlen ((const
char *) value[1].data), __s2_len = strlen ((const char *) "off"
), (!((size_t)(const void *)(((const char *) value[1].data) +
1) - (size_t)(const void *)((const char *) value[1].data) ==
1) || __s1_len >= 4) && (!((size_t)(const void *)
(((const char *) "off") + 1) - (size_t)(const void *)((const char
*) "off") == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const
char *) value[1].data, (const char *) "off") : (__builtin_constant_p
((const char *) value[1].data) && ((size_t)(const void
*)(((const char *) value[1].data) + 1) - (size_t)(const void
*)((const char *) value[1].data) == 1) && (__s1_len =
strlen ((const char *) value[1].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "off") && ((size_t)(const void *)(((
const char *) "off") + 1) - (size_t)(const void *)((const char
*) "off") == 1) ? __builtin_strcmp ((const char *) value[1].
data, (const char *) "off") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ((const char
*) "off"); int __result = (((const unsigned char *) (const char
*) ((const char *) value[1].data))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ((const char *) value[1].data))[1] - __s2
[1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[1].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[1].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "off") && (
(size_t)(const void *)(((const char *) "off") + 1) - (size_t)
(const void *)((const char *) "off") == 1) && (__s2_len
= strlen ((const char *) "off"), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[1].data) && ((size_t)(const void
*)(((const char *) value[1].data) + 1) - (size_t)(const void
*)((const char *) value[1].data) == 1) ? __builtin_strcmp ((
const char *) value[1].data, (const char *) "off") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[1].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "off"))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) "off"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "off"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "off"))[3] - __s2[3]); } } __result; })))
) : __builtin_strcmp ((const char *) value[1].data, (const char
*) "off")))); })
== 0) {
1164 llcf->off = 1;
1165 if (cf->args->nelts == 2) {
1166 return NGX_CONF_OK((void*)0);
1167 }
1168
1169 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1170 "invalid parameter \"%V\"", &value[2]);
1171 return NGX_CONF_ERROR(void *) -1;
1172 }
1173
1174 if (llcf->logs == NULL((void*)0)) {
1175 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
1176 if (llcf->logs == NULL((void*)0)) {
1177 return NGX_CONF_ERROR(void *) -1;
1178 }
1179 }
1180
1181 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module)((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[ngx_http_log_module
.ctx_index]
;
1182
1183 log = ngx_array_push(llcf->logs);
1184 if (log == NULL((void*)0)) {
1185 return NGX_CONF_ERROR(void *) -1;
1186 }
1187
1188 ngx_memzero(log, sizeof(ngx_http_log_t))(void) memset(log, 0, sizeof(ngx_http_log_t));
1189
1190
1191 if (ngx_strncmp(value[1].data, "syslog:", 7)(__extension__ (__builtin_constant_p (7) && ((__builtin_constant_p
((const char *) value[1].data) && strlen ((const char
*) value[1].data) < ((size_t) (7))) || (__builtin_constant_p
((const char *) "syslog:") && strlen ((const char *)
"syslog:") < ((size_t) (7)))) ? __extension__ ({ size_t __s1_len
, __s2_len; (__builtin_constant_p ((const char *) value[1].data
) && __builtin_constant_p ((const char *) "syslog:") &&
(__s1_len = strlen ((const char *) value[1].data), __s2_len =
strlen ((const char *) "syslog:"), (!((size_t)(const void *)
(((const char *) value[1].data) + 1) - (size_t)(const void *)
((const char *) value[1].data) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)(((const char *) "syslog:") + 1) - (
size_t)(const void *)((const char *) "syslog:") == 1) || __s2_len
>= 4)) ? __builtin_strcmp ((const char *) value[1].data, (
const char *) "syslog:") : (__builtin_constant_p ((const char
*) value[1].data) && ((size_t)(const void *)(((const
char *) value[1].data) + 1) - (size_t)(const void *)((const char
*) value[1].data) == 1) && (__s1_len = strlen ((const
char *) value[1].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "syslog:") && ((size_t)(const void *
)(((const char *) "syslog:") + 1) - (size_t)(const void *)((const
char *) "syslog:") == 1) ? __builtin_strcmp ((const char *) value
[1].data, (const char *) "syslog:") : (__extension__ ({ const
unsigned char *__s2 = (const unsigned char *) (const char *)
((const char *) "syslog:"); int __result = (((const unsigned
char *) (const char *) ((const char *) value[1].data))[0] - __s2
[0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[1].data))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) value[1].data))[2] - __s2[2]); if (__s1_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) ((const char *) value[1].data))[3] - __s2[
3]); } } __result; }))) : (__builtin_constant_p ((const char *
) "syslog:") && ((size_t)(const void *)(((const char *
) "syslog:") + 1) - (size_t)(const void *)((const char *) "syslog:"
) == 1) && (__s2_len = strlen ((const char *) "syslog:"
), __s2_len < 4) ? (__builtin_constant_p ((const char *) value
[1].data) && ((size_t)(const void *)(((const char *) value
[1].data) + 1) - (size_t)(const void *)((const char *) value[
1].data) == 1) ? __builtin_strcmp ((const char *) value[1].data
, (const char *) "syslog:") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ((const char
*) value[1].data); int __result = (((const unsigned char *) (
const char *) ((const char *) "syslog:"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ((const char *) "syslog:"))[
1] - __s2[1]); if (__s2_len > 1 && __result == 0) {
__result = (((const unsigned char *) (const char *) ((const char
*) "syslog:"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "syslog:"))[3] - __s2[3]); } } __result; }
)))) : __builtin_strcmp ((const char *) value[1].data, (const
char *) "syslog:")))); }) : strncmp ((const char *) value[1]
.data, (const char *) "syslog:", 7)))
== 0) {
1192
1193 peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t));
1194 if (peer == NULL((void*)0)) {
1195 return NGX_CONF_ERROR(void *) -1;
1196 }
1197
1198 if (ngx_syslog_process_conf(cf, peer) != NGX_CONF_OK((void*)0)) {
1199 return NGX_CONF_ERROR(void *) -1;
1200 }
1201
1202 log->syslog_peer = peer;
1203
1204 goto process_formats;
1205 }
1206
1207 n = ngx_http_script_variables_count(&value[1]);
1208
1209 if (n == 0) {
1210 log->file = ngx_conf_open_file(cf->cycle, &value[1]);
1211 if (log->file == NULL((void*)0)) {
1212 return NGX_CONF_ERROR(void *) -1;
1213 }
1214
1215 } else {
1216 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK0) {
1217 return NGX_CONF_ERROR(void *) -1;
1218 }
1219
1220 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
1221 if (log->script == NULL((void*)0)) {
1222 return NGX_CONF_ERROR(void *) -1;
1223 }
1224
1225 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t))(void) memset(&sc, 0, sizeof(ngx_http_script_compile_t));
1226
1227 sc.cf = cf;
1228 sc.source = &value[1];
1229 sc.lengths = &log->script->lengths;
1230 sc.values = &log->script->values;
1231 sc.variables = n;
1232 sc.complete_lengths = 1;
1233 sc.complete_values = 1;
1234
1235 if (ngx_http_script_compile(&sc) != NGX_OK0) {
1236 return NGX_CONF_ERROR(void *) -1;
1237 }
1238 }
1239
1240process_formats:
1241
1242 if (cf->args->nelts >= 3) {
1243 name = value[2];
1244
1245 if (ngx_strcmp(name.data, "combined")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) name.data) && __builtin_constant_p (
(const char *) "combined") && (__s1_len = strlen ((const
char *) name.data), __s2_len = strlen ((const char *) "combined"
), (!((size_t)(const void *)(((const char *) name.data) + 1) -
(size_t)(const void *)((const char *) name.data) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)(((const char *
) "combined") + 1) - (size_t)(const void *)((const char *) "combined"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const char
*) name.data, (const char *) "combined") : (__builtin_constant_p
((const char *) name.data) && ((size_t)(const void *
)(((const char *) name.data) + 1) - (size_t)(const void *)((const
char *) name.data) == 1) && (__s1_len = strlen ((const
char *) name.data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "combined") && ((size_t)(const void *
)(((const char *) "combined") + 1) - (size_t)(const void *)((
const char *) "combined") == 1) ? __builtin_strcmp ((const char
*) name.data, (const char *) "combined") : (__extension__ ({
const unsigned char *__s2 = (const unsigned char *) (const char
*) ((const char *) "combined"); int __result = (((const unsigned
char *) (const char *) ((const char *) name.data))[0] - __s2
[0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) name
.data))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) name.data))[2] - __s2[2]); if (__s1_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) ((const char *) name.data))[3] - __s2[3]); }
} __result; }))) : (__builtin_constant_p ((const char *) "combined"
) && ((size_t)(const void *)(((const char *) "combined"
) + 1) - (size_t)(const void *)((const char *) "combined") ==
1) && (__s2_len = strlen ((const char *) "combined")
, __s2_len < 4) ? (__builtin_constant_p ((const char *) name
.data) && ((size_t)(const void *)(((const char *) name
.data) + 1) - (size_t)(const void *)((const char *) name.data
) == 1) ? __builtin_strcmp ((const char *) name.data, (const char
*) "combined") : (- (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) name
.data); int __result = (((const unsigned char *) (const char *
) ((const char *) "combined"))[0] - __s2[0]); if (__s2_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) "combined"))[1] - __s2[1])
; if (__s2_len > 1 && __result == 0) { __result = (
((const unsigned char *) (const char *) ((const char *) "combined"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ((const
char *) "combined"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
((const char *) name.data, (const char *) "combined")))); })
== 0) {
1246 lmcf->combined_used = 1;
1247 }
1248
1249 } else {
1250 ngx_str_set(&name, "combined")(&name)->len = sizeof("combined") - 1; (&name)->
data = (u_char *) "combined"
;
1251 lmcf->combined_used = 1;
1252 }
1253
1254 fmt = lmcf->formats.elts;
1255 for (i = 0; i < lmcf->formats.nelts; i++) {
1256 if (fmt[i].name.len == name.len
1257 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
1258 {
1259 log->format = &fmt[i];
1260 break;
1261 }
1262 }
1263
1264 if (log->format == NULL((void*)0)) {
1265 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1266 "unknown log format \"%V\"", &name);
1267 return NGX_CONF_ERROR(void *) -1;
1268 }
1269
1270 size = 0;
1271 flush = 0;
1272 gzip = 0;
1273
1274 for (i = 3; i < cf->args->nelts; i++) {
1275
1276 if (ngx_strncmp(value[i].data, "buffer=", 7)(__extension__ (__builtin_constant_p (7) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (7))) || (__builtin_constant_p
((const char *) "buffer=") && strlen ((const char *)
"buffer=") < ((size_t) (7)))) ? __extension__ ({ size_t __s1_len
, __s2_len; (__builtin_constant_p ((const char *) value[i].data
) && __builtin_constant_p ((const char *) "buffer=") &&
(__s1_len = strlen ((const char *) value[i].data), __s2_len =
strlen ((const char *) "buffer="), (!((size_t)(const void *)
(((const char *) value[i].data) + 1) - (size_t)(const void *)
((const char *) value[i].data) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)(((const char *) "buffer=") + 1) - (
size_t)(const void *)((const char *) "buffer=") == 1) || __s2_len
>= 4)) ? __builtin_strcmp ((const char *) value[i].data, (
const char *) "buffer=") : (__builtin_constant_p ((const char
*) value[i].data) && ((size_t)(const void *)(((const
char *) value[i].data) + 1) - (size_t)(const void *)((const char
*) value[i].data) == 1) && (__s1_len = strlen ((const
char *) value[i].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "buffer=") && ((size_t)(const void *
)(((const char *) "buffer=") + 1) - (size_t)(const void *)((const
char *) "buffer=") == 1) ? __builtin_strcmp ((const char *) value
[i].data, (const char *) "buffer=") : (__extension__ ({ const
unsigned char *__s2 = (const unsigned char *) (const char *)
((const char *) "buffer="); int __result = (((const unsigned
char *) (const char *) ((const char *) value[i].data))[0] - __s2
[0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) value[i].data))[2] - __s2[2]); if (__s1_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) ((const char *) value[i].data))[3] - __s2[
3]); } } __result; }))) : (__builtin_constant_p ((const char *
) "buffer=") && ((size_t)(const void *)(((const char *
) "buffer=") + 1) - (size_t)(const void *)((const char *) "buffer="
) == 1) && (__s2_len = strlen ((const char *) "buffer="
), __s2_len < 4) ? (__builtin_constant_p ((const char *) value
[i].data) && ((size_t)(const void *)(((const char *) value
[i].data) + 1) - (size_t)(const void *)((const char *) value[
i].data) == 1) ? __builtin_strcmp ((const char *) value[i].data
, (const char *) "buffer=") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ((const char
*) value[i].data); int __result = (((const unsigned char *) (
const char *) ((const char *) "buffer="))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ((const char *) "buffer="))[
1] - __s2[1]); if (__s2_len > 1 && __result == 0) {
__result = (((const unsigned char *) (const char *) ((const char
*) "buffer="))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "buffer="))[3] - __s2[3]); } } __result; }
)))) : __builtin_strcmp ((const char *) value[i].data, (const
char *) "buffer=")))); }) : strncmp ((const char *) value[i]
.data, (const char *) "buffer=", 7)))
== 0) {
1277 s.len = value[i].len - 7;
1278 s.data = value[i].data + 7;
1279
1280 size = ngx_parse_size(&s);
1281
1282 if (size == NGX_ERROR-1 || size == 0) {
1283 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1284 "invalid buffer size \"%V\"", &s);
1285 return NGX_CONF_ERROR(void *) -1;
1286 }
1287
1288 continue;
1289 }
1290
1291 if (ngx_strncmp(value[i].data, "flush=", 6)(__extension__ (__builtin_constant_p (6) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (6))) || (__builtin_constant_p
((const char *) "flush=") && strlen ((const char *) "flush="
) < ((size_t) (6)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p ((const char *) value[i].data) &&
__builtin_constant_p ((const char *) "flush=") && (__s1_len
= strlen ((const char *) value[i].data), __s2_len = strlen (
(const char *) "flush="), (!((size_t)(const void *)(((const char
*) value[i].data) + 1) - (size_t)(const void *)((const char *
) value[i].data) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(((const char *) "flush=") + 1) - (size_t)(const
void *)((const char *) "flush=") == 1) || __s2_len >= 4))
? __builtin_strcmp ((const char *) value[i].data, (const char
*) "flush=") : (__builtin_constant_p ((const char *) value[i
].data) && ((size_t)(const void *)(((const char *) value
[i].data) + 1) - (size_t)(const void *)((const char *) value[
i].data) == 1) && (__s1_len = strlen ((const char *) value
[i].data), __s1_len < 4) ? (__builtin_constant_p ((const char
*) "flush=") && ((size_t)(const void *)(((const char
*) "flush=") + 1) - (size_t)(const void *)((const char *) "flush="
) == 1) ? __builtin_strcmp ((const char *) value[i].data, (const
char *) "flush=") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) "flush="
); int __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) value[i].data))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "flush=") &&
((size_t)(const void *)(((const char *) "flush=") + 1) - (size_t
)(const void *)((const char *) "flush=") == 1) && (__s2_len
= strlen ((const char *) "flush="), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "flush=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "flush="))[0
] - __s2[0]); if (__s2_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) ((const char
*) "flush="))[1] - __s2[1]); if (__s2_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) "flush="))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "flush="))[3] - __s2[3]); } } __result; }
)))) : __builtin_strcmp ((const char *) value[i].data, (const
char *) "flush=")))); }) : strncmp ((const char *) value[i].
data, (const char *) "flush=", 6)))
== 0) {
1292 s.len = value[i].len - 6;
1293 s.data = value[i].data + 6;
1294
1295 flush = ngx_parse_time(&s, 0);
1296
1297 if (flush == (ngx_msec_t) NGX_ERROR-1 || flush == 0) {
1298 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1299 "invalid flush time \"%V\"", &s);
1300 return NGX_CONF_ERROR(void *) -1;
1301 }
1302
1303 continue;
1304 }
1305
1306 if (ngx_strncmp(value[i].data, "gzip", 4)(__extension__ (__builtin_constant_p (4) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (4))) || (__builtin_constant_p
((const char *) "gzip") && strlen ((const char *) "gzip"
) < ((size_t) (4)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p ((const char *) value[i].data) &&
__builtin_constant_p ((const char *) "gzip") && (__s1_len
= strlen ((const char *) value[i].data), __s2_len = strlen (
(const char *) "gzip"), (!((size_t)(const void *)(((const char
*) value[i].data) + 1) - (size_t)(const void *)((const char *
) value[i].data) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(((const char *) "gzip") + 1) - (size_t)(const
void *)((const char *) "gzip") == 1) || __s2_len >= 4)) ?
__builtin_strcmp ((const char *) value[i].data, (const char *
) "gzip") : (__builtin_constant_p ((const char *) value[i].data
) && ((size_t)(const void *)(((const char *) value[i]
.data) + 1) - (size_t)(const void *)((const char *) value[i].
data) == 1) && (__s1_len = strlen ((const char *) value
[i].data), __s1_len < 4) ? (__builtin_constant_p ((const char
*) "gzip") && ((size_t)(const void *)(((const char *
) "gzip") + 1) - (size_t)(const void *)((const char *) "gzip"
) == 1) ? __builtin_strcmp ((const char *) value[i].data, (const
char *) "gzip") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) "gzip"
); int __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) value[i].data))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "gzip") &&
((size_t)(const void *)(((const char *) "gzip") + 1) - (size_t
)(const void *)((const char *) "gzip") == 1) && (__s2_len
= strlen ((const char *) "gzip"), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "gzip") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "gzip"))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) "gzip"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "gzip"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "gzip"))[3] - __s2[3]); } } __result; }))
)) : __builtin_strcmp ((const char *) value[i].data, (const char
*) "gzip")))); }) : strncmp ((const char *) value[i].data, (
const char *) "gzip", 4)))
== 0
1307 && (value[i].len == 4 || value[i].data[4] == '='))
1308 {
1309#if (NGX_ZLIB1)
1310 if (size == 0) {
1311 size = 64 * 1024;
1312 }
1313
1314 if (value[i].len == 4) {
1315 gzip = Z_BEST_SPEED1;
1316 continue;
1317 }
1318
1319 s.len = value[i].len - 5;
1320 s.data = value[i].data + 5;
1321
1322 gzip = ngx_atoi(s.data, s.len);
1323
1324 if (gzip < 1 || gzip > 9) {
1325 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1326 "invalid compression level \"%V\"", &s);
1327 return NGX_CONF_ERROR(void *) -1;
1328 }
1329
1330 continue;
1331
1332#else
1333 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1334 "nginx was built without zlib support");
1335 return NGX_CONF_ERROR(void *) -1;
1336#endif
1337 }
1338
1339 if (ngx_strncmp(value[i].data, "if=", 3)(__extension__ (__builtin_constant_p (3) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (3))) || (__builtin_constant_p
((const char *) "if=") && strlen ((const char *) "if="
) < ((size_t) (3)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p ((const char *) value[i].data) &&
__builtin_constant_p ((const char *) "if=") && (__s1_len
= strlen ((const char *) value[i].data), __s2_len = strlen (
(const char *) "if="), (!((size_t)(const void *)(((const char
*) value[i].data) + 1) - (size_t)(const void *)((const char *
) value[i].data) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(((const char *) "if=") + 1) - (size_t)(const void
*)((const char *) "if=") == 1) || __s2_len >= 4)) ? __builtin_strcmp
((const char *) value[i].data, (const char *) "if=") : (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) && (__s1_len =
strlen ((const char *) value[i].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "if=") && ((size_t)(const void *)(((
const char *) "if=") + 1) - (size_t)(const void *)((const char
*) "if=") == 1) ? __builtin_strcmp ((const char *) value[i].
data, (const char *) "if=") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ((const char
*) "if="); int __result = (((const unsigned char *) (const char
*) ((const char *) value[i].data))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ((const char *) value[i].data))[1] - __s2
[1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "if=") && (
(size_t)(const void *)(((const char *) "if=") + 1) - (size_t)
(const void *)((const char *) "if=") == 1) && (__s2_len
= strlen ((const char *) "if="), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "if=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "if="))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) "if="
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "if="))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "if="))[3] - __s2[3]); } } __result; })))
) : __builtin_strcmp ((const char *) value[i].data, (const char
*) "if=")))); }) : strncmp ((const char *) value[i].data, (const
char *) "if=", 3)))
== 0) {
1340 s.len = value[i].len - 3;
1341 s.data = value[i].data + 3;
1342
1343 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t))(void) memset(&ccv, 0, sizeof(ngx_http_compile_complex_value_t
))
;
1344
1345 ccv.cf = cf;
1346 ccv.value = &s;
1347 ccv.complex_value = ngx_palloc(cf->pool,
1348 sizeof(ngx_http_complex_value_t));
1349 if (ccv.complex_value == NULL((void*)0)) {
1350 return NGX_CONF_ERROR(void *) -1;
1351 }
1352
1353 if (ngx_http_compile_complex_value(&ccv) != NGX_OK0) {
1354 return NGX_CONF_ERROR(void *) -1;
1355 }
1356
1357 log->filter = ccv.complex_value;
1358
1359 continue;
1360 }
1361
1362 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1363 "invalid parameter \"%V\"", &value[i]);
1364 return NGX_CONF_ERROR(void *) -1;
1365 }
1366
1367 if (flush && size == 0) {
1368 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1369 "no buffer is defined for access_log \"%V\"",
1370 &value[1]);
1371 return NGX_CONF_ERROR(void *) -1;
1372 }
1373
1374 if (size) {
1375
1376 if (log->script) {
1377 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1378 "buffered logs cannot have variables in name");
1379 return NGX_CONF_ERROR(void *) -1;
1380 }
1381
1382 if (log->syslog_peer) {
1383 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1384 "logs to syslog cannot be buffered");
1385 return NGX_CONF_ERROR(void *) -1;
1386 }
1387
1388 if (log->file->data) {
1389 buffer = log->file->data;
1390
1391 if (buffer->last - buffer->start != size
1392 || buffer->flush != flush
1393 || buffer->gzip != gzip)
1394 {
1395 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1396 "access_log \"%V\" already defined "
1397 "with conflicting parameters",
1398 &value[1]);
1399 return NGX_CONF_ERROR(void *) -1;
1400 }
1401
1402 return NGX_CONF_OK((void*)0);
1403 }
1404
1405 buffer = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_buf_t));
1406 if (buffer == NULL((void*)0)) {
1407 return NGX_CONF_ERROR(void *) -1;
1408 }
1409
1410 buffer->start = ngx_pnalloc(cf->pool, size);
1411 if (buffer->start == NULL((void*)0)) {
1412 return NGX_CONF_ERROR(void *) -1;
1413 }
1414
1415 buffer->pos = buffer->start;
1416 buffer->last = buffer->start + size;
1417
1418 if (flush) {
1419 buffer->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t));
1420 if (buffer->event == NULL((void*)0)) {
1421 return NGX_CONF_ERROR(void *) -1;
1422 }
1423
1424 buffer->event->data = log->file;
1425 buffer->event->handler = ngx_http_log_flush_handler;
1426 buffer->event->log = &cf->cycle->new_log;
1427 buffer->event->cancelable = 1;
1428
1429 buffer->flush = flush;
1430 }
1431
1432 buffer->gzip = gzip;
1433
1434 log->file->flush = ngx_http_log_flush;
1435 log->file->data = buffer;
1436 }
1437
1438 return NGX_CONF_OK((void*)0);
1439}
1440
1441
1442static char *
1443ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1444{
1445 ngx_http_log_main_conf_t *lmcf = conf;
1446
1447 ngx_str_t *value;
1448 ngx_uint_t i;
1449 ngx_http_log_fmt_t *fmt;
1450
1451 value = cf->args->elts;
1452
1453 fmt = lmcf->formats.elts;
1454 for (i = 0; i < lmcf->formats.nelts; i++) {
1455 if (fmt[i].name.len == value[1].len
1456 && ngx_strcmp(fmt[i].name.data, value[1].data)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) fmt[i].name.data) && __builtin_constant_p
((const char *) value[1].data) && (__s1_len = strlen
((const char *) fmt[i].name.data), __s2_len = strlen ((const
char *) value[1].data), (!((size_t)(const void *)(((const char
*) fmt[i].name.data) + 1) - (size_t)(const void *)((const char
*) fmt[i].name.data) == 1) || __s1_len >= 4) && (
!((size_t)(const void *)(((const char *) value[1].data) + 1) -
(size_t)(const void *)((const char *) value[1].data) == 1) ||
__s2_len >= 4)) ? __builtin_strcmp ((const char *) fmt[i]
.name.data, (const char *) value[1].data) : (__builtin_constant_p
((const char *) fmt[i].name.data) && ((size_t)(const
void *)(((const char *) fmt[i].name.data) + 1) - (size_t)(const
void *)((const char *) fmt[i].name.data) == 1) && (__s1_len
= strlen ((const char *) fmt[i].name.data), __s1_len < 4)
? (__builtin_constant_p ((const char *) value[1].data) &&
((size_t)(const void *)(((const char *) value[1].data) + 1) -
(size_t)(const void *)((const char *) value[1].data) == 1) ?
__builtin_strcmp ((const char *) fmt[i].name.data, (const char
*) value[1].data) : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) value
[1].data); int __result = (((const unsigned char *) (const char
*) ((const char *) fmt[i].name.data))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ((const char *) fmt[i].name.data))[1]
- __s2[1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) fmt
[i].name.data))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) fmt[i].name.data))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p ((const char *) value[1].data)
&& ((size_t)(const void *)(((const char *) value[1].
data) + 1) - (size_t)(const void *)((const char *) value[1].data
) == 1) && (__s2_len = strlen ((const char *) value[1
].data), __s2_len < 4) ? (__builtin_constant_p ((const char
*) fmt[i].name.data) && ((size_t)(const void *)(((const
char *) fmt[i].name.data) + 1) - (size_t)(const void *)((const
char *) fmt[i].name.data) == 1) ? __builtin_strcmp ((const char
*) fmt[i].name.data, (const char *) value[1].data) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) fmt[i].name.data); int __result = ((
(const unsigned char *) (const char *) ((const char *) value[
1].data))[0] - __s2[0]); if (__s2_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) value[1].data))[1] - __s2[1]); if (__s2_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) value[1].data))[2] - __s2[
2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) ((const char *) value
[1].data))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
((const char *) fmt[i].name.data, (const char *) value[1].data
)))); })
== 0)
1457 {
1458 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1459 "duplicate \"log_format\" name \"%V\"",
1460 &value[1]);
1461 return NGX_CONF_ERROR(void *) -1;
1462 }
1463 }
1464
1465 fmt = ngx_array_push(&lmcf->formats);
1466 if (fmt == NULL((void*)0)) {
1467 return NGX_CONF_ERROR(void *) -1;
1468 }
1469
1470 fmt->name = value[1];
1471
1472 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t));
1473 if (fmt->flushes == NULL((void*)0)) {
1474 return NGX_CONF_ERROR(void *) -1;
1475 }
1476
1477 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
1478 if (fmt->ops == NULL((void*)0)) {
1479 return NGX_CONF_ERROR(void *) -1;
1480 }
1481
1482 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2);
1483}
1484
1485
1486static char *
1487ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
1488 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s)
1489{
1490 u_char *data, *p, ch;
1491 size_t i, len;
1492 ngx_str_t *value, var;
1493 ngx_int_t *flush;
1494 ngx_uint_t bracket;
1495 ngx_http_log_op_t *op;
1496 ngx_http_log_var_t *v;
1497
1498 value = args->elts;
1499
1500 for ( /* void */ ; s < args->nelts; s++) {
1501
1502 i = 0;
1503
1504 while (i < value[s].len) {
1505
1506 op = ngx_array_push(ops);
1507 if (op == NULL((void*)0)) {
1508 return NGX_CONF_ERROR(void *) -1;
1509 }
1510
1511 data = &value[s].data[i];
1512
1513 if (value[s].data[i] == '$') {
1514
1515 if (++i == value[s].len) {
1516 goto invalid;
1517 }
1518
1519 if (value[s].data[i] == '{') {
1520 bracket = 1;
1521
1522 if (++i == value[s].len) {
1523 goto invalid;
1524 }
1525
1526 var.data = &value[s].data[i];
1527
1528 } else {
1529 bracket = 0;
1530 var.data = &value[s].data[i];
1531 }
1532
1533 for (var.len = 0; i < value[s].len; i++, var.len++) {
1534 ch = value[s].data[i];
1535
1536 if (ch == '}' && bracket) {
1537 i++;
1538 bracket = 0;
1539 break;
1540 }
1541
1542 if ((ch >= 'A' && ch <= 'Z')
1543 || (ch >= 'a' && ch <= 'z')
1544 || (ch >= '0' && ch <= '9')
1545 || ch == '_')
1546 {
1547 continue;
1548 }
1549
1550 break;
1551 }
1552
1553 if (bracket) {
1554 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1555 "the closing bracket in \"%V\" "
1556 "variable is missing", &var);
1557 return NGX_CONF_ERROR(void *) -1;
1558 }
1559
1560 if (var.len == 0) {
1561 goto invalid;
1562 }
1563
1564 for (v = ngx_http_log_vars; v->name.len; v++) {
1565
1566 if (v->name.len == var.len
1567 && ngx_strncmp(v->name.data, var.data, var.len)(__extension__ (__builtin_constant_p (var.len) && ((__builtin_constant_p
((const char *) v->name.data) && strlen ((const char
*) v->name.data) < ((size_t) (var.len))) || (__builtin_constant_p
((const char *) var.data) && strlen ((const char *) var
.data) < ((size_t) (var.len)))) ? __extension__ ({ size_t __s1_len
, __s2_len; (__builtin_constant_p ((const char *) v->name.
data) && __builtin_constant_p ((const char *) var.data
) && (__s1_len = strlen ((const char *) v->name.data
), __s2_len = strlen ((const char *) var.data), (!((size_t)(const
void *)(((const char *) v->name.data) + 1) - (size_t)(const
void *)((const char *) v->name.data) == 1) || __s1_len >=
4) && (!((size_t)(const void *)(((const char *) var.
data) + 1) - (size_t)(const void *)((const char *) var.data) ==
1) || __s2_len >= 4)) ? __builtin_strcmp ((const char *) v
->name.data, (const char *) var.data) : (__builtin_constant_p
((const char *) v->name.data) && ((size_t)(const void
*)(((const char *) v->name.data) + 1) - (size_t)(const void
*)((const char *) v->name.data) == 1) && (__s1_len
= strlen ((const char *) v->name.data), __s1_len < 4) ?
(__builtin_constant_p ((const char *) var.data) && (
(size_t)(const void *)(((const char *) var.data) + 1) - (size_t
)(const void *)((const char *) var.data) == 1) ? __builtin_strcmp
((const char *) v->name.data, (const char *) var.data) : (
__extension__ ({ const unsigned char *__s2 = (const unsigned char
*) (const char *) ((const char *) var.data); int __result = (
((const unsigned char *) (const char *) ((const char *) v->
name.data))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) v->name.data))[1] - __s2[1]); if (__s1_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) v->name.data))[2] - __s2
[2]); if (__s1_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) ((const char *) v->
name.data))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
((const char *) var.data) && ((size_t)(const void *)
(((const char *) var.data) + 1) - (size_t)(const void *)((const
char *) var.data) == 1) && (__s2_len = strlen ((const
char *) var.data), __s2_len < 4) ? (__builtin_constant_p (
(const char *) v->name.data) && ((size_t)(const void
*)(((const char *) v->name.data) + 1) - (size_t)(const void
*)((const char *) v->name.data) == 1) ? __builtin_strcmp (
(const char *) v->name.data, (const char *) var.data) : (-
(__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) ((const char *) v->name.data); int
__result = (((const unsigned char *) (const char *) ((const char
*) var.data))[0] - __s2[0]); if (__s2_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) var.data))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) var.data))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) var.data))[3] - __s2[
3]); } } __result; })))) : __builtin_strcmp ((const char *) v
->name.data, (const char *) var.data)))); }) : strncmp ((const
char *) v->name.data, (const char *) var.data, var.len)))
== 0)
1568 {
1569 op->len = v->len;
1570 op->getlen = NULL((void*)0);
1571 op->run = v->run;
1572 op->data = 0;
1573
1574 goto found;
1575 }
1576 }
1577
1578 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK0) {
1579 return NGX_CONF_ERROR(void *) -1;
1580 }
1581
1582 if (flushes) {
1583
1584 flush = ngx_array_push(flushes);
1585 if (flush == NULL((void*)0)) {
1586 return NGX_CONF_ERROR(void *) -1;
1587 }
1588
1589 *flush = op->data; /* variable index */
1590 }
1591
1592 found:
1593
1594 continue;
1595 }
1596
1597 i++;
1598
1599 while (i < value[s].len && value[s].data[i] != '$') {
1600 i++;
1601 }
1602
1603 len = &value[s].data[i] - data;
1604
1605 if (len) {
1606
1607 op->len = len;
1608 op->getlen = NULL((void*)0);
1609
1610 if (len <= sizeof(uintptr_t)) {
1611 op->run = ngx_http_log_copy_short;
1612 op->data = 0;
1613
1614 while (len--) {
1615 op->data <<= 8;
1616 op->data |= data[len];
1617 }
1618
1619 } else {
1620 op->run = ngx_http_log_copy_long;
1621
1622 p = ngx_pnalloc(cf->pool, len);
1623 if (p == NULL((void*)0)) {
1624 return NGX_CONF_ERROR(void *) -1;
1625 }
1626
1627 ngx_memcpy(p, data, len)(void) memcpy(p, data, len);
1628 op->data = (uintptr_t) p;
1629 }
1630 }
1631 }
1632 }
1633
1634 return NGX_CONF_OK((void*)0);
1635
1636invalid:
1637
1638 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0, "invalid parameter \"%s\"", data);
1639
1640 return NGX_CONF_ERROR(void *) -1;
1641}
1642
1643
1644static char *
1645ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1646{
1647 ngx_http_log_loc_conf_t *llcf = conf;
1648
1649 time_t inactive, valid;
1650 ngx_str_t *value, s;
1651 ngx_int_t max, min_uses;
1652 ngx_uint_t i;
1653
1654 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR(void *) -1) {
1655 return "is duplicate";
1656 }
1657
1658 value = cf->args->elts;
1659
1660 max = 0;
1661 inactive = 10;
1662 valid = 60;
1663 min_uses = 1;
1664
1665 for (i = 1; i < cf->args->nelts; i++) {
1666
1667 if (ngx_strncmp(value[i].data, "max=", 4)(__extension__ (__builtin_constant_p (4) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (4))) || (__builtin_constant_p
((const char *) "max=") && strlen ((const char *) "max="
) < ((size_t) (4)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p ((const char *) value[i].data) &&
__builtin_constant_p ((const char *) "max=") && (__s1_len
= strlen ((const char *) value[i].data), __s2_len = strlen (
(const char *) "max="), (!((size_t)(const void *)(((const char
*) value[i].data) + 1) - (size_t)(const void *)((const char *
) value[i].data) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(((const char *) "max=") + 1) - (size_t)(const
void *)((const char *) "max=") == 1) || __s2_len >= 4)) ?
__builtin_strcmp ((const char *) value[i].data, (const char *
) "max=") : (__builtin_constant_p ((const char *) value[i].data
) && ((size_t)(const void *)(((const char *) value[i]
.data) + 1) - (size_t)(const void *)((const char *) value[i].
data) == 1) && (__s1_len = strlen ((const char *) value
[i].data), __s1_len < 4) ? (__builtin_constant_p ((const char
*) "max=") && ((size_t)(const void *)(((const char *
) "max=") + 1) - (size_t)(const void *)((const char *) "max="
) == 1) ? __builtin_strcmp ((const char *) value[i].data, (const
char *) "max=") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) "max="
); int __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) value[i].data))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "max=") &&
((size_t)(const void *)(((const char *) "max=") + 1) - (size_t
)(const void *)((const char *) "max=") == 1) && (__s2_len
= strlen ((const char *) "max="), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "max=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "max="))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) "max="
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "max="))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "max="))[3] - __s2[3]); } } __result; }))
)) : __builtin_strcmp ((const char *) value[i].data, (const char
*) "max=")))); }) : strncmp ((const char *) value[i].data, (
const char *) "max=", 4)))
== 0) {
1668
1669 max = ngx_atoi(value[i].data + 4, value[i].len - 4);
1670 if (max == NGX_ERROR-1) {
1671 goto failed;
1672 }
1673
1674 continue;
1675 }
1676
1677 if (ngx_strncmp(value[i].data, "inactive=", 9)(__extension__ (__builtin_constant_p (9) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (9))) || (__builtin_constant_p
((const char *) "inactive=") && strlen ((const char *
) "inactive=") < ((size_t) (9)))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p ((const char *) value
[i].data) && __builtin_constant_p ((const char *) "inactive="
) && (__s1_len = strlen ((const char *) value[i].data
), __s2_len = strlen ((const char *) "inactive="), (!((size_t
)(const void *)(((const char *) value[i].data) + 1) - (size_t
)(const void *)((const char *) value[i].data) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)(((const char *
) "inactive=") + 1) - (size_t)(const void *)((const char *) "inactive="
) == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const char
*) value[i].data, (const char *) "inactive=") : (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) && (__s1_len =
strlen ((const char *) value[i].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "inactive=") && ((size_t)(const void
*)(((const char *) "inactive=") + 1) - (size_t)(const void *
)((const char *) "inactive=") == 1) ? __builtin_strcmp ((const
char *) value[i].data, (const char *) "inactive=") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) "inactive="); int __result = (((const
unsigned char *) (const char *) ((const char *) value[i].data
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) value[i].data))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) value[i].data))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) value[i].data))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p ((const char
*) "inactive=") && ((size_t)(const void *)(((const char
*) "inactive=") + 1) - (size_t)(const void *)((const char *)
"inactive=") == 1) && (__s2_len = strlen ((const char
*) "inactive="), __s2_len < 4) ? (__builtin_constant_p ((
const char *) value[i].data) && ((size_t)(const void *
)(((const char *) value[i].data) + 1) - (size_t)(const void *
)((const char *) value[i].data) == 1) ? __builtin_strcmp ((const
char *) value[i].data, (const char *) "inactive=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "inactive=")
)[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "inactive="))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) "inactive="))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) "inactive="))[3] - __s2
[3]); } } __result; })))) : __builtin_strcmp ((const char *) value
[i].data, (const char *) "inactive=")))); }) : strncmp ((const
char *) value[i].data, (const char *) "inactive=", 9)))
== 0) {
1678
1679 s.len = value[i].len - 9;
1680 s.data = value[i].data + 9;
1681
1682 inactive = ngx_parse_time(&s, 1);
1683 if (inactive == (time_t) NGX_ERROR-1) {
1684 goto failed;
1685 }
1686
1687 continue;
1688 }
1689
1690 if (ngx_strncmp(value[i].data, "min_uses=", 9)(__extension__ (__builtin_constant_p (9) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (9))) || (__builtin_constant_p
((const char *) "min_uses=") && strlen ((const char *
) "min_uses=") < ((size_t) (9)))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p ((const char *) value
[i].data) && __builtin_constant_p ((const char *) "min_uses="
) && (__s1_len = strlen ((const char *) value[i].data
), __s2_len = strlen ((const char *) "min_uses="), (!((size_t
)(const void *)(((const char *) value[i].data) + 1) - (size_t
)(const void *)((const char *) value[i].data) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)(((const char *
) "min_uses=") + 1) - (size_t)(const void *)((const char *) "min_uses="
) == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const char
*) value[i].data, (const char *) "min_uses=") : (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) && (__s1_len =
strlen ((const char *) value[i].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "min_uses=") && ((size_t)(const void
*)(((const char *) "min_uses=") + 1) - (size_t)(const void *
)((const char *) "min_uses=") == 1) ? __builtin_strcmp ((const
char *) value[i].data, (const char *) "min_uses=") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) "min_uses="); int __result = (((const
unsigned char *) (const char *) ((const char *) value[i].data
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) value[i].data))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) value[i].data))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) value[i].data))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p ((const char
*) "min_uses=") && ((size_t)(const void *)(((const char
*) "min_uses=") + 1) - (size_t)(const void *)((const char *)
"min_uses=") == 1) && (__s2_len = strlen ((const char
*) "min_uses="), __s2_len < 4) ? (__builtin_constant_p ((
const char *) value[i].data) && ((size_t)(const void *
)(((const char *) value[i].data) + 1) - (size_t)(const void *
)((const char *) value[i].data) == 1) ? __builtin_strcmp ((const
char *) value[i].data, (const char *) "min_uses=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "min_uses=")
)[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "min_uses="))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ((const char *) "min_uses="))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ((const char *) "min_uses="))[3] - __s2
[3]); } } __result; })))) : __builtin_strcmp ((const char *) value
[i].data, (const char *) "min_uses=")))); }) : strncmp ((const
char *) value[i].data, (const char *) "min_uses=", 9)))
== 0) {
1691
1692 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9);
1693 if (min_uses == NGX_ERROR-1) {
1694 goto failed;
1695 }
1696
1697 continue;
1698 }
1699
1700 if (ngx_strncmp(value[i].data, "valid=", 6)(__extension__ (__builtin_constant_p (6) && ((__builtin_constant_p
((const char *) value[i].data) && strlen ((const char
*) value[i].data) < ((size_t) (6))) || (__builtin_constant_p
((const char *) "valid=") && strlen ((const char *) "valid="
) < ((size_t) (6)))) ? __extension__ ({ size_t __s1_len, __s2_len
; (__builtin_constant_p ((const char *) value[i].data) &&
__builtin_constant_p ((const char *) "valid=") && (__s1_len
= strlen ((const char *) value[i].data), __s2_len = strlen (
(const char *) "valid="), (!((size_t)(const void *)(((const char
*) value[i].data) + 1) - (size_t)(const void *)((const char *
) value[i].data) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)(((const char *) "valid=") + 1) - (size_t)(const
void *)((const char *) "valid=") == 1) || __s2_len >= 4))
? __builtin_strcmp ((const char *) value[i].data, (const char
*) "valid=") : (__builtin_constant_p ((const char *) value[i
].data) && ((size_t)(const void *)(((const char *) value
[i].data) + 1) - (size_t)(const void *)((const char *) value[
i].data) == 1) && (__s1_len = strlen ((const char *) value
[i].data), __s1_len < 4) ? (__builtin_constant_p ((const char
*) "valid=") && ((size_t)(const void *)(((const char
*) "valid=") + 1) - (size_t)(const void *)((const char *) "valid="
) == 1) ? __builtin_strcmp ((const char *) value[i].data, (const
char *) "valid=") : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) ((const char *) "valid="
); int __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ((const char *) value[i].data))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "valid=") &&
((size_t)(const void *)(((const char *) "valid=") + 1) - (size_t
)(const void *)((const char *) "valid=") == 1) && (__s2_len
= strlen ((const char *) "valid="), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "valid=") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "valid="))[0
] - __s2[0]); if (__s2_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) ((const char
*) "valid="))[1] - __s2[1]); if (__s2_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
(const char *) "valid="))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "valid="))[3] - __s2[3]); } } __result; }
)))) : __builtin_strcmp ((const char *) value[i].data, (const
char *) "valid=")))); }) : strncmp ((const char *) value[i].
data, (const char *) "valid=", 6)))
== 0) {
1701
1702 s.len = value[i].len - 6;
1703 s.data = value[i].data + 6;
1704
1705 valid = ngx_parse_time(&s, 1);
1706 if (valid == (time_t) NGX_ERROR-1) {
1707 goto failed;
1708 }
1709
1710 continue;
1711 }
1712
1713 if (ngx_strcmp(value[i].data, "off")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
((const char *) value[i].data) && __builtin_constant_p
((const char *) "off") && (__s1_len = strlen ((const
char *) value[i].data), __s2_len = strlen ((const char *) "off"
), (!((size_t)(const void *)(((const char *) value[i].data) +
1) - (size_t)(const void *)((const char *) value[i].data) ==
1) || __s1_len >= 4) && (!((size_t)(const void *)
(((const char *) "off") + 1) - (size_t)(const void *)((const char
*) "off") == 1) || __s2_len >= 4)) ? __builtin_strcmp ((const
char *) value[i].data, (const char *) "off") : (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) && (__s1_len =
strlen ((const char *) value[i].data), __s1_len < 4) ? (__builtin_constant_p
((const char *) "off") && ((size_t)(const void *)(((
const char *) "off") + 1) - (size_t)(const void *)((const char
*) "off") == 1) ? __builtin_strcmp ((const char *) value[i].
data, (const char *) "off") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ((const char
*) "off"); int __result = (((const unsigned char *) (const char
*) ((const char *) value[i].data))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ((const char *) value[i].data))[1] - __s2
[1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) value
[i].data))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) ((
const char *) value[i].data))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p ((const char *) "off") && (
(size_t)(const void *)(((const char *) "off") + 1) - (size_t)
(const void *)((const char *) "off") == 1) && (__s2_len
= strlen ((const char *) "off"), __s2_len < 4) ? (__builtin_constant_p
((const char *) value[i].data) && ((size_t)(const void
*)(((const char *) value[i].data) + 1) - (size_t)(const void
*)((const char *) value[i].data) == 1) ? __builtin_strcmp ((
const char *) value[i].data, (const char *) "off") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ((const char *) value[i].data); int __result = (((const
unsigned char *) (const char *) ((const char *) "off"))[0] -
__s2[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ((const char *) "off"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ((const
char *) "off"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ((const char *) "off"))[3] - __s2[3]); } } __result; })))
) : __builtin_strcmp ((const char *) value[i].data, (const char
*) "off")))); })
== 0) {
1714
1715 llcf->open_file_cache = NULL((void*)0);
1716
1717 continue;
1718 }
1719
1720 failed:
1721
1722 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1723 "invalid \"open_log_file_cache\" parameter \"%V\"",
1724 &value[i]);
1725 return NGX_CONF_ERROR(void *) -1;
1726 }
1727
1728 if (llcf->open_file_cache == NULL((void*)0)) {
1729 return NGX_CONF_OK((void*)0);
1730 }
1731
1732 if (max == 0) {
1733 ngx_conf_log_error(NGX_LOG_EMERG1, cf, 0,
1734 "\"open_log_file_cache\" must have \"max\" parameter");
1735 return NGX_CONF_ERROR(void *) -1;
1736 }
1737
1738 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);
1739
1740 if (llcf->open_file_cache) {
1741
1742 llcf->open_file_cache_valid = valid;
1743 llcf->open_file_cache_min_uses = min_uses;
1744
1745 return NGX_CONF_OK((void*)0);
1746 }
1747
1748 return NGX_CONF_ERROR(void *) -1;
1749}
1750
1751
1752static ngx_int_t
1753ngx_http_log_init(ngx_conf_t *cf)
1754{
1755 ngx_str_t *value;
1756 ngx_array_t a;
1757 ngx_http_handler_pt *h;
1758 ngx_http_log_fmt_t *fmt;
1759 ngx_http_log_main_conf_t *lmcf;
1760 ngx_http_core_main_conf_t *cmcf;
1761
1762 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module)((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[ngx_http_log_module
.ctx_index]
;
1763
1764 if (lmcf->combined_used) {
1765 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK0) {
1766 return NGX_ERROR-1;
1767 }
1768
1769 value = ngx_array_push(&a);
1770 if (value == NULL((void*)0)) {
1771 return NGX_ERROR-1;
1772 }
1773
1774 *value = ngx_http_combined_fmt;
1775 fmt = lmcf->formats.elts;
1776
1777 if (ngx_http_log_compile_format(cf, NULL((void*)0), fmt->ops, &a, 0)
1778 != NGX_CONF_OK((void*)0))
1779 {
1780 return NGX_ERROR-1;
1781 }
1782 }
1783
1784 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module)((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[ngx_http_core_module
.ctx_index]
;
1785
1786 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers);
1787 if (h == NULL((void*)0)) {
1788 return NGX_ERROR-1;
1789 }
1790
1791 *h = ngx_http_log_handler;
1792
1793 return NGX_OK0;
1794}