comparison src/http/ngx_http_config.c @ 41:59e7c7f30d49

nginx-0.0.1-2002-12-26-19:26:23 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 26 Dec 2002 16:26:23 +0000
parents d45effe5854c
children cd035a94e0b6
comparison
equal deleted inserted replaced
40:d5d4f3bba6f0 41:59e7c7f30d49
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_config_file.h> 4 #include <ngx_config_file.h>
5 #include <ngx_http.h> 5 #include <ngx_http.h>
6 #include <ngx_http_core.h>
7 #include <ngx_http_config.h>
6 #include <ngx_http_write_filter.h> 8 #include <ngx_http_write_filter.h>
7 #include <ngx_http_output_filter.h> 9 #include <ngx_http_output_filter.h>
8 #include <ngx_http_index_handler.h> 10 #include <ngx_http_index_handler.h>
9 11
10 12
11 int ngx_max_module; 13 /* STUB */
12
13 int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
14
15 /* STUB: gobal srv and loc conf */
16 void **ngx_srv_conf; 14 void **ngx_srv_conf;
17 void **ngx_loc_conf; 15 void **ngx_loc_conf;
16 /**/
17
18
19 static int ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy);
20
21
22 void *null_loc_conf;
23
24
25 static ngx_command_t ngx_http_commands[] = {
26
27 {ngx_string("http"),
28 NGX_CONF_BLOCK|NGX_CONF_NOARGS,
29 ngx_http_block,
30 0,
31 0},
32
33 {ngx_string(""), 0, NULL, 0, 0}
34 };
35
36
37 static ngx_http_module_t ngx_http_module_ctx = {
38 NGX_HTTP_MODULE,
39
40 NULL, /* create server config */
41 NULL, /* create location config */
42
43 NULL, /* translate handler */
44
45 NULL, /* output header filter */
46 NULL, /* next output header filter */
47 NULL, /* output body filter */
48 NULL /* next output body filter */
49 };
50
51
52 ngx_module_t ngx_http_module = {
53 &ngx_http_module_ctx, /* module context */
54 ngx_http_commands, /* module directives */
55 0, /* module type */
56 NULL /* init module */
57 };
58
59
60 static int ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
61 {
62 int i, j;
63 ngx_http_module_t *module;
64 ngx_http_conf_ctx_t *ctx;
65
66 for (i = 0; ngx_modules[i]; i++) {
67 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
68 continue;
69 }
70
71 module = (ngx_http_module_t *) ngx_modules[i]->ctx;
72 module->index = i;
73 }
74
75 ngx_http_max_module = i;
76
77 ngx_test_null(null_loc_conf,
78 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
79 NGX_ERROR);
80
81 ctx->srv_conf = NULL;
82 ctx->loc_conf = null_loc_conf;
83
84 for (i = 0, j = 0; ngx_modules[i]; i++) {
85 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
86 continue;
87 }
88
89 module = (ngx_http_module_t *) ngx_modules[i]->ctx;
90 module->index = i;
91 if (module->create_loc_conf) {
92 ngx_test_null(null_loc_conf,
93 module->create_loc_conf(cf->pool),
94 NGX_ERROR);
95 j++;
96 }
97 }
98
99 cf->ctx = ctx;
100 cf->type = NGX_HTTP_MODULE_TYPE;
101 return ngx_conf_parse(cf, NULL);
102 }
103
18 104
19 #if 0 105 #if 0
20 int ngx_http_block(ngx_conf_t *cf)
21 {
22 ngx_http_conf_ctx_t *ctx;
23
24 ngx_test_null(ctx,
25 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
26 NGX_ERROR);
27
28 #if 0
29 /* null server config */
30 ngx_test_null(ctx->srv_conf,
31 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_max_module),
32 NGX_ERROR);
33 #endif
34
35 /* null location config */
36 ngx_test_null(ctx->loc_conf,
37 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_max_module),
38 NGX_ERROR);
39
40 for (i = 0; modules[i]; i++) {
41 #if 0
42 if (modules[i]->create_srv_conf)
43 ngx_test_null(ctx->srv_conf[i],
44 modules[i]->create_srv_conf(cf->pool),
45 NGX_ERROR);
46 #endif
47
48 if (modules[i]->create_loc_conf)
49 ngx_test_null(ctx->loc_conf[i],
50 modules[i]->create_loc_conf(cf->pool),
51 NGX_ERROR);
52 }
53
54 cf->ctx = ctx;
55 return ngx_conf_parse(cf);
56 }
57
58 int ngx_server_block(ngx_conf_t *cf) 106 int ngx_server_block(ngx_conf_t *cf)
59 { 107 {
60 ngx_http_conf_ctx_t *ctx, *prev; 108 ngx_http_conf_ctx_t *ctx, *prev;
61 109
62 ngx_test_null(ctx, 110 ngx_test_null(ctx,
153 return ngx_conf_parse(cf); 201 return ngx_conf_parse(cf);
154 } 202 }
155 203
156 #endif 204 #endif
157 205
158 int ngx_http_config_modules(ngx_pool_t *pool, ngx_http_module_t **modules) 206
207 int ngx_http_config_modules(ngx_pool_t *pool, ngx_module_t **modules)
159 { 208 {
160 int i; 209 int i;
161 210 ngx_http_module_t *module;
162 for (i = 0; modules[i]; i++) { 211
163 modules[i]->index = i; 212 for (i = 0; modules[i]; i++) {
164 } 213 if (modules[i]->type != NGX_HTTP_MODULE_TYPE) {
165 214 continue;
166 ngx_max_module = i; 215 }
167 216
217 module = (ngx_http_module_t *) modules[i]->ctx;
218 module->index = i;
219 }
220
221 ngx_http_max_module = i;
222
223 #if 0
168 ngx_test_null(ngx_srv_conf, 224 ngx_test_null(ngx_srv_conf,
169 ngx_pcalloc(pool, sizeof(void *) * ngx_max_module), 225 ngx_pcalloc(pool, sizeof(void *) * ngx_http_max_module),
170 NGX_ERROR); 226 NGX_ERROR);
171 ngx_test_null(ngx_loc_conf, 227 ngx_test_null(ngx_loc_conf,
172 ngx_pcalloc(pool, sizeof(void *) * ngx_max_module), 228 ngx_pcalloc(pool, sizeof(void *) * ngx_http_max_module),
173 NGX_ERROR); 229 NGX_ERROR);
174 230
175 for (i = 0; modules[i]; i++) { 231 for (i = 0; modules[i]; i++) {
176 if (modules[i]->create_srv_conf) 232 if (modules[i]->create_srv_conf)
177 ngx_srv_conf[i] = modules[i]->create_srv_conf(pool); 233 ngx_srv_conf[i] = modules[i]->create_srv_conf(pool);
178 234
179 if (modules[i]->create_loc_conf) 235 if (modules[i]->create_loc_conf)
180 ngx_loc_conf[i] = modules[i]->create_loc_conf(pool); 236 ngx_loc_conf[i] = modules[i]->create_loc_conf(pool);
181 } 237 }
182 } 238 #endif
183 239 }
184 int ngx_http_init_modules(ngx_pool_t *pool, ngx_http_module_t **modules) 240
185 { 241
186 int i; 242 void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules)
187 243 {
188 for (i = 0; modules[i]; i++) { 244 int i;
189 if (modules[i]->init_module) 245 ngx_http_module_t *module;
190 modules[i]->init_module(pool);
191 }
192 }
193
194 int ngx_http_init_filters(ngx_pool_t *pool, ngx_http_module_t **modules)
195 {
196 int i;
197 int (*ohf)(ngx_http_request_t *r); 246 int (*ohf)(ngx_http_request_t *r);
198 int (*obf)(ngx_http_request_t *r, ngx_chain_t *ch); 247 int (*obf)(ngx_http_request_t *r, ngx_chain_t *ch);
199 248
200 ohf = NULL; 249 ohf = NULL;
201 250 obf = NULL;
202 for (i = 0; modules[i]; i++) { 251
203 if (modules[i]->output_header_filter) { 252 for (i = 0; modules[i]; i++) {
204 modules[i]->next_output_header_filter = ohf; 253 if (modules[i]->type != NGX_HTTP_MODULE_TYPE) {
205 ohf = modules[i]->output_header_filter; 254 continue;
255 }
256
257 module = (ngx_http_module_t *) modules[i]->ctx;
258 if (module->output_header_filter) {
259 module->next_output_header_filter = ohf;
260 ohf = module->output_header_filter;
261 }
262
263 if (module->output_body_filter) {
264 module->next_output_body_filter = obf;
265 obf = module->output_body_filter;
206 } 266 }
207 } 267 }
208 268
209 ngx_http_top_header_filter = ohf; 269 ngx_http_top_header_filter = ohf;
210 270 }
211 obf = NULL;
212
213 for (i = 0; modules[i]; i++) {
214 if (modules[i]->output_body_filter) {
215 modules[i]->next_output_body_filter = obf;
216 obf = modules[i]->output_body_filter;
217 }
218 }
219 }
220
221
222 /* STUB */
223 ngx_http_output_filter_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
224 {
225 int i;
226 ngx_command_t *cmd;
227
228 for (i = 0; modules[i]; i++) {
229 if (modules[i] == &ngx_http_output_filter_module) {
230 for (cmd = modules[i]->commands; cmd->name; cmd++) {
231 if (strcmp(cmd->name, "output_buffer") == 0) {
232 cmd->set(ngx_loc_conf[i], cmd->offset, "32768");
233 }
234 }
235 }
236 }
237 }
238
239 ngx_http_write_filter_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
240 {
241 int i;
242 ngx_command_t *cmd;
243
244 for (i = 0; modules[i]; i++) {
245 if (modules[i] == &ngx_http_write_filter_module) {
246 for (cmd = modules[i]->commands; cmd->name; cmd++) {
247 if (strcmp(cmd->name, "write_buffer") == 0) {
248 cmd->set(ngx_loc_conf[i], cmd->offset, "1500");
249 }
250 }
251 }
252 }
253 }
254
255 ngx_http_index_set_stub(ngx_pool_t *pool, ngx_http_module_t **modules)
256 {
257 int i;
258 ngx_str_t index;
259 ngx_command_t *cmd;
260
261 for (i = 0; modules[i]; i++) {
262 if (modules[i] == &ngx_http_index_module) {
263 for (cmd = modules[i]->commands; cmd->name; cmd++) {
264 if (strcmp(cmd->name, "index") == 0) {
265 index.len = sizeof("index.html") - 1;
266 index.data = "index.html";
267 cmd->set(pool, ngx_loc_conf[i], &index);
268 }
269 }
270 }
271 }
272 }