comparison src/http/ngx_http.c @ 326:f70f2f565fe0 NGINX_0_5_33

nginx 0.5.33 *) Change: now by default the "echo" SSI command uses entity encoding. *) Feature: the "encoding" parameter in the "echo" SSI command. *) Change: mail proxy was split on three modules: pop3, imap and smtp. *) Feature: the --without-mail_pop3_module, --without-mail_imap_module, and --without-mail_smtp_module configuration parameters. *) Feature: the "smtp_greeting_delay" and "smtp_client_buffer" directives of the ngx_mail_smtp_module. *) Feature: the "server_name" and "valid_referers" directives support regular expressions. *) Feature: the "server_name", "map", and "valid_referers" directives support the "www.example.*" wildcards. *) Bugfix: sub_filter did not work with empty substitution. *) Bugfix: in sub_filter parsing. *) Bugfix: a worker process may got caught in an endless loop, if the memcached was used. *) Bugfix: nginx supported low case only "close" and "keep-alive" values in the "Connection" request header line; bug appeared in 0.5.32. *) Bugfix: nginx could not start on Solaris if the shared PCRE library located in non-standard place was used.
author Igor Sysoev <http://sysoev.ru>
date Wed, 07 Nov 2007 00:00:00 +0300
parents 7cf404023f50
children
comparison
equal deleted inserted replaced
325:5bb1b28ddeaa 326:f70f2f565fe0
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;
97 ngx_http_virtual_names_t *vn; 96 ngx_http_virtual_names_t *vn;
98 ngx_http_core_srv_conf_t **cscfp, *cscf; 97 ngx_http_core_srv_conf_t **cscfp, *cscf;
99 ngx_http_core_loc_conf_t *clcf; 98 ngx_http_core_loc_conf_t *clcf;
100 ngx_http_phase_handler_pt checker; 99 ngx_http_phase_handler_pt checker;
101 ngx_http_core_main_conf_t *cmcf; 100 ngx_http_core_main_conf_t *cmcf;
101 #if (NGX_PCRE)
102 ngx_uint_t regex;
103 #endif
102 #if (NGX_WIN32) 104 #if (NGX_WIN32)
103 ngx_iocp_conf_t *iocpcf; 105 ngx_iocp_conf_t *iocpcf;
104 #endif 106 #endif
105 107
106 /* the main http context */ 108 /* the main http context */
654 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) { 656 if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) {
655 ngx_destroy_pool(ha.temp_pool); 657 ngx_destroy_pool(ha.temp_pool);
656 return NGX_CONF_ERROR; 658 return NGX_CONF_ERROR;
657 } 659 }
658 660
661 #if (NGX_PCRE)
662 regex = 0;
663 #endif
664
659 name = in_addr[a].names.elts; 665 name = in_addr[a].names.elts;
666
660 for (s = 0; s < in_addr[a].names.nelts; s++) { 667 for (s = 0; s < in_addr[a].names.nelts; s++) {
661 668
662 ch = name[s].name.data[0]; 669 #if (NGX_PCRE)
663 670 if (name[s].regex) {
664 if (ch == '*' || ch == '.') { 671 regex++;
665 continue; 672 continue;
666 } 673 }
674 #endif
667 675
668 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf, 676 rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
669 0); 677 NGX_HASH_WILDCARD_KEY);
670 678
671 if (rc == NGX_ERROR) { 679 if (rc == NGX_ERROR) {
672 return NGX_CONF_ERROR; 680 return NGX_CONF_ERROR;
673 } 681 }
674 682
675 if (rc == NGX_BUSY) { 683 if (rc == NGX_DECLINED) {
676 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 684 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
677 "conflicting server name \"%V\" on %s, ignored", 685 "invalid server name or wildcard \"%V\" on %s",
678 &name[s].name, in_addr[a].listen_conf->addr); 686 &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; 687 return NGX_CONF_ERROR;
695 } 688 }
696 689
697 if (rc == NGX_BUSY) { 690 if (rc == NGX_BUSY) {
698 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 691 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
716 ngx_destroy_pool(ha.temp_pool); 709 ngx_destroy_pool(ha.temp_pool);
717 return NGX_CONF_ERROR; 710 return NGX_CONF_ERROR;
718 } 711 }
719 } 712 }
720 713
721 if (ha.dns_wildcards.nelts) { 714 if (ha.dns_wc_head.nelts) {
722 715
723 ngx_qsort(ha.dns_wildcards.elts, 716 ngx_qsort(ha.dns_wc_head.elts,
724 (size_t) ha.dns_wildcards.nelts, 717 (size_t) ha.dns_wc_head.nelts,
725 sizeof(ngx_hash_key_t), 718 sizeof(ngx_hash_key_t),
726 ngx_http_cmp_dns_wildcards); 719 ngx_http_cmp_dns_wildcards);
727 720
728 hash.hash = NULL; 721 hash.hash = NULL;
729 hash.temp_pool = ha.temp_pool; 722 hash.temp_pool = ha.temp_pool;
730 723
731 if (ngx_hash_wildcard_init(&hash, ha.dns_wildcards.elts, 724 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
732 ha.dns_wildcards.nelts) 725 ha.dns_wc_head.nelts)
733 != NGX_OK) 726 != NGX_OK)
734 { 727 {
735 ngx_destroy_pool(ha.temp_pool); 728 ngx_destroy_pool(ha.temp_pool);
736 return NGX_CONF_ERROR; 729 return NGX_CONF_ERROR;
737 } 730 }
738 731
739 in_addr[a].dns_wildcards = (ngx_hash_wildcard_t *) hash.hash; 732 in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash;
733 }
734
735 if (ha.dns_wc_tail.nelts) {
736
737 ngx_qsort(ha.dns_wc_tail.elts,
738 (size_t) ha.dns_wc_tail.nelts,
739 sizeof(ngx_hash_key_t),
740 ngx_http_cmp_dns_wildcards);
741
742 hash.hash = NULL;
743 hash.temp_pool = ha.temp_pool;
744
745 if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
746 ha.dns_wc_tail.nelts)
747 != NGX_OK)
748 {
749 ngx_destroy_pool(ha.temp_pool);
750 return NGX_CONF_ERROR;
751 }
752
753 in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash;
740 } 754 }
741 755
742 ngx_destroy_pool(ha.temp_pool); 756 ngx_destroy_pool(ha.temp_pool);
757
758 #if (NGX_PCRE)
759
760 if (regex == 0) {
761 continue;
762 }
763
764 in_addr[a].nregex = regex;
765 in_addr[a].regex = ngx_palloc(cf->pool,
766 regex * sizeof(ngx_http_server_name_t));
767
768 if (in_addr[a].regex == NULL) {
769 return NGX_CONF_ERROR;
770 }
771
772 for (i = 0, s = 0; s < in_addr[a].names.nelts; s++) {
773 if (name[s].regex) {
774 in_addr[a].regex[i++] = name[s];
775 }
776 }
777 #endif
743 } 778 }
744 779
745 in_addr = in_port[p].addrs.elts; 780 in_addr = in_port[p].addrs.elts;
746 last = in_port[p].addrs.nelts; 781 last = in_port[p].addrs.nelts;
747 782
855 for (i = 0; i < hip->naddrs; i++) { 890 for (i = 0; i < hip->naddrs; i++) {
856 hip->addrs[i].addr = in_addr[i].addr; 891 hip->addrs[i].addr = in_addr[i].addr;
857 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf; 892 hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf;
858 893
859 if (in_addr[i].hash.buckets == NULL 894 if (in_addr[i].hash.buckets == NULL
860 && (in_addr[i].dns_wildcards == NULL 895 && (in_addr[i].wc_head == NULL
861 || in_addr[i].dns_wildcards->hash.buckets == NULL)) 896 || in_addr[i].wc_head->hash.buckets == NULL)
897 && (in_addr[i].wc_head == NULL
898 || in_addr[i].wc_head->hash.buckets == NULL))
862 { 899 {
863 continue; 900 continue;
864 } 901 }
865 902
866 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t)); 903 vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
867 if (vn == NULL) { 904 if (vn == NULL) {
868 return NGX_CONF_ERROR; 905 return NGX_CONF_ERROR;
869 } 906 }
870 hip->addrs[i].virtual_names = vn; 907 hip->addrs[i].virtual_names = vn;
871 908
872 vn->hash = in_addr[i].hash; 909 vn->names.hash = in_addr[i].hash;
873 vn->dns_wildcards = in_addr[i].dns_wildcards; 910 vn->names.wc_head = in_addr[i].wc_head;
911 vn->names.wc_tail = in_addr[i].wc_tail;
912 #if (NGX_PCRE)
913 vn->nregex = in_addr[i].nregex;
914 vn->regex = in_addr[i].regex;
915 #endif
874 } 916 }
875 917
876 if (done) { 918 if (done) {
877 break; 919 break;
878 } 920 }
927 { 969 {
928 ngx_http_conf_in_addr_t *in_addr; 970 ngx_http_conf_in_addr_t *in_addr;
929 971
930 if (in_port->addrs.elts == NULL) { 972 if (in_port->addrs.elts == NULL) {
931 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4, 973 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4,
932 sizeof(ngx_http_conf_in_addr_t)) != NGX_OK) 974 sizeof(ngx_http_conf_in_addr_t))
975 != NGX_OK)
933 { 976 {
934 return NGX_ERROR; 977 return NGX_ERROR;
935 } 978 }
936 } 979 }
937 980
941 } 984 }
942 985
943 in_addr->addr = lscf->addr; 986 in_addr->addr = lscf->addr;
944 in_addr->hash.buckets = NULL; 987 in_addr->hash.buckets = NULL;
945 in_addr->hash.size = 0; 988 in_addr->hash.size = 0;
946 in_addr->dns_wildcards = NULL; 989 in_addr->wc_head = NULL;
990 in_addr->wc_tail = NULL;
947 in_addr->names.elts = NULL; 991 in_addr->names.elts = NULL;
992 #if (NGX_PCRE)
993 in_addr->nregex = 0;
994 in_addr->regex = NULL;
995 #endif
948 in_addr->core_srv_conf = cscf; 996 in_addr->core_srv_conf = cscf;
949 in_addr->default_server = lscf->conf.default_server; 997 in_addr->default_server = lscf->conf.default_server;
950 in_addr->bind = lscf->conf.bind; 998 in_addr->bind = lscf->conf.bind;
951 in_addr->listen_conf = &lscf->conf; 999 in_addr->listen_conf = &lscf->conf;
952 1000
975 ngx_uint_t i, n; 1023 ngx_uint_t i, n;
976 ngx_http_server_name_t *server_names, *name; 1024 ngx_http_server_name_t *server_names, *name;
977 1025
978 if (in_addr->names.elts == NULL) { 1026 if (in_addr->names.elts == NULL) {
979 if (ngx_array_init(&in_addr->names, cf->temp_pool, 4, 1027 if (ngx_array_init(&in_addr->names, cf->temp_pool, 4,
980 sizeof(ngx_http_server_name_t)) != NGX_OK) 1028 sizeof(ngx_http_server_name_t))
1029 != NGX_OK)
981 { 1030 {
982 return NGX_ERROR; 1031 return NGX_ERROR;
983 } 1032 }
984 } 1033 }
985 1034
986 server_names = cscf->server_names.elts; 1035 server_names = cscf->server_names.elts;
1036
987 for (i = 0; i < cscf->server_names.nelts; i++) { 1037 for (i = 0; i < cscf->server_names.nelts; i++) {
988 1038
989 for (n = 0; n < server_names[i].name.len; n++) { 1039 for (n = 0; n < server_names[i].name.len; n++) {
990 server_names[i].name.data[n] = 1040 server_names[i].name.data[n] =
991 ngx_tolower(server_names[i].name.data[n]); 1041 ngx_tolower(server_names[i].name.data[n]);
992 } 1042 }
993 1043
994 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, 1044 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
995 "name: %V", &server_names[i].name); 1045 "name: %V", &server_names[i].name);
996
997 1046
998 name = ngx_array_push(&in_addr->names); 1047 name = ngx_array_push(&in_addr->names);
999 if (name == NULL) { 1048 if (name == NULL) {
1000 return NGX_ERROR; 1049 return NGX_ERROR;
1001 } 1050 }