comparison src/core/ngx_config_command.c @ 19:d7908993fdeb

nginx-0.0.1-2002-12-02-19:09:40 import; resume after 2 months stall
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Dec 2002 16:09:40 +0000
parents 2aba961a1d34
children
comparison
equal deleted inserted replaced
18:72ad26c77d2d 19:d7908993fdeb
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3
4
5 #if 0
6
7 typedef struct ngx_conf_file_t {
8 ngx_fd_t fd;
9 char *name;
10 int line;
11 char *pos;
12 };
13
14 typedef struct ngx_conf_t {
15 char *name;
16 ngx_array_t *args;
17
18 ngx_conf_file_t *file;
19 ngx_log_t *log;
20
21 void *context; # ngx_http_conf_t
22 };
23
24 static int argument_number[] = {
25 NGX_CONF_NOARGS,
26 NGX_CONF_TAKE1,
27 NGX_CONF_TAKE2,
28 NGX_CONF_TAKE3
29 };
30
31
32 ngx_conf_parse(cf, container, filename)
33 {
34 create cf;
35
36 *conatiner(cf);
37
38 if (filename) {
39 open;
40 }
41
42 for ( ;; ) {
43 rc = ngx_conf_read_token(cf);
44
45 NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE
46
47 if (rc != NGX_OK)
48 return rc;
49
50 "listen address:port;"
51 "location /images/ {"
52
53 cmd = ngx_conf_find_token(cf);
54 if (cmd == NULL) {
55 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
56 "unknown directive \"%s\" in %s:%d",
57 cf->name, cf->file->name, cf->file->line);
58 return NGX_ERROR;
59 }
60
61 if (cmd->type == NGX_CONF_CONTAINER) {
62 ngx_conf_parse(cf, cmd->container, NULL);
63
64 } else if (cmd->type == NGX_CONF_FLAG) {
65
66 if (cf->args->nelts != 1) {
67 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
68 "invalid number of arguments "
69 "in directive \"%s\" in %s:%d",
70 cf->name, cf->file->name, cf->file->line);
71 return NGX_ERROR;
72 }
73
74 if (ngx_strcasecmp(cf->args->elts[0], "on") == 0) {
75 flag = 1;
76
77 } else if (ngx_strcasecmp(cf->args->elts[0], "off") == 0) {
78 flag = 0;
79
80 } else {
81 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
82 "invalid flag in directive \"%s\" in %s:%d",
83 cf->name, cf->file->name, cf->file->line);
84 return NGX_ERROR;
85 }
86
87 rv = cmd->set(cf, cmd->offset, flag);
88 if (rv) {
89 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
90 "%s in directive \"%s\" in %s:%d",
91 rv, cf->name, cf->file->name, cf->file->line);
92 return NGX_ERROR;
93 }
94
95 } else if (cmd->type & argument_number[args->nelts]) {
96 rv = cmd->set(cf, cmd->offset, cf->args);
97 if (rv) {
98 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
99 "%s in directive \"%s\" in %s:%d",
100 rv, cf->name, cf->file->name, cf->file->line);
101 return NGX_ERROR;
102 }
103
104 } else {
105 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
106 "invalid number of arguments "
107 "in directive \"%s\" in %s:%d",
108 cf->name, cf->file->name, cf->file->line);
109 return NGX_ERROR;
110 }
111 }
112
113 if (filename) {
114 close;
115 }
116 }
117
118 int ngx_conf_read_token(ngx_conf_t *cf)
119 {
120
121 need_space = 0;
122 last_space = 1;
123 len = 0;
124 quoted = s_quoted = d_quoted = 0;
125
126 cf->args->nelts = 0;
127
128 for (/* void */ ; cf->pos < cf->end; cf->pos++) {
129
130 ch = *cf->pos;
131
132 if (ch == LF)
133 cf->line++;
134
135 if (quoted) {
136 quoted = 0;
137 continue;
138 }
139
140 len++;
141
142 if (ch = '\\') {
143 quoted = 1;
144 continue;
145 }
146
147 if (d_quoted) {
148
149 if (ch == '"') {
150 d_qouted = 0;
151 need_space = 1;
152 last_space = 1;
153 continue;
154 }
155
156 } else if (s_quoted) {
157
158 if (ch == '\'') {
159 s_qouted = 0;
160 need_space = 1;
161 last_space = 1;
162 continue;
163 }
164
165 } else {
166
167 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
168 ngx_test_null(word, ngx_push_array(cf->args), NGX_ERRROR);
169 ngx_test_null(*word, ngx_palloc(cf->temp_pool, len + 1),
170 NGX_ERROR);
171
172 for (dst = *word, src = cf->start; src < cf->pos; /* void */) {
173 if (*src == '\\')
174 src++;
175 *dst++ = *src++;
176 }
177 *dst = '\0';
178
179 need_space = 0;
180 last_space = 1;
181 continue;
182 }
183
184 if (need_space) {
185 return NGX_ERROR;
186 }
187
188 if (ch == ';')
189 return NGX_OK;
190
191 if (ch == '{')
192 return NGX_OK;
193
194 if (ch == '}')
195 return NGX_BLOCK_DONE;
196
197 if (last_space) {
198 if (ch == '"') {
199 d_qouted = 1;
200 continue;
201 }
202
203 if (ch == '\'') {
204 s_qouted = 1;
205 continue;
206 }
207 }
208
209 last_space = 0;
210 }
211 }
212 }
213
214 container
215 server
216 location
217 module
218 if
219
220 http_conf current server
221 current location
222
223
224 ngx_conf_t *ngx_conf_open(char *filename, ngx_log_t *log)
225 {
226 ngx_cf->fd = ngx_open_file(config, NGX_FILE_RDONLY);
227 if (ngx_conf->fd == -1) {
228 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
229 "ngx_conf_open: "
230 ngx_open_file_n " %s failed", filename);
231
232 return NULL;
233 }
234
235 ngx_conf->name = filename;
236 ngx_conf->log = log;
237 return ngx_conf;
238 }
239
240 void ngx_conf_close(ngx_conf_t *cf)
241 {
242 if (ngx_close_file(cf->fd) == -1) {
243 ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno,
244 ngx_close_file_n " %s failed", cf->name);
245 }
246
247 cf->fd = -1;
248 }
249
250
251
252
253
254
255 #endif
256
3 257
4 char *ngx_conf_set_size_slot(char *conf, int offset, char *value) 258 char *ngx_conf_set_size_slot(char *conf, int offset, char *value)
5 { 259 {
6 int size; 260 int size;
7 261