Mercurial > hg > nginx-ranges
comparison src/http/ngx_http_core_module.c @ 34:aab2ea7c0458 NGINX_0_1_17
nginx 0.1.17
*) Change: the ngx_http_rewrite_module was rewritten from the scratch.
Now it is possible to redirect, to return the error codes, to check
the variables and referrers. The directives can be used inside
locations. The redirect directive was canceled.
*) Feature: the ngx_http_geo_module.
*) Feature: the proxy_set_x_var and fastcgi_set_var directives.
*) Bugfix: the location configuration with "=" modifier may be used in
another location.
*) Bugfix: the correct content type was set only for requests that use
small caps letters in extension.
*) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the
location, and access was denied, and the error was redirected to a
static page, then the segmentation fault occurred.
*) Bugfix: if in a proxied "Location" header was a relative URL, then a
host name and a slash were added to them; bug appeared in 0.1.14.
*) Bugfix: the system error message was not logged on Linux.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 03 Feb 2005 00:00:00 +0300 |
parents | da8c190bdaba |
children | a39d1b793287 |
comparison
equal
deleted
inserted
replaced
33:27f09a550803 | 34:aab2ea7c0458 |
---|---|
15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 | 15 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 |
16 #define NGX_HTTP_LOCATION_NOREGEX 3 | 16 #define NGX_HTTP_LOCATION_NOREGEX 3 |
17 #define NGX_HTTP_LOCATION_REGEX 4 | 17 #define NGX_HTTP_LOCATION_REGEX 4 |
18 | 18 |
19 | 19 |
20 static void ngx_http_phase_event_handler(ngx_event_t *rev); | 20 static void ngx_http_core_phase_event_handler(ngx_event_t *rev); |
21 static void ngx_http_run_phases(ngx_http_request_t *r); | 21 static void ngx_http_core_run_phases(ngx_http_request_t *r); |
22 static ngx_int_t ngx_http_find_location(ngx_http_request_t *r, | 22 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, |
23 ngx_array_t *locations, size_t len); | 23 ngx_array_t *locations, size_t len); |
24 | 24 |
25 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); | 25 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
26 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); | 26 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
27 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); | 27 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
28 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, | 28 static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
29 void *parent, void *child); | 29 void *parent, void *child); |
30 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); | 30 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); |
31 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, | 31 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
32 void *parent, void *child); | 32 void *parent, void *child); |
33 | 33 |
34 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); | 34 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, |
35 static int ngx_cmp_locations(const void *first, const void *second); | 35 void *dummy); |
36 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, | 36 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, |
37 void *dummy); | 37 void *dummy); |
38 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 38 static int ngx_http_core_cmp_locations(const void *first, const void *second); |
39 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | 39 |
40 static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 40 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, |
41 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, | |
42 void *conf); | 41 void *conf); |
43 static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 42 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, |
44 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 43 void *conf); |
45 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 44 |
46 static char *ngx_set_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 45 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, |
47 | 46 void *conf); |
48 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data); | 47 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
49 | 48 void *conf); |
50 static ngx_conf_post_t ngx_http_lowat_post = { ngx_http_lowat_check } ; | 49 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
50 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, | |
51 void *conf); | |
52 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, | |
53 void *conf); | |
54 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, | |
55 void *conf); | |
56 | |
57 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); | |
58 | |
59 static ngx_conf_post_t ngx_http_core_lowat_post = | |
60 { ngx_http_core_lowat_check }; | |
51 | 61 |
52 | 62 |
53 static ngx_conf_enum_t ngx_http_restrict_host_names[] = { | 63 static ngx_conf_enum_t ngx_http_restrict_host_names[] = { |
54 { ngx_string("off"), NGX_HTTP_RESTRICT_HOST_OFF }, | 64 { ngx_string("off"), NGX_HTTP_RESTRICT_HOST_OFF }, |
55 { ngx_string("on"), NGX_HTTP_RESTRICT_HOST_ON }, | 65 { ngx_string("on"), NGX_HTTP_RESTRICT_HOST_ON }, |
74 offsetof(ngx_http_core_main_conf_t, server_names_hash_threshold), | 84 offsetof(ngx_http_core_main_conf_t, server_names_hash_threshold), |
75 NULL }, | 85 NULL }, |
76 | 86 |
77 { ngx_string("server"), | 87 { ngx_string("server"), |
78 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | 88 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
79 ngx_server_block, | 89 ngx_http_core_server, |
80 0, | 90 0, |
81 0, | 91 0, |
82 NULL }, | 92 NULL }, |
83 | 93 |
84 { ngx_string("connection_pool_size"), | 94 { ngx_string("connection_pool_size"), |
130 offsetof(ngx_http_core_srv_conf_t, restrict_host_names), | 140 offsetof(ngx_http_core_srv_conf_t, restrict_host_names), |
131 &ngx_http_restrict_host_names }, | 141 &ngx_http_restrict_host_names }, |
132 | 142 |
133 { ngx_string("location"), | 143 { ngx_string("location"), |
134 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12, | 144 NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12, |
135 ngx_location_block, | 145 ngx_http_core_location, |
136 NGX_HTTP_SRV_CONF_OFFSET, | 146 NGX_HTTP_SRV_CONF_OFFSET, |
137 0, | 147 0, |
138 NULL }, | 148 NULL }, |
139 | 149 |
140 { ngx_string("listen"), | 150 { ngx_string("listen"), |
141 #if 0 | 151 #if 0 |
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | 152 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
143 #else | 153 #else |
144 NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12, | 154 NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12, |
145 #endif | 155 #endif |
146 ngx_http_listen, | 156 ngx_http_core_listen, |
147 NGX_HTTP_SRV_CONF_OFFSET, | 157 NGX_HTTP_SRV_CONF_OFFSET, |
148 0, | 158 0, |
149 NULL }, | 159 NULL }, |
150 | 160 |
151 { ngx_string("server_name"), | 161 { ngx_string("server_name"), |
152 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, | 162 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
153 ngx_set_server_name, | 163 ngx_http_core_server_name, |
154 NGX_HTTP_SRV_CONF_OFFSET, | 164 NGX_HTTP_SRV_CONF_OFFSET, |
155 0, | 165 0, |
156 NULL }, | 166 NULL }, |
157 | 167 |
158 { ngx_string("types"), | 168 { ngx_string("types"), |
159 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF | 169 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |
160 |NGX_CONF_BLOCK|NGX_CONF_NOARGS, | 170 |NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
161 ngx_types_block, | 171 ngx_http_core_types, |
162 NGX_HTTP_LOC_CONF_OFFSET, | 172 NGX_HTTP_LOC_CONF_OFFSET, |
163 0, | 173 0, |
164 NULL }, | 174 NULL }, |
165 | 175 |
166 { ngx_string("default_type"), | 176 { ngx_string("default_type"), |
170 offsetof(ngx_http_core_loc_conf_t, default_type), | 180 offsetof(ngx_http_core_loc_conf_t, default_type), |
171 NULL }, | 181 NULL }, |
172 | 182 |
173 { ngx_string("root"), | 183 { ngx_string("root"), |
174 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 184 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
175 ngx_set_root, | 185 ngx_http_core_root, |
176 NGX_HTTP_LOC_CONF_OFFSET, | 186 NGX_HTTP_LOC_CONF_OFFSET, |
177 0, | 187 0, |
178 NULL }, | 188 NULL }, |
179 | 189 |
180 { ngx_string("alias"), | 190 { ngx_string("alias"), |
181 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 191 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
182 ngx_set_root, | 192 ngx_http_core_root, |
183 NGX_HTTP_LOC_CONF_OFFSET, | 193 NGX_HTTP_LOC_CONF_OFFSET, |
184 0, | 194 0, |
185 NULL }, | 195 NULL }, |
186 | 196 |
187 { ngx_string("client_max_body_size"), | 197 { ngx_string("client_max_body_size"), |
243 { ngx_string("send_lowat"), | 253 { ngx_string("send_lowat"), |
244 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 254 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
245 ngx_conf_set_size_slot, | 255 ngx_conf_set_size_slot, |
246 NGX_HTTP_LOC_CONF_OFFSET, | 256 NGX_HTTP_LOC_CONF_OFFSET, |
247 offsetof(ngx_http_core_loc_conf_t, send_lowat), | 257 offsetof(ngx_http_core_loc_conf_t, send_lowat), |
248 &ngx_http_lowat_post }, | 258 &ngx_http_core_lowat_post }, |
249 | 259 |
250 { ngx_string("postpone_output"), | 260 { ngx_string("postpone_output"), |
251 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 261 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
252 ngx_conf_set_size_slot, | 262 ngx_conf_set_size_slot, |
253 NGX_HTTP_LOC_CONF_OFFSET, | 263 NGX_HTTP_LOC_CONF_OFFSET, |
254 offsetof(ngx_http_core_loc_conf_t, postpone_output), | 264 offsetof(ngx_http_core_loc_conf_t, postpone_output), |
255 NULL }, | 265 NULL }, |
256 | 266 |
257 { ngx_string("limit_rate"), | 267 { ngx_string("limit_rate"), |
258 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 268 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
269 |NGX_CONF_TAKE1, | |
259 ngx_conf_set_size_slot, | 270 ngx_conf_set_size_slot, |
260 NGX_HTTP_LOC_CONF_OFFSET, | 271 NGX_HTTP_LOC_CONF_OFFSET, |
261 offsetof(ngx_http_core_loc_conf_t, limit_rate), | 272 offsetof(ngx_http_core_loc_conf_t, limit_rate), |
262 NULL }, | 273 NULL }, |
263 | 274 |
264 { ngx_string("keepalive_timeout"), | 275 { ngx_string("keepalive_timeout"), |
265 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, | 276 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
266 ngx_set_keepalive, | 277 ngx_http_core_keepalive, |
267 NGX_HTTP_LOC_CONF_OFFSET, | 278 NGX_HTTP_LOC_CONF_OFFSET, |
268 0, | 279 0, |
269 NULL }, | 280 NULL }, |
270 | 281 |
271 { ngx_string("lingering_time"), | 282 { ngx_string("lingering_time"), |
296 offsetof(ngx_http_core_loc_conf_t, msie_padding), | 307 offsetof(ngx_http_core_loc_conf_t, msie_padding), |
297 NULL }, | 308 NULL }, |
298 | 309 |
299 { ngx_string("error_page"), | 310 { ngx_string("error_page"), |
300 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | 311 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, |
301 ngx_set_error_page, | 312 ngx_http_core_error_page, |
302 NGX_HTTP_LOC_CONF_OFFSET, | 313 NGX_HTTP_LOC_CONF_OFFSET, |
303 0, | 314 0, |
304 NULL }, | 315 NULL }, |
305 | 316 |
306 { ngx_string("error_log"), | 317 { ngx_string("error_log"), |
307 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 318 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
308 ngx_set_error_log, | 319 ngx_http_core_error_log, |
309 NGX_HTTP_LOC_CONF_OFFSET, | 320 NGX_HTTP_LOC_CONF_OFFSET, |
310 0, | 321 0, |
311 NULL }, | 322 NULL }, |
312 | 323 |
313 #if (NGX_HTTP_CACHE) | 324 #if (NGX_HTTP_CACHE) |
397 | 408 |
398 #if 0 | 409 #if 0 |
399 /* TEST STUB */ r->lingering_close = 1; | 410 /* TEST STUB */ r->lingering_close = 1; |
400 #endif | 411 #endif |
401 | 412 |
402 r->connection->write->event_handler = ngx_http_phase_event_handler; | 413 r->connection->write->event_handler = ngx_http_core_phase_event_handler; |
403 | 414 |
404 ngx_http_run_phases(r); | 415 r->uri_changed = 1; |
416 r->uri_changes = 11; | |
417 | |
418 ngx_http_core_run_phases(r); | |
405 | 419 |
406 return; | 420 return; |
407 } | 421 } |
408 | 422 |
409 | 423 |
410 static void ngx_http_phase_event_handler(ngx_event_t *ev) | 424 static void ngx_http_core_phase_event_handler(ngx_event_t *ev) |
411 { | 425 { |
412 ngx_connection_t *c; | 426 ngx_connection_t *c; |
413 ngx_http_request_t *r; | 427 ngx_http_request_t *r; |
414 | 428 |
415 c = ev->data; | 429 c = ev->data; |
416 r = c->data; | 430 r = c->data; |
417 | 431 |
418 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler"); | 432 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler"); |
419 | 433 |
420 ngx_http_run_phases(r); | 434 ngx_http_core_run_phases(r); |
421 | 435 |
422 return; | 436 return; |
423 } | 437 } |
424 | 438 |
425 | 439 |
426 static void ngx_http_run_phases(ngx_http_request_t *r) | 440 static void ngx_http_core_run_phases(ngx_http_request_t *r) |
427 { | 441 { |
428 char *path; | |
429 ngx_int_t rc; | 442 ngx_int_t rc; |
430 ngx_http_handler_pt *h; | 443 ngx_http_handler_pt *h; |
431 ngx_http_core_loc_conf_t *clcf; | 444 ngx_http_core_loc_conf_t *clcf; |
432 ngx_http_core_main_conf_t *cmcf; | 445 ngx_http_core_main_conf_t *cmcf; |
433 | 446 |
434 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 447 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
435 | 448 |
436 for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) { | 449 for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) { |
437 | 450 |
451 if (r->phase == NGX_HTTP_FIND_CONFIG_PHASE && !r->uri_changed) { | |
452 continue; | |
453 } | |
454 | |
455 if (r->phase == NGX_HTTP_FIND_CONFIG_PHASE + 1 && r->uri_changed) { | |
456 | |
457 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
458 "uri changes: %d", r->uri_changes); | |
459 | |
460 /* | |
461 * gcc before 3.3 compiles the broken code for | |
462 * if (r->uri_changes-- == 0) | |
463 * if the r->uri_changes is defined as | |
464 * unsigned uri_changes:4 | |
465 */ | |
466 | |
467 r->uri_changes--; | |
468 | |
469 if (r->uri_changes == 0) { | |
470 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
471 "rewrite cycle"); | |
472 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
473 return; | |
474 } | |
475 | |
476 r->uri_changed = 0; | |
477 r->phase = NGX_HTTP_REWRITE_PHASE; | |
478 } | |
479 | |
438 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) { | 480 if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) { |
439 r->connection->write->event_handler = ngx_http_empty_handler; | 481 r->connection->write->event_handler = ngx_http_empty_handler; |
440 rc = r->content_handler(r); | 482 ngx_http_finalize_request(r, r->content_handler(r)); |
441 ngx_http_finalize_request(r, rc); | |
442 return; | 483 return; |
443 } | 484 } |
444 | 485 |
445 h = cmcf->phases[r->phase].handlers.elts; | 486 h = cmcf->phases[r->phase].handlers.elts; |
446 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1; | 487 for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1; |
481 break; | 522 break; |
482 } | 523 } |
483 } | 524 } |
484 } | 525 } |
485 | 526 |
527 /* no content handler was found */ | |
486 | 528 |
487 if (r->uri.data[r->uri.len - 1] == '/') { | 529 if (r->uri.data[r->uri.len - 1] == '/') { |
488 | 530 |
489 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 531 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
490 | 532 |
491 if (!(path = ngx_palloc(r->pool, clcf->root.len + r->uri.len))) { | |
492 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
493 return; | |
494 } | |
495 | |
496 ngx_cpystrn(ngx_cpymem(path, clcf->root.data, clcf->root.len), | |
497 r->uri.data, r->uri.len + 1); | |
498 | |
499 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 533 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
500 "directory index of \"%s\" is forbidden", path); | 534 "directory index of \"%V%V\" is forbidden", |
535 &clcf->root, &r->uri); | |
501 | 536 |
502 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN); | 537 ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN); |
503 return; | 538 return; |
504 } | 539 } |
505 | 540 |
516 ngx_http_core_loc_conf_t *clcf; | 551 ngx_http_core_loc_conf_t *clcf; |
517 ngx_http_core_srv_conf_t *cscf; | 552 ngx_http_core_srv_conf_t *cscf; |
518 | 553 |
519 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 554 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
520 | 555 |
521 rc = ngx_http_find_location(r, &cscf->locations, 0); | 556 rc = ngx_http_core_find_location(r, &cscf->locations, 0); |
522 | 557 |
523 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | 558 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { |
524 return rc; | 559 return rc; |
525 } | 560 } |
526 | 561 |
581 | 616 |
582 return NGX_OK; | 617 return NGX_OK; |
583 } | 618 } |
584 | 619 |
585 | 620 |
586 static ngx_int_t ngx_http_find_location(ngx_http_request_t *r, | 621 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, |
587 ngx_array_t *locations, size_t len) | 622 ngx_array_t *locations, size_t len) |
588 { | 623 { |
589 ngx_int_t n, rc; | 624 ngx_int_t n, rc; |
590 ngx_uint_t i, found, noregex; | 625 ngx_uint_t i, found, noregex; |
591 ngx_http_core_loc_conf_t *clcf, **clcfp; | 626 ngx_http_core_loc_conf_t *clcf, **clcfp; |
592 | 627 |
601 #if (NGX_PCRE) | 636 #if (NGX_PCRE) |
602 if (clcfp[i]->regex) { | 637 if (clcfp[i]->regex) { |
603 break; | 638 break; |
604 } | 639 } |
605 #endif | 640 #endif |
641 | |
642 if (clcfp[i]->noname) { | |
643 break; | |
644 } | |
606 | 645 |
607 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 646 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
608 "find location: %s\"%V\"", | 647 "find location: %s\"%V\"", |
609 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name); | 648 clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name); |
610 | 649 |
630 /* the locations are lexicographically sorted */ | 669 /* the locations are lexicographically sorted */ |
631 break; | 670 break; |
632 } | 671 } |
633 | 672 |
634 if (n == 0) { | 673 if (n == 0) { |
635 if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) { | 674 if (clcfp[i]->exact_match) { |
636 r->loc_conf = clcfp[i]->loc_conf; | 675 |
637 return NGX_HTTP_LOCATION_EXACT; | 676 if (r->uri.len == clcfp[i]->name.len) { |
677 r->loc_conf = clcfp[i]->loc_conf; | |
678 return NGX_HTTP_LOCATION_EXACT; | |
679 } | |
680 | |
681 continue; | |
638 } | 682 } |
639 | 683 |
640 if (len > clcfp[i]->name.len) { | 684 if (len > clcfp[i]->name.len) { |
641 /* the previous match is longer */ | 685 /* the previous match is longer */ |
642 break; | 686 break; |
650 | 694 |
651 if (found) { | 695 if (found) { |
652 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 696 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
653 | 697 |
654 if (clcf->locations.nelts) { | 698 if (clcf->locations.nelts) { |
655 rc = ngx_http_find_location(r, &clcf->locations, len); | 699 rc = ngx_http_core_find_location(r, &clcf->locations, len); |
656 | 700 |
657 if (rc != NGX_OK) { | 701 if (rc != NGX_OK) { |
658 return rc; | 702 return rc; |
659 } | 703 } |
660 } | 704 } |
670 | 714 |
671 for (/* void */; i < locations->nelts; i++) { | 715 for (/* void */; i < locations->nelts; i++) { |
672 | 716 |
673 if (!clcfp[i]->regex) { | 717 if (!clcfp[i]->regex) { |
674 continue; | 718 continue; |
719 } | |
720 | |
721 if (clcfp[i]->noname) { | |
722 break; | |
675 } | 723 } |
676 | 724 |
677 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 725 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
678 "find location: ~ \"%V\"", &clcfp[i]->name); | 726 "find location: ~ \"%V\"", &clcfp[i]->name); |
679 | 727 |
704 } | 752 } |
705 | 753 |
706 | 754 |
707 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) | 755 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) |
708 { | 756 { |
757 u_char c, *p, *exten; | |
709 uint32_t key; | 758 uint32_t key; |
710 ngx_uint_t i; | 759 ngx_uint_t i; |
711 ngx_http_type_t *type; | 760 ngx_http_type_t *type; |
712 ngx_http_core_loc_conf_t *clcf; | 761 ngx_http_core_loc_conf_t *clcf; |
713 | 762 |
722 r->headers_out.content_type->value.data = NULL; | 771 r->headers_out.content_type->value.data = NULL; |
723 | 772 |
724 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 773 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
725 | 774 |
726 if (r->exten.len) { | 775 if (r->exten.len) { |
776 | |
777 if (!r->low_case_exten) { | |
778 for (i = 0; i < r->exten.len; i++) { | |
779 c = r->exten.data[i]; | |
780 if (c >= 'A' && c <= 'Z') { | |
781 break; | |
782 } | |
783 } | |
784 | |
785 if (i < r->exten.len) { | |
786 if (!(p = ngx_palloc(r->pool, r->exten.len))) { | |
787 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
788 } | |
789 | |
790 exten = p; | |
791 | |
792 for (i = 0; i < r->exten.len; i++) { | |
793 c = r->exten.data[i]; | |
794 if (c >= 'A' && c <= 'Z') { | |
795 *p++ = (u_char) (c | 0x20); | |
796 } else { | |
797 *p++ = c; | |
798 } | |
799 } | |
800 | |
801 r->exten.data = exten; | |
802 } | |
803 | |
804 r->low_case_exten = 1; | |
805 } | |
806 | |
727 #if 0 | 807 #if 0 |
728 key = ngx_crc(r->exten.data, r->exten.key); | 808 key = ngx_crc(r->exten.data, r->exten.key); |
729 #endif | 809 #endif |
730 ngx_http_types_hash_key(key, r->exten); | 810 ngx_http_types_hash_key(key, r->exten); |
731 | 811 |
824 } else if (r->uri.data[i] == '/') { | 904 } else if (r->uri.data[i] == '/') { |
825 break; | 905 break; |
826 } | 906 } |
827 } | 907 } |
828 | 908 |
909 r->low_case_exten = 0; | |
910 | |
829 return NGX_OK; | 911 return NGX_OK; |
830 } | 912 } |
831 | 913 |
832 | 914 |
833 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, | 915 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, |
862 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); | 944 ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); |
863 } | 945 } |
864 | 946 |
865 r->phase = 0; | 947 r->phase = 0; |
866 r->phase_handler = 0; | 948 r->phase_handler = 0; |
949 r->content_handler = NULL; | |
867 | 950 |
868 ngx_http_handler(r); | 951 ngx_http_handler(r); |
869 | 952 |
870 return NGX_DONE; | 953 return NGX_DONE; |
871 } | 954 } |
891 } | 974 } |
892 | 975 |
893 #endif | 976 #endif |
894 | 977 |
895 | 978 |
896 #if 0 | 979 ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf) |
897 | 980 { |
898 static ngx_int_t ngx_http_core_init_process(ngx_cycle_t *cycle) | 981 ngx_http_variable_t *var; |
899 { | 982 ngx_http_core_main_conf_t *cmcf; |
900 ngx_uint_t i; | 983 |
901 ngx_http_core_srv_conf_t **cscfp; | 984 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
902 ngx_http_core_main_conf_t *cmcf; | 985 |
903 | 986 if (cmcf->variables.elts == NULL) { |
904 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module); | 987 if (ngx_array_init(&cmcf->variables, cf->pool, 5, |
905 | 988 sizeof(ngx_http_variable_t)) == NGX_ERROR) |
906 #if 0 | 989 { |
907 ngx_http_core_init_module: | 990 return NULL; |
908 | 991 } |
909 ngx_http_handler_pt *h; | 992 } |
910 | 993 |
911 ngx_test_null(h, ngx_push_array( | 994 if (!(var = ngx_array_push(&cmcf->variables))) { |
912 &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), | 995 return NULL; |
913 NGX_ERROR); | 996 } |
914 *h = ngx_http_delay_handler; | 997 |
915 #endif | 998 var->index = cmcf->variables.nelts - 1; |
916 | 999 |
917 cscfp = cmcf->servers.elts; | 1000 return var; |
918 | 1001 } |
919 for (i = 0; i < cmcf->servers.nelts; i++) { | 1002 |
920 if (cscfp[i]->recv == NULL) { | 1003 |
921 cscfp[i]->recv = ngx_io.recv; | 1004 ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r, |
922 cscfp[i]->send_chain = ngx_io.send_chain; | 1005 ngx_uint_t index) |
923 } | 1006 { |
924 } | 1007 ngx_http_variable_t *v; |
925 | 1008 ngx_http_core_main_conf_t *cmcf; |
926 return NGX_OK; | 1009 |
927 } | 1010 /* TODO: cached variables */ |
928 | 1011 |
929 #endif | 1012 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
930 | 1013 |
931 | 1014 if (cmcf->variables.elts == NULL || cmcf->variables.nelts <= index) { |
932 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | 1015 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
1016 "unknown variable index: %d", index); | |
1017 return NULL; | |
1018 } | |
1019 | |
1020 v = cmcf->variables.elts; | |
1021 | |
1022 return v[index].handler(r, v[index].data); | |
1023 } | |
1024 | |
1025 | |
1026 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
1027 void *dummy) | |
933 { | 1028 { |
934 int m; | 1029 int m; |
935 char *rv; | 1030 char *rv; |
936 ngx_http_module_t *module; | 1031 ngx_http_module_t *module; |
937 ngx_conf_t pvcf; | 1032 ngx_conf_t save; |
938 ngx_http_conf_ctx_t *ctx, *http_ctx; | 1033 ngx_http_conf_ctx_t *ctx, *http_ctx; |
939 ngx_http_core_main_conf_t *cmcf; | 1034 ngx_http_core_main_conf_t *cmcf; |
940 ngx_http_core_srv_conf_t *cscf, **cscfp; | 1035 ngx_http_core_srv_conf_t *cscf, **cscfp; |
941 | 1036 |
942 ngx_test_null(ctx, | 1037 ngx_test_null(ctx, |
987 ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR); | 1082 ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR); |
988 *cscfp = cscf; | 1083 *cscfp = cscf; |
989 | 1084 |
990 /* parse inside server{} */ | 1085 /* parse inside server{} */ |
991 | 1086 |
992 pvcf = *cf; | 1087 save = *cf; |
993 cf->ctx = ctx; | 1088 cf->ctx = ctx; |
994 cf->cmd_type = NGX_HTTP_SRV_CONF; | 1089 cf->cmd_type = NGX_HTTP_SRV_CONF; |
1090 | |
995 rv = ngx_conf_parse(cf, NULL); | 1091 rv = ngx_conf_parse(cf, NULL); |
996 *cf = pvcf; | 1092 |
1093 *cf = save; | |
997 | 1094 |
998 if (rv != NGX_CONF_OK) { | 1095 if (rv != NGX_CONF_OK) { |
999 return rv; | 1096 return rv; |
1000 } | 1097 } |
1001 | 1098 |
1002 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts, | 1099 ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts, |
1003 sizeof(ngx_http_core_loc_conf_t *), ngx_cmp_locations); | 1100 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); |
1004 | 1101 |
1005 return rv; | 1102 return rv; |
1006 } | 1103 } |
1007 | 1104 |
1008 | 1105 |
1009 static int ngx_cmp_locations(const void *one, const void *two) | 1106 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, |
1010 { | 1107 void *dummy) |
1011 ngx_int_t rc; | |
1012 ngx_http_core_loc_conf_t *first, *second; | |
1013 | |
1014 first = *(ngx_http_core_loc_conf_t **) one; | |
1015 second = *(ngx_http_core_loc_conf_t **) two; | |
1016 | |
1017 #if (NGX_PCRE) | |
1018 | |
1019 if (first->regex && !second->regex) { | |
1020 /* shift the regex matches to the end */ | |
1021 return 1; | |
1022 } | |
1023 | |
1024 if (!first->regex && second->regex) { | |
1025 /* shift the regex matches to the end */ | |
1026 return -1; | |
1027 } | |
1028 | |
1029 if (first->regex || second->regex) { | |
1030 /* do not sort the regex matches */ | |
1031 return 0; | |
1032 } | |
1033 | |
1034 #endif | |
1035 | |
1036 rc = ngx_strcmp(first->name.data, second->name.data); | |
1037 | |
1038 if (rc == 0 && second->exact_match) { | |
1039 /* an exact match must be before the same inclusive one */ | |
1040 return 1; | |
1041 } | |
1042 | |
1043 return (int) rc; | |
1044 } | |
1045 | |
1046 | |
1047 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | |
1048 { | 1108 { |
1049 char *rv; | 1109 char *rv; |
1050 ngx_int_t m; | 1110 ngx_int_t m; |
1051 ngx_str_t *value; | 1111 ngx_str_t *value; |
1052 ngx_conf_t pcf; | 1112 ngx_conf_t save; |
1053 ngx_http_module_t *module; | 1113 ngx_http_module_t *module; |
1054 ngx_http_conf_ctx_t *ctx, *pctx; | 1114 ngx_http_conf_ctx_t *ctx, *pctx; |
1055 ngx_http_core_srv_conf_t *cscf; | 1115 ngx_http_core_srv_conf_t *cscf; |
1056 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp; | 1116 ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp; |
1057 #if (NGX_PCRE) | 1117 #if (NGX_PCRE) |
1148 if (!(clcfp = ngx_push_array(&cscf->locations))) { | 1208 if (!(clcfp = ngx_push_array(&cscf->locations))) { |
1149 return NGX_CONF_ERROR; | 1209 return NGX_CONF_ERROR; |
1150 } | 1210 } |
1151 | 1211 |
1152 } else { | 1212 } else { |
1213 #if 0 | |
1153 clcf->prev_location = pclcf; | 1214 clcf->prev_location = pclcf; |
1215 #endif | |
1154 | 1216 |
1155 if (pclcf->exact_match) { | 1217 if (pclcf->exact_match) { |
1156 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1218 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1157 "location \"%V\" could not be inside " | 1219 "location \"%V\" could not be inside " |
1158 "the exact location \"%V\"", | 1220 "the exact location \"%V\"", |
1174 &clcf->name, &pclcf->name); | 1236 &clcf->name, &pclcf->name); |
1175 return NGX_CONF_ERROR; | 1237 return NGX_CONF_ERROR; |
1176 } | 1238 } |
1177 | 1239 |
1178 if (pclcf->locations.elts == NULL) { | 1240 if (pclcf->locations.elts == NULL) { |
1179 ngx_init_array(pclcf->locations, cf->pool, 5, sizeof(void *), | 1241 ngx_init_array(pclcf->locations, cf->pool, 4, sizeof(void *), |
1180 NGX_CONF_ERROR); | 1242 NGX_CONF_ERROR); |
1181 } | 1243 } |
1182 | 1244 |
1183 if (!(clcfp = ngx_push_array(&pclcf->locations))) { | 1245 if (!(clcfp = ngx_push_array(&pclcf->locations))) { |
1184 return NGX_CONF_ERROR; | 1246 return NGX_CONF_ERROR; |
1185 } | 1247 } |
1186 } | 1248 } |
1187 | 1249 |
1188 *clcfp = clcf; | 1250 *clcfp = clcf; |
1189 | 1251 |
1190 pcf = *cf; | 1252 save = *cf; |
1191 cf->ctx = ctx; | 1253 cf->ctx = ctx; |
1192 cf->cmd_type = NGX_HTTP_LOC_CONF; | 1254 cf->cmd_type = NGX_HTTP_LOC_CONF; |
1255 | |
1193 rv = ngx_conf_parse(cf, NULL); | 1256 rv = ngx_conf_parse(cf, NULL); |
1194 *cf = pcf; | 1257 |
1258 *cf = save; | |
1259 | |
1260 if (rv != NGX_CONF_OK) { | |
1261 return rv; | |
1262 } | |
1263 | |
1264 ngx_qsort(clcf->locations.elts, (size_t) clcf->locations.nelts, | |
1265 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); | |
1195 | 1266 |
1196 return rv; | 1267 return rv; |
1197 } | 1268 } |
1198 | 1269 |
1199 | 1270 |
1200 static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1271 static int ngx_http_core_cmp_locations(const void *one, const void *two) |
1272 { | |
1273 ngx_int_t rc; | |
1274 ngx_http_core_loc_conf_t *first, *second; | |
1275 | |
1276 first = *(ngx_http_core_loc_conf_t **) one; | |
1277 second = *(ngx_http_core_loc_conf_t **) two; | |
1278 | |
1279 if (first->noname && !second->noname) { | |
1280 /* shift no named locations to the end */ | |
1281 return 1; | |
1282 } | |
1283 | |
1284 if (!first->noname && second->noname) { | |
1285 /* shift no named locations to the end */ | |
1286 return -1; | |
1287 } | |
1288 | |
1289 if (first->noname || second->noname) { | |
1290 /* do not sort no named locations */ | |
1291 return 0; | |
1292 } | |
1293 | |
1294 #if (NGX_PCRE) | |
1295 | |
1296 if (first->regex && !second->regex) { | |
1297 /* shift the regex matches to the end */ | |
1298 return 1; | |
1299 } | |
1300 | |
1301 if (!first->regex && second->regex) { | |
1302 /* shift the regex matches to the end */ | |
1303 return -1; | |
1304 } | |
1305 | |
1306 if (first->regex || second->regex) { | |
1307 /* do not sort the regex matches */ | |
1308 return 0; | |
1309 } | |
1310 | |
1311 #endif | |
1312 | |
1313 rc = ngx_strcmp(first->name.data, second->name.data); | |
1314 | |
1315 if (rc == 0 && second->exact_match) { | |
1316 /* an exact match must be before the same inclusive one */ | |
1317 return 1; | |
1318 } | |
1319 | |
1320 return (int) rc; | |
1321 } | |
1322 | |
1323 | |
1324 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1201 { | 1325 { |
1202 char *rv; | 1326 char *rv; |
1203 ngx_conf_t pcf; | 1327 ngx_conf_t save; |
1204 | 1328 |
1205 pcf = *cf; | 1329 save = *cf; |
1206 cf->handler = ngx_set_type; | 1330 cf->handler = ngx_http_core_type; |
1207 cf->handler_conf = conf; | 1331 cf->handler_conf = conf; |
1332 | |
1208 rv = ngx_conf_parse(cf, NULL); | 1333 rv = ngx_conf_parse(cf, NULL); |
1209 *cf = pcf; | 1334 |
1335 *cf = save; | |
1210 | 1336 |
1211 return rv; | 1337 return rv; |
1212 } | 1338 } |
1213 | 1339 |
1214 | 1340 |
1215 static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | 1341 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, |
1342 void *conf) | |
1216 { | 1343 { |
1217 ngx_http_core_loc_conf_t *lcf = conf; | 1344 ngx_http_core_loc_conf_t *lcf = conf; |
1218 | 1345 |
1219 uint32_t key; | 1346 uint32_t key; |
1220 ngx_uint_t i; | 1347 ngx_uint_t i; |
1221 ngx_str_t *args; | 1348 ngx_str_t *value; |
1222 ngx_http_type_t *type; | 1349 ngx_http_type_t *type; |
1223 | 1350 |
1224 if (lcf->types == NULL) { | 1351 if (lcf->types == NULL) { |
1225 lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME | 1352 lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME |
1226 * sizeof(ngx_array_t)); | 1353 * sizeof(ngx_array_t)); |
1235 return NGX_CONF_ERROR; | 1362 return NGX_CONF_ERROR; |
1236 } | 1363 } |
1237 } | 1364 } |
1238 } | 1365 } |
1239 | 1366 |
1240 args = (ngx_str_t *) cf->args->elts; | 1367 value = cf->args->elts; |
1241 | 1368 |
1242 for (i = 1; i < cf->args->nelts; i++) { | 1369 for (i = 1; i < cf->args->nelts; i++) { |
1243 ngx_http_types_hash_key(key, args[i]); | 1370 ngx_http_types_hash_key(key, value[i]); |
1244 | 1371 |
1245 if (!(type = ngx_array_push(&lcf->types[key]))) { | 1372 if (!(type = ngx_array_push(&lcf->types[key]))) { |
1246 return NGX_CONF_ERROR; | 1373 return NGX_CONF_ERROR; |
1247 } | 1374 } |
1248 | 1375 |
1249 type->exten = args[i]; | 1376 type->exten = value[i]; |
1250 type->type = args[0]; | 1377 type->type = value[0]; |
1251 } | 1378 } |
1252 | 1379 |
1253 return NGX_CONF_OK; | 1380 return NGX_CONF_OK; |
1254 } | 1381 } |
1255 | 1382 |
1256 | 1383 |
1257 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) | 1384 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) |
1258 { | 1385 { |
1259 ngx_http_core_main_conf_t *cmcf; | 1386 ngx_http_core_main_conf_t *cmcf; |
1260 | 1387 |
1261 ngx_test_null(cmcf, | 1388 if (!(cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)))) { |
1262 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)), | 1389 return NGX_CONF_ERROR; |
1263 NGX_CONF_ERROR); | 1390 } |
1264 | 1391 |
1265 ngx_init_array(cmcf->servers, cf->pool, | 1392 if (ngx_array_init(&cmcf->servers, cf->pool, 5, |
1266 5, sizeof(ngx_http_core_srv_conf_t *), | 1393 sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR) |
1267 NGX_CONF_ERROR); | 1394 { |
1395 return NGX_CONF_ERROR; | |
1396 } | |
1268 | 1397 |
1269 cmcf->server_names_hash = NGX_CONF_UNSET_UINT; | 1398 cmcf->server_names_hash = NGX_CONF_UNSET_UINT; |
1270 cmcf->server_names_hash_threshold = NGX_CONF_UNSET_UINT; | 1399 cmcf->server_names_hash_threshold = NGX_CONF_UNSET_UINT; |
1271 | 1400 |
1272 return cmcf; | 1401 return cmcf; |
1394 } | 1523 } |
1395 | 1524 |
1396 | 1525 |
1397 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) | 1526 static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
1398 { | 1527 { |
1399 ngx_http_core_loc_conf_t *lcf; | 1528 ngx_http_core_loc_conf_t *lcf; |
1400 | 1529 |
1401 ngx_test_null(lcf, | 1530 ngx_test_null(lcf, |
1402 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), | 1531 ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), |
1403 NGX_CONF_ERROR); | 1532 NGX_CONF_ERROR); |
1404 | 1533 |
1545 | 1674 |
1546 return NGX_CONF_OK; | 1675 return NGX_CONF_OK; |
1547 } | 1676 } |
1548 | 1677 |
1549 | 1678 |
1550 static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1679 static char *ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, |
1680 void *conf) | |
1551 { | 1681 { |
1552 ngx_http_core_srv_conf_t *scf = conf; | 1682 ngx_http_core_srv_conf_t *scf = conf; |
1553 | 1683 |
1554 u_char *addr; | 1684 u_char *addr; |
1555 ngx_int_t port; | 1685 ngx_int_t port; |
1631 | 1761 |
1632 return NGX_CONF_OK; | 1762 return NGX_CONF_OK; |
1633 } | 1763 } |
1634 | 1764 |
1635 | 1765 |
1636 static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1766 static char *ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
1767 void *conf) | |
1637 { | 1768 { |
1638 ngx_http_core_srv_conf_t *scf = conf; | 1769 ngx_http_core_srv_conf_t *scf = conf; |
1639 | 1770 |
1640 ngx_uint_t i; | 1771 ngx_uint_t i; |
1641 ngx_str_t *value; | 1772 ngx_str_t *value; |
1681 | 1812 |
1682 return NGX_CONF_OK; | 1813 return NGX_CONF_OK; |
1683 } | 1814 } |
1684 | 1815 |
1685 | 1816 |
1686 static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1817 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1687 { | 1818 { |
1688 ngx_http_core_loc_conf_t *lcf = conf; | 1819 ngx_http_core_loc_conf_t *lcf = conf; |
1689 | 1820 |
1690 ngx_uint_t alias; | 1821 ngx_uint_t alias; |
1691 ngx_str_t *value; | 1822 ngx_str_t *value; |
1721 | 1852 |
1722 return NGX_CONF_OK; | 1853 return NGX_CONF_OK; |
1723 } | 1854 } |
1724 | 1855 |
1725 | 1856 |
1726 static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1857 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, |
1858 void *conf) | |
1727 { | 1859 { |
1728 ngx_http_core_loc_conf_t *lcf = conf; | 1860 ngx_http_core_loc_conf_t *lcf = conf; |
1729 | 1861 |
1730 int overwrite; | 1862 int overwrite; |
1731 ngx_uint_t i, n; | 1863 ngx_uint_t i, n; |
1791 | 1923 |
1792 return NGX_CONF_OK; | 1924 return NGX_CONF_OK; |
1793 } | 1925 } |
1794 | 1926 |
1795 | 1927 |
1796 static char *ngx_set_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1928 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, |
1929 void *conf) | |
1797 { | 1930 { |
1798 ngx_http_core_loc_conf_t *lcf = conf; | 1931 ngx_http_core_loc_conf_t *lcf = conf; |
1799 | 1932 |
1800 ngx_str_t *value; | 1933 ngx_str_t *value; |
1801 | 1934 |
1829 | 1962 |
1830 return NGX_CONF_OK; | 1963 return NGX_CONF_OK; |
1831 } | 1964 } |
1832 | 1965 |
1833 | 1966 |
1834 static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1967 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, |
1968 void *conf) | |
1835 { | 1969 { |
1836 ngx_http_core_loc_conf_t *lcf = conf; | 1970 ngx_http_core_loc_conf_t *lcf = conf; |
1837 | 1971 |
1838 if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) { | 1972 if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) { |
1839 return NGX_CONF_ERROR; | 1973 return NGX_CONF_ERROR; |
1841 | 1975 |
1842 return ngx_set_error_log_levels(cf, lcf->err_log); | 1976 return ngx_set_error_log_levels(cf, lcf->err_log); |
1843 } | 1977 } |
1844 | 1978 |
1845 | 1979 |
1846 static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) | 1980 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data) |
1847 { | 1981 { |
1848 #if (NGX_FREEBSD) | 1982 #if (NGX_FREEBSD) |
1849 ssize_t *np = data; | 1983 ssize_t *np = data; |
1850 | 1984 |
1851 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { | 1985 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { |