Mercurial > hg > nginx-quic
comparison src/http/ngx_http_core_module.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 | src/http/ngx_http_core.c@53cd05892261 |
children | f1ee46c036a4 |
comparison
equal
deleted
inserted
replaced
43:53cd05892261 | 44:0e81ac0bb3e2 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 | |
4 #include <ngx_core.h> | |
5 #include <ngx_conf_file.h> | |
6 | |
7 #include <ngx_http.h> | |
8 #include <ngx_http_config.h> | |
9 #include <ngx_http_core_module.h> | |
10 | |
11 #if 0 | |
12 #include <ngx_http_write_filter.h> | |
13 #include <ngx_http_output_filter.h> | |
14 #include <ngx_http_index_handler.h> | |
15 #endif | |
16 | |
17 /* STUB */ | |
18 #include <ngx_http_output_filter.h> | |
19 int ngx_http_static_handler(ngx_http_request_t *r); | |
20 int ngx_http_index_handler(ngx_http_request_t *r); | |
21 int ngx_http_proxy_handler(ngx_http_request_t *r); | |
22 /**/ | |
23 | |
24 | |
25 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); | |
26 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, | |
27 char *dummy); | |
28 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); | |
29 static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf); | |
30 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); | |
31 | |
32 | |
33 static ngx_command_t ngx_http_core_commands[] = { | |
34 | |
35 {ngx_string("server"), | |
36 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
37 ngx_server_block, | |
38 0, | |
39 0}, | |
40 | |
41 {ngx_string("location"), | |
42 NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
43 ngx_location_block, | |
44 0, | |
45 0}, | |
46 | |
47 {ngx_string("root"), | |
48 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
49 ngx_conf_set_str_slot, | |
50 NGX_HTTP_LOC_CONF_OFFSET, | |
51 offsetof(ngx_http_core_loc_conf_t, doc_root)}, | |
52 | |
53 {ngx_string("send_timeout"), | |
54 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, | |
55 ngx_conf_set_time_slot, | |
56 NGX_HTTP_LOC_CONF_OFFSET, | |
57 offsetof(ngx_http_core_loc_conf_t, send_timeout)}, | |
58 | |
59 {ngx_string(""), 0, NULL, 0, 0} | |
60 }; | |
61 | |
62 | |
63 ngx_http_module_t ngx_http_core_module_ctx = { | |
64 NGX_HTTP_MODULE, | |
65 | |
66 ngx_http_core_create_srv_conf, /* create server config */ | |
67 ngx_http_core_init_srv_conf, /* init server config */ | |
68 ngx_http_core_create_loc_conf, /* create location config */ | |
69 NULL, /* merge location config */ | |
70 | |
71 ngx_http_core_translate_handler, /* translate handler */ | |
72 | |
73 NULL, /* output header filter */ | |
74 NULL, /* next output header filter */ | |
75 NULL, /* output body filter */ | |
76 NULL /* next output body filter */ | |
77 }; | |
78 | |
79 | |
80 ngx_module_t ngx_http_core_module = { | |
81 0, /* module index */ | |
82 &ngx_http_core_module_ctx, /* module context */ | |
83 ngx_http_core_commands, /* module directives */ | |
84 NGX_HTTP_MODULE_TYPE, /* module type */ | |
85 NULL /* init module */ | |
86 }; | |
87 | |
88 | |
89 int ngx_http_handler(ngx_http_request_t *r) | |
90 { | |
91 int rc, i; | |
92 ngx_http_module_t *module; | |
93 ngx_http_conf_ctx_t *ctx; | |
94 | |
95 r->connection->unexpected_eof = 0; | |
96 r->lingering_close = 1; | |
97 r->keepalive = 0; | |
98 | |
99 ctx = (ngx_http_conf_ctx_t *) r->connection->ctx; | |
100 r->srv_conf = ctx->srv_conf; | |
101 r->loc_conf = ctx->loc_conf; | |
102 | |
103 ngx_log_debug(r->connection->log, "srv_conf: %0x" _ r->srv_conf); | |
104 ngx_log_debug(r->connection->log, "loc_conf: %0x" _ r->loc_conf); | |
105 ngx_log_debug(r->connection->log, "servers: %0x" _ r->connection->servers); | |
106 | |
107 | |
108 #if 1 | |
109 r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; | |
110 #endif | |
111 | |
112 /* run translation phase */ | |
113 for (i = 0; ngx_modules[i]; i++) { | |
114 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
115 continue; | |
116 } | |
117 | |
118 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | |
119 | |
120 if (module->translate_handler == NULL) { | |
121 continue; | |
122 } | |
123 | |
124 rc = module->translate_handler(r); | |
125 if (rc == NGX_OK) { | |
126 break; | |
127 } | |
128 | |
129 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
130 return ngx_http_special_response(r, rc); | |
131 } | |
132 } | |
133 | |
134 rc = r->handler(r); | |
135 | |
136 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
137 return ngx_http_special_response(r, rc); | |
138 } | |
139 | |
140 return rc; | |
141 } | |
142 | |
143 | |
144 int ngx_http_core_translate_handler(ngx_http_request_t *r) | |
145 { | |
146 int i, rc; | |
147 char *location, *last; | |
148 ngx_err_t err; | |
149 ngx_table_elt_t *h; | |
150 ngx_http_core_srv_conf_t *scf; | |
151 ngx_http_core_loc_conf_t **lcf, *loc_conf; | |
152 | |
153 scf = (ngx_http_core_srv_conf_t *) | |
154 ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx); | |
155 | |
156 /* find location config */ | |
157 lcf = (ngx_http_core_loc_conf_t **) scf->locations.elts; | |
158 for (i = 0; i < scf->locations.nelts; i++) { | |
159 ngx_log_debug(r->connection->log, "trans: %s" _ lcf[i]->name.data); | |
160 if (r->uri.len < lcf[i]->name.len) { | |
161 continue; | |
162 } | |
163 | |
164 rc = ngx_strncmp(r->uri.data, lcf[i]->name.data, lcf[i]->name.len); | |
165 | |
166 if (rc < 0) { | |
167 break; | |
168 } | |
169 | |
170 if (rc == 0) { | |
171 r->loc_conf = lcf[i]->loc_conf; | |
172 } | |
173 } | |
174 | |
175 if (r->uri.data[r->uri.len - 1] == '/') { | |
176 /* TODO: find index handler */ | |
177 /* STUB */ r->handler = ngx_http_index_handler; | |
178 | |
179 return NGX_OK; | |
180 } | |
181 | |
182 loc_conf = (ngx_http_core_loc_conf_t *) | |
183 ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx); | |
184 | |
185 r->file.name.len = loc_conf->doc_root.len + r->uri.len; | |
186 | |
187 ngx_test_null(r->file.name.data, | |
188 ngx_palloc(r->pool, r->file.name.len + 1), | |
189 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
190 | |
191 location = ngx_cpystrn(r->file.name.data, loc_conf->doc_root.data, | |
192 loc_conf->doc_root.len + 1); | |
193 last = ngx_cpystrn(location, r->uri.data, r->uri.len + 1); | |
194 | |
195 ngx_log_debug(r->connection->log, "HTTP filename: '%s'" _ | |
196 r->file.name.data); | |
197 | |
198 #if (WIN9X) | |
199 | |
200 /* There is no way to open file or directory in Win9X with | |
201 one syscall: Win9X has not FILE_FLAG_BACKUP_SEMANTICS flag. | |
202 so we need to check its type before opening */ | |
203 | |
204 r->file.info.dwFileAttributes = GetFileAttributes(r->file.name.data); | |
205 if (r->file.info.dwFileAttributes == INVALID_FILE_ATTRIBUTES) { | |
206 err = ngx_errno; | |
207 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | |
208 "ngx_http_core_translate_handler: " | |
209 ngx_file_type_n " %s failed", r->file.name.data); | |
210 | |
211 if (err == ERROR_FILE_NOT_FOUND) { | |
212 return NGX_HTTP_NOT_FOUND; | |
213 } else if (err == ERROR_PATH_NOT_FOUND) { | |
214 return NGX_HTTP_NOT_FOUND; | |
215 } else { | |
216 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
217 } | |
218 } | |
219 | |
220 #else | |
221 | |
222 if (r->file.fd == NGX_INVALID_FILE) { | |
223 r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY); | |
224 } | |
225 | |
226 if (r->file.fd == NGX_INVALID_FILE) { | |
227 err = ngx_errno; | |
228 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
229 "ngx_http_core_handler: " | |
230 ngx_open_file_n " %s failed", r->file.name.data); | |
231 | |
232 if (err == NGX_ENOENT) { | |
233 return NGX_HTTP_NOT_FOUND; | |
234 #if (WIN32) | |
235 } else if (err == ERROR_PATH_NOT_FOUND) { | |
236 return NGX_HTTP_NOT_FOUND; | |
237 #endif | |
238 } else { | |
239 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
240 } | |
241 } | |
242 | |
243 if (!r->file.info_valid) { | |
244 if (ngx_stat_fd(r->file.fd, &r->file.info) == NGX_FILE_ERROR) { | |
245 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
246 "ngx_http_core_handler: " | |
247 ngx_stat_fd_n " %s failed", r->file.name.data); | |
248 | |
249 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | |
250 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
251 "ngx_http_core_handler: " | |
252 ngx_close_file_n " %s failed", r->file.name.data); | |
253 } | |
254 | |
255 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
256 } | |
257 | |
258 r->file.info_valid = 1; | |
259 } | |
260 #endif | |
261 | |
262 if (ngx_is_dir(r->file.info)) { | |
263 ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data); | |
264 | |
265 #if !(WIN9X) | |
266 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | |
267 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
268 "ngx_http_core_handler: " | |
269 ngx_close_file_n " %s failed", r->file.name.data); | |
270 } | |
271 #endif | |
272 | |
273 /* BROKEN: need to include server name */ | |
274 | |
275 ngx_test_null(h, ngx_push_table(r->headers_out.headers), | |
276 NGX_HTTP_INTERNAL_SERVER_ERROR); | |
277 | |
278 *last++ = '/'; | |
279 *last = '\0'; | |
280 h->key.len = 8; | |
281 h->key.data = "Location" ; | |
282 h->value.len = last - location; | |
283 h->value.data = location; | |
284 r->headers_out.location = h; | |
285 | |
286 return NGX_HTTP_MOVED_PERMANENTLY; | |
287 } | |
288 | |
289 /* TODO: r->handler = loc_conf->default_handler; */ | |
290 /* STUB */ r->handler = ngx_http_static_handler; | |
291 | |
292 return NGX_OK; | |
293 } | |
294 | |
295 | |
296 int ngx_http_send_header(ngx_http_request_t *r) | |
297 { | |
298 return (*ngx_http_top_header_filter)(r); | |
299 } | |
300 | |
301 | |
302 int ngx_http_redirect(ngx_http_request_t *r, int redirect) | |
303 { | |
304 /* STUB */ | |
305 | |
306 /* log request */ | |
307 | |
308 return ngx_http_close_request(r); | |
309 } | |
310 | |
311 | |
312 int ngx_http_error(ngx_http_request_t *r, int error) | |
313 { | |
314 /* STUB */ | |
315 ngx_log_debug(r->connection->log, "http error: %d" _ error); | |
316 | |
317 /* log request */ | |
318 | |
319 ngx_http_special_response(r, error); | |
320 return ngx_http_close_request(r); | |
321 } | |
322 | |
323 | |
324 int ngx_http_close_request(ngx_http_request_t *r) | |
325 { | |
326 ngx_log_debug(r->connection->log, "CLOSE#: %d" _ r->file.fd); | |
327 | |
328 ngx_http_log_handler(r); | |
329 | |
330 ngx_assert((r->file.fd != NGX_INVALID_FILE), /* void */ ; , | |
331 r->connection->log, "file already closed"); | |
332 | |
333 if (r->file.fd != NGX_INVALID_FILE) { | |
334 if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { | |
335 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, | |
336 ngx_close_file_n " failed"); | |
337 } | |
338 } | |
339 | |
340 /* | |
341 if (r->logging) | |
342 ngx_http_log_request(r); | |
343 */ | |
344 | |
345 ngx_destroy_pool(r->pool); | |
346 | |
347 ngx_log_debug(r->connection->log, "http close"); | |
348 | |
349 ngx_del_timer(r->connection->read); | |
350 ngx_del_timer(r->connection->write); | |
351 | |
352 return NGX_DONE; | |
353 } | |
354 | |
355 | |
356 int ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t uri) | |
357 { | |
358 ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri.data); | |
359 | |
360 r->uri.len = uri.len; | |
361 r->uri.data = uri.data; | |
362 | |
363 /* NEEDED ? */ | |
364 r->uri_start = uri.data; | |
365 r->uri_end = uri.data + uri.len; | |
366 /**/ | |
367 | |
368 return ngx_http_handler(r); | |
369 } | |
370 | |
371 | |
372 #if 0 | |
373 void *ngx_http_find_server_conf(ngx_http_request_t *r) | |
374 { | |
375 int i; | |
376 ngx_http_listen_t *fs, *ls; | |
377 ngx_http_server_name_t *n; | |
378 | |
379 fs = NULL; | |
380 ls = (ngx_http_listen_t *) http->ports.elts; | |
381 | |
382 for (i = 0; i < http->ports.nelts; i++) { | |
383 if (s->family != ls[i].family || s->port != ls[i].port) { | |
384 continue; | |
385 } | |
386 | |
387 if (s->family == AF_INET) { | |
388 | |
389 if (ls[i].addr == INADDR_ANY || ls[i].addr == s->addr) { | |
390 fs = &ls[i]; | |
391 break; | |
392 } | |
393 | |
394 } else { | |
395 /* STUB: AF_INET only */ | |
396 } | |
397 } | |
398 | |
399 if (fs == NULL) { | |
400 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
401 "unknown local socket %s:%d", | |
402 s->addr_text.data, s->port); | |
403 return NULL; | |
404 } | |
405 | |
406 if (r->headers_in.host && fs->server_names.nelts) { | |
407 | |
408 n = (ngx_http_server_name_t *) fs->server_names.elts; | |
409 for (i = 0; i < fs->server_names.nelts; i++) { | |
410 if (r->headers_in.host->value.len != n[i].name.len) { | |
411 continue; | |
412 } | |
413 | |
414 if (ngx_strcmp(r->headers_in.host->value.data, n[i].name.data) == 0) { | |
415 return n[i].srv_conf; | |
416 } | |
417 } | |
418 } | |
419 | |
420 return fs->srv_conf; | |
421 } | |
422 #endif | |
423 | |
424 | |
425 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) | |
426 { | |
427 int i, j; | |
428 char *rv; | |
429 ngx_http_module_t *module; | |
430 ngx_http_conf_ctx_t *ctx, *prev; | |
431 ngx_http_core_srv_conf_t *scf; | |
432 ngx_http_core_loc_conf_t **lcf; | |
433 | |
434 ngx_test_null(ctx, | |
435 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | |
436 NGX_CONF_ERROR); | |
437 | |
438 /* server config */ | |
439 ngx_test_null(ctx->srv_conf, | |
440 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
441 NGX_CONF_ERROR); | |
442 | |
443 /* server location config */ | |
444 ngx_test_null(ctx->loc_conf, | |
445 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
446 NGX_CONF_ERROR); | |
447 | |
448 for (i = 0; ngx_modules[i]; i++) { | |
449 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
450 continue; | |
451 } | |
452 | |
453 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | |
454 | |
455 if (module->create_srv_conf) { | |
456 ngx_test_null(ctx->srv_conf[module->index], | |
457 module->create_srv_conf(cf->pool), | |
458 NGX_CONF_ERROR); | |
459 ngx_log_debug(cf->log, "srv_conf: %d:%0x" _ | |
460 module->index _ ctx->loc_conf[module->index]); | |
461 } | |
462 | |
463 if (module->create_loc_conf) { | |
464 ngx_test_null(ctx->loc_conf[module->index], | |
465 module->create_loc_conf(cf->pool), | |
466 NGX_CONF_ERROR); | |
467 ngx_log_debug(cf->log, "srv loc_conf: %d:%0x" _ | |
468 module->index _ ctx->loc_conf[module->index]); | |
469 } | |
470 } | |
471 | |
472 prev = cf->ctx; | |
473 cf->ctx = ctx; | |
474 rv = ngx_conf_parse(cf, NULL); | |
475 cf->ctx = prev; | |
476 | |
477 if (rv != NGX_CONF_OK) | |
478 return rv; | |
479 | |
480 | |
481 scf = ctx->srv_conf[ngx_http_core_module_ctx.index]; | |
482 scf->ctx = ctx; | |
483 | |
484 lcf = (ngx_http_core_loc_conf_t **)scf->locations.elts; | |
485 | |
486 for (i = 0; ngx_modules[i]; i++) { | |
487 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
488 continue; | |
489 } | |
490 | |
491 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | |
492 | |
493 if (module->init_srv_conf) { | |
494 if (module->init_srv_conf(cf->pool, | |
495 ctx->srv_conf[module->index]) | |
496 == NGX_CONF_ERROR) { | |
497 return NGX_CONF_ERROR; | |
498 } | |
499 } | |
500 | |
501 if (module->merge_loc_conf) { | |
502 if (module->merge_loc_conf(cf->pool, | |
503 prev->loc_conf[module->index], | |
504 ctx->loc_conf[module->index]) | |
505 == NGX_CONF_ERROR) { | |
506 return NGX_CONF_ERROR; | |
507 } | |
508 | |
509 for (j = 0; j < scf->locations.nelts; j++) { | |
510 ngx_log_debug(cf->log, "%d:%0x" _ j _ lcf[j]); | |
511 ngx_log_debug(cf->log, "%d:'%s'" _ lcf[j]->name.len _ lcf[j]->name.data); | |
512 if (module->merge_loc_conf(cf->pool, | |
513 ctx->loc_conf[module->index], | |
514 lcf[j]->loc_conf[module->index]) | |
515 == NGX_CONF_ERROR) { | |
516 return NGX_CONF_ERROR; | |
517 } | |
518 } | |
519 } | |
520 } | |
521 | |
522 return NGX_CONF_OK; | |
523 } | |
524 | |
525 | |
526 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) | |
527 { | |
528 int i; | |
529 char *rv; | |
530 void **loc; | |
531 ngx_str_t *location; | |
532 ngx_http_module_t *module; | |
533 ngx_http_conf_ctx_t *ctx, *prev; | |
534 ngx_http_core_srv_conf_t *scf; | |
535 ngx_http_core_loc_conf_t *lcf; | |
536 | |
537 ngx_test_null(ctx, | |
538 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | |
539 NGX_CONF_ERROR); | |
540 | |
541 prev = (ngx_http_conf_ctx_t *) cf->ctx; | |
542 ctx->srv_conf = prev->srv_conf; | |
543 | |
544 ngx_test_null(ctx->loc_conf, | |
545 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | |
546 NGX_CONF_ERROR); | |
547 | |
548 for (i = 0; ngx_modules[i]; i++) { | |
549 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
550 continue; | |
551 } | |
552 | |
553 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | |
554 | |
555 if (module->create_loc_conf) { | |
556 ngx_test_null(ctx->loc_conf[module->index], | |
557 module->create_loc_conf(cf->pool), | |
558 NGX_CONF_ERROR); | |
559 ngx_log_debug(cf->log, "loc_conf: %d:%0x" _ | |
560 module->index _ ctx->loc_conf[module->index]); | |
561 } | |
562 } | |
563 | |
564 lcf = (ngx_http_core_loc_conf_t *) | |
565 ctx->loc_conf[ngx_http_core_module_ctx.index]; | |
566 location = (ngx_str_t *) cf->args->elts; | |
567 lcf->name.len = location[1].len; | |
568 lcf->name.data = location[1].data; | |
569 lcf->loc_conf = ctx->loc_conf; | |
570 | |
571 scf = (ngx_http_core_srv_conf_t *) | |
572 ctx->srv_conf[ngx_http_core_module_ctx.index]; | |
573 ngx_test_null(loc, ngx_push_array(&scf->locations), NGX_CONF_ERROR); | |
574 *loc = lcf; | |
575 | |
576 ngx_log_debug(cf->log, "%0x:%s" _ lcf _ lcf->name.data); | |
577 | |
578 cf->ctx = ctx; | |
579 rv = ngx_conf_parse(cf, NULL); | |
580 cf->ctx = prev; | |
581 | |
582 return rv; | |
583 } | |
584 | |
585 | |
586 int ngx_http_config_modules(ngx_pool_t *pool, ngx_module_t **modules) | |
587 { | |
588 int i; | |
589 ngx_http_module_t *module; | |
590 | |
591 for (i = 0; modules[i]; i++) { | |
592 if (modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
593 continue; | |
594 } | |
595 | |
596 module = (ngx_http_module_t *) modules[i]->ctx; | |
597 module->index = i; | |
598 } | |
599 | |
600 ngx_http_max_module = i; | |
601 | |
602 #if 0 | |
603 ngx_test_null(ngx_srv_conf, | |
604 ngx_pcalloc(pool, sizeof(void *) * ngx_http_max_module), | |
605 NGX_ERROR); | |
606 ngx_test_null(ngx_loc_conf, | |
607 ngx_pcalloc(pool, sizeof(void *) * ngx_http_max_module), | |
608 NGX_ERROR); | |
609 | |
610 for (i = 0; modules[i]; i++) { | |
611 if (modules[i]->create_srv_conf) | |
612 ngx_srv_conf[i] = modules[i]->create_srv_conf(pool); | |
613 | |
614 if (modules[i]->create_loc_conf) | |
615 ngx_loc_conf[i] = modules[i]->create_loc_conf(pool); | |
616 } | |
617 #endif | |
618 } | |
619 | |
620 | |
621 void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules) | |
622 { | |
623 int i; | |
624 ngx_http_module_t *module; | |
625 int (*ohf)(ngx_http_request_t *r); | |
626 int (*obf)(ngx_http_request_t *r, ngx_chain_t *ch); | |
627 | |
628 ohf = NULL; | |
629 obf = NULL; | |
630 | |
631 for (i = 0; modules[i]; i++) { | |
632 if (modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
633 continue; | |
634 } | |
635 | |
636 module = (ngx_http_module_t *) modules[i]->ctx; | |
637 | |
638 if (module->output_header_filter) { | |
639 module->next_output_header_filter = ohf; | |
640 ohf = module->output_header_filter; | |
641 } | |
642 | |
643 if (module->output_body_filter) { | |
644 module->next_output_body_filter = obf; | |
645 obf = module->output_body_filter; | |
646 } | |
647 } | |
648 | |
649 ngx_http_top_header_filter = ohf; | |
650 } | |
651 | |
652 | |
653 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) | |
654 { | |
655 ngx_http_core_srv_conf_t *scf, **cf; | |
656 | |
657 ngx_test_null(scf, | |
658 ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)), | |
659 NGX_CONF_ERROR); | |
660 | |
661 ngx_init_array(scf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR); | |
662 ngx_init_array(scf->listen, pool, 5, sizeof(ngx_http_listen_t), | |
663 NGX_CONF_ERROR); | |
664 | |
665 ngx_test_null(cf, ngx_push_array(&ngx_http_servers), NGX_CONF_ERROR); | |
666 *cf = scf; | |
667 | |
668 return scf; | |
669 } | |
670 | |
671 | |
672 static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf) | |
673 { | |
674 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf; | |
675 | |
676 ngx_http_listen_t *l; | |
677 | |
678 if (scf->listen.nelts == 0) { | |
679 ngx_test_null(l, ngx_push_array(&scf->listen), NGX_CONF_ERROR); | |
680 l->addr = INADDR_ANY; | |
681 l->port = 8000; | |
682 l->family = AF_INET; | |
683 } | |
684 | |
685 return NGX_CONF_OK; | |
686 } | |
687 | |
688 | |
689 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool) | |
690 { | |
691 ngx_http_core_loc_conf_t *lcf; | |
692 | |
693 ngx_test_null(lcf, | |
694 ngx_pcalloc(pool, sizeof(ngx_http_core_loc_conf_t)), | |
695 NGX_CONF_ERROR); | |
696 | |
697 lcf->doc_root.len = 4; | |
698 lcf->doc_root.data = "html"; | |
699 | |
700 lcf->send_timeout = 10; | |
701 lcf->discarded_buffer_size = 1500; | |
702 lcf->lingering_time = 30; | |
703 lcf->lingering_timeout = 5000; | |
704 | |
705 /* | |
706 lcf->send_timeout = NGX_CONF_UNSET; | |
707 */ | |
708 | |
709 return lcf; | |
710 } |