comparison src/http/ngx_http_request.c @ 142:84910468f6de NGINX_0_3_18

nginx 0.3.18 *) Feature: the "server_names" directive supports the ".domain.tld" names. *) Feature: the "server_names" directive uses the hash for the "*.domain.tld" names and more effective hash for usual names. *) Change: the "server_names_hash_max_size" and "server_names_hash_bucket_size" directives. *) Change: the "server_names_hash" and "server_names_hash_threshold" directives were canceled. *) Feature: the "valid_referers" directive uses the hash site names. *) Change: now the "valid_referers" directive checks the site names only without the URI part. *) Bugfix: some ".domain.tld" names incorrectly processed by the ngx_http_map_module. *) Bugfix: segmentation fault was occurred if configuration file did not exist; bug appeared in 0.3.12. *) Bugfix: on 64-bit platforms segmentation fault may occurred on start; bug appeared in 0.3.16.
author Igor Sysoev <http://sysoev.ru>
date Mon, 26 Dec 2005 00:00:00 +0300
parents 8e6d4d96ec4c
children 36af50a5582d
comparison
equal deleted inserted replaced
141:249e67502bf3 142:84910468f6de
201 ngx_uint_t i; 201 ngx_uint_t i;
202 socklen_t len; 202 socklen_t len;
203 struct sockaddr_in sin; 203 struct sockaddr_in sin;
204 ngx_connection_t *c; 204 ngx_connection_t *c;
205 ngx_http_request_t *r; 205 ngx_http_request_t *r;
206 ngx_http_in_port_t *in_port; 206 ngx_http_in_port_t *hip;
207 ngx_http_in_addr_t *in_addr; 207 ngx_http_in_addr_t *hia;
208 ngx_http_log_ctx_t *ctx; 208 ngx_http_log_ctx_t *ctx;
209 ngx_http_connection_t *hc; 209 ngx_http_connection_t *hc;
210 ngx_http_server_name_t *server_name;
211 ngx_http_core_srv_conf_t *cscf; 210 ngx_http_core_srv_conf_t *cscf;
212 ngx_http_core_loc_conf_t *clcf; 211 ngx_http_core_loc_conf_t *clcf;
213 ngx_http_core_main_conf_t *cmcf; 212 ngx_http_core_main_conf_t *cmcf;
214 #if (NGX_HTTP_SSL) 213 #if (NGX_HTTP_SSL)
215 ngx_http_ssl_srv_conf_t *sscf; 214 ngx_http_ssl_srv_conf_t *sscf;
267 266
268 /* find the server configuration for the address:port */ 267 /* find the server configuration for the address:port */
269 268
270 /* AF_INET only */ 269 /* AF_INET only */
271 270
272 in_port = c->servers; 271 hip = c->servers;
273 in_addr = in_port->addrs.elts; 272 hia = hip->addrs;
274 273
275 r->port = in_port->port; 274 r->port = hip->port;
276 r->port_text = &in_port->port_text; 275 r->port_text = &hip->port_text;
277 276
278 i = 0; 277 i = 0;
279 278
280 if (in_port->addrs.nelts > 1) { 279 if (hip->naddrs > 1) {
281 280
282 /* 281 /*
283 * There are several addresses on this port and one of them 282 * There are several addresses on this port and one of them
284 * is the "*:port" wildcard so getsockname() is needed to determine 283 * is the "*:port" wildcard so getsockname() is needed to determine
285 * the server address. 284 * the server address.
306 r->in_addr = sin.sin_addr.s_addr; 305 r->in_addr = sin.sin_addr.s_addr;
307 } 306 }
308 307
309 /* the last in_port->addrs address is "*" */ 308 /* the last in_port->addrs address is "*" */
310 309
311 for ( /* void */ ; i < in_port->addrs.nelts - 1; i++) { 310 for ( /* void */ ; i < hip->naddrs - 1; i++) {
312 if (in_addr[i].addr == r->in_addr) { 311 if (hia[i].addr == r->in_addr) {
313 break; 312 break;
314 } 313 }
315 } 314 }
316 315
317 } else { 316 } else {
318 r->in_addr = in_addr[0].addr; 317 r->in_addr = hia[0].addr;
319 } 318 }
320 319
321 r->virtual_names = &in_addr[i]; 320 r->virtual_names = hia[i].virtual_names;
322 321
323 /* the default server configuration for the address:port */ 322 /* the default server configuration for the address:port */
324 cscf = in_addr[i].core_srv_conf; 323 cscf = hia[i].core_srv_conf;
325 324
326 r->main_conf = cscf->ctx->main_conf; 325 r->main_conf = cscf->ctx->main_conf;
327 r->srv_conf = cscf->ctx->srv_conf; 326 r->srv_conf = cscf->ctx->srv_conf;
328 r->loc_conf = cscf->ctx->loc_conf; 327 r->loc_conf = cscf->ctx->loc_conf;
328
329 r->server_name = cscf->server_name;
329 330
330 rev->handler = ngx_http_process_request_line; 331 rev->handler = ngx_http_process_request_line;
331 332
332 #if (NGX_HTTP_SSL) 333 #if (NGX_HTTP_SSL)
333 334
347 348
348 r->main_filter_need_in_memory = 1; 349 r->main_filter_need_in_memory = 1;
349 } 350 }
350 351
351 #endif 352 #endif
352
353 server_name = cscf->server_names.elts;
354 r->server_name = server_name->name;
355 353
356 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 354 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
357 c->log->file = clcf->err_log->file; 355 c->log->file = clcf->err_log->file;
358 if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { 356 if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
359 c->log->log_level = clcf->err_log->log_level; 357 c->log->log_level = clcf->err_log->log_level;
1319 1317
1320 1318
1321 static ngx_int_t 1319 static ngx_int_t
1322 ngx_http_find_virtual_server(ngx_http_request_t *r) 1320 ngx_http_find_virtual_server(ngx_http_request_t *r)
1323 { 1321 {
1324 ngx_int_t rc; 1322 size_t len;
1325 ngx_uint_t i, n, key; 1323 u_char *host;
1326 ngx_http_server_name_t *name; 1324 ngx_http_virtual_names_t *vn;
1327 ngx_http_core_loc_conf_t *clcf; 1325 ngx_http_core_loc_conf_t *clcf;
1328 ngx_http_core_srv_conf_t *cscf; 1326 ngx_http_core_srv_conf_t *cscf;
1329 ngx_http_core_main_conf_t *cmcf; 1327
1330 1328 vn = r->virtual_names;
1331 if (r->virtual_names->hash) { 1329
1332 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); 1330 if (vn == NULL) {
1333 1331 return NGX_OK;
1334 ngx_http_server_names_hash_key(key, 1332 }
1335 r->headers_in.host->value.data, 1333
1336 r->headers_in.host_name_len, 1334 host = r->headers_in.host->value.data;
1337 cmcf->server_names_hash); 1335 len = r->headers_in.host_name_len;
1338 1336
1339 name = r->virtual_names->hash[key].elts; 1337 /* STUB: ngx_hash_key() here is STUB */
1340 n = r->virtual_names->hash[key].nelts; 1338
1341 1339 if (vn->hash.buckets) {
1342 } else { 1340 cscf = ngx_hash_find(&vn->hash, ngx_hash_key(host, len), host, len);
1343 name = r->virtual_names->names.elts; 1341 if (cscf) {
1344 n = r->virtual_names->names.nelts;
1345 }
1346
1347 for (i = 0; i < n; i++) {
1348
1349 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1350 "server name: %V", &name[i].name);
1351
1352 if (r->headers_in.host_name_len != name[i].name.len) {
1353 continue;
1354 }
1355
1356 rc = ngx_strncmp(r->headers_in.host->value.data,
1357 name[i].name.data, name[i].name.len);
1358
1359 if (rc == 0) {
1360 r->server_name = name[i].name;
1361 goto found; 1342 goto found;
1362 } 1343 }
1363 1344 }
1364 if (rc < 0) { 1345
1365 /* the server names are lexicographically sorted */ 1346 if (vn->dns_wildcards && vn->dns_wildcards->hash.buckets) {
1366 break; 1347 cscf = ngx_hash_find_wildcard(vn->dns_wildcards, host, len);
1367 } 1348
1368 } 1349 if (cscf) {
1369 1350 goto found;
1370 if (r->virtual_names->wildcards.nelts) {
1371
1372 name = r->virtual_names->wildcards.elts;
1373 for (i = 0; i < r->virtual_names->wildcards.nelts; i++) {
1374
1375 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1376 "server name: %V", &name[i].name);
1377
1378 if (r->headers_in.host_name_len <= name[i].name.len) {
1379 continue;
1380 }
1381
1382 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1383 "server name: %s",
1384 r->headers_in.host->value.data
1385 + (r->headers_in.host_name_len - name[i].name.len));
1386
1387 if (ngx_strncmp(r->headers_in.host->value.data
1388 + (r->headers_in.host_name_len - name[i].name.len),
1389 name[i].name.data, name[i].name.len) == 0)
1390 {
1391 r->server_name.len = r->headers_in.host_name_len;
1392 r->server_name.data = r->headers_in.host->value.data;
1393
1394 goto found;
1395 }
1396 } 1351 }
1397 } 1352 }
1398 1353
1399 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 1354 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1400 1355
1404 1359
1405 return NGX_ERROR; 1360 return NGX_ERROR;
1406 1361
1407 found: 1362 found:
1408 1363
1409 r->srv_conf = name[i].core_srv_conf->ctx->srv_conf; 1364 r->server_name.len = len;
1410 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; 1365 r->server_name.data = host;
1366
1367 r->srv_conf = cscf->ctx->srv_conf;
1368 r->loc_conf = cscf->ctx->loc_conf;
1411 1369
1412 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 1370 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1413 r->connection->log->file = clcf->err_log->file; 1371 r->connection->log->file = clcf->err_log->file;
1414 1372
1415 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { 1373 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {