comparison src/http/ngx_http.c @ 1617:cacb565c554e stable-0.5

r1254, r1416, r1493 merge: the "www.example.*" wildcard hash support
author Igor Sysoev <igor@sysoev.ru>
date Wed, 07 Nov 2007 13:39:53 +0000
parents 9b10ba85b249
children fbf94b8341bf
comparison
equal deleted inserted replaced
1615:ca6845b19113 1617:cacb565c554e
71 71
72 static char * 72 static char *
73 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 73 ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
74 { 74 {
75 char *rv; 75 char *rv;
76 u_char ch;
77 ngx_int_t rc, j; 76 ngx_int_t rc, j;
78 ngx_uint_t mi, m, s, l, p, a, i, n; 77 ngx_uint_t mi, m, s, l, p, a, i, n;
79 ngx_uint_t find_config_index, use_rewrite, use_access; 78 ngx_uint_t find_config_index, use_rewrite, use_access;
80 ngx_uint_t last, bind_all, done; 79 ngx_uint_t last, bind_all, done;
81 ngx_conf_t pcf; 80 ngx_conf_t pcf;
655 ngx_destroy_pool(ha.temp_pool); 654 ngx_destroy_pool(ha.temp_pool);
656 return NGX_CONF_ERROR; 655 return NGX_CONF_ERROR;
657 } 656 }
658 657
659 name = in_addr[a].names.elts; 658 name = in_addr[a].names.elts;
659
660 for (s = 0; s < in_addr[a].names.nelts; s++) { 660 for (s = 0; s < in_addr[a].names.nelts; s++) {
661 661
662 ch = name[s].name.data[0];
663
664 if (ch == '*' || ch == '.') {
665 continue;
666 }
667
668 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, 662 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
669 0); 663 NGX_HASH_WILDCARD_KEY);
670 664
671 if (rc == NGX_ERROR) { 665 if (rc == NGX_ERROR) {
672 return NGX_CONF_ERROR; 666 return NGX_CONF_ERROR;
673 } 667 }
674 668
675 if (rc == NGX_BUSY) { 669 if (rc == NGX_DECLINED) {
676 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 670 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
677 "conflicting server name \"%V\" on %s, ignored", 671 "invalid server name or wildcard \"%V\" on %s",
678 &name[s].name, in_addr[a].listen_conf->addr); 672 &name[s].name, in_addr[a].listen_conf->addr);
679 }
680 }
681
682 for (s = 0; s < in_addr[a].names.nelts; s++) {
683
684 ch = name[s].name.data[0];
685
686 if (ch != '*' && ch != '.') {
687 continue;
688 }
689
690 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
691 NGX_HASH_WILDCARD_KEY);
692
693 if (rc == NGX_ERROR) {
694 return NGX_CONF_ERROR; 673 return NGX_CONF_ERROR;
695 } 674 }
696 675
697 if (rc == NGX_BUSY) { 676 if (rc == NGX_BUSY) {
698 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 677 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
716 ngx_destroy_pool(ha.temp_pool); 695 ngx_destroy_pool(ha.temp_pool);
717 return NGX_CONF_ERROR; 696 return NGX_CONF_ERROR;
718 } 697 }
719 } 698 }
720 699
721 if (ha.dns_wildcards.nelts) { 700 if (ha.dns_wc_head.nelts) {
722 701
723 ngx_qsort(ha.dns_wildcards.elts, 702 ngx_qsort(ha.dns_wc_head.elts,
724 (size_t) ha.dns_wildcards.nelts, 703 (size_t) ha.dns_wc_head.nelts,
725 sizeof(ngx_hash_key_t), 704 sizeof(ngx_hash_key_t),
726 ngx_http_cmp_dns_wildcards); 705 ngx_http_cmp_dns_wildcards);
727 706
728 hash.hash = NULL; 707 hash.hash = NULL;
729 hash.temp_pool = ha.temp_pool; 708 hash.temp_pool = ha.temp_pool;
730 709
731 if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, 710 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
732 ha.dns_wildcards.nelts) 711 ha.dns_wc_head.nelts)
733 != NGX_OK) 712 != NGX_OK)
734 { 713 {
735 ngx_destroy_pool(ha.temp_pool); 714 ngx_destroy_pool(ha.temp_pool);
736 return NGX_CONF_ERROR; 715 return NGX_CONF_ERROR;
737 } 716 }
738 717
739 in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; 718 in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash;
719 }
720
721 if (ha.dns_wc_tail.nelts) {
722
723 ngx_qsort(ha.dns_wc_tail.elts,
724 (size_t) ha.dns_wc_tail.nelts,
725 sizeof(ngx_hash_key_t),
726 ngx_http_cmp_dns_wildcards);
727
728 hash.hash = NULL;
729 hash.temp_pool = ha.temp_pool;
730
731 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
732 ha.dns_wc_tail.nelts)
733 != NGX_OK)
734 {
735 ngx_destroy_pool(ha.temp_pool);
736 return NGX_CONF_ERROR;
737 }
738
739 in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash;
740 } 740 }
741 741
742 ngx_destroy_pool(ha.temp_pool); 742 ngx_destroy_pool(ha.temp_pool);
743 } 743 }
744 744
855 for (i = 0; i < hip->naddrs; i++) { 855 for (i = 0; i < hip->naddrs; i++) {
856 hip->addrs[i].addr = in_addr[i].addr; 856 hip->addrs[i].addr = in_addr[i].addr;
857 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; 857 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf;
858 858
859 if (in_addr[i].hash.buckets == NULL 859 if (in_addr[i].hash.buckets == NULL
860 && (in_addr[i].dns_wildcards == NULL 860 && (in_addr[i].wc_head == NULL
861 || in_addr[i].dns_wildcards->hash.buckets == NULL)) 861 || in_addr[i].wc_head->hash.buckets == NULL)
862 && (in_addr[i].wc_head == NULL
863 || in_addr[i].wc_head->hash.buckets == NULL))
862 { 864 {
863 continue; 865 continue;
864 } 866 }
865 867
866 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); 868 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
868 return NGX_CONF_ERROR; 870 return NGX_CONF_ERROR;
869 } 871 }
870 hip->addrs[i].virtual_names = vn; 872 hip->addrs[i].virtual_names = vn;
871 873
872 vn->hash = in_addr[i].hash; 874 vn->hash = in_addr[i].hash;
873 vn->dns_wildcards = in_addr[i].dns_wildcards; 875 vn->wc_head = in_addr[i].wc_head;
876 vn->wc_tail = in_addr[i].wc_tail;
874 } 877 }
875 878
876 if (done) { 879 if (done) {
877 break; 880 break;
878 } 881 }
941 } 944 }
942 945
943 in_addr->addr = lscf->addr; 946 in_addr->addr = lscf->addr;
944 in_addr->hash.buckets = NULL; 947 in_addr->hash.buckets = NULL;
945 in_addr->hash.size = 0; 948 in_addr->hash.size = 0;
946 in_addr->dns_wildcards = NULL; 949 in_addr->wc_head = NULL;
950 in_addr->wc_tail = NULL;
947 in_addr->names.elts = NULL; 951 in_addr->names.elts = NULL;
948 in_addr->core_srv_conf = cscf; 952 in_addr->core_srv_conf = cscf;
949 in_addr->default_server = lscf->conf.default_server; 953 in_addr->default_server = lscf->conf.default_server;
950 in_addr->bind = lscf->conf.bind; 954 in_addr->bind = lscf->conf.bind;
951 in_addr->listen_conf = &lscf->conf; 955 in_addr->listen_conf = &lscf->conf;