Mercurial > hg > nginx-quic
annotate src/http/ngx_http.c @ 1609:7bdf156fc852 stable-0.5
r1491 merge:
add rpath for Solaris
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 29 Oct 2007 14:32:18 +0000 |
parents | 9b10ba85b249 |
children | cacb565c554e |
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; |
1395 | 405 cmcf->phase_engine.location_rewrite_index = (ngx_uint_t) -1; |
681 | 406 find_config_index = 0; |
407 use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0; | |
408 use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0; | |
409 | |
410 n = use_rewrite + use_access + 1; /* find config phase */ | |
411 | |
412 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
413 n += cmcf->phases[i].handlers.nelts; | |
414 } | |
415 | |
416 ph = ngx_pcalloc(cf->pool, | |
417 n * sizeof(ngx_http_phase_handler_t) + sizeof(void *)); | |
418 if (ph == NULL) { | |
419 return NGX_CONF_ERROR; | |
420 } | |
421 | |
422 cmcf->phase_engine.handlers = ph; | |
423 n = 0; | |
424 | |
425 for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) { | |
426 h = cmcf->phases[i].handlers.elts; | |
427 | |
428 switch (i) { | |
429 | |
430 case NGX_HTTP_SERVER_REWRITE_PHASE: | |
431 if (cmcf->phase_engine.server_rewrite_index == (ngx_uint_t) -1) { | |
432 cmcf->phase_engine.server_rewrite_index = n; | |
433 } | |
434 checker = ngx_http_core_generic_phase; | |
435 | |
436 break; | |
437 | |
438 case NGX_HTTP_FIND_CONFIG_PHASE: | |
439 find_config_index = n; | |
440 | |
441 ph->checker = ngx_http_core_find_config_phase; | |
442 n++; | |
443 ph++; | |
444 | |
445 continue; | |
446 | |
1395 | 447 case NGX_HTTP_REWRITE_PHASE: |
448 if (cmcf->phase_engine.location_rewrite_index == (ngx_uint_t) -1) { | |
449 cmcf->phase_engine.location_rewrite_index = n; | |
450 } | |
451 checker = ngx_http_core_generic_phase; | |
452 | |
453 break; | |
454 | |
681 | 455 case NGX_HTTP_POST_REWRITE_PHASE: |
456 if (use_rewrite) { | |
457 ph->checker = ngx_http_core_post_rewrite_phase; | |
458 ph->next = find_config_index; | |
459 n++; | |
460 ph++; | |
461 } | |
462 | |
463 continue; | |
464 | |
465 case NGX_HTTP_ACCESS_PHASE: | |
466 checker = ngx_http_core_access_phase; | |
467 n++; | |
468 break; | |
469 | |
470 case NGX_HTTP_POST_ACCESS_PHASE: | |
471 if (use_access) { | |
472 ph->checker = ngx_http_core_post_access_phase; | |
473 ph->next = n; | |
474 ph++; | |
475 } | |
476 | |
477 continue; | |
478 | |
479 case NGX_HTTP_CONTENT_PHASE: | |
480 checker = ngx_http_core_content_phase; | |
481 break; | |
482 | |
483 default: | |
484 checker = ngx_http_core_generic_phase; | |
485 } | |
486 | |
487 n += cmcf->phases[i].handlers.nelts; | |
488 | |
489 for (j = cmcf->phases[i].handlers.nelts - 1; j >=0; j--) { | |
490 ph->checker = checker; | |
491 ph->handler = h[j]; | |
492 ph->next = n; | |
493 ph++; | |
494 } | |
495 } | |
496 | |
497 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
498 /* |
455 | 499 * create the lists of ports, addresses and server names |
500 * 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
|
501 */ |
54
27b628ef907e
nginx-0.0.1-2003-01-28-18:56:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
502 |
593 | 503 if (ngx_array_init(&in_ports, cf->temp_pool, 2, |
504 sizeof(ngx_http_conf_in_port_t)) | |
501 | 505 != NGX_OK) |
455 | 506 { |
507 return NGX_CONF_ERROR; | |
508 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
509 |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
510 /* "server" directives */ |
455 | 511 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
512 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
|
513 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
|
514 |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
515 /* "listen" directives */ |
455 | 516 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
517 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
|
518 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
|
519 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
520 /* AF_INET only */ |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
521 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
522 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
|
523 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
|
524 |
593 | 525 if (lscf[l].port != in_port[p].port) { |
526 continue; | |
527 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
528 |
593 | 529 /* 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
|
530 |
593 | 531 in_addr = in_port[p].addrs.elts; |
532 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
|
533 |
593 | 534 if (lscf[l].addr != in_addr[a].addr) { |
535 continue; | |
536 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
537 |
593 | 538 /* 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
|
539 |
593 | 540 if (ngx_http_add_names(cf, &in_addr[a], cscfp[s]) != NGX_OK) |
541 { | |
542 return NGX_CONF_ERROR; | |
543 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
544 |
593 | 545 /* |
546 * check the duplicate "default" server | |
547 * for this address:port | |
548 */ | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
549 |
593 | 550 if (lscf[l].conf.default_server) { |
455 | 551 |
593 | 552 if (in_addr[a].default_server) { |
553 ngx_log_error(NGX_LOG_ERR, cf->log, 0, | |
1533 | 554 "the duplicate default server in %s:%ui", |
555 &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
|
556 |
593 | 557 return NGX_CONF_ERROR; |
558 } | |
455 | 559 |
593 | 560 in_addr[a].core_srv_conf = cscfp[s]; |
561 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
|
562 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
563 |
593 | 564 goto found; |
455 | 565 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
566 |
593 | 567 /* |
568 * add the address to the addresses list that | |
569 * bound to this port | |
570 */ | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
571 |
593 | 572 if (ngx_http_add_address(cf, &in_port[p], &lscf[l], cscfp[s]) |
501 | 573 != NGX_OK) |
455 | 574 { |
575 return NGX_CONF_ERROR; | |
576 } | |
593 | 577 |
578 goto found; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
579 } |
593 | 580 |
581 /* add the port to the in_port list */ | |
582 | |
583 in_port = ngx_array_push(&in_ports); | |
584 if (in_port == NULL) { | |
585 return NGX_CONF_ERROR; | |
586 } | |
587 | |
588 in_port->port = lscf[l].port; | |
589 in_port->addrs.elts = NULL; | |
590 | |
591 if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s]) != NGX_OK) | |
592 { | |
593 return NGX_CONF_ERROR; | |
594 } | |
595 | |
596 found: | |
597 | |
598 continue; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
599 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
600 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
601 |
455 | 602 |
603 /* 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
|
604 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
605 /* AF_INET only */ |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
606 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
607 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
|
608 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
|
609 |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
610 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
|
611 sizeof(ngx_http_conf_in_addr_t), ngx_http_cmp_conf_in_addrs); |
523 | 612 |
455 | 613 /* |
614 * check whether all name-based servers have the same configuraiton | |
603 | 615 * as the default server, |
609 | 616 * or some servers disable optimizing the server names |
455 | 617 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
618 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
619 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
|
620 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
|
621 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
622 name = in_addr[a].names.elts; |
603 | 623 for (s = 0; s < in_addr[a].names.nelts; s++) { |
624 | |
625 if (in_addr[a].core_srv_conf != name[s].core_srv_conf | |
613 | 626 || name[s].core_srv_conf->optimize_server_names == 0) |
455 | 627 { |
593 | 628 goto virtual_names; |
477 | 629 } |
630 } | |
631 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
632 /* |
455 | 633 * if all name-based servers have the same configuration |
603 | 634 * as the default server, |
609 | 635 * and no servers disable optimizing the server names |
455 | 636 * 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
|
637 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
638 |
593 | 639 in_addr[a].names.nelts = 0; |
640 | |
641 continue; | |
642 | |
643 virtual_names: | |
644 | |
619 | 645 ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t)); |
646 | |
593 | 647 ha.temp_pool = ngx_create_pool(16384, cf->log); |
648 if (ha.temp_pool == NULL) { | |
649 return NGX_CONF_ERROR; | |
477 | 650 } |
651 | |
593 | 652 ha.pool = cf->pool; |
477 | 653 |
593 | 654 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { |
655 ngx_destroy_pool(ha.temp_pool); | |
656 return NGX_CONF_ERROR; | |
657 } | |
477 | 658 |
593 | 659 name = in_addr[a].names.elts; |
660 for (s = 0; s < in_addr[a].names.nelts; s++) { | |
477 | 661 |
593 | 662 ch = name[s].name.data[0]; |
477 | 663 |
593 | 664 if (ch == '*' || ch == '.') { |
665 continue; | |
666 } | |
667 | |
668 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, | |
669 0); | |
670 | |
671 if (rc == NGX_ERROR) { | |
477 | 672 return NGX_CONF_ERROR; |
673 } | |
674 | |
593 | 675 if (rc == NGX_BUSY) { |
676 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
631 | 677 "conflicting server name \"%V\" on %s, ignored", |
678 &name[s].name, in_addr[a].listen_conf->addr); | |
593 | 679 } |
680 } | |
681 | |
682 for (s = 0; s < in_addr[a].names.nelts; s++) { | |
683 | |
684 ch = name[s].name.data[0]; | |
685 | |
686 if (ch != '*' && ch != '.') { | |
687 continue; | |
688 } | |
689 | |
690 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, | |
691 NGX_HASH_WILDCARD_KEY); | |
692 | |
693 if (rc == NGX_ERROR) { | |
694 return NGX_CONF_ERROR; | |
477 | 695 } |
696 | |
593 | 697 if (rc == NGX_BUSY) { |
698 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
631 | 699 "conflicting server name \"%V\" on %s, ignored", |
700 &name[s].name, in_addr[a].listen_conf->addr); | |
593 | 701 } |
702 } | |
477 | 703 |
593 | 704 hash.key = ngx_hash_key_lc; |
705 hash.max_size = cmcf->server_names_hash_max_size; | |
706 hash.bucket_size = cmcf->server_names_hash_bucket_size; | |
707 hash.name = "server_names_hash"; | |
708 hash.pool = cf->pool; | |
477 | 709 |
593 | 710 if (ha.keys.nelts) { |
711 hash.hash = &in_addr[a].hash; | |
712 hash.temp_pool = NULL; | |
713 | |
714 if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) | |
715 { | |
716 ngx_destroy_pool(ha.temp_pool); | |
717 return NGX_CONF_ERROR; | |
477 | 718 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
719 } |
593 | 720 |
721 if (ha.dns_wildcards.nelts) { | |
722 | |
723 ngx_qsort(ha.dns_wildcards.elts, | |
724 (size_t) ha.dns_wildcards.nelts, | |
725 sizeof(ngx_hash_key_t), | |
726 ngx_http_cmp_dns_wildcards); | |
727 | |
728 hash.hash = NULL; | |
729 hash.temp_pool = ha.temp_pool; | |
730 | |
731 if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, | |
732 ha.dns_wildcards.nelts) | |
733 != NGX_OK) | |
734 { | |
735 ngx_destroy_pool(ha.temp_pool); | |
736 return NGX_CONF_ERROR; | |
737 } | |
738 | |
739 in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; | |
740 } | |
741 | |
742 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
|
743 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
744 |
593 | 745 in_addr = in_port[p].addrs.elts; |
746 last = in_port[p].addrs.nelts; | |
747 | |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
748 /* |
477 | 749 * if there is the binding to the "*:port" then we need to bind() |
750 * 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
|
751 */ |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
752 |
593 | 753 if (in_addr[last - 1].addr == INADDR_ANY) { |
754 in_addr[last - 1].bind = 1; | |
755 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
|
756 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
757 } else { |
593 | 758 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
|
759 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
760 |
593 | 761 for (a = 0; a < last; /* void */ ) { |
762 | |
763 if (!bind_all && !in_addr[a].bind) { | |
764 a++; | |
765 continue; | |
766 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
767 |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
768 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
|
769 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
|
770 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
|
771 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
|
772 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
773 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
774 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
|
775 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
776 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
|
777 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
778 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
|
779 ls->pool_size = cscf->connection_pool_size; |
523 | 780 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
|
781 |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
782 clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; |
543 | 783 |
784 ls->log = *clcf->err_log; | |
785 ls->log.data = &ls->addr_text; | |
786 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
|
787 |
461 | 788 #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
|
789 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
|
790 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
|
791 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
|
792 } |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
793 #endif |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
794 |
593 | 795 ls->backlog = in_addr[a].listen_conf->backlog; |
796 ls->rcvbuf = in_addr[a].listen_conf->rcvbuf; | |
797 ls->sndbuf = in_addr[a].listen_conf->sndbuf; | |
523 | 798 |
799 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | |
593 | 800 ls->accept_filter = in_addr[a].listen_conf->accept_filter; |
523 | 801 #endif |
802 | |
803 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | |
593 | 804 ls->deferred_accept = in_addr[a].listen_conf->deferred_accept; |
523 | 805 #endif |
806 | |
593 | 807 hip = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t)); |
808 if (hip == NULL) { | |
809 return NGX_CONF_ERROR; | |
810 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
811 |
593 | 812 hip->port = in_port[p].port; |
813 | |
814 hip->port_text.data = ngx_palloc(cf->pool, 7); | |
815 if (hip->port_text.data == NULL) { | |
816 return NGX_CONF_ERROR; | |
817 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
818 |
593 | 819 ls->servers = hip; |
820 | |
821 hip->port_text.len = ngx_sprintf(hip->port_text.data, ":%d", | |
822 hip->port) | |
823 - 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
|
824 |
593 | 825 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
|
826 |
593 | 827 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { |
828 hip->naddrs = 1; | |
829 done = 0; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
830 |
593 | 831 } else if (in_port[p].addrs.nelts > 1 |
832 && in_addr[last - 1].addr == INADDR_ANY) | |
833 { | |
834 hip->naddrs = last; | |
835 done = 1; | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
836 |
593 | 837 } else { |
838 hip->naddrs = 1; | |
839 done = 0; | |
840 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
841 |
593 | 842 #if 0 |
843 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, | |
844 "%ui: %V %d %ui %ui", | |
845 a, &ls->addr_text, in_addr[a].bind, | |
846 hip->naddrs, last); | |
847 #endif | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
848 |
593 | 849 hip->addrs = ngx_pcalloc(cf->pool, |
850 hip->naddrs * sizeof(ngx_http_in_addr_t)); | |
851 if (hip->addrs == NULL) { | |
852 return NGX_CONF_ERROR; | |
853 } | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
854 |
593 | 855 for (i = 0; i < hip->naddrs; i++) { |
856 hip->addrs[i].addr = in_addr[i].addr; | |
857 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
|
858 |
593 | 859 if (in_addr[i].hash.buckets == NULL |
860 && (in_addr[i].dns_wildcards == NULL | |
861 || in_addr[i].dns_wildcards->hash.buckets == NULL)) | |
862 { | |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
863 continue; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
864 } |
593 | 865 |
866 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); | |
867 if (vn == NULL) { | |
868 return NGX_CONF_ERROR; | |
869 } | |
870 hip->addrs[i].virtual_names = vn; | |
871 | |
872 vn->hash = in_addr[i].hash; | |
873 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
|
874 } |
89
29bf798b583f
nginx-0.0.1-2003-05-15-19:42:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
88
diff
changeset
|
875 |
593 | 876 if (done) { |
877 break; | |
878 } | |
879 | |
880 in_addr++; | |
881 in_port[p].addrs.elts = in_addr; | |
882 last--; | |
883 | |
884 a = 0; | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
885 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
886 } |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
887 |
589 | 888 #if 0 |
455 | 889 { |
890 u_char address[20]; | |
589 | 891 ngx_uint_t p, a; |
455 | 892 |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
893 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
|
894 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
|
895 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 896 "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
|
897 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
|
898 for (a = 0; a < in_port[p].addrs.nelts; a++) { |
455 | 899 ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20); |
900 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0, | |
461 | 901 "%s:%d %p", |
455 | 902 address, in_port[p].port, in_addr[a].core_srv_conf); |
593 | 903 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
|
904 for (n = 0; n < in_addr[a].names.nelts; n++) { |
455 | 905 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 906 "%s:%d %V %p", |
593 | 907 address, in_port[p].port, &name[n].name, |
908 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
|
909 } |
56
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
910 } |
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
911 } |
455 | 912 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
913 #endif |
56
058f01f78761
nginx-0.0.1-2003-01-29-20:02:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
55
diff
changeset
|
914 |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
41
diff
changeset
|
915 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
|
916 } |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
917 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
918 |
455 | 919 /* |
920 * add the server address, the server names and the server core module | |
921 * configurations to the port (in_port) | |
922 */ | |
923 | |
499 | 924 static ngx_int_t |
593 | 925 ngx_http_add_address(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port, |
499 | 926 ngx_http_listen_t *lscf, ngx_http_core_srv_conf_t *cscf) |
455 | 927 { |
593 | 928 ngx_http_conf_in_addr_t *in_addr; |
455 | 929 |
930 if (in_port->addrs.elts == NULL) { | |
593 | 931 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4, |
932 sizeof(ngx_http_conf_in_addr_t)) != NGX_OK) | |
455 | 933 { |
934 return NGX_ERROR; | |
935 } | |
936 } | |
937 | |
501 | 938 in_addr = ngx_array_push(&in_port->addrs); |
939 if (in_addr == NULL) { | |
455 | 940 return NGX_ERROR; |
941 } | |
942 | |
943 in_addr->addr = lscf->addr; | |
593 | 944 in_addr->hash.buckets = NULL; |
945 in_addr->hash.size = 0; | |
946 in_addr->dns_wildcards = NULL; | |
455 | 947 in_addr->names.elts = NULL; |
948 in_addr->core_srv_conf = cscf; | |
593 | 949 in_addr->default_server = lscf->conf.default_server; |
950 in_addr->bind = lscf->conf.bind; | |
951 in_addr->listen_conf = &lscf->conf; | |
455 | 952 |
953 #if (NGX_DEBUG) | |
954 { | |
955 u_char text[20]; | |
956 ngx_inet_ntop(AF_INET, &in_addr->addr, text, 20); | |
957 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, "address: %s:%d", | |
958 text, in_port->port); | |
959 } | |
960 #endif | |
961 | |
962 return ngx_http_add_names(cf, in_addr, cscf); | |
963 } | |
964 | |
965 | |
966 /* | |
967 * add the server names and the server core module | |
968 * configurations to the address:port (in_addr) | |
969 */ | |
970 | |
499 | 971 static ngx_int_t |
593 | 972 ngx_http_add_names(ngx_conf_t *cf, ngx_http_conf_in_addr_t *in_addr, |
499 | 973 ngx_http_core_srv_conf_t *cscf) |
455 | 974 { |
477 | 975 ngx_uint_t i, n; |
455 | 976 ngx_http_server_name_t *server_names, *name; |
977 | |
978 if (in_addr->names.elts == NULL) { | |
593 | 979 if (ngx_array_init(&in_addr->names, cf->temp_pool, 4, |
501 | 980 sizeof(ngx_http_server_name_t)) != NGX_OK) |
477 | 981 { |
982 return NGX_ERROR; | |
983 } | |
984 } | |
985 | |
455 | 986 server_names = cscf->server_names.elts; |
987 for (i = 0; i < cscf->server_names.nelts; i++) { | |
988 | |
477 | 989 for (n = 0; n < server_names[i].name.len; n++) { |
990 server_names[i].name.data[n] = | |
991 ngx_tolower(server_names[i].name.data[n]); | |
992 } | |
993 | |
455 | 994 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
461 | 995 "name: %V", &server_names[i].name); |
455 | 996 |
997 | |
593 | 998 name = ngx_array_push(&in_addr->names); |
501 | 999 if (name == NULL) { |
455 | 1000 return NGX_ERROR; |
1001 } | |
1002 | |
1003 *name = server_names[i]; | |
1004 } | |
1005 | |
1006 return NGX_OK; | |
1007 } | |
1008 | |
1009 | |
499 | 1010 static char * |
1011 ngx_http_merge_locations(ngx_conf_t *cf, ngx_array_t *locations, | |
1012 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
|
1013 { |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1014 char *rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1015 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
|
1016 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
|
1017 |
593 | 1018 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
|
1019 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 return rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1025 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1026 |
1236
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1027 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
|
1028 continue; |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1029 } |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1030 |
5e4d3b5d7ad0
use pointer to an array instead of array for inclusive locations inside location
Igor Sysoev <igor@sysoev.ru>
parents:
1209
diff
changeset
|
1031 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
|
1032 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
|
1033 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
|
1034 return rv; |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1035 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1036 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1037 |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
368
diff
changeset
|
1038 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
|
1039 } |
593 | 1040 |
1041 | |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
751
diff
changeset
|
1042 static int |
593 | 1043 ngx_http_cmp_conf_in_addrs(const void *one, const void *two) |
1044 { | |
1045 ngx_http_conf_in_addr_t *first, *second; | |
1046 | |
1047 first = (ngx_http_conf_in_addr_t *) one; | |
1048 second = (ngx_http_conf_in_addr_t *) two; | |
1049 | |
1050 if (first->addr == INADDR_ANY) { | |
1051 /* the INADDR_ANY must be the last resort, shift it to the end */ | |
1052 return 1; | |
1053 } | |
1054 | |
1055 if (first->bind && !second->bind) { | |
1056 /* shift explicit bind()ed addresses to the start */ | |
1057 return -1; | |
1058 } | |
1059 | |
1060 if (!first->bind && second->bind) { | |
1061 /* shift explicit bind()ed addresses to the start */ | |
1062 return 1; | |
1063 } | |
1064 | |
1065 /* do not sort by default */ | |
1066 | |
1067 return 0; | |
1068 } | |
1069 | |
1070 | |
1071 static int ngx_libc_cdecl | |
1072 ngx_http_cmp_dns_wildcards(const void *one, const void *two) | |
1073 { | |
1074 ngx_hash_key_t *first, *second; | |
1075 | |
1076 first = (ngx_hash_key_t *) one; | |
1077 second = (ngx_hash_key_t *) two; | |
1078 | |
1079 return ngx_strcmp(first->key.data, second->key.data); | |
1080 } |