Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 44:0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 09 Jan 2003 05:36:00 +0000 |
parents | 53cd05892261 |
children | f1ee46c036a4 |
comparison
equal
deleted
inserted
replaced
43:53cd05892261 | 44:0e81ac0bb3e2 |
---|---|
11 }; | 11 }; |
12 | 12 |
13 static int ngx_conf_read_token(ngx_conf_t *cf); | 13 static int ngx_conf_read_token(ngx_conf_t *cf); |
14 | 14 |
15 | 15 |
16 int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) | 16 char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
17 { | 17 { |
18 int rc, i; | 18 int i, rc, found; |
19 char *error; | 19 char *rv; |
20 void *conf, **pconf; | |
20 ngx_str_t *name; | 21 ngx_str_t *name; |
21 ngx_fd_t fd; | 22 ngx_fd_t fd; |
22 ngx_conf_file_t *prev; | 23 ngx_conf_file_t *prev; |
23 ngx_command_t *cmd; | 24 ngx_command_t *cmd; |
24 | 25 |
27 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); | 28 fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); |
28 if (fd == NGX_INVALID_FILE) { | 29 if (fd == NGX_INVALID_FILE) { |
29 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 30 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
30 "ngx_conf_file: " | 31 "ngx_conf_file: " |
31 ngx_open_file_n " %s failed", filename->data); | 32 ngx_open_file_n " %s failed", filename->data); |
32 return NGX_ERROR; | 33 return NGX_CONF_ERROR; |
33 } | 34 } |
34 | 35 |
35 prev = cf->conf_file; | 36 prev = cf->conf_file; |
36 ngx_test_null(cf->conf_file, | 37 ngx_test_null(cf->conf_file, |
37 ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), | 38 ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), |
38 NGX_ERROR); | 39 NGX_CONF_ERROR); |
39 | 40 |
40 if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { | 41 if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { |
41 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, | 42 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
42 "ngx_conf_file: " | 43 "ngx_conf_file: " |
43 ngx_stat_fd_n " %s failed", filename->data); | 44 ngx_stat_fd_n " %s failed", filename->data); |
44 } | 45 } |
45 | 46 |
46 ngx_test_null(cf->conf_file->hunk, | 47 ngx_test_null(cf->conf_file->hunk, |
47 ngx_create_temp_hunk(cf->pool, 1024, 0, 0), | 48 ngx_create_temp_hunk(cf->pool, 1024, 0, 0), |
48 NGX_ERROR); | 49 NGX_CONF_ERROR); |
49 | 50 |
50 cf->conf_file->file.fd = fd; | 51 cf->conf_file->file.fd = fd; |
51 cf->conf_file->file.name.len = filename->len; | 52 cf->conf_file->file.name.len = filename->len; |
52 cf->conf_file->file.name.data = filename->data; | 53 cf->conf_file->file.name.data = filename->data; |
53 cf->conf_file->file.log = cf->log;; | 54 cf->conf_file->file.log = cf->log;; |
57 for ( ;; ) { | 58 for ( ;; ) { |
58 rc = ngx_conf_read_token(cf); | 59 rc = ngx_conf_read_token(cf); |
59 | 60 |
60 /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ | 61 /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ |
61 | 62 |
62 if (rc == NGX_ERROR || rc == NGX_CONF_FILE_DONE) { | 63 ngx_log_debug(cf->log, "token %d" _ rc); |
63 return rc; | 64 |
65 if (rc == NGX_ERROR) { | |
66 return NGX_CONF_ERROR; | |
67 } | |
68 | |
69 if (rc != NGX_OK) { | |
70 return NGX_CONF_OK; | |
64 } | 71 } |
65 | 72 |
66 if (cf->handler) { | 73 if (cf->handler) { |
67 | 74 |
68 if ((*cf->handler)(cf) == NGX_ERROR) { | 75 if ((*cf->handler)(cf) == NGX_CONF_ERROR) { |
69 return NGX_ERROR; | 76 return NGX_CONF_ERROR; |
70 } | 77 } |
71 | 78 |
72 continue; | 79 continue; |
73 } | 80 } |
74 | 81 |
75 name = (ngx_str_t *) cf->args->elts; | 82 name = (ngx_str_t *) cf->args->elts; |
76 | 83 found = 0; |
77 for (i = 0; ngx_modules[i]; i++) { | 84 |
85 for (i = 0; !found && ngx_modules[i]; i++) { | |
78 if (ngx_modules[i]->type != NULL | 86 if (ngx_modules[i]->type != NULL |
79 && ngx_modules[i]->type != cf->type) | 87 && ngx_modules[i]->type != cf->type) |
80 { | 88 { |
81 continue; | 89 continue; |
82 } | 90 } |
91 && ngx_strcmp(name->data, cmd->name.data) == 0) | 99 && ngx_strcmp(name->data, cmd->name.data) == 0) |
92 { | 100 { |
93 | 101 |
94 ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); | 102 ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); |
95 | 103 |
96 cmd->set(cf, cmd, NULL); | 104 if (!(cmd->type & argument_number[cf->args->nelts - 1])) { |
105 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
106 "invalid number arguments in " | |
107 "directive \"%s\" in %s:%d", | |
108 name->data, | |
109 cf->conf_file->file.name.data, | |
110 cf->conf_file->line); | |
111 return NGX_CONF_ERROR; | |
112 } | |
113 | |
114 conf = NULL; | |
115 if (cf->ctx) { | |
116 pconf = *(void **) ((char *) cf->ctx + cmd->conf); | |
117 | |
118 if (pconf) { | |
119 conf = pconf[ngx_modules[i]->index]; | |
120 } | |
121 } | |
122 | |
123 rv = cmd->set(cf, cmd, conf); | |
124 | |
125 ngx_log_debug(cf->log, "rv: %d" _ rv); | |
126 | |
127 if (rv == NGX_CONF_OK) { | |
128 found = 1; | |
129 break; | |
130 | |
131 } else if (rv == NGX_CONF_ERROR) { | |
132 return NGX_CONF_ERROR; | |
133 | |
134 } else { | |
135 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
136 "%s", rv); | |
137 return NGX_CONF_ERROR; | |
138 } | |
97 } | 139 } |
98 | 140 |
99 cmd++; | 141 cmd++; |
100 } | 142 } |
101 } | 143 } |
102 | 144 |
103 #if 0 | 145 if (!found) { |
104 cmd = ngx_conf_find_token(cf); | |
105 if (cmd == NULL) { | |
106 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 146 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
107 "unknown directive \"%s\" in %s:%d", | 147 "unknown directive \"%s\" in %s:%d", |
108 cf->name, cf->file->name, cf->file->line); | 148 name->data, |
109 return NGX_ERROR; | 149 cf->conf_file->file.name.data, |
110 } | 150 cf->conf_file->line); |
111 | 151 |
112 if (cmd->type & argument_number[cf->args->nelts - 1]) { | 152 return NGX_CONF_ERROR; |
113 error = cmd->set(cf, cmd->offset, cf->args); | 153 } |
114 | |
115 if (error) { | |
116 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
117 "%s in directive \"%s\" in %s:%d", | |
118 error, cf->name, cf->file->name, cf->file->line); | |
119 return NGX_ERROR; | |
120 } | |
121 } | |
122 #endif | |
123 | |
124 #if 0 | |
125 if (cmd->type == NGX_CONF_CONTAINER) { | |
126 ngx_conf_parse(cf, cmd->container, NULL); | |
127 | |
128 } else if (cmd->type == NGX_CONF_FLAG) { | |
129 | |
130 if (cf->args->nelts != 1) { | |
131 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
132 "invalid number of arguments " | |
133 "in directive \"%s\" in %s:%d", | |
134 cf->name, cf->file->name, cf->file->line); | |
135 return NGX_ERROR; | |
136 } | |
137 | |
138 if (ngx_strcasecmp(cf->args->elts[0], "on") == 0) { | |
139 flag = 1; | |
140 | |
141 } else if (ngx_strcasecmp(cf->args->elts[0], "off") == 0) { | |
142 flag = 0; | |
143 | |
144 } else { | |
145 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
146 "invalid flag in directive \"%s\" in %s:%d", | |
147 cf->name, cf->file->name, cf->file->line); | |
148 return NGX_ERROR; | |
149 } | |
150 | |
151 rv = cmd->set(cf, cmd->offset, flag); | |
152 if (rv) { | |
153 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
154 "%s in directive \"%s\" in %s:%d", | |
155 rv, cf->name, cf->file->name, cf->file->line); | |
156 return NGX_ERROR; | |
157 } | |
158 | |
159 } else if (cmd->type & argument_number[args->nelts]) { | |
160 rv = cmd->set(cf, cmd->offset, cf->args); | |
161 if (rv) { | |
162 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
163 "%s in directive \"%s\" in %s:%d", | |
164 rv, cf->name, cf->file->name, cf->file->line); | |
165 return NGX_ERROR; | |
166 } | |
167 | |
168 } else { | |
169 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
170 "invalid number of arguments " | |
171 "in directive \"%s\" in %s:%d", | |
172 cf->name, cf->file->name, cf->file->line); | |
173 return NGX_ERROR; | |
174 } | |
175 #endif | |
176 } | 154 } |
177 | 155 |
178 if (filename) { | 156 if (filename) { |
179 cf->conf_file = prev; | 157 cf->conf_file = prev; |
180 | 158 |
181 if (ngx_close_file(fd) == NGX_FILE_ERROR) { | 159 if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
182 ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno, | 160 ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno, |
183 ngx_close_file_n " %s failed", | 161 ngx_close_file_n " %s failed", |
184 cf->conf_file->file.name.data); | 162 cf->conf_file->file.name.data); |
185 return NGX_ERROR; | 163 return NGX_CONF_ERROR; |
186 } | 164 } |
187 } | 165 } |
188 | 166 |
189 return NGX_OK; | 167 return NGX_CONF_OK; |
190 } | 168 } |
191 | 169 |
192 | 170 |
193 static int ngx_conf_read_token(ngx_conf_t *cf) | 171 static int ngx_conf_read_token(ngx_conf_t *cf) |
194 { | 172 { |
389 } | 367 } |
390 } | 368 } |
391 } | 369 } |
392 | 370 |
393 | 371 |
372 char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | |
373 { | |
374 ngx_str_t *field, *value; | |
375 | |
376 field = (ngx_str_t *) conf + cmd->offset; | |
377 value = (ngx_str_t *) cf->args->elts; | |
378 | |
379 field->len = value->len; | |
380 field->data = value->data; | |
381 | |
382 return NGX_CONF_OK; | |
383 } | |
384 | |
385 | |
394 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 386 char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) |
395 { | 387 { |
396 int size; | 388 int size; |
397 ngx_str_t *value; | 389 ngx_str_t *value; |
398 | 390 |
403 return "value must be greater or equal to zero"; | 395 return "value must be greater or equal to zero"; |
404 } | 396 } |
405 | 397 |
406 *(int *) (conf + cmd->offset) = size; | 398 *(int *) (conf + cmd->offset) = size; |
407 | 399 |
408 return NULL; | 400 return NGX_CONF_OK; |
409 } | 401 } |
410 | 402 |
411 | 403 |
412 char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 404 char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) |
413 { | 405 { |
421 return "value must be greater or equal to zero"; | 413 return "value must be greater or equal to zero"; |
422 } | 414 } |
423 | 415 |
424 *(int *) (conf + cmd->offset) = size; | 416 *(int *) (conf + cmd->offset) = size; |
425 | 417 |
426 return NULL; | 418 return NGX_CONF_OK; |
427 } | 419 } |