Mercurial > hg > nginx-mail
comparison src/http/ngx_http_core_module.c @ 308:94e16de3c33f NGINX_0_5_24
nginx 0.5.24
*) Security: the "ssl_verify_client" directive did not work if request
was made using HTTP/0.9.
*) Bugfix: a part of response body might be passed uncompressed if gzip
was used; bug appeared in 0.5.23.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 06 Jun 2007 00:00:00 +0400 |
parents | 9b7db0df50f0 |
children | 95d92ec39071 |
comparison
equal
deleted
inserted
replaced
307:0bcb7f864b94 | 308:94e16de3c33f |
---|---|
27 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1 | 27 #define NGX_HTTP_REQUEST_BODY_FILE_ON 1 |
28 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2 | 28 #define NGX_HTTP_REQUEST_BODY_FILE_CLEAN 2 |
29 | 29 |
30 | 30 |
31 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, | 31 static ngx_int_t ngx_http_core_find_location(ngx_http_request_t *r, |
32 ngx_array_t *locations, size_t len); | 32 ngx_array_t *locations, ngx_uint_t regex_start, size_t len); |
33 | 33 |
34 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); | 34 static ngx_int_t ngx_http_core_preconfiguration(ngx_conf_t *cf); |
35 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); | 35 static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
36 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); | 36 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
37 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); | 37 static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
627 r->content_handler = NULL; | 627 r->content_handler = NULL; |
628 r->uri_changed = 0; | 628 r->uri_changed = 0; |
629 | 629 |
630 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 630 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
631 | 631 |
632 rc = ngx_http_core_find_location(r, &cscf->locations, 0); | 632 rc = ngx_http_core_find_location(r, &cscf->locations, cscf->regex_start, 0); |
633 | 633 |
634 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { | 634 if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { |
635 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 635 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
636 return NGX_OK; | 636 return NGX_OK; |
637 } | 637 } |
928 } | 928 } |
929 | 929 |
930 | 930 |
931 static ngx_int_t | 931 static ngx_int_t |
932 ngx_http_core_find_location(ngx_http_request_t *r, | 932 ngx_http_core_find_location(ngx_http_request_t *r, |
933 ngx_array_t *locations, size_t len) | 933 ngx_array_t *locations, ngx_uint_t regex_start, size_t len) |
934 { | 934 { |
935 ngx_int_t n, rc; | 935 ngx_int_t n, rc; |
936 ngx_uint_t i, found, noregex; | 936 ngx_uint_t i, found, noregex; |
937 ngx_http_core_loc_conf_t *clcf, **clcfp; | 937 ngx_http_core_loc_conf_t *clcf, **clcfp; |
938 | 938 |
1006 } | 1006 } |
1007 | 1007 |
1008 if (found) { | 1008 if (found) { |
1009 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1009 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1010 | 1010 |
1011 if (clcf->locations.nelts) { | 1011 if (clcf->locations) { |
1012 rc = ngx_http_core_find_location(r, &clcf->locations, len); | 1012 rc = ngx_http_core_find_location(r, clcf->locations, |
1013 clcf->regex_start, len); | |
1013 | 1014 |
1014 if (rc != NGX_OK) { | 1015 if (rc != NGX_OK) { |
1015 return rc; | 1016 return rc; |
1016 } | 1017 } |
1017 } | 1018 } |
1023 return NGX_HTTP_LOCATION_NOREGEX; | 1024 return NGX_HTTP_LOCATION_NOREGEX; |
1024 } | 1025 } |
1025 | 1026 |
1026 /* regex matches */ | 1027 /* regex matches */ |
1027 | 1028 |
1028 for (/* void */; i < locations->nelts; i++) { | 1029 for (i = regex_start; i < locations->nelts; i++) { |
1029 | |
1030 if (!clcfp[i]->regex) { | |
1031 continue; | |
1032 } | |
1033 | 1030 |
1034 if (clcfp[i]->noname) { | 1031 if (clcfp[i]->noname) { |
1035 break; | 1032 break; |
1036 } | 1033 } |
1037 | 1034 |
1551 | 1548 |
1552 | 1549 |
1553 static char * | 1550 static char * |
1554 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | 1551 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
1555 { | 1552 { |
1556 char *rv; | 1553 char *rv; |
1557 void *mconf; | 1554 void *mconf; |
1558 ngx_uint_t m; | 1555 ngx_uint_t i, m; |
1559 ngx_conf_t pcf; | 1556 ngx_conf_t pcf; |
1560 ngx_http_module_t *module; | 1557 ngx_http_module_t *module; |
1561 ngx_http_conf_ctx_t *ctx, *http_ctx; | 1558 ngx_http_conf_ctx_t *ctx, *http_ctx; |
1562 ngx_http_core_srv_conf_t *cscf, **cscfp; | 1559 ngx_http_core_srv_conf_t *cscf, **cscfp; |
1563 ngx_http_core_main_conf_t *cmcf; | 1560 ngx_http_core_loc_conf_t **clcfp; |
1561 ngx_http_core_main_conf_t *cmcf; | |
1564 | 1562 |
1565 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | 1563 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
1566 if (ctx == NULL) { | 1564 if (ctx == NULL) { |
1567 return NGX_CONF_ERROR; | 1565 return NGX_CONF_ERROR; |
1568 } | 1566 } |
1642 } | 1640 } |
1643 | 1641 |
1644 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts, | 1642 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts, |
1645 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); | 1643 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); |
1646 | 1644 |
1645 cscf->regex_start = cscf->locations.nelts; | |
1646 clcfp = cscf->locations.elts; | |
1647 | |
1648 for (i = 0; i < cscf->locations.nelts; i++) { | |
1649 if (clcfp[i]->regex) { | |
1650 cscf->regex_start = i; | |
1651 break; | |
1652 } | |
1653 } | |
1654 | |
1647 return rv; | 1655 return rv; |
1648 } | 1656 } |
1649 | 1657 |
1650 | 1658 |
1651 static char * | 1659 static char * |
1652 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | 1660 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
1653 { | 1661 { |
1654 char *rv; | 1662 char *rv; |
1655 ngx_int_t m; | 1663 ngx_uint_t i, m; |
1656 ngx_str_t *value; | 1664 ngx_str_t *value; |
1657 ngx_conf_t save; | 1665 ngx_conf_t save; |
1658 ngx_http_module_t *module; | 1666 ngx_http_module_t *module; |
1659 ngx_http_conf_ctx_t *ctx, *pctx; | 1667 ngx_http_conf_ctx_t *ctx, *pctx; |
1660 ngx_http_core_srv_conf_t *cscf; | 1668 ngx_http_core_srv_conf_t *cscf; |
1783 "location \"%V\" is outside location \"%V\"", | 1791 "location \"%V\" is outside location \"%V\"", |
1784 &clcf->name, &pclcf->name); | 1792 &clcf->name, &pclcf->name); |
1785 return NGX_CONF_ERROR; | 1793 return NGX_CONF_ERROR; |
1786 } | 1794 } |
1787 | 1795 |
1788 if (pclcf->locations.elts == NULL) { | 1796 if (pclcf->locations == NULL) { |
1789 if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *)) | 1797 pclcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *)); |
1790 != NGX_OK) | 1798 |
1791 { | 1799 if (pclcf->locations == NULL) { |
1792 return NGX_CONF_ERROR; | 1800 return NGX_CONF_ERROR; |
1793 } | 1801 } |
1794 } | 1802 } |
1795 | 1803 |
1796 clcfp = ngx_array_push(&pclcf->locations); | 1804 clcfp = ngx_array_push(pclcf->locations); |
1797 if (clcfp == NULL) { | 1805 if (clcfp == NULL) { |
1798 return NGX_CONF_ERROR; | 1806 return NGX_CONF_ERROR; |
1799 } | 1807 } |
1800 } | 1808 } |
1801 | 1809 |
1811 | 1819 |
1812 if (rv != NGX_CONF_OK) { | 1820 if (rv != NGX_CONF_OK) { |
1813 return rv; | 1821 return rv; |
1814 } | 1822 } |
1815 | 1823 |
1816 ngx_sort(clcf->locations.elts, (size_t) clcf->locations.nelts, | 1824 if (clcf->locations == NULL) { |
1825 return rv; | |
1826 } | |
1827 | |
1828 ngx_sort(clcf->locations->elts, (size_t) clcf->locations->nelts, | |
1817 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); | 1829 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); |
1830 | |
1831 clcf->regex_start = clcf->locations->nelts; | |
1832 clcfp = clcf->locations->elts; | |
1833 | |
1834 for (i = 0; i < clcf->locations->nelts; i++) { | |
1835 if (clcfp[i]->regex) { | |
1836 clcf->regex_start = i; | |
1837 break; | |
1838 } | |
1839 } | |
1818 | 1840 |
1819 return rv; | 1841 return rv; |
1820 } | 1842 } |
1821 | 1843 |
1822 | 1844 |
2672 } | 2694 } |
2673 | 2695 |
2674 return NGX_CONF_ERROR; | 2696 return NGX_CONF_ERROR; |
2675 } | 2697 } |
2676 | 2698 |
2699 #if (NGX_PCRE) | |
2700 | |
2701 if (lcf->regex && alias) { | |
2702 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2703 "the \"alias\" directive may not be used " | |
2704 "inside location given by regular expression"); | |
2705 | |
2706 return NGX_CONF_ERROR; | |
2707 } | |
2708 | |
2709 #endif | |
2710 | |
2677 value = cf->args->elts; | 2711 value = cf->args->elts; |
2678 | 2712 |
2679 if (ngx_strstr(value[1].data, "$document_root") | 2713 if (ngx_strstr(value[1].data, "$document_root") |
2680 || ngx_strstr(value[1].data, "${document_root}")) | 2714 || ngx_strstr(value[1].data, "${document_root}")) |
2681 { | 2715 { |
2823 clcf->limit_except_loc_conf = ctx->loc_conf; | 2857 clcf->limit_except_loc_conf = ctx->loc_conf; |
2824 lcf->loc_conf = ctx->loc_conf; | 2858 lcf->loc_conf = ctx->loc_conf; |
2825 lcf->name = clcf->name; | 2859 lcf->name = clcf->name; |
2826 lcf->noname = 1; | 2860 lcf->noname = 1; |
2827 | 2861 |
2828 if (clcf->locations.elts == NULL) { | 2862 if (clcf->locations == NULL) { |
2829 if (ngx_array_init(&clcf->locations, cf->pool, 4, sizeof(void *)) | 2863 clcf->locations = ngx_array_create(cf->pool, 2, sizeof(void *)); |
2830 == NGX_ERROR) | 2864 if (clcf->locations == NULL) { |
2831 { | |
2832 return NGX_CONF_ERROR; | 2865 return NGX_CONF_ERROR; |
2833 } | 2866 } |
2834 } | 2867 } |
2835 | 2868 |
2836 clcfp = ngx_array_push(&clcf->locations); | 2869 clcfp = ngx_array_push(clcf->locations); |
2837 if (clcfp == NULL) { | 2870 if (clcfp == NULL) { |
2838 return NGX_CONF_ERROR; | 2871 return NGX_CONF_ERROR; |
2839 } | 2872 } |
2840 | 2873 |
2841 *clcfp = lcf; | 2874 *clcfp = lcf; |