Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 96:a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 27 May 2003 12:18:54 +0000 |
parents | 19cc647ecd91 |
children | c9b243802a17 |
comparison
equal
deleted
inserted
replaced
95:b48066122884 | 96:a23d010f356d |
---|---|
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 | 3 |
4 #include <ngx_core.h> | 4 #include <ngx_core.h> |
5 #include <ngx_files.h> | 5 #include <ngx_files.h> |
6 #include <ngx_conf_file.h> | 6 #include <ngx_conf_file.h> |
7 | |
8 | |
9 char ngx_conf_errstr[MAX_CONF_ERRSTR]; | |
7 | 10 |
8 | 11 |
9 static int argument_number[] = { | 12 static int argument_number[] = { |
10 NGX_CONF_NOARGS, | 13 NGX_CONF_NOARGS, |
11 NGX_CONF_TAKE1, | 14 NGX_CONF_TAKE1, |
15 static int ngx_conf_read_token(ngx_conf_t *cf); | 18 static int ngx_conf_read_token(ngx_conf_t *cf); |
16 | 19 |
17 | 20 |
18 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) | 21 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
19 { | 22 { |
20 int i, rc, found; | 23 int m, rc, found; |
21 char *rv; | 24 char *rv; |
22 void *conf, **confp; | 25 void *conf, **confp; |
23 ngx_str_t *name; | 26 ngx_str_t *name; |
24 ngx_fd_t fd; | 27 ngx_fd_t fd; |
25 ngx_conf_file_t *prev; | 28 ngx_conf_file_t *prev; |
30 /* open configuration file */ | 33 /* open configuration file */ |
31 | 34 |
32 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); | 35 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); |
33 if (fd == NGX_INVALID_FILE) { | 36 if (fd == NGX_INVALID_FILE) { |
34 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 37 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
35 "ngx_conf_file: " | |
36 ngx_open_file_n " %s failed", filename->data); | 38 ngx_open_file_n " %s failed", filename->data); |
37 return NGX_CONF_ERROR; | 39 return NGX_CONF_ERROR; |
38 } | 40 } |
39 | 41 |
40 prev = cf->conf_file; | 42 prev = cf->conf_file; |
42 ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), | 44 ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), |
43 NGX_CONF_ERROR); | 45 NGX_CONF_ERROR); |
44 | 46 |
45 if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { | 47 if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { |
46 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 48 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
47 "ngx_conf_file: " | |
48 ngx_stat_fd_n " %s failed", filename->data); | 49 ngx_stat_fd_n " %s failed", filename->data); |
49 } | 50 } |
50 | 51 |
51 ngx_test_null(cf->conf_file->hunk, | 52 ngx_test_null(cf->conf_file->hunk, |
52 ngx_create_temp_hunk(cf->pool, 1024, 0, 0), | 53 ngx_create_temp_hunk(cf->pool, 1024, 0, 0), |
99 } | 100 } |
100 | 101 |
101 name = (ngx_str_t *) cf->args->elts; | 102 name = (ngx_str_t *) cf->args->elts; |
102 found = 0; | 103 found = 0; |
103 | 104 |
104 for (i = 0; !found && ngx_modules[i]; i++) { | 105 for (m = 0; !found && ngx_modules[m]; m++) { |
105 | 106 |
106 /* look up the directive in the appropriate modules */ | 107 /* look up the directive in the appropriate modules */ |
107 | 108 |
108 if (ngx_modules[i]->type != NGX_CONF_MODULE_TYPE | 109 if (ngx_modules[m]->type != NGX_CONF_MODULE |
109 && ngx_modules[i]->type != cf->module_type) | 110 && ngx_modules[m]->type != cf->module_type) |
110 { | 111 { |
111 continue; | 112 continue; |
112 } | 113 } |
113 | 114 |
114 cmd = ngx_modules[i]->commands; | 115 cmd = ngx_modules[m]->commands; |
115 if (cmd == NULL) { | 116 if (cmd == NULL) { |
116 continue; | 117 continue; |
117 } | 118 } |
118 | 119 |
119 while (cmd->name.len) { | 120 while (cmd->name.len) { |
158 | 159 |
159 /* set up the directive's configuration context */ | 160 /* set up the directive's configuration context */ |
160 | 161 |
161 conf = NULL; | 162 conf = NULL; |
162 | 163 |
163 if (cf->module_type == NGX_CORE_MODULE_TYPE) { | 164 if (cf->module_type == NGX_CORE_MODULE) { |
164 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); | 165 conf = &(((void **) cf->ctx)[ngx_modules[m]->index]); |
165 | 166 |
166 } else if (cf->ctx) { | 167 } else if (cf->ctx) { |
167 confp = *(void **) ((char *) cf->ctx + cmd->conf); | 168 confp = *(void **) ((char *) cf->ctx + cmd->conf); |
168 | 169 |
169 if (confp) { | 170 if (confp) { |
170 conf = confp[*(int *)(ngx_modules[i]->ctx)]; | 171 conf = confp[ngx_modules[m]->ctx_index]; |
171 } | 172 } |
172 } | 173 } |
173 | 174 |
174 rv = cmd->set(cf, cmd, conf); | 175 rv = cmd->set(cf, cmd, conf); |
175 | 176 |
183 | 184 |
184 } else if (rv == NGX_CONF_ERROR) { | 185 } else if (rv == NGX_CONF_ERROR) { |
185 return NGX_CONF_ERROR; | 186 return NGX_CONF_ERROR; |
186 | 187 |
187 } else { | 188 } else { |
188 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 189 if (rv == ngx_conf_errstr) { |
189 "%s %s in %s:%d", | 190 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
190 name->data, rv, | 191 "%s in %s:%d", |
191 cf->conf_file->file.name.data, | 192 rv, |
192 cf->conf_file->line); | 193 cf->conf_file->file.name.data, |
194 cf->conf_file->line); | |
195 } else { | |
196 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
197 "%s %s in %s:%d", | |
198 name->data, rv, | |
199 cf->conf_file->file.name.data, | |
200 cf->conf_file->line); | |
201 } | |
193 | 202 |
194 return NGX_CONF_ERROR; | 203 return NGX_CONF_ERROR; |
195 } | 204 } |
196 } | 205 } |
197 | 206 |
428 } | 437 } |
429 } | 438 } |
430 } | 439 } |
431 | 440 |
432 | 441 |
433 char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 442 char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
434 { | 443 { |
435 int flag; | 444 int flag; |
436 ngx_str_t *value; | 445 ngx_str_t *value; |
437 | 446 |
438 if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { | 447 if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { |
455 | 464 |
456 return NGX_CONF_OK; | 465 return NGX_CONF_OK; |
457 } | 466 } |
458 | 467 |
459 | 468 |
460 char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 469 char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
461 { | 470 { |
462 ngx_str_t *field, *value; | 471 ngx_str_t *field, *value; |
463 | 472 |
464 field = (ngx_str_t *) (conf + cmd->offset); | 473 field = (ngx_str_t *) (conf + cmd->offset); |
465 | 474 |
466 if (field->len > 0) { | 475 if (field->data) { |
467 return "is duplicate"; | 476 return "is duplicate"; |
468 } | 477 } |
469 | 478 |
470 value = (ngx_str_t *) cf->args->elts; | 479 value = (ngx_str_t *) cf->args->elts; |
471 | 480 |
474 | 483 |
475 return NGX_CONF_OK; | 484 return NGX_CONF_OK; |
476 } | 485 } |
477 | 486 |
478 | 487 |
479 char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 488 char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
480 { | 489 { |
481 int num, len; | 490 int num, len; |
482 ngx_str_t *value; | 491 ngx_str_t *value; |
483 | 492 |
484 if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { | 493 if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { |
498 | 507 |
499 return NGX_CONF_OK; | 508 return NGX_CONF_OK; |
500 } | 509 } |
501 | 510 |
502 | 511 |
503 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 512 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
504 { | 513 { |
505 int size, len, scale; | 514 int size, len, scale; |
506 char last; | 515 char last; |
507 ngx_str_t *value; | 516 ngx_str_t *value; |
508 | 517 |
543 | 552 |
544 return NGX_CONF_OK; | 553 return NGX_CONF_OK; |
545 } | 554 } |
546 | 555 |
547 | 556 |
548 char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 557 char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
549 { | 558 { |
550 int size, total, len, scale; | 559 int size, total, len, scale; |
551 u_int max, i; | 560 u_int max, i; |
552 char last, *start; | 561 char last, *start; |
553 ngx_str_t *value; | 562 ngx_str_t *value; |
638 | 647 |
639 return NGX_CONF_OK; | 648 return NGX_CONF_OK; |
640 } | 649 } |
641 | 650 |
642 | 651 |
643 char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 652 char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
644 { | 653 { |
645 int size, total, len, scale; | 654 int size, total, len, scale; |
646 u_int max, i; | 655 u_int max, i; |
647 char last, *start; | 656 char last, *start; |
648 ngx_str_t *value; | 657 ngx_str_t *value; |
745 | 754 |
746 return NGX_CONF_OK; | 755 return NGX_CONF_OK; |
747 } | 756 } |
748 | 757 |
749 | 758 |
750 char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 759 char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
751 { | 760 { |
752 return "unsupported on this platform"; | 761 return "unsupported on this platform"; |
753 } | 762 } |