comparison src/http/ngx_http.c @ 96:a23d010f356d

nginx-0.0.1-2003-05-27-16:18:54 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 27 May 2003 12:18:54 +0000
parents b48066122884
children c9b243802a17
comparison
equal deleted inserted replaced
95:b48066122884 96:a23d010f356d
9 #include <ngx_http_config.h> 9 #include <ngx_http_config.h>
10 #include <ngx_http_core_module.h> 10 #include <ngx_http_core_module.h>
11 11
12 12
13 static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules); 13 static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules);
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, void *conf);
15 15
16 16
17 int ngx_http_max_module; 17 int ngx_http_max_module;
18 18
19 19
35 ngx_http_block, 35 ngx_http_block,
36 0, 36 0,
37 0, 37 0,
38 NULL}, 38 NULL},
39 39
40 {ngx_string(""), 0, NULL, 0, 0, NULL} 40 ngx_null_command
41 }; 41 };
42 42
43 43
44 ngx_module_t ngx_http_module = { 44 ngx_module_t ngx_http_module = {
45 NGX_MODULE,
45 &http_name, /* module context */ 46 &http_name, /* module context */
46 0, /* module index */
47 ngx_http_commands, /* module directives */ 47 ngx_http_commands, /* module directives */
48 NGX_CORE_MODULE_TYPE, /* module type */ 48 NGX_CORE_MODULE, /* module type */
49 NULL /* init module */ 49 NULL /* init module */
50 }; 50 };
51 51
52 52
53 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, void *conf)
54 { 54 {
55 int mi, m, s, l, p, a, n; 55 int mi, m, s, l, p, a, n;
56 int port_found, addr_found, virtual_names; 56 int port_found, addr_found, virtual_names;
57 char *rv; 57 char *rv;
58 struct sockaddr_in *addr_in; 58 struct sockaddr_in *addr_in;
79 79
80 /* count the number of the http modules and set up their indices */ 80 /* count the number of the http modules and set up their indices */
81 81
82 ngx_http_max_module = 0; 82 ngx_http_max_module = 0;
83 for (m = 0; ngx_modules[m]; m++) { 83 for (m = 0; ngx_modules[m]; m++) {
84 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { 84 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
85 continue; 85 continue;
86 } 86 }
87 87
88 module = (ngx_http_module_t *) ngx_modules[m]->ctx; 88 ngx_modules[m]->ctx_index = ngx_http_max_module++;
89 module->index = ngx_http_max_module++;
90 } 89 }
91 90
92 /* the main http main_conf, it's the same in the all http contexts */ 91 /* the main http main_conf, it's the same in the all http contexts */
93 ngx_test_null(ctx->main_conf, 92 ngx_test_null(ctx->main_conf,
94 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), 93 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module),
106 105
107 106
108 /* create the main_conf, srv_conf and loc_conf in all http modules */ 107 /* create the main_conf, srv_conf and loc_conf in all http modules */
109 108
110 for (m = 0; ngx_modules[m]; m++) { 109 for (m = 0; ngx_modules[m]; m++) {
111 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { 110 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
112 continue; 111 continue;
113 } 112 }
114 113
115 module = (ngx_http_module_t *) ngx_modules[m]->ctx; 114 module = ngx_modules[m]->ctx;
115 mi = ngx_modules[m]->ctx_index;
116 116
117 if (module->create_main_conf) { 117 if (module->create_main_conf) {
118 ngx_test_null(ctx->main_conf[module->index], 118 ngx_test_null(ctx->main_conf[mi],
119 module->create_main_conf(cf->pool), 119 module->create_main_conf(cf->pool),
120 NGX_CONF_ERROR); 120 NGX_CONF_ERROR);
121 } 121 }
122 122
123 if (module->create_srv_conf) { 123 if (module->create_srv_conf) {
124 ngx_test_null(ctx->srv_conf[module->index], 124 ngx_test_null(ctx->srv_conf[mi],
125 module->create_srv_conf(cf->pool), 125 module->create_srv_conf(cf->pool),
126 NGX_CONF_ERROR); 126 NGX_CONF_ERROR);
127 } 127 }
128 128
129 if (module->create_loc_conf) { 129 if (module->create_loc_conf) {
130 ngx_test_null(ctx->loc_conf[module->index], 130 ngx_test_null(ctx->loc_conf[mi],
131 module->create_loc_conf(cf->pool), 131 module->create_loc_conf(cf->pool),
132 NGX_CONF_ERROR); 132 NGX_CONF_ERROR);
133 } 133 }
134 } 134 }
135 135
136 136
137 /* parse inside the http{} block */ 137 /* parse inside the http{} block */
138 138
139 pcf = *cf; 139 pcf = *cf;
140 cf->ctx = ctx; 140 cf->ctx = ctx;
141 cf->module_type = NGX_HTTP_MODULE_TYPE; 141 cf->module_type = NGX_HTTP_MODULE;
142 cf->cmd_type = NGX_HTTP_MAIN_CONF; 142 cf->cmd_type = NGX_HTTP_MAIN_CONF;
143 rv = ngx_conf_parse(cf, NULL); 143 rv = ngx_conf_parse(cf, NULL);
144 *cf = pcf; 144 *cf = pcf;
145 145
146 if (rv != NGX_CONF_OK) 146 if (rv != NGX_CONF_OK)
148 148
149 149
150 /* init http{} main_conf's, merge the server{}s' srv_conf's 150 /* init http{} main_conf's, merge the server{}s' srv_conf's
151 and its location{}s' loc_conf's */ 151 and its location{}s' loc_conf's */
152 152
153 cmcf = ctx->main_conf[ngx_http_core_module_ctx.index]; 153 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
154 cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts; 154 cscfp = (ngx_http_core_srv_conf_t **)cmcf->servers.elts;
155 155
156 for (m = 0; ngx_modules[m]; m++) { 156 for (m = 0; ngx_modules[m]; m++) {
157 if (ngx_modules[m]->type != NGX_HTTP_MODULE_TYPE) { 157 if (ngx_modules[m]->type != NGX_HTTP_MODULE) {
158 continue; 158 continue;
159 } 159 }
160 160
161 module = (ngx_http_module_t *) ngx_modules[m]->ctx; 161 module = (ngx_http_module_t *) ngx_modules[m]->ctx;
162 mi = module->index; 162 mi = ngx_modules[m]->ctx_index;
163 163
164 /* init http{} main_conf's */ 164 /* init http{} main_conf's */
165 165
166 if (module->init_main_conf) { 166 if (module->init_main_conf) {
167 rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]); 167 rv = module->init_main_conf(cf->pool, ctx->main_conf[mi]);
308 308
309 ngx_memcpy(inaddr, &in_addr[a], 309 ngx_memcpy(inaddr, &in_addr[a],
310 sizeof(ngx_http_in_addr_t)); 310 sizeof(ngx_http_in_addr_t));
311 311
312 in_addr[a].addr = lscf[l].addr; 312 in_addr[a].addr = lscf[l].addr;
313 in_addr[a].flags = lscf[l].flags; 313 in_addr[a].flags = lscf[l].flags;
314 in_addr[a].core_srv_conf = cscfp[s]; 314 in_addr[a].core_srv_conf = cscfp[s];
315 315
316 /* create the empty list of the server names that 316 /* create the empty list of the server names that
317 can be served on this address:port */ 317 can be served on this address:port */
318 318
334 ngx_test_null(inaddr, 334 ngx_test_null(inaddr,
335 ngx_push_array(&in_port[p].addrs), 335 ngx_push_array(&in_port[p].addrs),
336 NGX_CONF_ERROR); 336 NGX_CONF_ERROR);
337 337
338 inaddr->addr = lscf[l].addr; 338 inaddr->addr = lscf[l].addr;
339 inaddr->flags = lscf[l].flags; 339 inaddr->flags = lscf[l].flags;
340 inaddr->core_srv_conf = cscfp[s]; 340 inaddr->core_srv_conf = cscfp[s];
341 341
342 /* create the empty list of the server names that 342 /* create the empty list of the server names that
343 can be served on this address:port */ 343 can be served on this address:port */
344 344
357 ngx_push_array(&in_ports), 357 ngx_push_array(&in_ports),
358 NGX_CONF_ERROR); 358 NGX_CONF_ERROR);
359 359
360 in_port->port = lscf[l].port; 360 in_port->port = lscf[l].port;
361 361
362 ngx_test_null(in_port->port_name.data, ngx_palloc(cf->pool, 7),
363 NGX_CONF_ERROR);
364 in_port->port_name.len = ngx_snprintf(in_port->port_name.data,
365 7, ":%d",
366 in_port->port);
367
362 /* create list of the addresses that bound to this port ... */ 368 /* create list of the addresses that bound to this port ... */
363 369
364 ngx_init_array(in_port->addrs, cf->pool, 10, 370 ngx_init_array(in_port->addrs, cf->pool, 10,
365 sizeof(ngx_http_in_addr_t), 371 sizeof(ngx_http_in_addr_t),
366 NGX_CONF_ERROR); 372 NGX_CONF_ERROR);
369 NGX_CONF_ERROR); 375 NGX_CONF_ERROR);
370 376
371 /* ... and add the address to this list */ 377 /* ... and add the address to this list */
372 378
373 inaddr->addr = lscf[l].addr; 379 inaddr->addr = lscf[l].addr;
374 inaddr->flags = lscf[l].flags; 380 inaddr->flags = lscf[l].flags;
375 inaddr->core_srv_conf = cscfp[s]; 381 inaddr->core_srv_conf = cscfp[s];
376 382
377 /* create the empty list of the server names that 383 /* create the empty list of the server names that
378 can be served on this address:port */ 384 can be served on this address:port */
379 385
482 ngx_palloc(cf->pool, 488 ngx_palloc(cf->pool,
483 sizeof(ngx_http_in_port_t)), 489 sizeof(ngx_http_in_port_t)),
484 NGX_CONF_ERROR); 490 NGX_CONF_ERROR);
485 491
486 inport->port = in_port[p].port; 492 inport->port = in_port[p].port;
493 inport->port_name = in_port[p].port_name;
487 494
488 /* init list of the addresses ... */ 495 /* init list of the addresses ... */
489 496
490 ngx_init_array(inport->addrs, cf->pool, 1, 497 ngx_init_array(inport->addrs, cf->pool, 1,
491 sizeof(ngx_http_in_addr_t), 498 sizeof(ngx_http_in_addr_t),