comparison src/http/ngx_http.c @ 312:429900ca25ee NGINX_0_6_0

nginx 0.6.0 *) Feature: the "server_name", "map", and "valid_referers" directives support the "www.example.*" wildcards.
author Igor Sysoev <http://sysoev.ru>
date Thu, 14 Jun 2007 00:00:00 +0400
parents 94e16de3c33f
children f7cd062ee035
comparison
equal deleted inserted replaced
311:fcb663e92663 312:429900ca25ee
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;
646 ngx_destroy_pool(ha.temp_pool); 645 ngx_destroy_pool(ha.temp_pool);
647 return NGX_CONF_ERROR; 646 return NGX_CONF_ERROR;
648 } 647 }
649 648
650 name = in_addr[a].names.elts; 649 name = in_addr[a].names.elts;
650
651 for (s = 0; s < in_addr[a].names.nelts; s++) { 651 for (s = 0; s < in_addr[a].names.nelts; s++) {
652 652
653 ch = name[s].name.data[0];
654
655 if (ch == '*' || ch == '.') {
656 continue;
657 }
658
659 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, 653 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
660 0); 654 NGX_HASH_WILDCARD_KEY);
661 655
662 if (rc == NGX_ERROR) { 656 if (rc == NGX_ERROR) {
663 return NGX_CONF_ERROR; 657 return NGX_CONF_ERROR;
664 } 658 }
665 659
666 if (rc == NGX_BUSY) { 660 if (rc == NGX_DECLINED) {
667 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 661 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
668 "conflicting server name \"%V\" on %s, ignored", 662 "invalid server name or wildcard \"%V\" on %s",
669 &name[s].name, in_addr[a].listen_conf->addr); 663 &name[s].name, in_addr[a].listen_conf->addr);
670 }
671 }
672
673 for (s = 0; s < in_addr[a].names.nelts; s++) {
674
675 ch = name[s].name.data[0];
676
677 if (ch != '*' && ch != '.') {
678 continue;
679 }
680
681 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
682 NGX_HASH_WILDCARD_KEY);
683
684 if (rc == NGX_ERROR) {
685 return NGX_CONF_ERROR; 664 return NGX_CONF_ERROR;
686 } 665 }
687 666
688 if (rc == NGX_BUSY) { 667 if (rc == NGX_BUSY) {
689 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 668 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
707 ngx_destroy_pool(ha.temp_pool); 686 ngx_destroy_pool(ha.temp_pool);
708 return NGX_CONF_ERROR; 687 return NGX_CONF_ERROR;
709 } 688 }
710 } 689 }
711 690
712 if (ha.dns_wildcards.nelts) { 691 if (ha.dns_wc_head.nelts) {
713 692
714 ngx_qsort(ha.dns_wildcards.elts, 693 ngx_qsort(ha.dns_wc_head.elts,
715 (size_t) ha.dns_wildcards.nelts, 694 (size_t) ha.dns_wc_head.nelts,
716 sizeof(ngx_hash_key_t), 695 sizeof(ngx_hash_key_t),
717 ngx_http_cmp_dns_wildcards); 696 ngx_http_cmp_dns_wildcards);
718 697
719 hash.hash = NULL; 698 hash.hash = NULL;
720 hash.temp_pool = ha.temp_pool; 699 hash.temp_pool = ha.temp_pool;
721 700
722 if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, 701 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
723 ha.dns_wildcards.nelts) 702 ha.dns_wc_head.nelts)
724 != NGX_OK) 703 != NGX_OK)
725 { 704 {
726 ngx_destroy_pool(ha.temp_pool); 705 ngx_destroy_pool(ha.temp_pool);
727 return NGX_CONF_ERROR; 706 return NGX_CONF_ERROR;
728 } 707 }
729 708
730 in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; 709 in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash;
710 }
711
712 if (ha.dns_wc_tail.nelts) {
713
714 ngx_qsort(ha.dns_wc_tail.elts,
715 (size_t) ha.dns_wc_tail.nelts,
716 sizeof(ngx_hash_key_t),
717 ngx_http_cmp_dns_wildcards);
718
719 hash.hash = NULL;
720 hash.temp_pool = ha.temp_pool;
721
722 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
723 ha.dns_wc_tail.nelts)
724 != NGX_OK)
725 {
726 ngx_destroy_pool(ha.temp_pool);
727 return NGX_CONF_ERROR;
728 }
729
730 in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash;
731 } 731 }
732 732
733 ngx_destroy_pool(ha.temp_pool); 733 ngx_destroy_pool(ha.temp_pool);
734 } 734 }
735 735
846 for (i = 0; i < hip->naddrs; i++) { 846 for (i = 0; i < hip->naddrs; i++) {
847 hip->addrs[i].addr = in_addr[i].addr; 847 hip->addrs[i].addr = in_addr[i].addr;
848 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; 848 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf;
849 849
850 if (in_addr[i].hash.buckets == NULL 850 if (in_addr[i].hash.buckets == NULL
851 && (in_addr[i].dns_wildcards == NULL 851 && (in_addr[i].wc_head == NULL
852 || in_addr[i].dns_wildcards->hash.buckets == NULL)) 852 || in_addr[i].wc_head->hash.buckets == NULL)
853 && (in_addr[i].wc_head == NULL
854 || in_addr[i].wc_head->hash.buckets == NULL))
853 { 855 {
854 continue; 856 continue;
855 } 857 }
856 858
857 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); 859 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
859 return NGX_CONF_ERROR; 861 return NGX_CONF_ERROR;
860 } 862 }
861 hip->addrs[i].virtual_names = vn; 863 hip->addrs[i].virtual_names = vn;
862 864
863 vn->hash = in_addr[i].hash; 865 vn->hash = in_addr[i].hash;
864 vn->dns_wildcards = in_addr[i].dns_wildcards; 866 vn->wc_head = in_addr[i].wc_head;
867 vn->wc_tail = in_addr[i].wc_tail;
865 } 868 }
866 869
867 if (done) { 870 if (done) {
868 break; 871 break;
869 } 872 }
932 } 935 }
933 936
934 in_addr->addr = lscf->addr; 937 in_addr->addr = lscf->addr;
935 in_addr->hash.buckets = NULL; 938 in_addr->hash.buckets = NULL;
936 in_addr->hash.size = 0; 939 in_addr->hash.size = 0;
937 in_addr->dns_wildcards = NULL; 940 in_addr->wc_head = NULL;
941 in_addr->wc_tail = NULL;
938 in_addr->names.elts = NULL; 942 in_addr->names.elts = NULL;
939 in_addr->core_srv_conf = cscf; 943 in_addr->core_srv_conf = cscf;
940 in_addr->default_server = lscf->conf.default_server; 944 in_addr->default_server = lscf->conf.default_server;
941 in_addr->bind = lscf->conf.bind; 945 in_addr->bind = lscf->conf.bind;
942 in_addr->listen_conf = &lscf->conf; 946 in_addr->listen_conf = &lscf->conf;