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