Mercurial > hg > nginx
comparison src/imap/ngx_imap_core_module.c @ 804:472cd9768ac2
now the "listen" directives use ngx_parse_url()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 24 Oct 2006 13:06:55 +0000 |
parents | 887d8dec72dc |
children | da9c1521319d |
comparison
equal
deleted
inserted
replaced
803:134a3c12d298 | 804:472cd9768ac2 |
---|---|
469 /* AF_INET only */ | 469 /* AF_INET only */ |
470 | 470 |
471 static char * | 471 static char * |
472 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 472 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
473 { | 473 { |
474 char *err; | |
475 ngx_str_t *value; | 474 ngx_str_t *value; |
476 in_addr_t in_addr; | 475 ngx_url_t u; |
477 ngx_uint_t i; | 476 ngx_uint_t i; |
478 struct hostent *h; | |
479 ngx_imap_listen_t *imls; | 477 ngx_imap_listen_t *imls; |
480 ngx_inet_upstream_t inet_upstream; | |
481 ngx_imap_core_main_conf_t *cmcf; | 478 ngx_imap_core_main_conf_t *cmcf; |
482 | 479 |
483 value = cf->args->elts; | 480 value = cf->args->elts; |
484 | 481 |
485 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t)); | 482 ngx_memzero(&u, sizeof(ngx_url_t)); |
486 | 483 |
487 inet_upstream.url = value[1]; | 484 u.url = value[1]; |
488 inet_upstream.port_only = 1; | 485 u.listen = 1; |
489 | 486 |
490 err = ngx_inet_parse_host_port(&inet_upstream); | 487 if (ngx_parse_url(cf, &u) != NGX_OK) { |
491 | 488 if (u.err) { |
492 if (err) { | 489 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
490 "%s in \"%V\" of the \"listen\" directive", | |
491 u.err, &u.url); | |
492 } | |
493 | |
494 return NGX_CONF_ERROR; | |
495 } | |
496 | |
497 cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module); | |
498 | |
499 imls = cmcf->listen.elts; | |
500 | |
501 for (i = 0; i < cmcf->listen.nelts; i++) { | |
502 | |
503 if (imls[i].addr != u.addr.in_addr || imls[i].port != u.portn) { | |
504 continue; | |
505 } | |
506 | |
493 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 507 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
494 "%s in \"%V\" of the \"listen\" directive", | 508 "duplicate \"%V\" address and port pair", &u.url); |
495 err, &inet_upstream.url); | |
496 return NGX_CONF_ERROR; | |
497 } | |
498 | |
499 if (inet_upstream.host.len == 1 && inet_upstream.host.data[0] == '*') { | |
500 inet_upstream.host.len = 0; | |
501 } | |
502 | |
503 if (inet_upstream.host.len) { | |
504 inet_upstream.host.data[inet_upstream.host.len] = '\0'; | |
505 | |
506 in_addr = inet_addr((const char *) inet_upstream.host.data); | |
507 | |
508 if (in_addr == INADDR_NONE) { | |
509 h = gethostbyname((const char *) inet_upstream.host.data); | |
510 | |
511 if (h == NULL || h->h_addr_list[0] == NULL) { | |
512 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
513 "can not resolve host \"%s\" " | |
514 "in the \"listen\" directive", | |
515 inet_upstream.host.data); | |
516 return NGX_CONF_ERROR; | |
517 } | |
518 | |
519 in_addr = *(in_addr_t *)(h->h_addr_list[0]); | |
520 } | |
521 | |
522 } else { | |
523 in_addr = INADDR_ANY; | |
524 } | |
525 | |
526 cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module); | |
527 | |
528 imls = cmcf->listen.elts; | |
529 | |
530 for (i = 0; i < cmcf->listen.nelts; i++) { | |
531 | |
532 if (imls[i].addr != in_addr || imls[i].port != inet_upstream.port) { | |
533 continue; | |
534 } | |
535 | |
536 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
537 "duplicate \"%V\" address and port pair", | |
538 &inet_upstream.url); | |
539 return NGX_CONF_ERROR; | 509 return NGX_CONF_ERROR; |
540 } | 510 } |
541 | 511 |
542 imls = ngx_array_push(&cmcf->listen); | 512 imls = ngx_array_push(&cmcf->listen); |
543 if (imls == NULL) { | 513 if (imls == NULL) { |
544 return NGX_CONF_ERROR; | 514 return NGX_CONF_ERROR; |
545 } | 515 } |
546 | 516 |
547 ngx_memzero(imls, sizeof(ngx_imap_listen_t)); | 517 ngx_memzero(imls, sizeof(ngx_imap_listen_t)); |
548 | 518 |
549 imls->addr = in_addr; | 519 imls->addr = u.addr.in_addr; |
550 imls->port = inet_upstream.port; | 520 imls->port = u.portn; |
551 imls->family = AF_INET; | 521 imls->family = AF_INET; |
552 imls->ctx = cf->ctx; | 522 imls->ctx = cf->ctx; |
553 | 523 |
554 if (cf->args->nelts == 2) { | 524 if (cf->args->nelts == 2) { |
555 return NGX_CONF_OK; | 525 return NGX_CONF_OK; |