comparison src/http/ngx_http_core_module.c @ 91:637625a2acdb

nginx-0.0.1-2003-05-19-20:39:14 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 19 May 2003 16:39:14 +0000
parents 37530da31268
children 19cc647ecd91
comparison
equal deleted inserted replaced
90:37530da31268 91:637625a2acdb
4 #include <ngx_listen.h> 4 #include <ngx_listen.h>
5 #include <ngx_core.h> 5 #include <ngx_core.h>
6 #include <ngx_string.h> 6 #include <ngx_string.h>
7 #include <ngx_conf_file.h> 7 #include <ngx_conf_file.h>
8 8
9 #include <nginx.h>
10
9 #include <ngx_http.h> 11 #include <ngx_http.h>
10 #include <ngx_http_config.h> 12 #include <ngx_http_config.h>
11 #include <ngx_http_core_module.h> 13 #include <ngx_http_core_module.h>
12 14
15
13 /* STUB for r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; */ 16 /* STUB for r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; */
14 #include <ngx_http_output_filter.h> 17 #include <ngx_http_output_filter.h>
15 18
16 int ngx_http_static_handler(ngx_http_request_t *r); 19 int ngx_http_static_handler(ngx_http_request_t *r);
17 int ngx_http_proxy_handler(ngx_http_request_t *r); 20 int ngx_http_proxy_handler(ngx_http_request_t *r);
19 22
20 static int ngx_http_core_index_handler(ngx_http_request_t *r); 23 static int ngx_http_core_index_handler(ngx_http_request_t *r);
21 24
22 static int ngx_http_core_init(ngx_pool_t *pool); 25 static int ngx_http_core_init(ngx_pool_t *pool);
23 26
27 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool);
28 static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf);
24 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool); 29 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool);
25 static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf); 30 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
31 void *parent, void *child);
26 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool); 32 static void *ngx_http_core_create_loc_conf(ngx_pool_t *pool);
27 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool, 33 static char *ngx_http_core_merge_loc_conf(ngx_pool_t *pool,
28 void *parent, void *child); 34 void *parent, void *child);
29 35
30 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); 36 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy);
44 NULL,}, 50 NULL,},
45 51
46 {ngx_string("post_accept_timeout"), 52 {ngx_string("post_accept_timeout"),
47 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 53 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
48 ngx_conf_set_msec_slot, 54 ngx_conf_set_msec_slot,
49 0, 55 NGX_HTTP_MAIN_CONF_OFFSET,
50 addressof(ngx_http_post_accept_timeout), 56 offsetof(ngx_http_core_main_conf_t, post_accept_timeout),
51 NULL}, 57 NULL},
52 58
53 {ngx_string("connection_pool_size"), 59 {ngx_string("connection_pool_size"),
54 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 60 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
55 ngx_conf_set_size_slot, 61 ngx_conf_set_size_slot,
56 0, 62 NGX_HTTP_MAIN_CONF_OFFSET,
57 addressof(ngx_http_connection_pool_size), 63 offsetof(ngx_http_core_main_conf_t, connection_pool_size),
58 NULL}, 64 NULL},
59 65
60 {ngx_string("request_pool_size"), 66 {ngx_string("request_pool_size"),
61 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 67 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
62 ngx_conf_set_size_slot, 68 ngx_conf_set_size_slot,
63 0, 69 NGX_HTTP_MAIN_CONF_OFFSET,
64 addressof(ngx_http_request_pool_size), 70 offsetof(ngx_http_core_main_conf_t, request_pool_size),
65 NULL}, 71 NULL},
66 72
67 {ngx_string("client_header_timeout"), 73 {ngx_string("client_header_timeout"),
68 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 74 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
69 ngx_conf_set_msec_slot, 75 ngx_conf_set_msec_slot,
70 0, 76 NGX_HTTP_MAIN_CONF_OFFSET,
71 addressof(ngx_http_client_header_timeout), 77 offsetof(ngx_http_core_main_conf_t, client_header_timeout),
72 NULL}, 78 NULL},
73 79
74 {ngx_string("client_header_buffer_size"), 80 {ngx_string("client_header_buffer_size"),
75 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, 81 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
76 ngx_conf_set_size_slot, 82 ngx_conf_set_size_slot,
79 NULL}, 85 NULL},
80 86
81 {ngx_string("large_client_header"), 87 {ngx_string("large_client_header"),
82 NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG, 88 NGX_HTTP_MAIN_CONF|NGX_CONF_FLAG,
83 ngx_conf_set_flag_slot, 89 ngx_conf_set_flag_slot,
84 0, 90 NGX_HTTP_MAIN_CONF_OFFSET,
85 addressof(ngx_http_large_client_header), 91 offsetof(ngx_http_core_main_conf_t, large_client_header),
86 NULL}, 92 NULL},
87 93
88 {ngx_string("location"), 94 {ngx_string("location"),
89 NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, 95 NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
90 ngx_location_block, 96 ngx_location_block,
91 NGX_HTTP_SRV_CONF_OFFSET, 97 NGX_HTTP_SRV_CONF_OFFSET,
92 0, 98 0,
93 NULL}, 99 NULL},
94 100
95 {ngx_string("listen"), 101 {ngx_string("listen"),
96 NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, 102 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
97 ngx_set_listen, 103 ngx_set_listen,
98 NGX_HTTP_SRV_CONF_OFFSET, 104 NGX_HTTP_SRV_CONF_OFFSET,
99 0, 105 0,
100 NULL}, 106 NULL},
101 107
102 {ngx_string("types"), 108 {ngx_string("types"),
103 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, 109 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
110 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
104 ngx_types_block, 111 ngx_types_block,
105 NGX_HTTP_LOC_CONF_OFFSET, 112 NGX_HTTP_LOC_CONF_OFFSET,
106 0, 113 0,
107 NULL}, 114 NULL},
108 115
109 {ngx_string("root"), 116 {ngx_string("root"),
110 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 117 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
111 ngx_conf_set_str_slot, 118 ngx_conf_set_str_slot,
112 NGX_HTTP_LOC_CONF_OFFSET, 119 NGX_HTTP_LOC_CONF_OFFSET,
113 offsetof(ngx_http_core_loc_conf_t, doc_root), 120 offsetof(ngx_http_core_loc_conf_t, doc_root),
114 NULL}, 121 NULL},
115 122
116 {ngx_string("sendfile"), 123 {ngx_string("sendfile"),
117 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 124 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
118 ngx_conf_set_flag_slot, 125 ngx_conf_set_flag_slot,
119 NGX_HTTP_LOC_CONF_OFFSET, 126 NGX_HTTP_LOC_CONF_OFFSET,
120 offsetof(ngx_http_core_loc_conf_t, sendfile), 127 offsetof(ngx_http_core_loc_conf_t, sendfile),
121 NULL}, 128 NULL},
122 129
123 {ngx_string("send_timeout"), 130 {ngx_string("send_timeout"),
124 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
125 ngx_conf_set_msec_slot, 132 ngx_conf_set_msec_slot,
126 NGX_HTTP_LOC_CONF_OFFSET, 133 NGX_HTTP_LOC_CONF_OFFSET,
127 offsetof(ngx_http_core_loc_conf_t, send_timeout), 134 offsetof(ngx_http_core_loc_conf_t, send_timeout),
128 NULL}, 135 NULL},
129 136
130 {ngx_string("lingering_time"), 137 {ngx_string("lingering_time"),
131 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
132 ngx_conf_set_msec_slot, 139 ngx_conf_set_msec_slot,
133 NGX_HTTP_LOC_CONF_OFFSET, 140 NGX_HTTP_LOC_CONF_OFFSET,
134 offsetof(ngx_http_core_loc_conf_t, lingering_time), 141 offsetof(ngx_http_core_loc_conf_t, lingering_time),
135 NULL}, 142 NULL},
136 143
137 {ngx_string("lingering_timeout"), 144 {ngx_string("lingering_timeout"),
138 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 145 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
139 ngx_conf_set_msec_slot, 146 ngx_conf_set_msec_slot,
140 NGX_HTTP_LOC_CONF_OFFSET, 147 NGX_HTTP_LOC_CONF_OFFSET,
141 offsetof(ngx_http_core_loc_conf_t, lingering_timeout), 148 offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
142 NULL}, 149 NULL},
143 150
146 153
147 154
148 ngx_http_module_t ngx_http_core_module_ctx = { 155 ngx_http_module_t ngx_http_core_module_ctx = {
149 NGX_HTTP_MODULE, 156 NGX_HTTP_MODULE,
150 157
151 ngx_http_core_create_srv_conf, /* create server config */ 158 ngx_http_core_create_main_conf, /* create main configuration */
152 ngx_http_core_init_srv_conf, /* init server config */ 159 ngx_http_core_init_main_conf, /* init main configuration */
153 160
154 ngx_http_core_create_loc_conf, /* create location config */ 161 ngx_http_core_create_srv_conf, /* create server configuration */
155 ngx_http_core_merge_loc_conf /* merge location config */ 162 ngx_http_core_merge_srv_conf, /* merge server configuration */
163
164 ngx_http_core_create_loc_conf, /* create location configuration */
165 ngx_http_core_merge_loc_conf /* merge location configuration */
156 }; 166 };
157 167
158 168
159 ngx_module_t ngx_http_core_module = { 169 ngx_module_t ngx_http_core_module = {
160 &ngx_http_core_module_ctx, /* module context */ 170 &ngx_http_core_module_ctx, /* module context */
205 ngx_log_debug(r->connection->log, "FOUND"); 215 ngx_log_debug(r->connection->log, "FOUND");
206 break; 216 break;
207 } 217 }
208 } 218 }
209 219
220 /* DEBUG */
210 if (a == in_port->addrs.nelts) { 221 if (a == in_port->addrs.nelts) {
211 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 222 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
212 "addr not found"); 223 "addr not found");
213 exit(1); 224 exit(1);
214 } 225 }
255 void ngx_http_handler(ngx_http_request_t *r) 266 void ngx_http_handler(ngx_http_request_t *r)
256 { 267 {
257 int rc, i; 268 int rc, i;
258 ngx_http_handler_pt *h; 269 ngx_http_handler_pt *h;
259 ngx_http_module_t *module; 270 ngx_http_module_t *module;
260 ngx_http_core_loc_conf_t *lcf, **plcf; 271 ngx_http_core_loc_conf_t *lcf, **lcfp;
261 ngx_http_core_srv_conf_t *scf; 272 ngx_http_core_srv_conf_t *scf;
262 273
263 r->connection->unexpected_eof = 0; 274 r->connection->unexpected_eof = 0;
264 275
265 r->keepalive = 0; 276 r->keepalive = 1;
266 277
267 if (r->headers_in.content_length_n > 0) { 278 if (r->headers_in.content_length_n > 0) {
268 r->lingering_close = 1; 279 r->lingering_close = 1;
269 } 280 }
270 281
277 /* find location config */ 288 /* find location config */
278 289
279 scf = (ngx_http_core_srv_conf_t *) 290 scf = (ngx_http_core_srv_conf_t *)
280 ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx); 291 ngx_http_get_module_srv_conf(r, ngx_http_core_module_ctx);
281 292
282 plcf = (ngx_http_core_loc_conf_t **) scf->locations.elts; 293 lcfp = (ngx_http_core_loc_conf_t **) scf->locations.elts;
283 for (i = 0; i < scf->locations.nelts; i++) { 294 for (i = 0; i < scf->locations.nelts; i++) {
284 #if 0 295 #if 0
285 ngx_log_debug(r->connection->log, "trans: %s" _ plcf[i]->name.data); 296 ngx_log_debug(r->connection->log, "trans: %s" _ lcfp[i]->name.data);
286 #endif 297 #endif
287 if (r->uri.len < plcf[i]->name.len) { 298 if (r->uri.len < lcfp[i]->name.len) {
288 continue; 299 continue;
289 } 300 }
290 301
291 rc = ngx_rstrncmp(r->uri.data, plcf[i]->name.data, plcf[i]->name.len); 302 rc = ngx_rstrncmp(r->uri.data, lcfp[i]->name.data, lcfp[i]->name.len);
292 303
293 if (rc < 0) { 304 if (rc < 0) {
294 break; 305 break;
295 } 306 }
296 307
297 if (rc == 0) { 308 if (rc == 0) {
298 r->loc_conf = plcf[i]->loc_conf; 309 r->loc_conf = lcfp[i]->loc_conf;
299 } 310 }
300 } 311 }
301 312
302 lcf = (ngx_http_core_loc_conf_t *) 313 lcf = (ngx_http_core_loc_conf_t *)
303 ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx); 314 ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
585 ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri.data); 596 ngx_log_debug(r->connection->log, "internal redirect: '%s'" _ uri.data);
586 597
587 r->uri.len = uri.len; 598 r->uri.len = uri.len;
588 r->uri.data = uri.data; 599 r->uri.data = uri.data;
589 600
590 /* NEEDED ? */ 601 /* BROKEN, NEEDED ? */
602 /* r->exten */
591 r->uri_start = uri.data; 603 r->uri_start = uri.data;
592 r->uri_end = uri.data + uri.len; 604 r->uri_end = uri.data + uri.len;
593 /**/ 605 /**/
594 606
595 ngx_http_handler(r); 607 ngx_http_handler(r);
609 } 621 }
610 622
611 623
612 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) 624 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
613 { 625 {
614 int i, j; 626 int i, j;
615 char *rv; 627 char *rv;
616 ngx_http_module_t *module; 628 ngx_http_module_t *module;
617 ngx_conf_t pcf; 629 ngx_conf_t pcf;
618 ngx_http_conf_ctx_t *ctx, *tctx, *pctx; 630 ngx_http_conf_ctx_t *ctx, *hctx, *pctx;
619 ngx_http_core_srv_conf_t *scf; 631 ngx_http_core_main_conf_t *cmcf;
620 ngx_http_core_loc_conf_t **plcf; 632 ngx_http_core_srv_conf_t *cscf, **cscfp;
621 633
622 ngx_test_null(ctx, 634 ngx_test_null(ctx,
623 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), 635 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
624 NGX_CONF_ERROR); 636 NGX_CONF_ERROR);
625 637
626 tctx = (ngx_http_conf_ctx_t *) cf->ctx; 638 hctx = (ngx_http_conf_ctx_t *) cf->ctx;
627 ctx->main_conf = tctx->main_conf; 639 ctx->main_conf = hctx->main_conf;
628 640
629 /* server configuration */ 641 /* the server{}'s srv_conf */
630 642
631 ngx_test_null(ctx->srv_conf, 643 ngx_test_null(ctx->srv_conf,
632 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), 644 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
633 NGX_CONF_ERROR); 645 NGX_CONF_ERROR);
634 646
635 /* server location configuration */ 647 /* the server{}'s loc_conf */
636 648
637 ngx_test_null(ctx->loc_conf, 649 ngx_test_null(ctx->loc_conf,
638 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), 650 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
639 NGX_CONF_ERROR); 651 NGX_CONF_ERROR);
640 652
655 ngx_test_null(ctx->loc_conf[module->index], 667 ngx_test_null(ctx->loc_conf[module->index],
656 module->create_loc_conf(cf->pool), 668 module->create_loc_conf(cf->pool),
657 NGX_CONF_ERROR); 669 NGX_CONF_ERROR);
658 } 670 }
659 } 671 }
672
673 /* create links of the srv_conf's */
674
675 cscf = ctx->srv_conf[ngx_http_core_module_ctx.index];
676 cscf->ctx = ctx;
677
678 cmcf = ctx->main_conf[ngx_http_core_module_ctx.index];
679 ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR);
680 *cscfp = cscf;
681
682 /* parse inside server{} */
660 683
661 pcf = *cf; 684 pcf = *cf;
662 pctx = cf->ctx; 685 pctx = cf->ctx;
663 cf->ctx = ctx; 686 cf->ctx = ctx;
664 cf->cmd_type = NGX_HTTP_SRV_CONF; 687 cf->cmd_type = NGX_HTTP_SRV_CONF;
665 rv = ngx_conf_parse(cf, NULL); 688 rv = ngx_conf_parse(cf, NULL);
666 *cf = pcf; 689 *cf = pcf;
667 690
668 if (rv != NGX_CONF_OK) 691 return rv;
669 return rv;
670
671
672 scf = ctx->srv_conf[ngx_http_core_module_ctx.index];
673 scf->ctx = ctx;
674
675 plcf = (ngx_http_core_loc_conf_t **)scf->locations.elts;
676
677 for (i = 0; ngx_modules[i]; i++) {
678 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
679 continue;
680 }
681
682 module = (ngx_http_module_t *) ngx_modules[i]->ctx;
683
684 if (module->init_srv_conf) {
685 if (module->init_srv_conf(cf->pool,
686 ctx->srv_conf[module->index])
687 == NGX_CONF_ERROR) {
688 return NGX_CONF_ERROR;
689 }
690 }
691
692 if (module->merge_loc_conf) {
693 rv = module->merge_loc_conf(cf->pool,
694 pctx->loc_conf[module->index],
695 ctx->loc_conf[module->index]);
696 if (rv != NGX_CONF_OK) {
697 return rv;
698 }
699
700 for (j = 0; j < scf->locations.nelts; j++) {
701 rv = module->merge_loc_conf(cf->pool,
702 ctx->loc_conf[module->index],
703 plcf[j]->loc_conf[module->index]);
704 if (rv != NGX_CONF_OK) {
705 return rv;
706 }
707 }
708 }
709 }
710
711 return NGX_CONF_OK;
712 } 692 }
713 693
714 694
715 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) 695 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
716 { 696 {
718 char *rv; 698 char *rv;
719 ngx_str_t *location; 699 ngx_str_t *location;
720 ngx_http_module_t *module; 700 ngx_http_module_t *module;
721 ngx_conf_t pcf; 701 ngx_conf_t pcf;
722 ngx_http_conf_ctx_t *ctx, *pctx; 702 ngx_http_conf_ctx_t *ctx, *pctx;
723 ngx_http_core_srv_conf_t *scf; 703 ngx_http_core_srv_conf_t *cscf;
724 ngx_http_core_loc_conf_t *lcf, **plcf; 704 ngx_http_core_loc_conf_t *clcf, **clcfp;
725 705
726 ngx_test_null(ctx, 706 ngx_test_null(ctx,
727 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), 707 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)),
728 NGX_CONF_ERROR); 708 NGX_CONF_ERROR);
729 709
730 pctx = (ngx_http_conf_ctx_t *) cf->ctx; 710 pctx = (ngx_http_conf_ctx_t *) cf->ctx;
711 ctx->main_conf = pctx->main_conf;
731 ctx->srv_conf = pctx->srv_conf; 712 ctx->srv_conf = pctx->srv_conf;
732 713
733 ngx_test_null(ctx->loc_conf, 714 ngx_test_null(ctx->loc_conf,
734 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), 715 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
735 NGX_CONF_ERROR); 716 NGX_CONF_ERROR);
746 module->create_loc_conf(cf->pool), 727 module->create_loc_conf(cf->pool),
747 NGX_CONF_ERROR); 728 NGX_CONF_ERROR);
748 } 729 }
749 } 730 }
750 731
751 lcf = (ngx_http_core_loc_conf_t *) 732 clcf = ctx->loc_conf[ngx_http_core_module_ctx.index];
752 ctx->loc_conf[ngx_http_core_module_ctx.index];
753 location = (ngx_str_t *) cf->args->elts; 733 location = (ngx_str_t *) cf->args->elts;
754 lcf->name.len = location[1].len; 734 clcf->name.len = location[1].len;
755 lcf->name.data = location[1].data; 735 clcf->name.data = location[1].data;
756 lcf->loc_conf = ctx->loc_conf; 736 clcf->loc_conf = ctx->loc_conf;
757 737
758 scf = (ngx_http_core_srv_conf_t *) 738 cscf = ctx->srv_conf[ngx_http_core_module_ctx.index];
759 ctx->srv_conf[ngx_http_core_module_ctx.index]; 739 ngx_test_null(clcfp, ngx_push_array(&cscf->locations), NGX_CONF_ERROR);
760 ngx_test_null(plcf, ngx_push_array(&scf->locations), NGX_CONF_ERROR); 740 *clcfp = clcf;
761 *plcf = lcf;
762 741
763 pcf = *cf; 742 pcf = *cf;
764 cf->ctx = ctx; 743 cf->ctx = ctx;
765 cf->cmd_type = NGX_HTTP_LOC_CONF; 744 cf->cmd_type = NGX_HTTP_LOC_CONF;
766 rv = ngx_conf_parse(cf, NULL); 745 rv = ngx_conf_parse(cf, NULL);
819 798
820 return rv; 799 return rv;
821 } 800 }
822 801
823 802
803 static void *ngx_http_core_create_main_conf(ngx_pool_t *pool)
804 {
805 ngx_http_core_main_conf_t *cmcf;
806
807 ngx_test_null(cmcf,
808 ngx_palloc(pool, sizeof(ngx_http_core_main_conf_t)),
809 NGX_CONF_ERROR);
810
811 cmcf->post_accept_timeout = NGX_CONF_UNSET;
812 cmcf->connection_pool_size = NGX_CONF_UNSET;
813 cmcf->request_pool_size = NGX_CONF_UNSET;
814 cmcf->client_header_timeout = NGX_CONF_UNSET;
815 cmcf->client_header_buffer_size = NGX_CONF_UNSET;
816 cmcf->large_client_header = NGX_CONF_UNSET;
817
818 ngx_init_array(cmcf->servers, pool, 5, sizeof(ngx_http_core_srv_conf_t *),
819 NGX_CONF_ERROR);
820
821 return cmcf;
822 }
823
824
825 static char *ngx_http_core_init_main_conf(ngx_pool_t *pool, void *conf)
826 {
827 ngx_http_core_main_conf_t *cmcf = (ngx_http_core_main_conf_t *) conf;
828
829 ngx_conf_init_msec_value(cmcf->post_accept_timeout, 30000);
830 ngx_conf_init_size_value(cmcf->connection_pool_size, 16384);
831 ngx_conf_init_size_value(cmcf->request_pool_size, 16384);
832 ngx_conf_init_msec_value(cmcf->client_header_timeout, 60000);
833 ngx_conf_init_size_value(cmcf->client_header_buffer_size, 1024);
834 ngx_conf_init_value(cmcf->large_client_header, 1);
835
836 return NGX_CONF_OK;
837 }
838
839
824 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool) 840 static void *ngx_http_core_create_srv_conf(ngx_pool_t *pool)
825 { 841 {
826 ngx_http_core_srv_conf_t *scf, **cf; 842 ngx_http_core_srv_conf_t *cscf;
827 843
828 ngx_test_null(scf, 844 ngx_test_null(cscf,
829 ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)), 845 ngx_pcalloc(pool, sizeof(ngx_http_core_srv_conf_t)),
830 NGX_CONF_ERROR); 846 NGX_CONF_ERROR);
831 847
832 ngx_init_array(scf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR); 848 ngx_init_array(cscf->locations, pool, 5, sizeof(void *), NGX_CONF_ERROR);
833 ngx_init_array(scf->listen, pool, 5, sizeof(ngx_http_listen_t), 849 ngx_init_array(cscf->listen, pool, 5, sizeof(ngx_http_listen_t),
834 NGX_CONF_ERROR); 850 NGX_CONF_ERROR);
835 ngx_init_array(scf->server_names, pool, 5, sizeof(ngx_http_server_name_t), 851 ngx_init_array(cscf->server_names, pool, 5, sizeof(ngx_http_server_name_t),
836 NGX_CONF_ERROR); 852 NGX_CONF_ERROR);
837 853
838 ngx_test_null(cf, ngx_push_array(&ngx_http_servers), NGX_CONF_ERROR); 854 return cscf;
839 *cf = scf; 855 }
840 856
841 return scf; 857
842 } 858 static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
843 859 void *parent, void *child)
844 860 {
845 static char *ngx_http_core_init_srv_conf(ngx_pool_t *pool, void *conf) 861 ngx_http_core_srv_conf_t *prev = (ngx_http_core_srv_conf_t *) parent;
846 { 862 ngx_http_core_srv_conf_t *conf = (ngx_http_core_srv_conf_t *) child;
847 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
848 863
849 ngx_http_listen_t *l; 864 ngx_http_listen_t *l;
850 ngx_http_server_name_t *n; 865 ngx_http_server_name_t *n;
851 866
852 if (scf->listen.nelts == 0) { 867 /* TODO: it does not merge, it init only */
853 ngx_test_null(l, ngx_push_array(&scf->listen), NGX_CONF_ERROR); 868
869 if (conf->listen.nelts == 0) {
870 ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
854 l->addr = INADDR_ANY; 871 l->addr = INADDR_ANY;
855 l->port = 8000; 872 l->port = 8000;
856 l->family = AF_INET; 873 l->family = AF_INET;
857 } 874 }
858 875
859 if (scf->server_names.nelts == 0) { 876 if (conf->server_names.nelts == 0) {
860 ngx_test_null(n, ngx_push_array(&scf->server_names), NGX_CONF_ERROR); 877 ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR);
861 ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN), 878 ngx_test_null(n->name.data, ngx_palloc(pool, NGX_MAXHOSTNAMELEN),
862 NGX_CONF_ERROR); 879 NGX_CONF_ERROR);
863 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) { 880 if (gethostname(n->name.data, NGX_MAXHOSTNAMELEN) == -1) {
864 /* STUB: no log here */ 881 /* STUB: no log here */
865 #if 0 882 #if 0
957 t->type.data = default_types[i].type.data; 974 t->type.data = default_types[i].type.data;
958 } 975 }
959 } 976 }
960 } 977 }
961 978
962 ngx_conf_merge(conf->sendfile, prev->sendfile, 0); 979 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
963 980
964 ngx_conf_msec_merge(conf->send_timeout, prev->send_timeout, 10000); 981 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 10000);
965 982
966 ngx_conf_size_merge(conf->discarded_buffer_size, 983 ngx_conf_merge_size_value(conf->discarded_buffer_size,
967 prev->discarded_buffer_size, 1500); 984 prev->discarded_buffer_size, 1500);
968 985 ngx_conf_merge_msec_value(conf->lingering_time, prev->lingering_time,
969 ngx_conf_msec_merge(conf->lingering_time, prev->lingering_time, 30000); 986 30000);
970 ngx_conf_msec_merge(conf->lingering_timeout, prev->lingering_timeout, 5000); 987 ngx_conf_merge_msec_value(conf->lingering_timeout, prev->lingering_timeout,
988 5000);
971 989
972 return NGX_CONF_OK; 990 return NGX_CONF_OK;
973 } 991 }
974 992
975 993
976 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) 994 static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
977 { 995 {
996 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
997
978 uint p; 998 uint p;
979 char *addr; 999 char *addr;
980 ngx_str_t *args; 1000 ngx_str_t *args;
981 ngx_http_listen_t *ls; 1001 ngx_http_listen_t *ls;
982 ngx_http_core_srv_conf_t *scf = (ngx_http_core_srv_conf_t *) conf;
983 1002
984 /* TODO: check duplicate 'listen' directives */ 1003 /* TODO: check duplicate 'listen' directives */
985 1004
986 ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR); 1005 ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR);
987 1006
999 if (addr[p] == ':') { 1018 if (addr[p] == ':') {
1000 addr[p++] = '\0'; 1019 addr[p++] = '\0';
1001 1020
1002 ls->addr = inet_addr(addr); 1021 ls->addr = inet_addr(addr);
1003 if (ls->addr == INADDR_NONE) { 1022 if (ls->addr == INADDR_NONE) {
1004 return "bad addr"; 1023 /* TODO: gethostbyname() */
1024 return "can not resolve host name";
1005 } 1025 }
1006 1026
1007 break; 1027 break;
1008 } 1028 }
1009 } 1029 }