comparison src/core/ngx_conf_file.c @ 2073:01b71aa095cc

-g switch
author Igor Sysoev <igor@sysoev.ru>
date Mon, 30 Jun 2008 12:35:16 +0000
parents 0835142149d2
children 853fc7a46792
comparison
equal deleted inserted replaced
2072:ee2fecdfdef7 2073:01b71aa095cc
56 NGX_CONF_TAKE7 56 NGX_CONF_TAKE7
57 }; 57 };
58 58
59 59
60 char * 60 char *
61 ngx_conf_param(ngx_conf_t *cf)
62 {
63 ngx_str_t *param;
64 ngx_buf_t b;
65 ngx_conf_file_t conf_file;
66
67 param = &cf->cycle->conf_param;
68
69 if (param->len == 0) {
70 return NGX_CONF_OK;
71 }
72
73 ngx_memzero(&conf_file, sizeof(ngx_conf_file_t));
74
75 ngx_memzero(&b, sizeof(ngx_buf_t));
76
77 b.start = param->data;
78 b.pos = param->data;
79 b.last = param->data + param->len;
80 b.end = b.last;
81 b.temporary = 1;
82
83 conf_file.file.fd = NGX_INVALID_FILE;
84 conf_file.file.name.data = (u_char *) "command line";
85 conf_file.line = 1;
86
87 cf->conf_file = &conf_file;
88 cf->conf_file->buffer = &b;
89
90 return ngx_conf_parse(cf, NULL);
91 }
92
93
94 char *
61 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 95 ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
62 { 96 {
63 char *rv; 97 char *rv;
64 ngx_fd_t fd; 98 ngx_fd_t fd;
65 ngx_int_t rc; 99 ngx_int_t rc;
66 ngx_buf_t *b; 100 ngx_buf_t *b;
67 ngx_uint_t block;
68 ngx_conf_file_t *prev; 101 ngx_conf_file_t *prev;
102 enum {
103 parse_file = 0,
104 parse_block,
105 parse_param
106 } type;
69 107
70 #if (NGX_SUPPRESS_WARN) 108 #if (NGX_SUPPRESS_WARN)
71 fd = NGX_INVALID_FILE; 109 fd = NGX_INVALID_FILE;
72 prev = NULL; 110 prev = NULL;
73 #endif 111 #endif
118 cf->conf_file->file.name.data = filename->data; 156 cf->conf_file->file.name.data = filename->data;
119 cf->conf_file->file.offset = 0; 157 cf->conf_file->file.offset = 0;
120 cf->conf_file->file.log = cf->log; 158 cf->conf_file->file.log = cf->log;
121 cf->conf_file->line = 1; 159 cf->conf_file->line = 1;
122 160
123 block = 0; 161 type = parse_file;
162
163 } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) {
164
165 type = parse_block;
124 166
125 } else { 167 } else {
126 block = 1; 168 type = parse_param;
127 } 169 }
128 170
129 171
130 for ( ;; ) { 172 for ( ;; ) {
131 rc = ngx_conf_read_token(cf); 173 rc = ngx_conf_read_token(cf);
144 goto done; 186 goto done;
145 } 187 }
146 188
147 if (rc == NGX_CONF_BLOCK_DONE) { 189 if (rc == NGX_CONF_BLOCK_DONE) {
148 190
149 if (!block) { 191 if (type != parse_block) {
150 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\""); 192 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\"");
151 goto failed; 193 goto failed;
152 } 194 }
153 195
154 goto done; 196 goto done;
155 } 197 }
156 198
157 if (rc == NGX_CONF_FILE_DONE) { 199 if (rc == NGX_CONF_FILE_DONE) {
158 200
159 if (block) { 201 if (type == parse_block) {
160 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 202 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
161 "unexpected end of file, expecting \"}\""); 203 "unexpected end of file, expecting \"}\"");
162 goto failed; 204 goto failed;
163 } 205 }
164 206
165 goto done; 207 goto done;
208 }
209
210 if (rc == NGX_CONF_BLOCK_START) {
211
212 if (type == parse_param) {
213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
214 "block directives are not supported "
215 "in -g option");
216 goto failed;
217 }
166 } 218 }
167 219
168 /* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */ 220 /* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */
169 221
170 if (cf->handler) { 222 if (cf->handler) {
400 start = b->pos; 452 start = b->pos;
401 453
402 for ( ;; ) { 454 for ( ;; ) {
403 455
404 if (b->pos >= b->last) { 456 if (b->pos >= b->last) {
457
405 if (cf->conf_file->file.offset 458 if (cf->conf_file->file.offset
406 >= ngx_file_size(&cf->conf_file->file.info)) 459 >= ngx_file_size(&cf->conf_file->file.info))
407 { 460 {
408 if (cf->args->nelts > 0) { 461 if (cf->args->nelts > 0) {
462
463 if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
464 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
465 "unexpected end of parameter, "
466 "expecting \";\"");
467 return NGX_ERROR;
468 }
469
409 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 470 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
410 "unexpected end of file, " 471 "unexpected end of file, "
411 "expecting \";\" or \"}\""); 472 "expecting \";\" or \"}\"");
412 return NGX_ERROR; 473 return NGX_ERROR;
413 } 474 }