Mercurial > hg > nginx-vendor-0-6
comparison src/core/ngx_conf_file.c @ 50:72eb30262aac NGINX_0_1_25
nginx 0.1.25
*) Bugfix: nginx did run on Linux parisc.
*) Feature: nginx now does not start under FreeBSD if the sysctl
kern.ipc.somaxconn value is too big.
*) Bugfix: if a request was internally redirected by the
ngx_http_index_module module to the ngx_http_proxy_module or
ngx_http_fastcgi_module modules, then the index file was not closed
after request completion.
*) Feature: the "proxy_pass" can be used in location with regular
expression.
*) Feature: the ngx_http_rewrite_filter_module module supports the
condition like "if ($HTTP_USER_AGENT ~ MSIE)".
*) Bugfix: nginx started too slow if the large number of addresses and
text values were used in the "geo" directive.
*) Change: a variable name must be declared as "$name" in the "geo"
directive. The previous variant without "$" is still supported, but
will be removed soon.
*) Feature: the "%{VARIABLE}v" logging parameter.
*) Feature: the "set $name value" directive.
*) Bugfix: gcc 4.0 compatibility.
*) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 00:00:00 +0300 |
parents | 6cfc63e68377 |
children | 0d75d65c642f |
comparison
equal
deleted
inserted
replaced
49:93dabbc9efb9 | 50:72eb30262aac |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); | |
11 static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 12 static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
12 | 13 |
13 | 14 |
14 static ngx_command_t ngx_conf_commands[] = { | 15 static ngx_command_t ngx_conf_commands[] = { |
15 | 16 |
51 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); | 52 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); |
52 | 53 |
53 | 54 |
54 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) | 55 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
55 { | 56 { |
56 int m, rc, found, valid; | |
57 char *rv; | 57 char *rv; |
58 void *conf, **confp; | |
59 ngx_fd_t fd; | 58 ngx_fd_t fd; |
60 ngx_str_t *name; | 59 ngx_int_t rc; |
61 ngx_conf_file_t *prev; | 60 ngx_conf_file_t *prev; |
62 ngx_command_t *cmd; | |
63 | 61 |
64 #if (NGX_SUPPRESS_WARN) | 62 #if (NGX_SUPPRESS_WARN) |
65 fd = NGX_INVALID_FILE; | 63 fd = NGX_INVALID_FILE; |
66 prev = NULL; | 64 prev = NULL; |
67 #endif | 65 #endif |
76 ngx_open_file_n " \"%s\" failed", filename->data); | 74 ngx_open_file_n " \"%s\" failed", filename->data); |
77 return NGX_CONF_ERROR; | 75 return NGX_CONF_ERROR; |
78 } | 76 } |
79 | 77 |
80 prev = cf->conf_file; | 78 prev = cf->conf_file; |
81 if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) { | 79 |
80 cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)); | |
81 if (cf->conf_file == NULL) { | |
82 return NGX_CONF_ERROR; | 82 return NGX_CONF_ERROR; |
83 } | 83 } |
84 | 84 |
85 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { | 85 if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { |
86 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 86 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
128 */ | 128 */ |
129 | 129 |
130 rv = (*cf->handler)(cf, NULL, cf->handler_conf); | 130 rv = (*cf->handler)(cf, NULL, cf->handler_conf); |
131 if (rv == NGX_CONF_OK) { | 131 if (rv == NGX_CONF_OK) { |
132 continue; | 132 continue; |
133 | 133 } |
134 } else if (rv == NGX_CONF_ERROR) { | 134 |
135 if (rv == NGX_CONF_ERROR) { | |
135 rc = NGX_ERROR; | 136 rc = NGX_ERROR; |
136 break; | 137 break; |
137 | 138 } |
138 } else { | 139 |
139 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
140 "%s in %s:%d", | |
141 rv, | |
142 cf->conf_file->file.name.data, | |
143 cf->conf_file->line); | |
144 rc = NGX_ERROR; | |
145 break; | |
146 } | |
147 } | |
148 | |
149 name = (ngx_str_t *) cf->args->elts; | |
150 found = 0; | |
151 | |
152 for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) { | |
153 | |
154 /* look up the directive in the appropriate modules */ | |
155 | |
156 if (ngx_modules[m]->type != NGX_CONF_MODULE | |
157 && ngx_modules[m]->type != cf->module_type) | |
158 { | |
159 continue; | |
160 } | |
161 | |
162 cmd = ngx_modules[m]->commands; | |
163 if (cmd == NULL) { | |
164 continue; | |
165 } | |
166 | |
167 while (cmd->name.len) { | |
168 if (name->len == cmd->name.len | |
169 && ngx_strcmp(name->data, cmd->name.data) == 0) | |
170 { | |
171 | |
172 found = 1; | |
173 | |
174 /* is the directive's location right ? */ | |
175 | |
176 if ((cmd->type & cf->cmd_type) == 0) { | |
177 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
178 "directive \"%s\" in %s:%d " | |
179 "is not allowed here", | |
180 name->data, | |
181 cf->conf_file->file.name.data, | |
182 cf->conf_file->line); | |
183 rc = NGX_ERROR; | |
184 break; | |
185 } | |
186 | |
187 if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK) | |
188 { | |
189 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
190 "directive \"%s\" in %s:%d " | |
191 "is not terminated by \";\"", | |
192 name->data, | |
193 cf->conf_file->file.name.data, | |
194 cf->conf_file->line); | |
195 rc = NGX_ERROR; | |
196 break; | |
197 } | |
198 | |
199 if ((cmd->type & NGX_CONF_BLOCK) | |
200 && rc != NGX_CONF_BLOCK_START) | |
201 { | |
202 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
203 "directive \"%s\" in %s:%d " | |
204 "has not the opening \"{\"", | |
205 name->data, | |
206 cf->conf_file->file.name.data, | |
207 cf->conf_file->line); | |
208 rc = NGX_ERROR; | |
209 break; | |
210 } | |
211 | |
212 /* is the directive's argument count right ? */ | |
213 | |
214 if (cmd->type & NGX_CONF_ANY) { | |
215 valid = 1; | |
216 | |
217 } else if (cmd->type & NGX_CONF_FLAG) { | |
218 | |
219 if (cf->args->nelts == 2) { | |
220 valid = 1; | |
221 } else { | |
222 valid = 0; | |
223 } | |
224 | |
225 } else if (cmd->type & NGX_CONF_1MORE) { | |
226 | |
227 if (cf->args->nelts > 1) { | |
228 valid = 1; | |
229 } else { | |
230 valid = 0; | |
231 } | |
232 | |
233 } else if (cmd->type & NGX_CONF_2MORE) { | |
234 | |
235 if (cf->args->nelts > 2) { | |
236 valid = 1; | |
237 } else { | |
238 valid = 0; | |
239 } | |
240 | |
241 } else if (cf->args->nelts <= 10 | |
242 && (cmd->type | |
243 & argument_number[cf->args->nelts - 1])) | |
244 { | |
245 valid = 1; | |
246 | |
247 } else { | |
248 valid = 0; | |
249 } | |
250 | |
251 if (!valid) { | |
252 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
253 "invalid number arguments in " | |
254 "directive \"%s\" in %s:%d", | |
255 name->data, | |
256 cf->conf_file->file.name.data, | |
257 cf->conf_file->line); | |
258 rc = NGX_ERROR; | |
259 break; | |
260 } | |
261 | |
262 /* set up the directive's configuration context */ | |
263 | |
264 conf = NULL; | |
265 | |
266 if (cmd->type & NGX_DIRECT_CONF) { | |
267 conf = ((void **) cf->ctx)[ngx_modules[m]->index]; | |
268 | |
269 } else if (cmd->type & NGX_MAIN_CONF) { | |
270 conf = &(((void **) cf->ctx)[ngx_modules[m]->index]); | |
271 | |
272 } else if (cf->ctx) { | |
273 confp = *(void **) ((char *) cf->ctx + cmd->conf); | |
274 | |
275 if (confp) { | |
276 conf = confp[ngx_modules[m]->ctx_index]; | |
277 } | |
278 } | |
279 | |
280 rv = cmd->set(cf, cmd, conf); | |
281 | |
282 if (rv == NGX_CONF_OK) { | |
283 break; | |
284 | |
285 } else if (rv == NGX_CONF_ERROR) { | |
286 rc = NGX_ERROR; | |
287 break; | |
288 | |
289 } else { | |
290 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
291 "the \"%s\" directive %s in %s:%d", | |
292 name->data, rv, | |
293 cf->conf_file->file.name.data, | |
294 cf->conf_file->line); | |
295 | |
296 rc = NGX_ERROR; | |
297 break; | |
298 } | |
299 } | |
300 | |
301 cmd++; | |
302 } | |
303 } | |
304 | |
305 if (!found) { | |
306 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 140 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
307 "unknown directive \"%s\" in %s:%d", | 141 "%s in %s:%d", |
308 name->data, | 142 rv, cf->conf_file->file.name.data, |
309 cf->conf_file->file.name.data, | 143 cf->conf_file->line); |
310 cf->conf_file->line); | |
311 | |
312 rc = NGX_ERROR; | 144 rc = NGX_ERROR; |
313 break; | 145 break; |
314 } | 146 } |
315 | 147 |
148 | |
149 rc = ngx_conf_handler(cf, rc); | |
150 | |
316 if (rc == NGX_ERROR) { | 151 if (rc == NGX_ERROR) { |
317 break; | 152 break; |
318 } | 153 } |
319 } | 154 } |
155 | |
320 | 156 |
321 if (filename) { | 157 if (filename) { |
322 cf->conf_file = prev; | 158 cf->conf_file = prev; |
323 | 159 |
324 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 160 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
332 if (rc == NGX_ERROR) { | 168 if (rc == NGX_ERROR) { |
333 return NGX_CONF_ERROR; | 169 return NGX_CONF_ERROR; |
334 } | 170 } |
335 | 171 |
336 return NGX_CONF_OK; | 172 return NGX_CONF_OK; |
173 } | |
174 | |
175 | |
176 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last) | |
177 { | |
178 char *rv; | |
179 void *conf, **confp; | |
180 ngx_uint_t i, valid; | |
181 ngx_str_t *name; | |
182 ngx_command_t *cmd; | |
183 | |
184 name = cf->args->elts; | |
185 | |
186 for (i = 0; ngx_modules[i]; i++) { | |
187 | |
188 /* look up the directive in the appropriate modules */ | |
189 | |
190 if (ngx_modules[i]->type != NGX_CONF_MODULE | |
191 && ngx_modules[i]->type != cf->module_type) | |
192 { | |
193 continue; | |
194 } | |
195 | |
196 cmd = ngx_modules[i]->commands; | |
197 if (cmd == NULL) { | |
198 continue; | |
199 } | |
200 | |
201 while (cmd->name.len) { | |
202 | |
203 if (name->len == cmd->name.len | |
204 && ngx_strcmp(name->data, cmd->name.data) == 0) | |
205 { | |
206 /* is the directive's location right ? */ | |
207 | |
208 if (!(cmd->type & cf->cmd_type)) { | |
209 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
210 "directive \"%s\" in %s:%d " | |
211 "is not allowed here", | |
212 name->data, cf->conf_file->file.name.data, | |
213 cf->conf_file->line); | |
214 return NGX_ERROR; | |
215 } | |
216 | |
217 if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) { | |
218 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
219 "directive \"%s\" in %s:%d " | |
220 "is not terminated by \";\"", | |
221 name->data, cf->conf_file->file.name.data, | |
222 cf->conf_file->line); | |
223 return NGX_ERROR; | |
224 } | |
225 | |
226 if ((cmd->type & NGX_CONF_BLOCK) | |
227 && last != NGX_CONF_BLOCK_START) | |
228 { | |
229 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
230 "directive \"%s\" in %s:%d " | |
231 "has not the opening \"{\"", | |
232 name->data, cf->conf_file->file.name.data, | |
233 cf->conf_file->line); | |
234 return NGX_ERROR; | |
235 } | |
236 | |
237 /* is the directive's argument count right ? */ | |
238 | |
239 if (cmd->type & NGX_CONF_ANY) { | |
240 valid = 1; | |
241 | |
242 } else if (cmd->type & NGX_CONF_FLAG) { | |
243 | |
244 if (cf->args->nelts == 2) { | |
245 valid = 1; | |
246 } else { | |
247 valid = 0; | |
248 } | |
249 | |
250 } else if (cmd->type & NGX_CONF_1MORE) { | |
251 | |
252 if (cf->args->nelts > 1) { | |
253 valid = 1; | |
254 } else { | |
255 valid = 0; | |
256 } | |
257 | |
258 } else if (cmd->type & NGX_CONF_2MORE) { | |
259 | |
260 if (cf->args->nelts > 2) { | |
261 valid = 1; | |
262 } else { | |
263 valid = 0; | |
264 } | |
265 | |
266 } else if (cf->args->nelts <= 10 | |
267 && (cmd->type | |
268 & argument_number[cf->args->nelts - 1])) | |
269 { | |
270 valid = 1; | |
271 | |
272 } else { | |
273 valid = 0; | |
274 } | |
275 | |
276 if (!valid) { | |
277 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
278 "invalid number arguments in " | |
279 "directive \"%s\" in %s:%d", | |
280 name->data, cf->conf_file->file.name.data, | |
281 cf->conf_file->line); | |
282 return NGX_ERROR; | |
283 } | |
284 | |
285 /* set up the directive's configuration context */ | |
286 | |
287 conf = NULL; | |
288 | |
289 if (cmd->type & NGX_DIRECT_CONF) { | |
290 conf = ((void **) cf->ctx)[ngx_modules[i]->index]; | |
291 | |
292 } else if (cmd->type & NGX_MAIN_CONF) { | |
293 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); | |
294 | |
295 } else if (cf->ctx) { | |
296 confp = *(void **) ((char *) cf->ctx + cmd->conf); | |
297 | |
298 if (confp) { | |
299 conf = confp[ngx_modules[i]->ctx_index]; | |
300 } | |
301 } | |
302 | |
303 rv = cmd->set(cf, cmd, conf); | |
304 | |
305 if (rv == NGX_CONF_OK) { | |
306 return NGX_OK; | |
307 } | |
308 | |
309 if (rv == NGX_CONF_ERROR) { | |
310 return NGX_ERROR; | |
311 } | |
312 | |
313 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
314 "the \"%s\" directive %s in %s:%d", | |
315 name->data, rv, cf->conf_file->file.name.data, | |
316 cf->conf_file->line); | |
317 | |
318 return NGX_ERROR; | |
319 } | |
320 | |
321 cmd++; | |
322 } | |
323 } | |
324 | |
325 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
326 "unknown directive \"%s\" in %s:%d", | |
327 name->data, cf->conf_file->file.name.data, | |
328 cf->conf_file->line); | |
329 | |
330 return NGX_ERROR; | |
337 } | 331 } |
338 | 332 |
339 | 333 |
340 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf) | 334 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf) |
341 { | 335 { |
521 last_space = 1; | 515 last_space = 1; |
522 found = 1; | 516 found = 1; |
523 } | 517 } |
524 | 518 |
525 if (found) { | 519 if (found) { |
526 if (!(word = ngx_push_array(cf->args))) { | 520 word = ngx_array_push(cf->args); |
521 if (word == NULL) { | |
527 return NGX_ERROR; | 522 return NGX_ERROR; |
528 } | 523 } |
529 | 524 |
530 if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) { | 525 word->data = ngx_palloc(cf->pool, b->pos - start + 1); |
526 if (word->data == NULL) { | |
531 return NGX_ERROR; | 527 return NGX_ERROR; |
532 } | 528 } |
533 | 529 |
534 for (dst = word->data, src = start, len = 0; | 530 for (dst = word->data, src = start, len = 0; |
535 src < b->pos - 1; | 531 src < b->pos - 1; |
621 old = *name; | 617 old = *name; |
622 | 618 |
623 name->len = cycle->root.len + old.len; | 619 name->len = cycle->root.len + old.len; |
624 | 620 |
625 if (cycle->connections) { | 621 if (cycle->connections) { |
626 if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) { | 622 name->data = ngx_palloc(cycle->pool, name->len + 1); |
623 if (name->data == NULL) { | |
627 return NGX_ERROR; | 624 return NGX_ERROR; |
628 } | 625 } |
629 | 626 |
630 } else { | 627 } else { |
631 | 628 |
632 /* the init_cycle */ | 629 /* the init_cycle */ |
633 | 630 |
634 if (!(name->data = ngx_alloc(name->len + 1, cycle->log))) { | 631 name->data = ngx_alloc(name->len + 1, cycle->log); |
632 if (name->data == NULL) { | |
635 return NGX_ERROR; | 633 return NGX_ERROR; |
636 } | 634 } |
637 } | 635 } |
638 | 636 |
639 p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len), | 637 p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len), |
684 return &file[i]; | 682 return &file[i]; |
685 } | 683 } |
686 } | 684 } |
687 } | 685 } |
688 | 686 |
689 if (!(file = ngx_list_push(&cycle->open_files))) { | 687 file = ngx_list_push(&cycle->open_files); |
688 if (file == NULL) { | |
690 return NULL; | 689 return NULL; |
691 } | 690 } |
692 | 691 |
693 if (name) { | 692 if (name) { |
694 file->fd = NGX_INVALID_FILE; | 693 file->fd = NGX_INVALID_FILE; |