62
ngx_conf_param(ngx_conf_t *cf)
67
ngx_conf_file_t conf_file;
69
param = &cf->cycle->conf_param;
71
if (param->len == 0) {
75
ngx_memzero(&conf_file, sizeof(ngx_conf_file_t));
77
ngx_memzero(&b, sizeof(ngx_buf_t));
79
b.start = param->data;
81
b.last = param->data + param->len;
85
conf_file.file.fd = NGX_INVALID_FILE;
86
conf_file.file.name.data = NULL;
89
cf->conf_file = &conf_file;
90
cf->conf_file->buffer = &b;
92
rv = ngx_conf_parse(cf, NULL);
61
101
ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
68
ngx_conf_file_t *prev;
107
ngx_conf_file_t *prev, conf_file;
70
114
#if (NGX_SUPPRESS_WARN)
71
115
fd = NGX_INVALID_FILE;
87
131
prev = cf->conf_file;
89
cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t));
90
if (cf->conf_file == NULL) {
91
return NGX_CONF_ERROR;
133
cf->conf_file = &conf_file;
94
135
if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
95
136
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
96
137
ngx_fd_info_n " \"%s\" failed", filename->data);
99
b = ngx_calloc_buf(cf->pool);
101
return NGX_CONF_ERROR;
104
cf->conf_file->buffer = b;
106
b->start = ngx_alloc(ngx_pagesize, cf->log);
107
if (b->start == NULL) {
108
return NGX_CONF_ERROR;
113
b->end = b->last + ngx_pagesize;
140
cf->conf_file->buffer = &buf;
142
buf.start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
143
if (buf.start == NULL) {
148
buf.last = buf.start;
149
buf.end = buf.last + NGX_CONF_BUFFER;
116
152
cf->conf_file->file.fd = fd;
117
153
cf->conf_file->file.name.len = filename->len;
147
187
if (rc == NGX_CONF_BLOCK_DONE) {
189
if (type != parse_block) {
149
190
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\"");
156
if (rc == NGX_CONF_FILE_DONE && block) {
157
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
158
"unexpected end of file, expecting \"}\"");
162
if (rc != NGX_OK && rc != NGX_CONF_BLOCK_START) {
197
if (rc == NGX_CONF_FILE_DONE) {
199
if (type == parse_block) {
200
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
201
"unexpected end of file, expecting \"}\"");
208
if (rc == NGX_CONF_BLOCK_START) {
210
if (type == parse_param) {
211
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
212
"block directives are not supported "
218
/* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */
166
220
if (cf->handler) {
202
ngx_free(cf->conf_file->buffer->start);
204
cf->conf_file = prev;
256
if (cf->conf_file->buffer->start) {
257
ngx_free(cf->conf_file->buffer->start);
206
260
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
207
261
ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
377
433
ngx_conf_read_token(ngx_conf_t *cf)
379
435
u_char *start, ch, *src, *dst;
381
int found, need_space, last_space, sharp_comment, variable;
382
int quoted, s_quoted, d_quoted;
439
ngx_uint_t found, need_space, last_space, sharp_comment, variable;
440
ngx_uint_t quoted, s_quoted, d_quoted, start_line;
390
447
sharp_comment = 0;
392
quoted = s_quoted = d_quoted = 0;
394
453
cf->args->nelts = 0;
395
454
b = cf->conf_file->buffer;
456
start_line = cf->conf_file->line;
458
file_size = ngx_file_size(&cf->conf_file->file.info);
400
462
if (b->pos >= b->last) {
401
if (cf->conf_file->file.offset
402
>= ngx_file_size(&cf->conf_file->file.info))
464
if (cf->conf_file->file.offset >= file_size) {
404
466
if (cf->args->nelts > 0) {
468
if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
469
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
470
"unexpected end of parameter, "
405
475
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
406
476
"unexpected end of file, "
407
477
"expecting \";\" or \"}\"");
411
481
return NGX_CONF_FILE_DONE;
414
if (b->pos - start) {
415
ngx_memcpy(b->start, start, b->pos - start);
418
n = ngx_read_file(&cf->conf_file->file,
419
b->start + (b->pos - start),
420
b->end - (b->start + (b->pos - start)),
484
len = b->pos - start;
486
if (len == NGX_CONF_BUFFER) {
487
cf->conf_file->line = start_line;
492
} else if (s_quoted) {
496
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
497
"too long parameter \"%*s...\" started",
502
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
503
"too long parameter, probably "
504
"missing terminating \"%c\" character", ch);
509
ngx_memcpy(b->start, start, len);
512
size = (ssize_t) (file_size - cf->conf_file->file.offset);
514
if (size > b->end - (b->start + len)) {
515
size = b->end - (b->start + len);
518
n = ngx_read_file(&cf->conf_file->file, b->start + len, size,
421
519
cf->conf_file->file.offset);
423
521
if (n == NGX_ERROR) {
424
522
return NGX_ERROR;
427
b->pos = b->start + (b->pos - start);
526
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
527
ngx_read_file_n " returned "
528
"only %z bytes instead of %z",
533
b->pos = b->start + len;
534
b->last = b->pos + n;
428
535
start = b->start;
429
b->last = b->pos + n;
642
749
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
644
if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR) {
751
if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) {
645
752
return NGX_CONF_ERROR;
820
if (name->data[0] == '/') {
719
828
if (conf_prefix) {
720
len = sizeof(NGX_CONF_PREFIX) - 1;
721
prefix = (u_char *) NGX_CONF_PREFIX;
829
len = cycle->conf_prefix.len;
830
prefix = cycle->conf_prefix.data;
724
len = cycle->root.len;
725
prefix = cycle->root.data;
833
len = cycle->prefix.len;
834
prefix = cycle->prefix.data;
728
837
name->len = len + old.len;
729
name->data = ngx_palloc(cycle->pool, name->len + 1);
838
name->data = ngx_pnalloc(cycle->pool, name->len + 1);
730
839
if (name->data == NULL) {
734
843
p = ngx_cpymem(name->data, prefix, len);
853
961
ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
856
u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
964
u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
859
967
last = errstr + NGX_MAX_CONF_ERRSTR;
861
969
va_start(args, fmt);
862
buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
970
p = ngx_vslprintf(errstr, last, fmt, args);
868
buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
869
buf = ngx_strerror_r(err, buf, last - buf - 1);
974
p = ngx_log_errno(p, last, err);
874
977
if (cf->conf_file == NULL) {
875
ngx_log_error(level, cf->log, 0, "%s", errstr);
879
ngx_log_error(level, cf->log, 0, "%s in %s:%ui",
880
errstr, cf->conf_file->file.name.data, cf->conf_file->line);
978
ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
982
if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
983
ngx_log_error(level, cf->log, 0, "%*s in command line",
988
ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
990
cf->conf_file->file.name.data, cf->conf_file->line);