Klaus Demo nginx / 6525b75
r1560 merge: use pool instead of ngx_conf_t Igor Sysoev 14 years ago
8 changed file(s) with 34 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
224224
225225
226226 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)
228228 {
229229 u_char *p, *host, *port_start;
230230 size_t len, port_len;
272272 return NGX_ERROR;
273273 }
274274
275 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
275 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
276276 if (u->addrs == NULL) {
277277 return NGX_ERROR;
278278 }
279279
280 saun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un));
280 saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));
281281 if (saun == NULL) {
282282 return NGX_ERROR;
283283 }
407407
408408 if (u->host.len) {
409409
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);
416416
417417 u->addr.in_addr = inet_addr((const char *) host);
418418
420420 h = gethostbyname((const char *) host);
421421
422422 if (h == NULL || h->h_addr_list[0] == NULL) {
423 ngx_free(host);
423424 u->err = "host not found";
424425 return NGX_ERROR;
425426 }
427428 u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]);
428429 }
429430
431 ngx_free(host);
432
430433 } else {
431434 u->addr.in_addr = INADDR_ANY;
432435 }
452455 return NGX_ERROR;
453456 }
454457
455 if (ngx_inet_resolve_host(cf, u) != NGX_OK) {
458 if (ngx_inet_resolve_host(pool, u) != NGX_OK) {
456459 return NGX_ERROR;
457460 }
458461
461464
462465
463466 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)
465468 {
466469 u_char *p, *host;
467470 size_t len;
470473 struct hostent *h;
471474 struct sockaddr_in *sin;
472475
473 host = ngx_palloc(cf->temp_pool, u->host.len + 1);
476 host = ngx_alloc(u->host.len + 1, pool->log);
474477 if (host == NULL) {
475478 return NGX_ERROR;
476479 }
484487 if (in_addr == INADDR_NONE) {
485488 h = gethostbyname((char *) host);
486489
490 ngx_free(host);
491
487492 if (h == NULL || h->h_addr_list[0] == NULL) {
488493 u->err = "host not found";
489494 return NGX_ERROR;
498503
499504 /* MP: ngx_shared_palloc() */
500505
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));
502507 if (u->addrs == NULL) {
503508 return NGX_ERROR;
504509 }
507512
508513 for (i = 0; h->h_addr_list[i] != NULL; i++) {
509514
510 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
515 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
511516 if (sin == NULL) {
512517 return NGX_ERROR;
513518 }
521526
522527 len = INET_ADDRSTRLEN - 1 + 1 + sizeof(":65536") - 1;
523528
524 p = ngx_palloc(cf->pool, len);
529 p = ngx_palloc(pool, len);
525530 if (p == NULL) {
526531 return NGX_ERROR;
527532 }
534539
535540 } else {
536541
542 ngx_free(host);
543
537544 /* MP: ngx_shared_palloc() */
538545
539 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
546 u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
540547 if (u->addrs == NULL) {
541548 return NGX_ERROR;
542549 }
543550
544 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
551 sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));
545552 if (sin == NULL) {
546553 return NGX_ERROR;
547554 }
555562 u->addrs[0].sockaddr = (struct sockaddr *) sin;
556563 u->addrs[0].socklen = sizeof(struct sockaddr_in);
557564
558 p = ngx_palloc(cf->pool, u->host.len + sizeof(":65536") - 1);
565 p = ngx_palloc(pool, u->host.len + sizeof(":65536") - 1);
559566 if (p == NULL) {
560567 return NGX_ERROR;
561568 }
6060 size_t ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, size_t len);
6161 size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len);
6262 ngx_int_t ngx_ptocidr(ngx_str_t *text, void *cidr);
63 ngx_int_t ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u);
64 ngx_int_t ngx_inet_resolve_host(ngx_conf_t *cf, ngx_url_t *u);
63 ngx_int_t ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u);
64 ngx_int_t ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u);
6565
6666
6767
25772577 u.listen = 1;
25782578 u.default_port = 80;
25792579
2580 if (ngx_parse_url(cf, &u) != NGX_OK) {
2580 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
25812581 if (u.err) {
25822582 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
25832583 "%s in \"%V\" of the \"listen\" directive",
30603060 u.url = value[1];
30613061 u.default_port = 80;
30623062
3063 if (ngx_parse_url(cf, &u) != NGX_OK) {
3063 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
30643064 if (u.err) {
30653065 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
30663066 "%s in upstream \"%V\"", u.err, &u.url);
31643164
31653165 if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) {
31663166
3167 if (ngx_parse_url(cf, u) != NGX_OK) {
3167 if (ngx_parse_url(cf->pool, u) != NGX_OK) {
31683168 if (u->err) {
31693169 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
31703170 "%s in upstream \"%V\"", u->err, &u->url);
7272 u.host = us->host;
7373 u.port = (in_port_t) (us->port ? us->port : us->default_port);
7474
75 if (ngx_inet_resolve_host(cf, &u) != NGX_OK) {
75 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
7676 if (u.err) {
7777 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
7878 "%s in upstream \"%V\" in %s:%ui",
13671367 u.url.data += 7;
13681368 }
13691369
1370 if (ngx_parse_url(cf, &u) != NGX_OK) {
1370 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
13711371 if (u.err) {
13721372 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
13731373 "%s in auth_http \"%V\"", u.err, &u.url);
284284 u.url = value[1];
285285 u.listen = 1;
286286
287 if (ngx_parse_url(cf, &u) != NGX_OK) {
287 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
288288 if (u.err) {
289289 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
290290 "%s in \"%V\" of the \"listen\" directive",
186186 u.url = value[1];
187187 u.default_port = 3306;
188188
189 if (ngx_parse_url(cf, &u) != NGX_OK) {
189 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
190190 if (u.err) {
191191 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
192192 "%s in upstream \"%V\"", u.err, &u.url);