224 | 224 |
|
225 | 225 |
|
226 | 226 |
ngx_int_t
|
227 | |
ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u)
|
|
227 |
ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)
|
228 | 228 |
{
|
229 | 229 |
u_char *p, *host, *port_start;
|
230 | 230 |
size_t len, port_len;
|
|
272 | 272 |
return NGX_ERROR;
|
273 | 273 |
}
|
274 | 274 |
|
275 | |
u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
|
|
275 |
u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
|
276 | 276 |
if (u->addrs == NULL) {
|
277 | 277 |
return NGX_ERROR;
|
278 | 278 |
}
|
279 | 279 |
|
280 | |
saun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un));
|
|
280 |
saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));
|
281 | 281 |
if (saun == NULL) {
|
282 | 282 |
return NGX_ERROR;
|
283 | 283 |
}
|
|
407 | 407 |
|
408 | 408 |
if (u->host.len) {
|
409 | 409 |
|
410 | |
host = ngx_palloc(cf->temp_pool, u->host.len + 1);
|
411 | |
if (host == NULL) {
|
412 | |
return NGX_ERROR;
|
413 | |
}
|
414 | |
|
415 | |
(void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
|
|
410 |
host = ngx_alloc(u->host.len + 1, pool->log);
|
|
411 |
if (host == NULL) {
|
|
412 |
return NGX_ERROR;
|
|
413 |
}
|
|
414 |
|
|
415 |
(void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
|
416 | 416 |
|
417 | 417 |
u->addr.in_addr = inet_addr((const char *) host);
|
418 | 418 |
|
|
420 | 420 |
h = gethostbyname((const char *) host);
|
421 | 421 |
|
422 | 422 |
if (h == NULL || h->h_addr_list[0] == NULL) {
|
|
423 |
ngx_free(host);
|
423 | 424 |
u->err = "host not found";
|
424 | 425 |
return NGX_ERROR;
|
425 | 426 |
}
|
|
427 | 428 |
u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]);
|
428 | 429 |
}
|
429 | 430 |
|
|
431 |
ngx_free(host);
|
|
432 |
|
430 | 433 |
} else {
|
431 | 434 |
u->addr.in_addr = INADDR_ANY;
|
432 | 435 |
}
|
|
452 | 455 |
return NGX_ERROR;
|
453 | 456 |
}
|
454 | 457 |
|
455 | |
if (ngx_inet_resolve_host(cf, u) != NGX_OK) {
|
|
458 |
if (ngx_inet_resolve_host(pool, u) != NGX_OK) {
|
456 | 459 |
return NGX_ERROR;
|
457 | 460 |
}
|
458 | 461 |
|
|
461 | 464 |
|
462 | 465 |
|
463 | 466 |
ngx_int_t
|
464 | |
ngx_inet_resolve_host(ngx_conf_t *cf, ngx_url_t *u)
|
|
467 |
ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
|
465 | 468 |
{
|
466 | 469 |
u_char *p, *host;
|
467 | 470 |
size_t len;
|
|
470 | 473 |
struct hostent *h;
|
471 | 474 |
struct sockaddr_in *sin;
|
472 | 475 |
|
473 | |
host = ngx_palloc(cf->temp_pool, u->host.len + 1);
|
|
476 |
host = ngx_alloc(u->host.len + 1, pool->log);
|
474 | 477 |
if (host == NULL) {
|
475 | 478 |
return NGX_ERROR;
|
476 | 479 |
}
|
|
484 | 487 |
if (in_addr == INADDR_NONE) {
|
485 | 488 |
h = gethostbyname((char *) host);
|
486 | 489 |
|
|
490 |
ngx_free(host);
|
|
491 |
|
487 | 492 |
if (h == NULL || h->h_addr_list[0] == NULL) {
|
488 | 493 |
u->err = "host not found";
|
489 | 494 |
return NGX_ERROR;
|
|
498 | 503 |
|
499 | 504 |
/* MP: ngx_shared_palloc() */
|
500 | 505 |
|
501 | |
u->addrs = ngx_pcalloc(cf->pool, i * sizeof(ngx_peer_addr_t));
|
|
506 |
u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_peer_addr_t));
|
502 | 507 |
if (u->addrs == NULL) {
|
503 | 508 |
return NGX_ERROR;
|
504 | 509 |
}
|
|
507 | 512 |
|
508 | 513 |
for (i = 0; h->h_addr_list[i] != NULL; i++) {
|
509 | 514 |
|
510 | |
sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
|
|
515 |
sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
|
511 | 516 |
if (sin == NULL) {
|
512 | 517 |
return NGX_ERROR;
|
513 | 518 |
}
|
|
521 | 526 |
|
522 | 527 |
len = INET_ADDRSTRLEN - 1 + 1 + sizeof(":65536") - 1;
|
523 | 528 |
|
524 | |
p = ngx_palloc(cf->pool, len);
|
|
529 |
p = ngx_palloc(pool, len);
|
525 | 530 |
if (p == NULL) {
|
526 | 531 |
return NGX_ERROR;
|
527 | 532 |
}
|
|
534 | 539 |
|
535 | 540 |
} else {
|
536 | 541 |
|
|
542 |
ngx_free(host);
|
|
543 |
|
537 | 544 |
/* MP: ngx_shared_palloc() */
|
538 | 545 |
|
539 | |
u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
|
|
546 |
u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
|
540 | 547 |
if (u->addrs == NULL) {
|
541 | 548 |
return NGX_ERROR;
|
542 | 549 |
}
|
543 | 550 |
|
544 | |
sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
|
|
551 |
sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
|
545 | 552 |
if (sin == NULL) {
|
546 | 553 |
return NGX_ERROR;
|
547 | 554 |
}
|
|
555 | 562 |
u->addrs[0].sockaddr = (struct sockaddr *) sin;
|
556 | 563 |
u->addrs[0].socklen = sizeof(struct sockaddr_in);
|
557 | 564 |
|
558 | |
p = ngx_palloc(cf->pool, u->host.len + sizeof(":65536") - 1);
|
|
565 |
p = ngx_palloc(pool, u->host.len + sizeof(":65536") - 1);
|
559 | 566 |
if (p == NULL) {
|
560 | 567 |
return NGX_ERROR;
|
561 | 568 |
}
|