Mercurial > hg > nginx-quic
annotate src/http/ngx_http.c @ 1328:c46a10172c9a stable-0.5
r1277 merge:
fix headers split in FastCGI records
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 22 Jul 2007 09:05:43 +0000 |
parents | 5e4d3b5d7ad0 |
children | 8ef04207c84f bf5b86d5f00e |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
5 |
2
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
2
diff
changeset
|
7 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
8 #include <ngx_core.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
9 #include <ngx_event.h> |
2
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
ffffe1499bce
nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
12 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
13 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
455 | 14 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf, |
593 | 15 ngx_http_conf_in_port_t *in_port, ngx_http_listen_t *lscf, |
499 | 16 ngx_http_core_srv_conf_t *cscf); |
455 | 17 static ngx_int_t ngx_http_add_names(ngx_conf_t *cf, |
593 | 18 ngx_http_conf_in_addr_t *in_addr, ngx_http_core_srv_conf_t *cscf); |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
19 static char *ngx_http_merge_locations(ngx_conf_t *cf, |
499 | 20 ngx_array_t *locations, void **loc_conf, ngx_http_module_t *module, |
21 ngx_uint_t ctx_index); | |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
22 static int ngx_http_cmp_conf_in_addrs(const void *one, const void *two); |
593 | 23 static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one, |
24 const void *two); | |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
201
diff
changeset
|
25 |
593 | 26 ngx_uint_t ngx_http_max_module; |
27 | |
28 ngx_uint_t ngx_http_total_requests; | |
29 uint64_t ngx_http_total_sent; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
30 |
45
f1ee46c036a4
nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
31 |
356
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
32 ngx_int_t (*ngx_http_top_header_filter) (ngx_http_request_t *r); |
2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
311
diff
changeset
|
33 ngx_int_t (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
34 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
35 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
36 static ngx_command_t ngx_http_commands[] = { |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
37 |
499 | 38 { ngx_string("http"), |
39 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
40 ngx_http_block, | |
41 0, | |
42 0, | |
43 NULL }, | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
44 |
499 | 45 ngx_null_command |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
46 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
47 |
577 | 48 |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
49 static ngx_core_module_t ngx_http_module_ctx = { |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
50 ngx_string("http"), |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
51 NULL, |
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
52 NULL |
577 | 53 }; |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
54 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
55 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
56 ngx_module_t ngx_http_module = { |
509 | 57 NGX_MODULE_V1, |
311
11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
58 &ngx_http_module_ctx, /* module context */ |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
59 ngx_http_commands, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
60 NGX_CORE_MODULE, /* module type */ |
541 | 61 NULL, /* init master */ |
116
571bcbff82c5
nginx-0.0.1-2003-07-11-08:50:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
114
diff
changeset
|
62 NULL, /* init module */ |
541 | 63 NULL, /* init process */ |
64 NULL, /* init thread */ | |
65 NULL, /* exit thread */ | |
66 NULL, /* exit process */ | |
67 NULL, /* exit master */ | |
68 NGX_MODULE_V1_PADDING | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
69 }; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
70 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
71 |
499 | 72 static char * |
73 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
74 { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
75 char *rv; |
593 | 76 u_char ch; |
681 | 77 ngx_int_t rc, j; |
78 ngx_uint_t mi, m, s, l, p, a, i, n; | |
79 ngx_uint_t find_config_index, use_rewrite, use_access; | |
593 | 80 ngx_uint_t last, bind_all, done; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
81 ngx_conf_t pcf; |
649 | 82 ngx_array_t headers_in, in_ports; |
83 ngx_hash_key_t *hk; | |
593 | 84 ngx_hash_init_t hash; |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
85 ngx_listening_t *ls; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
86 ngx_http_listen_t *lscf; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
87 ngx_http_module_t *module; |
649 | 88 ngx_http_header_t *header; |
593 | 89 ngx_http_in_port_t *hip; |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
90 ngx_http_handler_pt *h; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
91 ngx_http_conf_ctx_t *ctx; |
593 | 92 ngx_http_conf_in_port_t *in_port; |
93 ngx_http_conf_in_addr_t *in_addr; | |
94 ngx_hash_keys_arrays_t ha; | |
95 ngx_http_server_name_t *name; | |
681 | 96 ngx_http_phase_handler_t *ph; |
593 | 97 ngx_http_virtual_names_t *vn; |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
98 ngx_http_core_srv_conf_t **cscfp, *cscf; |
401
b32ca005e025
nginx-0.0.9-2004-07-26-22:31:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
99 ngx_http_core_loc_conf_t *clcf; |
681 | 100 ngx_http_phase_handler_pt checker; |
216
f1d0e5f09c1e
nginx-0.0.1-2003-12-25-23:26:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
101 ngx_http_core_main_conf_t *cmcf; |
461 | 102 #if (NGX_WIN32) |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
103 ngx_iocp_conf_t *iocpcf; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
104 #endif |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
105 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
106 /* the main http context */ |
477 | 107 |
501 | 108 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
109 if (ctx == NULL) { | |
485 | 110 return NGX_CONF_ERROR; |
111 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
112 |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
113 *(ngx_http_conf_ctx_t **) conf = ctx; |
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
114 |
485 | 115 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
116 /* count the number of the http modules and set up their indices */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
117 |
71
59229033ae93
nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
118 ngx_http_max_module = 0; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
119 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
120 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
121 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
122 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
123 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
124 ngx_modules[m]->ctx_index = ngx_http_max_module++; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
125 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
126 |
477 | 127 |
485 | 128 /* the http main_conf context, it is the same in the all http contexts */ |
90
37530da31268
nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
89
diff
changeset
|
129 |
485 | 130 ctx->main_conf = ngx_pcalloc(cf->pool, |
131 sizeof(void *) * ngx_http_max_module); | |
132 if (ctx->main_conf == NULL) { | |
133 return NGX_CONF_ERROR; | |
134 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
135 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
136 |
485 | 137 /* |
138 * the http null srv_conf context, it is used to merge | |
139 * the server{}s' srv_conf's | |
140 */ | |
141 | |
142 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
143 if (ctx->srv_conf == NULL) { | |
144 return NGX_CONF_ERROR; | |
145 } | |
146 | |
147 | |
148 /* | |
149 * the http null loc_conf context, it is used to merge | |
150 * the server{}s' loc_conf's | |
151 */ | |
152 | |
153 ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); | |
154 if (ctx->loc_conf == NULL) { | |
155 return NGX_CONF_ERROR; | |
156 } | |
157 | |
158 | |
159 /* | |
160 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
161 * of the all http modules | |
162 */ | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
163 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
164 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
165 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
166 continue; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
167 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
168 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
169 module = ngx_modules[m]->ctx; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
170 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
171 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
172 if (module->create_main_conf) { |
501 | 173 ctx->main_conf[mi] = module->create_main_conf(cf); |
174 if (ctx->main_conf[mi] == NULL) { | |
485 | 175 return NGX_CONF_ERROR; |
176 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
177 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
178 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
179 if (module->create_srv_conf) { |
501 | 180 ctx->srv_conf[mi] = module->create_srv_conf(cf); |
181 if (ctx->srv_conf[mi] == NULL) { | |
485 | 182 return NGX_CONF_ERROR; |
183 } | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
184 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
185 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
186 if (module->create_loc_conf) { |
501 | 187 ctx->loc_conf[mi] = module->create_loc_conf(cf); |
188 if (ctx->loc_conf[mi] == NULL) { | |
485 | 189 return NGX_CONF_ERROR; |
190 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
191 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
192 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
193 |
509 | 194 pcf = *cf; |
195 cf->ctx = ctx; | |
196 | |
197 for (m = 0; ngx_modules[m]; m++) { | |
198 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
199 continue; | |
200 } | |
201 | |
202 module = ngx_modules[m]->ctx; | |
203 mi = ngx_modules[m]->ctx_index; | |
204 | |
205 if (module->preconfiguration) { | |
206 if (module->preconfiguration(cf) != NGX_OK) { | |
207 return NGX_CONF_ERROR; | |
208 } | |
209 } | |
210 } | |
485 | 211 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
212 /* parse inside the http{} block */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
213 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
214 cf->module_type = NGX_HTTP_MODULE; |
88
674d333f4296
nginx-0.0.1-2003-05-14-21:13:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
81
diff
changeset
|
215 cf->cmd_type = NGX_HTTP_MAIN_CONF; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
216 rv = ngx_conf_parse(cf, NULL); |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
217 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
218 if (rv != NGX_CONF_OK) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
219 *cf = pcf; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
220 return rv; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
221 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
222 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
223 /* |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
224 * init http{} main_conf's, merge the server{}s' srv_conf's |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
225 * and its location{}s' loc_conf's |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
226 */ |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
227 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
228 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
229 cscfp = cmcf->servers.elts; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
230 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
231 for (m = 0; ngx_modules[m]; m++) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
232 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
233 continue; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
234 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
235 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
236 module = ngx_modules[m]->ctx; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
237 mi = ngx_modules[m]->ctx_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
238 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
239 /* init http{} main_conf's */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
240 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
241 if (module->init_main_conf) { |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
242 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
243 if (rv != NGX_CONF_OK) { |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
244 *cf = pcf; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
245 return rv; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
246 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
247 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
248 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
249 for (s = 0; s < cmcf->servers.nelts; s++) { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
250 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
251 /* merge the server{}s' srv_conf's */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
252 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
253 if (module->merge_srv_conf) { |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
254 rv = module->merge_srv_conf(cf, |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
255 ctx->srv_conf[mi], |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
256 cscfp[s]->ctx->srv_conf[mi]); |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
257 if (rv != NGX_CONF_OK) { |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
258 *cf = pcf; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
259 return rv; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
260 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
261 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
262 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
263 if (module->merge_loc_conf) { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
264 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
265 /* merge the server{}'s loc_conf */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
266 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
267 rv = module->merge_loc_conf(cf, |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
268 ctx->loc_conf[mi], |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
269 cscfp[s]->ctx->loc_conf[mi]); |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
270 if (rv != NGX_CONF_OK) { |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
271 *cf = pcf; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
272 return rv; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
273 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
274 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
275 /* merge the locations{}' loc_conf's */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
276 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
277 rv = ngx_http_merge_locations(cf, &cscfp[s]->locations, |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
278 cscfp[s]->ctx->loc_conf, |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
279 module, mi); |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
280 if (rv != NGX_CONF_OK) { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
281 *cf = pcf; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
282 return rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
283 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
284 } |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
285 } |
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
286 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
287 |
485 | 288 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
143
diff
changeset
|
289 /* init lists of the handlers */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
290 |
573 | 291 if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers, |
292 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
293 != NGX_OK) | |
485 | 294 { |
295 return NGX_CONF_ERROR; | |
296 } | |
297 | |
573 | 298 |
299 if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers, | |
300 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
301 != NGX_OK) | |
302 { | |
303 return NGX_CONF_ERROR; | |
304 } | |
305 | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
306 |
573 | 307 if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers, |
308 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
309 != NGX_OK) | |
310 { | |
311 return NGX_CONF_ERROR; | |
312 } | |
313 | |
314 | |
581 | 315 if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers, |
316 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
317 != NGX_OK) | |
318 { | |
319 return NGX_CONF_ERROR; | |
320 } | |
321 | |
322 | |
485 | 323 if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers, |
581 | 324 cf->pool, 2, sizeof(ngx_http_handler_pt)) |
573 | 325 != NGX_OK) |
485 | 326 { |
327 return NGX_CONF_ERROR; | |
328 } | |
329 | |
368
15c84a40e87d
nginx-0.0.7-2004-06-24-20:07:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
330 |
485 | 331 if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers, |
573 | 332 cf->pool, 4, sizeof(ngx_http_handler_pt)) |
333 != NGX_OK) | |
485 | 334 { |
335 return NGX_CONF_ERROR; | |
336 } | |
337 | |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
67
diff
changeset
|
338 |
581 | 339 if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers, |
340 cf->pool, 1, sizeof(ngx_http_handler_pt)) | |
341 != NGX_OK) | |
342 { | |
343 return NGX_CONF_ERROR; | |
344 } | |
345 | |
346 | |
649 | 347 if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t)) |
507 | 348 != NGX_OK) |
349 { | |
350 return NGX_CONF_ERROR; | |
351 } | |
352 | |
649 | 353 for (header = ngx_http_headers_in; header->name.len; header++) { |
354 hk = ngx_array_push(&headers_in); | |
355 if (hk == NULL) { | |
356 return NGX_CONF_ERROR; | |
357 } | |
358 | |
359 hk->key = header->name; | |
360 hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len); | |
361 hk->value = header; | |
362 } | |
363 | |
364 hash.hash = &cmcf->headers_in_hash; | |
365 hash.key = ngx_hash_key_lc; | |
366 hash.max_size = 512; | |
751
bae59a740c40
align hash bucket size to cache line
Igor Sysoev <igor@sysoev.ru>
parents:
750
diff
changeset
|
367 hash.bucket_size = ngx_align(64, ngx_cacheline_size); |
649 | 368 hash.name = "headers_in_hash"; |
369 hash.pool = cf->pool; | |
370 hash.temp_pool = NULL; | |
371 | |
372 if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) { | |
373 return NGX_CONF_ERROR; | |
374 } | |
375 | |
509 | 376 |
377 for (m = 0; ngx_modules[m]; m++) { | |
378 if (ngx_modules[m]->type != NGX_HTTP_MODULE) { | |
379 continue; | |
380 } | |
381 | |
382 module = ngx_modules[m]->ctx; | |
383 mi = ngx_modules[m]->ctx_index; | |
384 | |
385 if (module->postconfiguration) { | |
386 if (module->postconfiguration(cf) != NGX_OK) { | |
387 return NGX_CONF_ERROR; | |
388 } | |
389 } | |
390 } | |
391 | |
573 | 392 if (ngx_http_variables_init_vars(cf) != NGX_OK) { |
393 return NGX_CONF_ERROR; | |
394 } | |
509 | 395 |
396 /* | |
397 * http{}'s cf->ctx was needed while the configuration merging | |
398 * and in postconfiguration process | |
399 */ | |
400 | |
401 *cf = pcf; | |
402 | |
507 | 403 |
681 | 404 cmcf->phase_engine.server_rewrite_index = (ngx_uint_t) -1; |
405 find_config_index = 0; | |
406 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; | |
407 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; | |
408 | |
409 n = use_rewrite + use_access + 1; /* find config phase */ | |
410 | |
411 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
412 n += cmcf->phases[i].handlers.nelts; | |
413 } | |
414 | |
415 ph = ngx_pcalloc(cf->pool, | |
416 n * sizeof(ngx_http_phase_handler_t) + sizeof(void *)); | |
417 if (ph == NULL) { | |
418 return NGX_CONF_ERROR; | |
419 } | |
420 | |
421 cmcf->phase_engine.handlers = ph; | |
422 n = 0; | |
423 | |
424 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
425 h = cmcf->phases[i].handlers.elts; | |
426 | |
427 switch (i) { | |
428 | |
429 case NGX_HTTP_SERVER_REWRITE_PHASE: | |
430 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { | |
431 cmcf->phase_engine.server_rewrite_index = n; | |
432 } | |
433 checker = ngx_http_core_generic_phase; | |
434 | |
435 break; | |
436 | |
437 case NGX_HTTP_FIND_CONFIG_PHASE: | |
438 find_config_index = n; | |
439 | |
440 ph->checker = ngx_http_core_find_config_phase; | |
441 n++; | |
442 ph++; | |
443 | |
444 continue; | |
445 | |
446 case NGX_HTTP_POST_REWRITE_PHASE: | |
447 if (use_rewrite) { | |
448 ph->checker = ngx_http_core_post_rewrite_phase; | |
449 ph->next = find_config_index; | |
450 n++; | |
451 ph++; | |
452 } | |
453 | |
454 continue; | |
455 | |
456 case NGX_HTTP_ACCESS_PHASE: | |
457 checker = ngx_http_core_access_phase; | |
458 n++; | |
459 break; | |
460 | |
461 case NGX_HTTP_POST_ACCESS_PHASE: | |
462 if (use_access) { | |
463 ph->checker = ngx_http_core_post_access_phase; | |
464 ph->next = n; | |
465 ph++; | |
466 } | |
467 | |
468 continue; | |
469 | |
470 case NGX_HTTP_CONTENT_PHASE: | |
471 checker = ngx_http_core_content_phase; | |
472 break; | |
473 | |
474 default: | |
475 checker = ngx_http_core_generic_phase; | |
476 } | |
477 | |
478 n += cmcf->phases[i].handlers.nelts; | |
479 | |
480 for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) { | |
481 ph->checker = checker; | |
482 ph->handler = h[j]; | |
483 ph->next = n; | |
484 ph++; | |
485 } | |
486 } | |
487 | |
488 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
489 /* |
455 | 490 * create the lists of ports, addresses and server names |
491 * to quickly find the server core module configuration at run-time | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
492 */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
493 |
593 | 494 if (ngx_array_init(&in_ports, cf->temp_pool, 2, |
495 sizeof(ngx_http_conf_in_port_t)) | |
501 | 496 != NGX_OK) |
455 | 497 { |
498 return NGX_CONF_ERROR; | |
499 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
500 |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
501 /* "server" directives */ |
455 | 502 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
503 cscfp = cmcf->servers.elts; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
504 for (s = 0; s < cmcf->servers.nelts; s++) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
505 |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
506 /* "listen" directives */ |
455 | 507 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
508 lscf = cscfp[s]->listen.elts; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
509 for (l = 0; l < cscfp[s]->listen.nelts; l++) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
510 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
511 /* AF_INET only */ |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
512 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
513 in_port = in_ports.elts; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
514 for (p = 0; p < in_ports.nelts; p++) { |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
515 |
593 | 516 if (lscf[l].port != in_port[p].port) { |
517 continue; | |
518 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
519 |
593 | 520 /* the port is already in the port list */ |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
521 |
593 | 522 in_addr = in_port[p].addrs.elts; |
523 for (a = 0; a < in_port[p].addrs.nelts; a++) { | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
524 |
593 | 525 if (lscf[l].addr != in_addr[a].addr) { |
526 continue; | |
527 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
528 |
593 | 529 /* the address is already in the address list */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
530 |
593 | 531 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) != NGX_OK) |
532 { | |
533 return NGX_CONF_ERROR; | |
534 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
535 |
593 | 536 /* |
537 * check the duplicate "default" server | |
538 * for this address:port | |
539 */ | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
540 |
593 | 541 if (lscf[l].conf.default_server) { |
455 | 542 |
593 | 543 if (in_addr[a].default_server) { |
544 ngx_log_error(NGX_LOG_ERR, cf->log, 0, | |
461 | 545 "the duplicate default server in %V:%d", |
546 &lscf[l].file_name, lscf[l].line); | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
547 |
593 | 548 return NGX_CONF_ERROR; |
549 } | |
455 | 550 |
593 | 551 in_addr[a].core_srv_conf = cscfp[s]; |
552 in_addr[a].default_server = 1; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
553 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
554 |
593 | 555 goto found; |
455 | 556 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
557 |
593 | 558 /* |
559 * add the address to the addresses list that | |
560 * bound to this port | |
561 */ | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
562 |
593 | 563 if (ngx_http_add_address(cf, &in_port[p], &lscf[l], cscfp[s]) |
501 | 564 != NGX_OK) |
455 | 565 { |
566 return NGX_CONF_ERROR; | |
567 } | |
593 | 568 |
569 goto found; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
570 } |
593 | 571 |
572 /* add the port to the in_port list */ | |
573 | |
574 in_port = ngx_array_push(&in_ports); | |
575 if (in_port == NULL) { | |
576 return NGX_CONF_ERROR; | |
577 } | |
578 | |
579 in_port->port = lscf[l].port; | |
580 in_port->addrs.elts = NULL; | |
581 | |
582 if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s]) != NGX_OK) | |
583 { | |
584 return NGX_CONF_ERROR; | |
585 } | |
586 | |
587 found: | |
588 | |
589 continue; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
590 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
591 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
592 |
455 | 593 |
594 /* optimize the lists of ports, addresses and server names */ | |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
595 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
596 /* AF_INET only */ |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
597 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
598 in_port = in_ports.elts; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
599 for (p = 0; p < in_ports.nelts; p++) { |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
600 |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
601 ngx_sort(in_port[p].addrs.elts, (size_t) in_port[p].addrs.nelts, |
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
602 sizeof(ngx_http_conf_in_addr_t), ngx_http_cmp_conf_in_addrs); |
523 | 603 |
455 | 604 /* |
605 * check whether all name-based servers have the same configuraiton | |
603 | 606 * as the default server, |
609 | 607 * or some servers disable optimizing the server names |
455 | 608 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
609 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
610 in_addr = in_port[p].addrs.elts; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
611 for (a = 0; a < in_port[p].addrs.nelts; a++) { |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
612 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
613 name = in_addr[a].names.elts; |
603 | 614 for (s = 0; s < in_addr[a].names.nelts; s++) { |
615 | |
616 if (in_addr[a].core_srv_conf != name[s].core_srv_conf | |
613 | 617 || name[s].core_srv_conf->optimize_server_names == 0) |
455 | 618 { |
593 | 619 goto virtual_names; |
477 | 620 } |
621 } | |
622 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
623 /* |
455 | 624 * if all name-based servers have the same configuration |
603 | 625 * as the default server, |
609 | 626 * and no servers disable optimizing the server names |
455 | 627 * then we do not need to check them at run-time at all |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
628 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
629 |
593 | 630 in_addr[a].names.nelts = 0; |
631 | |
632 continue; | |
633 | |
634 virtual_names: | |
635 | |
619 | 636 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); |
637 | |
593 | 638 ha.temp_pool = ngx_create_pool(16384, cf->log); |
639 if (ha.temp_pool == NULL) { | |
640 return NGX_CONF_ERROR; | |
477 | 641 } |
642 | |
593 | 643 ha.pool = cf->pool; |
477 | 644 |
593 | 645 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { |
646 ngx_destroy_pool(ha.temp_pool); | |
647 return NGX_CONF_ERROR; | |
648 } | |
477 | 649 |
593 | 650 name = in_addr[a].names.elts; |
651 for (s = 0; s < in_addr[a].names.nelts; s++) { | |
477 | 652 |
593 | 653 ch = name[s].name.data[0]; |
477 | 654 |
593 | 655 if (ch == '*' || ch == '.') { |
656 continue; | |
657 } | |
658 | |
659 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, | |
660 0); | |
661 | |
662 if (rc == NGX_ERROR) { | |
477 | 663 return NGX_CONF_ERROR; |
664 } | |
665 | |
593 | 666 if (rc == NGX_BUSY) { |
667 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
631 | 668 "conflicting server name \"%V\" on %s, ignored", |
669 &name[s].name, in_addr[a].listen_conf->addr); | |
593 | 670 } |
671 } | |
672 | |
673 for (s = 0; s < in_addr[a].names.nelts; s++) { | |
674 | |
675 ch = name[s].name.data[0]; | |
676 | |
677 if (ch != '*' && ch != '.') { | |
678 continue; | |
679 } | |
680 | |
681 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, | |
682 NGX_HASH_WILDCARD_KEY); | |
683 | |
684 if (rc == NGX_ERROR) { | |
685 return NGX_CONF_ERROR; | |
477 | 686 } |
687 | |
593 | 688 if (rc == NGX_BUSY) { |
689 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
631 | 690 "conflicting server name \"%V\" on %s, ignored", |
691 &name[s].name, in_addr[a].listen_conf->addr); | |
593 | 692 } |
693 } | |
477 | 694 |
593 | 695 hash.key = ngx_hash_key_lc; |
696 hash.max_size = cmcf->server_names_hash_max_size; | |
697 hash.bucket_size = cmcf->server_names_hash_bucket_size; | |
698 hash.name = "server_names_hash"; | |
699 hash.pool = cf->pool; | |
477 | 700 |
593 | 701 if (ha.keys.nelts) { |
702 hash.hash = &in_addr[a].hash; | |
703 hash.temp_pool = NULL; | |
704 | |
705 if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) | |
706 { | |
707 ngx_destroy_pool(ha.temp_pool); | |
708 return NGX_CONF_ERROR; | |
477 | 709 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
710 } |
593 | 711 |
712 if (ha.dns_wildcards.nelts) { | |
713 | |
714 ngx_qsort(ha.dns_wildcards.elts, | |
715 (size_t) ha.dns_wildcards.nelts, | |
716 sizeof(ngx_hash_key_t), | |
717 ngx_http_cmp_dns_wildcards); | |
718 | |
719 hash.hash = NULL; | |
720 hash.temp_pool = ha.temp_pool; | |
721 | |
722 if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, | |
723 ha.dns_wildcards.nelts) | |
724 != NGX_OK) | |
725 { | |
726 ngx_destroy_pool(ha.temp_pool); | |
727 return NGX_CONF_ERROR; | |
728 } | |
729 | |
730 in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; | |
731 } | |
732 | |
733 ngx_destroy_pool(ha.temp_pool); | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
734 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
735 |
593 | 736 in_addr = in_port[p].addrs.elts; |
737 last = in_port[p].addrs.nelts; | |
738 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
739 /* |
477 | 740 * if there is the binding to the "*:port" then we need to bind() |
741 * to the "*:port" only and ignore the other bindings | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
742 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
743 |
593 | 744 if (in_addr[last - 1].addr == INADDR_ANY) { |
745 in_addr[last - 1].bind = 1; | |
746 bind_all = 0; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
747 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
748 } else { |
593 | 749 bind_all = 1; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
750 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
751 |
593 | 752 for (a = 0; a < last; /* void */ ) { |
753 | |
754 if (!bind_all && !in_addr[a].bind) { | |
755 a++; | |
756 continue; | |
757 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
758 |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
759 ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr, |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
760 in_port[p].port); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
761 if (ls == NULL) { |
416
b9bd635011de
nginx-0.0.10-2004-09-06-22:45:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
762 return NGX_CONF_ERROR; |
b9bd635011de
nginx-0.0.10-2004-09-06-22:45:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
763 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
764 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
765 ls->addr_ntop = 1; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
766 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
767 ls->handler = ngx_http_init_connection; |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
768 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
769 cscf = in_addr[a].core_srv_conf; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
770 ls->pool_size = cscf->connection_pool_size; |
523 | 771 ls->post_accept_timeout = cscf->client_header_timeout; |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
772 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
773 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
543 | 774 |
775 ls->log = *clcf->err_log; | |
776 ls->log.data = &ls->addr_text; | |
777 ls->log.handler = ngx_accept_log_error; | |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
778 |
461 | 779 #if (NGX_WIN32) |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
780 iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
781 if (iocpcf->acceptex_read) { |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
782 ls->post_accept_buffer_size = cscf->client_header_buffer_size; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
783 } |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
784 #endif |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
785 |
593 | 786 ls->backlog = in_addr[a].listen_conf->backlog; |
787 ls->rcvbuf = in_addr[a].listen_conf->rcvbuf; | |
788 ls->sndbuf = in_addr[a].listen_conf->sndbuf; | |
523 | 789 |
790 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | |
593 | 791 ls->accept_filter = in_addr[a].listen_conf->accept_filter; |
523 | 792 #endif |
793 | |
794 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | |
593 | 795 ls->deferred_accept = in_addr[a].listen_conf->deferred_accept; |
523 | 796 #endif |
797 | |
593 | 798 hip = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t)); |
799 if (hip == NULL) { | |
800 return NGX_CONF_ERROR; | |
801 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
802 |
593 | 803 hip->port = in_port[p].port; |
804 | |
805 hip->port_text.data = ngx_palloc(cf->pool, 7); | |
806 if (hip->port_text.data == NULL) { | |
807 return NGX_CONF_ERROR; | |
808 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
809 |
593 | 810 ls->servers = hip; |
811 | |
812 hip->port_text.len = ngx_sprintf(hip->port_text.data, ":%d", | |
813 hip->port) | |
814 - hip->port_text.data; | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
815 |
593 | 816 in_addr = in_port[p].addrs.elts; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
817 |
593 | 818 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { |
819 hip->naddrs = 1; | |
820 done = 0; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
821 |
593 | 822 } else if (in_port[p].addrs.nelts > 1 |
823 && in_addr[last - 1].addr == INADDR_ANY) | |
824 { | |
825 hip->naddrs = last; | |
826 done = 1; | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
827 |
593 | 828 } else { |
829 hip->naddrs = 1; | |
830 done = 0; | |
831 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
832 |
593 | 833 #if 0 |
834 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, | |
835 "%ui: %V %d %ui %ui", | |
836 a, &ls->addr_text, in_addr[a].bind, | |
837 hip->naddrs, last); | |
838 #endif | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
839 |
593 | 840 hip->addrs = ngx_pcalloc(cf->pool, |
841 hip->naddrs * sizeof(ngx_http_in_addr_t)); | |
842 if (hip->addrs == NULL) { | |
843 return NGX_CONF_ERROR; | |
844 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
845 |
593 | 846 for (i = 0; i < hip->naddrs; i++) { |
847 hip->addrs[i].addr = in_addr[i].addr; | |
848 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
849 |
593 | 850 if (in_addr[i].hash.buckets == NULL |
851 && (in_addr[i].dns_wildcards == NULL | |
852 || in_addr[i].dns_wildcards->hash.buckets == NULL)) | |
853 { | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
854 continue; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
855 } |
593 | 856 |
857 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); | |
858 if (vn == NULL) { | |
859 return NGX_CONF_ERROR; | |
860 } | |
861 hip->addrs[i].virtual_names = vn; | |
862 | |
863 vn->hash = in_addr[i].hash; | |
864 vn->dns_wildcards = in_addr[i].dns_wildcards; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
865 } |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
866 |
593 | 867 if (done) { |
868 break; | |
869 } | |
870 | |
871 in_addr++; | |
872 in_port[p].addrs.elts = in_addr; | |
873 last--; | |
874 | |
875 a = 0; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
876 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
877 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
878 |
589 | 879 #if 0 |
455 | 880 { |
881 u_char address[20]; | |
589 | 882 ngx_uint_t p, a; |
455 | 883 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
884 in_port = in_ports.elts; |
56
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
885 for (p = 0; p < in_ports.nelts; p++) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
886 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 887 "port: %d %p", in_port[p].port, &in_port[p]); |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
888 in_addr = in_port[p].addrs.elts; |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
889 for (a = 0; a < in_port[p].addrs.nelts; a++) { |
455 | 890 ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20); |
891 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0, | |
461 | 892 "%s:%d %p", |
455 | 893 address, in_port[p].port, in_addr[a].core_srv_conf); |
593 | 894 name = in_addr[a].names.elts; |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
895 for (n = 0; n < in_addr[a].names.nelts; n++) { |
455 | 896 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 897 "%s:%d %V %p", |
593 | 898 address, in_port[p].port, &name[n].name, |
899 name[n].core_srv_conf); | |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
900 } |
56
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
901 } |
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
902 } |
455 | 903 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
904 #endif |
56
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
905 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
906 return NGX_CONF_OK; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
907 } |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
908 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
909 |
455 | 910 /* |
911 * add the server address, the server names and the server core module | |
912 * configurations to the port (in_port) | |
913 */ | |
914 | |
499 | 915 static ngx_int_t |
593 | 916 ngx_http_add_address(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port, |
499 | 917 ngx_http_listen_t *lscf, ngx_http_core_srv_conf_t *cscf) |
455 | 918 { |
593 | 919 ngx_http_conf_in_addr_t *in_addr; |
455 | 920 |
921 if (in_port->addrs.elts == NULL) { | |
593 | 922 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4, |
923 sizeof(ngx_http_conf_in_addr_t)) != NGX_OK) | |
455 | 924 { |
925 return NGX_ERROR; | |
926 } | |
927 } | |
928 | |
501 | 929 in_addr = ngx_array_push(&in_port->addrs); |
930 if (in_addr == NULL) { | |
455 | 931 return NGX_ERROR; |
932 } | |
933 | |
934 in_addr->addr = lscf->addr; | |
593 | 935 in_addr->hash.buckets = NULL; |
936 in_addr->hash.size = 0; | |
937 in_addr->dns_wildcards = NULL; | |
455 | 938 in_addr->names.elts = NULL; |
939 in_addr->core_srv_conf = cscf; | |
593 | 940 in_addr->default_server = lscf->conf.default_server; |
941 in_addr->bind = lscf->conf.bind; | |
942 in_addr->listen_conf = &lscf->conf; | |
455 | 943 |
944 #if (NGX_DEBUG) | |
945 { | |
946 u_char text[20]; | |
947 ngx_inet_ntop(AF_INET, &in_addr->addr, text, 20); | |
948 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, "address: %s:%d", | |
949 text, in_port->port); | |
950 } | |
951 #endif | |
952 | |
953 return ngx_http_add_names(cf, in_addr, cscf); | |
954 } | |
955 | |
956 | |
957 /* | |
958 * add the server names and the server core module | |
959 * configurations to the address:port (in_addr) | |
960 */ | |
961 | |
499 | 962 static ngx_int_t |
593 | 963 ngx_http_add_names(ngx_conf_t *cf, ngx_http_conf_in_addr_t *in_addr, |
499 | 964 ngx_http_core_srv_conf_t *cscf) |
455 | 965 { |
477 | 966 ngx_uint_t i, n; |
455 | 967 ngx_http_server_name_t *server_names, *name; |
968 | |
969 if (in_addr->names.elts == NULL) { | |
593 | 970 if (ngx_array_init(&in_addr->names, cf->temp_pool, 4, |
501 | 971 sizeof(ngx_http_server_name_t)) != NGX_OK) |
477 | 972 { |
973 return NGX_ERROR; | |
974 } | |
975 } | |
976 | |
455 | 977 server_names = cscf->server_names.elts; |
978 for (i = 0; i < cscf->server_names.nelts; i++) { | |
979 | |
477 | 980 for (n = 0; n < server_names[i].name.len; n++) { |
981 server_names[i].name.data[n] = | |
982 ngx_tolower(server_names[i].name.data[n]); | |
983 } | |
984 | |
455 | 985 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 986 "name: %V", &server_names[i].name); |
455 | 987 |
988 | |
593 | 989 name = ngx_array_push(&in_addr->names); |
501 | 990 if (name == NULL) { |
455 | 991 return NGX_ERROR; |
992 } | |
993 | |
994 *name = server_names[i]; | |
995 } | |
996 | |
997 return NGX_OK; | |
998 } | |
999 | |
1000 | |
499 | 1001 static char * |
1002 ngx_http_merge_locations(ngx_conf_t *cf, ngx_array_t *locations, | |
1003 void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index) | |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1004 { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1005 char *rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1006 ngx_uint_t i; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1007 ngx_http_core_loc_conf_t **clcfp; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1008 |
593 | 1009 clcfp = locations->elts; |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1010 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1011 for (i = 0; i < locations->nelts; i++) { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1012 rv = module->merge_loc_conf(cf, loc_conf[ctx_index], |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1013 clcfp[i]->loc_conf[ctx_index]); |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1014 if (rv != NGX_CONF_OK) { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1015 return rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1016 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1017 |
1236
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1018 if (clcfp[i]->locations == NULL) { |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1019 continue; |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1020 } |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1021 |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1022 rv = ngx_http_merge_locations(cf, clcfp[i]->locations, |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1023 clcfp[i]->loc_conf, module, ctx_index); |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1024 if (rv != NGX_CONF_OK) { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1025 return rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1026 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1027 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1028 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1029 return NGX_CONF_OK; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1030 } |
593 | 1031 |
1032 | |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
1033 static int |
593 | 1034 ngx_http_cmp_conf_in_addrs(const void *one, const void *two) |
1035 { | |
1036 ngx_http_conf_in_addr_t *first, *second; | |
1037 | |
1038 first = (ngx_http_conf_in_addr_t *) one; | |
1039 second = (ngx_http_conf_in_addr_t *) two; | |
1040 | |
1041 if (first->addr == INADDR_ANY) { | |
1042 /* the INADDR_ANY must be the last resort, shift it to the end */ | |
1043 return 1; | |
1044 } | |
1045 | |
1046 if (first->bind && !second->bind) { | |
1047 /* shift explicit bind()ed addresses to the start */ | |
1048 return -1; | |
1049 } | |
1050 | |
1051 if (!first->bind && second->bind) { | |
1052 /* shift explicit bind()ed addresses to the start */ | |
1053 return 1; | |
1054 } | |
1055 | |
1056 /* do not sort by default */ | |
1057 | |
1058 return 0; | |
1059 } | |
1060 | |
1061 | |
1062 static int ngx_libc_cdecl | |
1063 ngx_http_cmp_dns_wildcards(const void *one, const void *two) | |
1064 { | |
1065 ngx_hash_key_t *first, *second; | |
1066 | |
1067 first = (ngx_hash_key_t *) one; | |
1068 second = (ngx_hash_key_t *) two; | |
1069 | |
1070 return ngx_strcmp(first->key.data, second->key.data); | |
1071 } |