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