Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 90:37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 16 May 2003 15:27:48 +0000 |
parents | 29bf798b583f |
children | 637625a2acdb |
comparison
equal
deleted
inserted
replaced
89:29bf798b583f | 90:37530da31268 |
---|---|
25 ngx_conf_file_t *prev; | 25 ngx_conf_file_t *prev; |
26 ngx_command_t *cmd; | 26 ngx_command_t *cmd; |
27 | 27 |
28 if (filename) { | 28 if (filename) { |
29 | 29 |
30 /* open configuration file */ | |
31 | |
30 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); | 32 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); |
31 if (fd == NGX_INVALID_FILE) { | 33 if (fd == NGX_INVALID_FILE) { |
32 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 34 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
33 "ngx_conf_file: " | 35 "ngx_conf_file: " |
34 ngx_open_file_n " %s failed", filename->data); | 36 ngx_open_file_n " %s failed", filename->data); |
58 } | 60 } |
59 | 61 |
60 for ( ;; ) { | 62 for ( ;; ) { |
61 rc = ngx_conf_read_token(cf); | 63 rc = ngx_conf_read_token(cf); |
62 | 64 |
63 /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ | 65 /* ngx_conf_read_token() returns NGX_OK, NGX_ERROR, |
66 NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE */ | |
64 | 67 |
65 #if 0 | 68 #if 0 |
66 ngx_log_debug(cf->log, "token %d" _ rc); | 69 ngx_log_debug(cf->log, "token %d" _ rc); |
67 #endif | 70 #endif |
68 | 71 |
73 if (rc != NGX_OK) { | 76 if (rc != NGX_OK) { |
74 return NGX_CONF_OK; | 77 return NGX_CONF_OK; |
75 } | 78 } |
76 | 79 |
77 if (cf->handler) { | 80 if (cf->handler) { |
81 | |
82 /* custom handler, i.e. used in http "types { ... }" directive */ | |
78 | 83 |
79 rv = (*cf->handler)(cf, NULL, cf->handler_conf); | 84 rv = (*cf->handler)(cf, NULL, cf->handler_conf); |
80 if (rv == NGX_CONF_OK) { | 85 if (rv == NGX_CONF_OK) { |
81 continue; | 86 continue; |
82 | 87 |
95 | 100 |
96 name = (ngx_str_t *) cf->args->elts; | 101 name = (ngx_str_t *) cf->args->elts; |
97 found = 0; | 102 found = 0; |
98 | 103 |
99 for (i = 0; !found && ngx_modules[i]; i++) { | 104 for (i = 0; !found && ngx_modules[i]; i++) { |
105 | |
106 /* look up the directive in the appropriate modules */ | |
107 | |
100 if (ngx_modules[i]->type != NGX_CONF_MODULE_TYPE | 108 if (ngx_modules[i]->type != NGX_CONF_MODULE_TYPE |
101 && ngx_modules[i]->type != cf->module_type) | 109 && ngx_modules[i]->type != cf->module_type) |
102 { | 110 { |
103 continue; | 111 continue; |
104 } | 112 } |
114 { | 122 { |
115 | 123 |
116 #if 0 | 124 #if 0 |
117 ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); | 125 ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); |
118 #endif | 126 #endif |
127 /* is the directive's location right ? */ | |
119 | 128 |
120 if ((cmd->type & cf->cmd_type) == 0) { | 129 if ((cmd->type & cf->cmd_type) == 0) { |
121 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 130 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
122 "directive \"%s\" in %s:%d " | 131 "directive \"%s\" in %s:%d " |
123 "is not allowed here", | 132 "is not allowed here", |
124 name->data, | 133 name->data, |
125 cf->conf_file->file.name.data, | 134 cf->conf_file->file.name.data, |
126 cf->conf_file->line); | 135 cf->conf_file->line); |
127 return NGX_CONF_ERROR; | 136 return NGX_CONF_ERROR; |
128 } | 137 } |
138 | |
139 /* is the directive's argument count right ? */ | |
129 | 140 |
130 if (!(cmd->type & NGX_CONF_ANY) | 141 if (!(cmd->type & NGX_CONF_ANY) |
131 && ((cmd->type & NGX_CONF_FLAG && cf->args->nelts != 2) | 142 && ((cmd->type & NGX_CONF_FLAG && cf->args->nelts != 2) |
132 || (!(cmd->type & NGX_CONF_FLAG) | 143 || (!(cmd->type & NGX_CONF_FLAG) |
133 && !(cmd->type | 144 && !(cmd->type |
143 cf->conf_file->file.name.data, | 154 cf->conf_file->file.name.data, |
144 cf->conf_file->line); | 155 cf->conf_file->line); |
145 return NGX_CONF_ERROR; | 156 return NGX_CONF_ERROR; |
146 } | 157 } |
147 | 158 |
159 /* set up the directive's configuration context */ | |
160 | |
148 conf = NULL; | 161 conf = NULL; |
149 if (cf->ctx) { | 162 |
163 if (cf->module_type == NGX_CORE_MODULE_TYPE) { | |
164 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); | |
165 | |
166 } else if (cf->ctx) { | |
150 pconf = *(void **) ((char *) cf->ctx + cmd->conf); | 167 pconf = *(void **) ((char *) cf->ctx + cmd->conf); |
151 | 168 |
152 if (pconf) { | 169 if (pconf) { |
153 conf = pconf[*(int *)(ngx_modules[i]->ctx)]; | 170 conf = pconf[*(int *)(ngx_modules[i]->ctx)]; |
154 } | 171 } |
195 | 212 |
196 if (filename) { | 213 if (filename) { |
197 cf->conf_file = prev; | 214 cf->conf_file = prev; |
198 | 215 |
199 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 216 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
200 ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno, | 217 ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
201 ngx_close_file_n " %s failed", | 218 ngx_close_file_n " %s failed", |
202 cf->conf_file->file.name.data); | 219 cf->conf_file->file.name.data); |
203 return NGX_CONF_ERROR; | 220 return NGX_CONF_ERROR; |
204 } | 221 } |
205 } | 222 } |
448 | 465 |
449 return NGX_CONF_OK; | 466 return NGX_CONF_OK; |
450 } | 467 } |
451 | 468 |
452 | 469 |
470 char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | |
471 { | |
472 int num, len; | |
473 ngx_str_t *value; | |
474 | |
475 value = (ngx_str_t *) cf->args->elts; | |
476 | |
477 len = value[1].len; | |
478 | |
479 num = ngx_atoi(value[1].data, len); | |
480 if (num == NGX_ERROR) { | |
481 return "invalid value"; | |
482 } | |
483 | |
484 *(int *) (conf + cmd->offset) = num; | |
485 | |
486 return NGX_CONF_OK; | |
487 } | |
488 | |
489 | |
453 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 490 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) |
454 { | 491 { |
455 int size, len, scale; | 492 int size, len, scale; |
456 char last; | 493 char last; |
457 ngx_str_t *value; | 494 ngx_str_t *value; |