Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 1353:7443fbe0b013
named location
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 29 Jul 2007 18:11:39 +0000 |
parents | e958b3cab51a |
children | 0d57c150115b |
comparison
equal
deleted
inserted
replaced
1352:e958b3cab51a | 1353:7443fbe0b013 |
---|---|
943 noregex = 0; | 943 noregex = 0; |
944 | 944 |
945 clcfp = locations->elts; | 945 clcfp = locations->elts; |
946 for (i = 0; i < locations->nelts; i++) { | 946 for (i = 0; i < locations->nelts; i++) { |
947 | 947 |
948 if (clcfp[i]->noname | |
948 #if (NGX_PCRE) | 949 #if (NGX_PCRE) |
949 if (clcfp[i]->regex) { | 950 || clcfp[i]->regex |
950 break; | |
951 } | |
952 #endif | 951 #endif |
953 | 952 || clcfp[i]->named) |
954 if (clcfp[i]->noname) { | 953 { |
955 break; | 954 break; |
956 } | 955 } |
957 | 956 |
958 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 957 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
959 "find location: %s\"%V\"", | 958 "find location: %s\"%V\"", |
1026 | 1025 |
1027 /* regex matches */ | 1026 /* regex matches */ |
1028 | 1027 |
1029 for (i = regex_start; i < locations->nelts; i++) { | 1028 for (i = regex_start; i < locations->nelts; i++) { |
1030 | 1029 |
1031 if (clcfp[i]->noname) { | 1030 if (!clcfp[i]->regex) { |
1032 break; | 1031 break; |
1033 } | 1032 } |
1034 | 1033 |
1035 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1034 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1036 "find location: ~ \"%V\"", &clcfp[i]->name); | 1035 "find location: ~ \"%V\"", &clcfp[i]->name); |
1512 | 1511 |
1513 return NGX_DONE; | 1512 return NGX_DONE; |
1514 } | 1513 } |
1515 | 1514 |
1516 | 1515 |
1516 ngx_int_t | |
1517 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name) | |
1518 { | |
1519 ngx_uint_t i; | |
1520 ngx_http_core_srv_conf_t *cscf; | |
1521 ngx_http_core_loc_conf_t **clcfp; | |
1522 ngx_http_core_main_conf_t *cmcf; | |
1523 | |
1524 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1525 | |
1526 clcfp = cscf->locations.elts; | |
1527 | |
1528 for (i = cscf->named_start; i < cscf->locations.nelts; i++) { | |
1529 | |
1530 if (name->len != clcfp[i]->name.len | |
1531 || ngx_strncmp(name->data, clcfp[i]->name.data, name->len) != 0) | |
1532 { | |
1533 continue; | |
1534 } | |
1535 | |
1536 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1537 "named location: %V \"%V?%V\"", name, &r->uri, &r->args); | |
1538 | |
1539 r->internal = 1; | |
1540 | |
1541 r->loc_conf = clcfp[i]->loc_conf; | |
1542 | |
1543 ngx_http_update_location_config(r); | |
1544 | |
1545 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1546 | |
1547 r->phase_handler = cmcf->phase_engine.location_rewrite_index; | |
1548 ngx_http_core_run_phases(r); | |
1549 | |
1550 return NGX_DONE; | |
1551 } | |
1552 | |
1553 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1554 "could not find name location \"%V\"", name); | |
1555 | |
1556 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1557 return NGX_DONE; | |
1558 } | |
1559 | |
1560 | |
1517 ngx_http_cleanup_t * | 1561 ngx_http_cleanup_t * |
1518 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size) | 1562 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size) |
1519 { | 1563 { |
1520 ngx_http_cleanup_t *cln; | 1564 ngx_http_cleanup_t *cln; |
1521 | 1565 |
1556 ngx_uint_t i; | 1600 ngx_uint_t i; |
1557 ngx_conf_t pcf; | 1601 ngx_conf_t pcf; |
1558 ngx_http_module_t *module; | 1602 ngx_http_module_t *module; |
1559 ngx_http_conf_ctx_t *ctx, *http_ctx; | 1603 ngx_http_conf_ctx_t *ctx, *http_ctx; |
1560 ngx_http_core_srv_conf_t *cscf, **cscfp; | 1604 ngx_http_core_srv_conf_t *cscf, **cscfp; |
1605 ngx_http_core_loc_conf_t **clcfp; | |
1561 ngx_http_core_main_conf_t *cmcf; | 1606 ngx_http_core_main_conf_t *cmcf; |
1562 #if (NGX_PCRE) | |
1563 ngx_http_core_loc_conf_t **clcfp; | |
1564 #endif | |
1565 | 1607 |
1566 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | 1608 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
1567 if (ctx == NULL) { | 1609 if (ctx == NULL) { |
1568 return NGX_CONF_ERROR; | 1610 return NGX_CONF_ERROR; |
1569 } | 1611 } |
1643 } | 1685 } |
1644 | 1686 |
1645 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts, | 1687 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts, |
1646 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); | 1688 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); |
1647 | 1689 |
1690 clcfp = cscf->locations.elts; | |
1691 | |
1648 #if (NGX_PCRE) | 1692 #if (NGX_PCRE) |
1649 | 1693 |
1650 cscf->regex_start = cscf->locations.nelts; | 1694 cscf->regex_start = cscf->locations.nelts; |
1651 clcfp = cscf->locations.elts; | |
1652 | 1695 |
1653 for (i = 0; i < cscf->locations.nelts; i++) { | 1696 for (i = 0; i < cscf->locations.nelts; i++) { |
1654 if (clcfp[i]->regex) { | 1697 if (clcfp[i]->regex) { |
1655 cscf->regex_start = i; | 1698 cscf->regex_start = i; |
1656 break; | 1699 break; |
1657 } | 1700 } |
1658 } | 1701 } |
1659 | 1702 |
1660 #endif | 1703 #endif |
1704 | |
1705 cscf->named_start = cscf->locations.nelts; | |
1706 | |
1707 for (i = 0; i < cscf->locations.nelts; i++) { | |
1708 if (clcfp[i]->named) { | |
1709 cscf->named_start = i; | |
1710 break; | |
1711 } | |
1712 } | |
1661 | 1713 |
1662 return rv; | 1714 return rv; |
1663 } | 1715 } |
1664 | 1716 |
1665 | 1717 |
1757 "invalid location modifier \"%V\"", &value[1]); | 1809 "invalid location modifier \"%V\"", &value[1]); |
1758 return NGX_CONF_ERROR; | 1810 return NGX_CONF_ERROR; |
1759 } | 1811 } |
1760 | 1812 |
1761 } else { | 1813 } else { |
1814 | |
1762 clcf->name = value[1]; | 1815 clcf->name = value[1]; |
1816 | |
1817 if (value[1].data[0] == '@') { | |
1818 clcf->named = 1; | |
1819 } | |
1763 } | 1820 } |
1764 | 1821 |
1765 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; | 1822 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; |
1766 | 1823 |
1767 if (pclcf->name.len == 0) { | 1824 if (pclcf->name.len == 0) { |
1779 | 1836 |
1780 if (pclcf->exact_match) { | 1837 if (pclcf->exact_match) { |
1781 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1838 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1782 "location \"%V\" could not be inside " | 1839 "location \"%V\" could not be inside " |
1783 "the exact location \"%V\"", | 1840 "the exact location \"%V\"", |
1841 &clcf->name, &pclcf->name); | |
1842 return NGX_CONF_ERROR; | |
1843 } | |
1844 | |
1845 if (pclcf->named) { | |
1846 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1847 "location \"%V\" could not be inside " | |
1848 "the named location \"%V\"", | |
1784 &clcf->name, &pclcf->name); | 1849 &clcf->name, &pclcf->name); |
1785 return NGX_CONF_ERROR; | 1850 return NGX_CONF_ERROR; |
1786 } | 1851 } |
1787 | 1852 |
1788 #if (NGX_PCRE) | 1853 #if (NGX_PCRE) |
1859 ngx_int_t rc; | 1924 ngx_int_t rc; |
1860 ngx_http_core_loc_conf_t *first, *second; | 1925 ngx_http_core_loc_conf_t *first, *second; |
1861 | 1926 |
1862 first = *(ngx_http_core_loc_conf_t **) one; | 1927 first = *(ngx_http_core_loc_conf_t **) one; |
1863 second = *(ngx_http_core_loc_conf_t **) two; | 1928 second = *(ngx_http_core_loc_conf_t **) two; |
1929 | |
1930 if (first->named && !second->named) { | |
1931 /* shift named locations to the end */ | |
1932 return 1; | |
1933 } | |
1934 | |
1935 if (!first->named && second->named) { | |
1936 /* shift named locations to the end */ | |
1937 return -1; | |
1938 } | |
1939 | |
1940 if (first->named && second->named) { | |
1941 return ngx_strcmp(first->name.data, second->name.data); | |
1942 } | |
1864 | 1943 |
1865 if (first->noname && !second->noname) { | 1944 if (first->noname && !second->noname) { |
1866 /* shift no named locations to the end */ | 1945 /* shift no named locations to the end */ |
1867 return 1; | 1946 return 1; |
1868 } | 1947 } |
2705 } | 2784 } |
2706 | 2785 |
2707 return NGX_CONF_ERROR; | 2786 return NGX_CONF_ERROR; |
2708 } | 2787 } |
2709 | 2788 |
2789 if (lcf->named && alias) { | |
2790 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2791 "the \"alias\" directive may not be used " | |
2792 "inside named location"); | |
2793 | |
2794 return NGX_CONF_ERROR; | |
2795 } | |
2796 | |
2710 #if (NGX_PCRE) | 2797 #if (NGX_PCRE) |
2711 | 2798 |
2712 if (lcf->regex && alias) { | 2799 if (lcf->regex && alias) { |
2713 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2800 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2714 "the \"alias\" directive may not be used " | 2801 "the \"alias\" directive may not be used " |