Mercurial > hg > nginx
comparison src/http/ngx_http.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 |
---|---|
14 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); | 14 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); |
15 | 15 |
16 | 16 |
17 int ngx_http_max_module; | 17 int ngx_http_max_module; |
18 | 18 |
19 ngx_array_t ngx_http_servers; /* array of ngx_http_core_srv_conf_t */ | |
20 | |
21 int ngx_http_post_accept_timeout = 30000; | |
22 int ngx_http_connection_pool_size = 16384; | |
23 int ngx_http_request_pool_size = 16384; | |
24 int ngx_http_client_header_timeout = 60000; | |
25 int ngx_http_client_header_buffer_size = 1024; | |
26 int ngx_http_large_client_header = 1; | |
27 | |
28 int ngx_http_url_in_error_log = 1; | |
29 | |
30 | 19 |
31 ngx_array_t ngx_http_translate_handlers; | 20 ngx_array_t ngx_http_translate_handlers; |
32 ngx_array_t ngx_http_index_handlers; | 21 ngx_array_t ngx_http_index_handlers; |
33 | 22 |
34 | 23 |
61 }; | 50 }; |
62 | 51 |
63 | 52 |
64 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 53 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) |
65 { | 54 { |
66 int i, s, l, p, a, n, start; | 55 int mi, m, s, l, p, a, n; |
67 int port_found, addr_found, virtual_names; | 56 int port_found, addr_found, virtual_names; |
68 char *rv; | 57 char *rv; |
69 struct sockaddr_in *addr_in; | 58 struct sockaddr_in *addr_in; |
70 ngx_array_t in_ports; | 59 ngx_array_t in_ports; |
71 ngx_listen_t *ls; | 60 ngx_listen_t *ls; |
72 ngx_http_module_t *module; | 61 ngx_http_module_t *module; |
73 ngx_conf_t pcf; | 62 ngx_conf_t pcf; |
74 ngx_http_conf_ctx_t *ctx; | 63 ngx_http_conf_ctx_t *ctx; |
75 ngx_http_in_port_t *in_port, *inport; | 64 ngx_http_in_port_t *in_port, *inport; |
76 ngx_http_in_addr_t *in_addr, *inaddr; | 65 ngx_http_in_addr_t *in_addr, *inaddr; |
77 ngx_http_core_srv_conf_t **cscf; | 66 ngx_http_core_main_conf_t *cmcf; |
78 ngx_http_listen_t *lscf; | 67 ngx_http_core_srv_conf_t **cscfp; |
79 ngx_http_server_name_t *s_name, *name; | 68 ngx_http_core_loc_conf_t **clcfp; |
80 | 69 ngx_http_listen_t *lscf; |
81 ngx_init_array(ngx_http_servers, cf->pool, 10, | 70 ngx_http_server_name_t *s_name, *name; |
82 sizeof(ngx_http_core_srv_conf_t *), NGX_CONF_ERROR); | 71 |
83 | 72 /* the main http context */ |
84 ngx_test_null(ctx, | 73 ngx_test_null(ctx, |
85 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | 74 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), |
86 NGX_CONF_ERROR); | 75 NGX_CONF_ERROR); |
87 | 76 |
88 *(ngx_http_conf_ctx_t **) conf = ctx; | 77 *(ngx_http_conf_ctx_t **) conf = ctx; |
89 | 78 |
79 | |
80 /* count the number of the http modules and set up their indices */ | |
81 | |
90 ngx_http_max_module = 0; | 82 ngx_http_max_module = 0; |
91 for (i = 0; ngx_modules[i]; i++) { | 83 for (m = 0; ngx_modules[m]; m++) { |
92 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | 84 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { |
93 continue; | 85 continue; |
94 } | 86 } |
95 | 87 |
96 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | 88 module = (ngx_http_module_t *) ngx_modules[m]->ctx; |
97 | |
98 module->index = ngx_http_max_module++; | 89 module->index = ngx_http_max_module++; |
99 } | 90 } |
100 | 91 |
101 /* TODO: http main_conf */ | 92 /* the main http main_conf, it's the same in the all http contexts */ |
102 | |
103 ngx_test_null(ctx->main_conf, | 93 ngx_test_null(ctx->main_conf, |
104 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | 94 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
105 NGX_CONF_ERROR); | 95 NGX_CONF_ERROR); |
106 | 96 |
107 /* TODO: http srv_conf */ | 97 /* the http null srv_conf, it's used to merge the server{}s' srv_conf's */ |
108 | |
109 ngx_test_null(ctx->srv_conf, | 98 ngx_test_null(ctx->srv_conf, |
110 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | 99 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
111 NGX_CONF_ERROR); | 100 NGX_CONF_ERROR); |
112 | 101 |
113 /* http null loc_conf */ | 102 /* the http null loc_conf, it's used to merge the server{}s' loc_conf's */ |
114 | |
115 ngx_test_null(ctx->loc_conf, | 103 ngx_test_null(ctx->loc_conf, |
116 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | 104 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
117 NGX_CONF_ERROR); | 105 NGX_CONF_ERROR); |
118 | 106 |
119 for (i = 0; ngx_modules[i]; i++) { | 107 |
120 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | 108 /* create the main_conf, srv_conf and loc_conf in all http modules */ |
109 | |
110 for (m = 0; ngx_modules[m]; m++) { | |
111 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { | |
121 continue; | 112 continue; |
122 } | 113 } |
123 | 114 |
124 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | 115 module = (ngx_http_module_t *) ngx_modules[m]->ctx; |
116 | |
117 if (module->create_main_conf) { | |
118 ngx_test_null(ctx->main_conf[module->index], | |
119 module->create_main_conf(cf->pool), | |
120 NGX_CONF_ERROR); | |
121 } | |
122 | |
123 if (module->create_srv_conf) { | |
124 ngx_test_null(ctx->srv_conf[module->index], | |
125 module->create_srv_conf(cf->pool), | |
126 NGX_CONF_ERROR); | |
127 } | |
125 | 128 |
126 if (module->create_loc_conf) { | 129 if (module->create_loc_conf) { |
127 ngx_test_null(ctx->loc_conf[module->index], | 130 ngx_test_null(ctx->loc_conf[module->index], |
128 module->create_loc_conf(cf->pool), | 131 module->create_loc_conf(cf->pool), |
129 NGX_CONF_ERROR); | 132 NGX_CONF_ERROR); |
130 } | 133 } |
131 } | 134 } |
135 | |
136 | |
137 /* parse inside the http{} block */ | |
132 | 138 |
133 pcf = *cf; | 139 pcf = *cf; |
134 cf->ctx = ctx; | 140 cf->ctx = ctx; |
135 cf->module_type = NGX_HTTP_MODULE_TYPE; | 141 cf->module_type = NGX_HTTP_MODULE_TYPE; |
136 cf->cmd_type = NGX_HTTP_MAIN_CONF; | 142 cf->cmd_type = NGX_HTTP_MAIN_CONF; |
139 | 145 |
140 if (rv != NGX_CONF_OK) | 146 if (rv != NGX_CONF_OK) |
141 return rv; | 147 return rv; |
142 | 148 |
143 | 149 |
144 #if 0 | 150 /* init http{} main_conf's, merge the server{}s' srv_conf's |
145 /* DEBUG STUFF */ | 151 and its location{}s' loc_conf's */ |
146 cscf = (ngx_http_core_srv_conf_t **) ngx_http_servers.elts; | 152 |
147 for (s = 0; s < ngx_http_servers.nelts; s++) { | 153 cmcf = ctx->main_conf[ngx_http_core_module_ctx.index]; |
148 ngx_http_core_loc_conf_t **loc; | 154 cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts; |
149 | 155 |
150 ngx_log_debug(cf->log, "srv: %08x" _ cscf[s]); | 156 for (m = 0; ngx_modules[m]; m++) { |
151 loc = (ngx_http_core_loc_conf_t **) cscf[s]->locations.elts; | 157 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { |
152 for (l = 0; l < cscf[s]->locations.nelts; l++) { | 158 continue; |
153 ngx_log_debug(cf->log, "loc: %08x:%s, %08x:%s" _ | 159 } |
154 loc[l] _ loc[l]->name.data _ | 160 |
155 &loc[l]->doc_root _ loc[l]->doc_root.data); | 161 module = (ngx_http_module_t *) ngx_modules[m]->ctx; |
162 mi = module->index; | |
163 | |
164 /* init http{} main_conf's */ | |
165 | |
166 if (module->init_main_conf) { | |
167 rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]); | |
168 if (rv != NGX_CONF_OK) { | |
169 return rv; | |
170 } | |
171 } | |
172 | |
173 for (s = 0; s < cmcf->servers.nelts; s++) { | |
174 | |
175 /* merge the server{}s' srv_conf's */ | |
176 | |
177 if (module->merge_srv_conf) { | |
178 rv = module->merge_srv_conf(cf->pool, | |
179 ctx->srv_conf[mi], | |
180 cscfp[s]->ctx->srv_conf[mi]); | |
181 if (rv != NGX_CONF_OK) { | |
182 return rv; | |
183 } | |
184 } | |
185 | |
186 if (module->merge_loc_conf) { | |
187 | |
188 /* merge the server{}'s loc_conf */ | |
189 | |
190 rv = module->merge_loc_conf(cf->pool, | |
191 ctx->loc_conf[mi], | |
192 cscfp[s]->ctx->loc_conf[mi]); | |
193 if (rv != NGX_CONF_OK) { | |
194 return rv; | |
195 } | |
196 | |
197 /* merge the locations{}' loc_conf's */ | |
198 | |
199 clcfp = (ngx_http_core_loc_conf_t **)cscfp[s]->locations.elts; | |
200 | |
201 for (l = 0; l < cscfp[s]->locations.nelts; l++) { | |
202 rv = module->merge_loc_conf(cf->pool, | |
203 cscfp[s]->ctx->loc_conf[mi], | |
204 clcfp[l]->loc_conf[mi]); | |
205 if (rv != NGX_CONF_OK) { | |
206 return rv; | |
207 } | |
208 } | |
209 } | |
156 } | 210 } |
157 } | 211 } |
158 /**/ | 212 |
159 #endif | 213 |
214 /* init list of the handlers */ | |
160 | 215 |
161 ngx_init_array(ngx_http_translate_handlers, | 216 ngx_init_array(ngx_http_translate_handlers, |
162 cf->pool, 10, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR); | 217 cf->pool, 10, sizeof(ngx_http_handler_pt), NGX_CONF_ERROR); |
163 | 218 |
164 ngx_init_array(ngx_http_index_handlers, | 219 ngx_init_array(ngx_http_index_handlers, |
170 | 225 |
171 ngx_init_array(in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t), | 226 ngx_init_array(in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t), |
172 NGX_CONF_ERROR); | 227 NGX_CONF_ERROR); |
173 | 228 |
174 /* "server" directives */ | 229 /* "server" directives */ |
175 cscf = (ngx_http_core_srv_conf_t **) ngx_http_servers.elts; | 230 cscfp = (ngx_http_core_srv_conf_t **) cmcf->servers.elts; |
176 for (s = 0; s < ngx_http_servers.nelts; s++) { | 231 for (s = 0; s < cmcf->servers.nelts; s++) { |
177 | 232 |
178 /* "listen" directives */ | 233 /* "listen" directives */ |
179 lscf = (ngx_http_listen_t *) cscf[s]->listen.elts; | 234 lscf = (ngx_http_listen_t *) cscfp[s]->listen.elts; |
180 for (l = 0; l < cscf[s]->listen.nelts; l++) { | 235 for (l = 0; l < cscfp[s]->listen.nelts; l++) { |
181 | 236 |
182 port_found = 0; | 237 port_found = 0; |
183 | 238 |
184 /* AF_INET only */ | 239 /* AF_INET only */ |
185 | 240 |
200 | 255 |
201 /* the address is already bound to this port */ | 256 /* the address is already bound to this port */ |
202 | 257 |
203 /* "server_name" directives */ | 258 /* "server_name" directives */ |
204 s_name = (ngx_http_server_name_t *) | 259 s_name = (ngx_http_server_name_t *) |
205 cscf[s]->server_names.elts; | 260 cscfp[s]->server_names.elts; |
206 for (n = 0; n < cscf[s]->server_names.nelts; n++) { | 261 for (n = 0; n < cscfp[s]->server_names.nelts; n++) { |
207 | 262 |
208 /* add the server name and server core module | 263 /* add the server name and server core module |
209 configuration to the address:port */ | 264 configuration to the address:port */ |
210 | 265 |
211 /* TODO: duplicate names can be checked here */ | 266 /* TODO: duplicate names can be checked here */ |
232 | 287 |
233 return NGX_CONF_ERROR; | 288 return NGX_CONF_ERROR; |
234 } | 289 } |
235 | 290 |
236 in_addr[a].flags |= NGX_HTTP_DEFAULT_SERVER; | 291 in_addr[a].flags |= NGX_HTTP_DEFAULT_SERVER; |
237 in_addr[a].core_srv_conf = cscf[s]; | 292 in_addr[a].core_srv_conf = cscfp[s]; |
238 } | 293 } |
239 | 294 |
240 addr_found = 1; | 295 addr_found = 1; |
241 | 296 |
242 break; | 297 break; |
254 ngx_memcpy(inaddr, &in_addr[a], | 309 ngx_memcpy(inaddr, &in_addr[a], |
255 sizeof(ngx_http_in_addr_t)); | 310 sizeof(ngx_http_in_addr_t)); |
256 | 311 |
257 in_addr[a].addr = lscf[l].addr; | 312 in_addr[a].addr = lscf[l].addr; |
258 in_addr[a].flags = lscf[l].flags; | 313 in_addr[a].flags = lscf[l].flags; |
259 in_addr[a].core_srv_conf = cscf[s]; | 314 in_addr[a].core_srv_conf = cscfp[s]; |
260 | 315 |
261 /* create the empty list of the server names that | 316 /* create the empty list of the server names that |
262 can be served on this address:port */ | 317 can be served on this address:port */ |
263 | 318 |
264 ngx_init_array(inaddr->names, cf->pool, 10, | 319 ngx_init_array(inaddr->names, cf->pool, 10, |
280 ngx_push_array(&in_port[p].addrs), | 335 ngx_push_array(&in_port[p].addrs), |
281 NGX_CONF_ERROR); | 336 NGX_CONF_ERROR); |
282 | 337 |
283 inaddr->addr = lscf[l].addr; | 338 inaddr->addr = lscf[l].addr; |
284 inaddr->flags = lscf[l].flags; | 339 inaddr->flags = lscf[l].flags; |
285 inaddr->core_srv_conf = cscf[s]; | 340 inaddr->core_srv_conf = cscfp[s]; |
286 | 341 |
287 /* create the empty list of the server names that | 342 /* create the empty list of the server names that |
288 can be served on this address:port */ | 343 can be served on this address:port */ |
289 | 344 |
290 ngx_init_array(inaddr->names, cf->pool, 10, | 345 ngx_init_array(inaddr->names, cf->pool, 10, |
315 | 370 |
316 /* ... and add the address to this list */ | 371 /* ... and add the address to this list */ |
317 | 372 |
318 inaddr->addr = lscf[l].addr; | 373 inaddr->addr = lscf[l].addr; |
319 inaddr->flags = lscf[l].flags; | 374 inaddr->flags = lscf[l].flags; |
320 inaddr->core_srv_conf = cscf[s]; | 375 inaddr->core_srv_conf = cscfp[s]; |
321 | 376 |
322 /* create the empty list of the server names that | 377 /* create the empty list of the server names that |
323 can be served on this address:port */ | 378 can be served on this address:port */ |
324 | 379 |
325 ngx_init_array(inaddr->names, cf->pool, 10, | 380 ngx_init_array(inaddr->names, cf->pool, 10, |
405 ls->sockaddr = (struct sockaddr *) addr_in; | 460 ls->sockaddr = (struct sockaddr *) addr_in; |
406 ls->socklen = sizeof(struct sockaddr_in); | 461 ls->socklen = sizeof(struct sockaddr_in); |
407 ls->addr = offsetof(struct sockaddr_in, sin_addr); | 462 ls->addr = offsetof(struct sockaddr_in, sin_addr); |
408 ls->addr_text_max_len = INET_ADDRSTRLEN; | 463 ls->addr_text_max_len = INET_ADDRSTRLEN; |
409 ls->backlog = -1; | 464 ls->backlog = -1; |
410 ls->post_accept_timeout = ngx_http_post_accept_timeout; | 465 ls->post_accept_timeout = cmcf->post_accept_timeout; |
411 ls->nonblocking = 1; | 466 ls->nonblocking = 1; |
412 | 467 |
413 ls->handler = ngx_http_init_connection; | 468 ls->handler = ngx_http_init_connection; |
414 ls->log = cf->log; | 469 ls->log = cf->log; |
415 ls->pool_size = ngx_http_connection_pool_size; | 470 ls->pool_size = cmcf->connection_pool_size; |
416 ls->ctx = ctx; | 471 ls->ctx = ctx; |
417 | 472 |
418 if (in_port[p].addrs.nelts > 1) { | 473 if (in_port[p].addrs.nelts > 1) { |
419 | 474 |
420 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; | 475 in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts; |
473 } | 528 } |
474 /**/ | 529 /**/ |
475 | 530 |
476 return NGX_CONF_OK; | 531 return NGX_CONF_OK; |
477 } | 532 } |
478 | |
479 | |
480 #if 0 | |
481 /* STUB */ | |
482 | |
483 static struct sockaddr_in addr; | |
484 static char addr_text[22]; | |
485 | |
486 | |
487 int ngx_http_init(ngx_pool_t *pool, ngx_log_t *log) | |
488 { | |
489 ngx_listen_t *ls; | |
490 | |
491 ngx_http_server.connection_pool_size = 16384; | |
492 ngx_http_server.request_pool_size = 16384; | |
493 ngx_http_server.header_timeout = 20000; | |
494 ngx_http_server.header_buffer_size = 1024; | |
495 ngx_http_server.discarded_buffer_size = 1500; | |
496 | |
497 ngx_http_server.lingering_timeout = 5000; | |
498 ngx_http_server.lingering_time = 30; | |
499 | |
500 #if (WIN32) | |
501 ngx_http_server.doc_root = "html"; | |
502 #else | |
503 ngx_http_server.doc_root = "/home/is/dox/"; | |
504 ngx_http_server.doc_root = "/home/is/work/xml/site-1.0.0/html"; | |
505 ngx_http_server.doc_root = "/spool/test/lperltk"; | |
506 ngx_http_server.doc_root = "/home/is/dox/ora/lperltk"; | |
507 #endif | |
508 ngx_http_server.doc_root_len = strlen(ngx_http_server.doc_root) + 1; | |
509 | |
510 | |
511 ngx_http_config_modules(pool, ngx_modules); | |
512 | |
513 #if 0 | |
514 /* STUB */ | |
515 ngx_http_output_filter_set_stub(pool, ngx_http_modules); | |
516 ngx_http_write_filter_set_stub(pool, ngx_http_modules); | |
517 ngx_http_index_set_stub(pool, ngx_http_modules); | |
518 | |
519 ngx_http_init_modules(pool, ngx_http_modules); | |
520 #endif | |
521 | |
522 ngx_http_init_filters(pool, ngx_modules); | |
523 | |
524 ls = ngx_push_array(&ngx_listening_sockets); | |
525 ngx_memzero(ls, sizeof(ngx_listen_t)); | |
526 | |
527 addr.sin_family = AF_INET; | |
528 addr.sin_addr.s_addr = inet_addr("0.0.0.0"); | |
529 addr.sin_port = htons(8000); | |
530 | |
531 ngx_snprintf(ngx_cpystrn(addr_text, inet_ntoa(addr.sin_addr), 16), | |
532 7, ":%d", ntohs(addr.sin_port)); | |
533 | |
534 ls->family = AF_INET; | |
535 ls->type = SOCK_STREAM; | |
536 ls->protocol = IPPROTO_IP; | |
537 | |
538 #if (NGX_OVERLAPPED) | |
539 ls->flags = WSA_FLAG_OVERLAPPED; | |
540 #else | |
541 ls->nonblocking = 1; | |
542 #endif | |
543 | |
544 ls->sockaddr = (struct sockaddr *) &addr; | |
545 ls->socklen = sizeof(struct sockaddr_in); | |
546 ls->addr = offsetof(struct sockaddr_in, sin_addr); | |
547 ls->addr_text.len = INET_ADDRSTRLEN; | |
548 ls->addr_text.data = addr_text; | |
549 ls->backlog = -1; | |
550 ls->post_accept_timeout = 10000; | |
551 | |
552 ls->handler = ngx_http_init_connection; | |
553 ls->server = &ngx_http_server; | |
554 ls->log = log; | |
555 | |
556 | |
557 return 1; | |
558 } | |
559 | |
560 /**/ | |
561 #endif |