comparison src/core/ngx_inet.c @ 340:10cc350ed8a1 NGINX_0_6_14

nginx 0.6.14 *) Change: now by default the "echo" SSI command uses entity encoding. *) Feature: the "encoding" parameter in the "echo" SSI command. *) Feature: the "access_log" directive may be used inside the "limit_except" block. *) Bugfix: if all upstream servers were failed, then all servers had got weight the was equal one until servers became alive; bug appeared in 0.6.6. *) Bugfix: a segmentation fault occurred in worker process if $date_local and $date_gmt were used outside the ngx_http_ssi_filter_module. *) Bugfix: a segmentation fault might occur in worker process if debug log was enabled. Thanks to Andrei Nigmatulin. *) Bugfix: ngx_http_memcached_module did not set $upstream_response_time. Thanks to Maxim Dounin. *) Bugfix: a worker process may got caught in an endless loop, if the memcached was used. *) Bugfix: nginx supported low case only "close" and "keep-alive" values in the "Connection" request header line; bug appeared in 0.6.11. *) Bugfix: sub_filter did not work with empty substitution. *) Bugfix: in sub_filter parsing.
author Igor Sysoev <http://sysoev.ru>
date Mon, 15 Oct 2007 00:00:00 +0400
parents 9fc4ab6673f9
children e10168d6e371
comparison
equal deleted inserted replaced
339:d19550b67059 340:10cc350ed8a1
223 return NGX_DONE; 223 return NGX_DONE;
224 } 224 }
225 225
226 226
227 ngx_int_t 227 ngx_int_t
228 ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u) 228 ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)
229 { 229 {
230 u_char *p, *host, *port_start; 230 u_char *p, *host, *port_start;
231 size_t len, port_len; 231 size_t len, port_len;
232 ngx_int_t port; 232 ngx_int_t port;
233 ngx_uint_t i; 233 ngx_uint_t i;
271 if (len + 1 > sizeof(saun->sun_path)) { 271 if (len + 1 > sizeof(saun->sun_path)) {
272 u->err = "too long path in the unix domain socket"; 272 u->err = "too long path in the unix domain socket";
273 return NGX_ERROR; 273 return NGX_ERROR;
274 } 274 }
275 275
276 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t)); 276 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
277 if (u->addrs == NULL) { 277 if (u->addrs == NULL) {
278 return NGX_ERROR; 278 return NGX_ERROR;
279 } 279 }
280 280
281 saun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un)); 281 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));
282 if (saun == NULL) { 282 if (saun == NULL) {
283 return NGX_ERROR; 283 return NGX_ERROR;
284 } 284 }
285 285
286 u->naddrs = 1; 286 u->naddrs = 1;
406 406
407 /* AF_INET only */ 407 /* AF_INET only */
408 408
409 if (u->host.len) { 409 if (u->host.len) {
410 410
411 host = ngx_palloc(cf->temp_pool, u->host.len + 1); 411 host = ngx_alloc(u->host.len + 1, pool->log);
412 if (host == NULL) { 412 if (host == NULL) {
413 return NGX_ERROR; 413 return NGX_ERROR;
414 } 414 }
415 415
416 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); 416 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
417 417
418 u->addr.in_addr = inet_addr((const char *) host); 418 u->addr.in_addr = inet_addr((const char *) host);
419 419
420 if (u->addr.in_addr == INADDR_NONE) { 420 if (u->addr.in_addr == INADDR_NONE) {
421 h = gethostbyname((const char *) host); 421 h = gethostbyname((const char *) host);
422 422
423 if (h == NULL || h->h_addr_list[0] == NULL) { 423 if (h == NULL || h->h_addr_list[0] == NULL) {
424 ngx_free(host);
424 u->err = "host not found"; 425 u->err = "host not found";
425 return NGX_ERROR; 426 return NGX_ERROR;
426 } 427 }
427 428
428 u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]); 429 u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]);
429 } 430 }
430 431
432 ngx_free(host);
433
431 } else { 434 } else {
432 u->addr.in_addr = INADDR_ANY; 435 u->addr.in_addr = INADDR_ANY;
433 } 436 }
434 437
435 return NGX_OK; 438 return NGX_OK;
451 if (u->port == 0) { 454 if (u->port == 0) {
452 u->err = "no port"; 455 u->err = "no port";
453 return NGX_ERROR; 456 return NGX_ERROR;
454 } 457 }
455 458
456 if (ngx_inet_resolve_host(cf, u) != NGX_OK) { 459 if (ngx_inet_resolve_host(pool, u) != NGX_OK) {
457 return NGX_ERROR; 460 return NGX_ERROR;
458 } 461 }
459 462
460 return NGX_OK; 463 return NGX_OK;
461 } 464 }
462 465
463 466
464 ngx_int_t 467 ngx_int_t
465 ngx_inet_resolve_host(ngx_conf_t *cf, ngx_url_t *u) 468 ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
466 { 469 {
467 u_char *p, *host; 470 u_char *p, *host;
468 size_t len; 471 size_t len;
469 in_addr_t in_addr; 472 in_addr_t in_addr;
470 ngx_uint_t i; 473 ngx_uint_t i;
471 struct hostent *h; 474 struct hostent *h;
472 struct sockaddr_in *sin; 475 struct sockaddr_in *sin;
473 476
474 host = ngx_palloc(cf->temp_pool, u->host.len + 1); 477 host = ngx_alloc(u->host.len + 1, pool->log);
475 if (host == NULL) { 478 if (host == NULL) {
476 return NGX_ERROR; 479 return NGX_ERROR;
477 } 480 }
478 481
479 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); 482 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
483 in_addr = inet_addr((char *) host); 486 in_addr = inet_addr((char *) host);
484 487
485 if (in_addr == INADDR_NONE) { 488 if (in_addr == INADDR_NONE) {
486 h = gethostbyname((char *) host); 489 h = gethostbyname((char *) host);
487 490
491 ngx_free(host);
492
488 if (h == NULL || h->h_addr_list[0] == NULL) { 493 if (h == NULL || h->h_addr_list[0] == NULL) {
489 u->err = "host not found"; 494 u->err = "host not found";
490 return NGX_ERROR; 495 return NGX_ERROR;
491 } 496 }
492 497
497 i = 1; 502 i = 1;
498 } 503 }
499 504
500 /* MP: ngx_shared_palloc() */ 505 /* MP: ngx_shared_palloc() */
501 506
502 u->addrs = ngx_pcalloc(cf->pool, i * sizeof(ngx_peer_addr_t)); 507 u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_peer_addr_t));
503 if (u->addrs == NULL) { 508 if (u->addrs == NULL) {
504 return NGX_ERROR; 509 return NGX_ERROR;
505 } 510 }
506 511
507 u->naddrs = i; 512 u->naddrs = i;
508 513
509 for (i = 0; h->h_addr_list[i] != NULL; i++) { 514 for (i = 0; h->h_addr_list[i] != NULL; i++) {
510 515
511 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)); 516 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
512 if (sin == NULL) { 517 if (sin == NULL) {
513 return NGX_ERROR; 518 return NGX_ERROR;
514 } 519 }
515 520
516 sin->sin_family = AF_INET; 521 sin->sin_family = AF_INET;
520 u->addrs[i].sockaddr = (struct sockaddr *) sin; 525 u->addrs[i].sockaddr = (struct sockaddr *) sin;
521 u->addrs[i].socklen = sizeof(struct sockaddr_in); 526 u->addrs[i].socklen = sizeof(struct sockaddr_in);
522 527
523 len = INET_ADDRSTRLEN - 1 + 1 + sizeof(":65536") - 1; 528 len = INET_ADDRSTRLEN - 1 + 1 + sizeof(":65536") - 1;
524 529
525 p = ngx_palloc(cf->pool, len); 530 p = ngx_palloc(pool, len);
526 if (p == NULL) { 531 if (p == NULL) {
527 return NGX_ERROR; 532 return NGX_ERROR;
528 } 533 }
529 534
530 len = ngx_sock_ntop(AF_INET, (struct sockaddr *) sin, p, len); 535 len = ngx_sock_ntop(AF_INET, (struct sockaddr *) sin, p, len);
533 u->addrs[i].name.data = p; 538 u->addrs[i].name.data = p;
534 } 539 }
535 540
536 } else { 541 } else {
537 542
543 ngx_free(host);
544
538 /* MP: ngx_shared_palloc() */ 545 /* MP: ngx_shared_palloc() */
539 546
540 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t)); 547 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
541 if (u->addrs == NULL) { 548 if (u->addrs == NULL) {
542 return NGX_ERROR; 549 return NGX_ERROR;
543 } 550 }
544 551
545 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)); 552 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
546 if (sin == NULL) { 553 if (sin == NULL) {
547 return NGX_ERROR; 554 return NGX_ERROR;
548 } 555 }
549 556
550 u->naddrs = 1; 557 u->naddrs = 1;
554 sin->sin_addr.s_addr = in_addr; 561 sin->sin_addr.s_addr = in_addr;
555 562
556 u->addrs[0].sockaddr = (struct sockaddr *) sin; 563 u->addrs[0].sockaddr = (struct sockaddr *) sin;
557 u->addrs[0].socklen = sizeof(struct sockaddr_in); 564 u->addrs[0].socklen = sizeof(struct sockaddr_in);
558 565
559 p = ngx_palloc(cf->pool, u->host.len + sizeof(":65536") - 1); 566 p = ngx_palloc(pool, u->host.len + sizeof(":65536") - 1);
560 if (p == NULL) { 567 if (p == NULL) {
561 return NGX_ERROR; 568 return NGX_ERROR;
562 } 569 }
563 570
564 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", &u->host, u->port) - p; 571 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", &u->host, u->port) - p;