comparison src/http/ngx_http_request.c @ 3325:42c16d8bddbe

regex named captures
author Igor Sysoev <igor@sysoev.ru>
date Mon, 16 Nov 2009 12:19:02 +0000
parents 63fafb988446
children 1b8c3599e3ce
comparison
equal deleted inserted replaced
3324:616da2ea901f 3325:42c16d8bddbe
1698 } 1698 }
1699 1699
1700 #if (NGX_PCRE) 1700 #if (NGX_PCRE)
1701 1701
1702 if (len && r->virtual_names->nregex) { 1702 if (len && r->virtual_names->nregex) {
1703 size_t ncaptures;
1704 ngx_int_t n; 1703 ngx_int_t n;
1705 ngx_uint_t i; 1704 ngx_uint_t i;
1706 ngx_str_t name; 1705 ngx_str_t name;
1707 ngx_http_server_name_t *sn; 1706 ngx_http_server_name_t *sn;
1708 1707
1709 name.len = len; 1708 name.len = len;
1710 name.data = host; 1709 name.data = host;
1711 1710
1712 ncaptures = 0;
1713
1714 sn = r->virtual_names->regex; 1711 sn = r->virtual_names->regex;
1715 1712
1716 for (i = 0; i < r->virtual_names->nregex; i++) { 1713 for (i = 0; i < r->virtual_names->nregex; i++) {
1717 1714
1718 if (sn[i].server->captures && r->captures == NULL) { 1715 n = ngx_http_regex_exec(r, sn[i].regex, &name);
1719 1716
1720 ncaptures = (NGX_HTTP_MAX_CAPTURES + 1) * 3; 1717 if (n == NGX_OK) {
1721 1718 cscf = sn[i].server;
1722 r->captures = ngx_palloc(r->pool, ncaptures * sizeof(int)); 1719 goto found;
1723 if (r->captures == NULL) { 1720 }
1724 return NGX_ERROR; 1721
1725 } 1722 if (n == NGX_DECLINED) {
1726 }
1727
1728 n = ngx_regex_exec(sn[i].regex, &name, r->captures, ncaptures);
1729
1730 if (n == NGX_REGEX_NO_MATCHED) {
1731 continue; 1723 continue;
1732 } 1724 }
1733 1725
1734 if (n < 0) { 1726 return NGX_ERROR;
1735 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1736 ngx_regex_exec_n
1737 " failed: %d on \"%V\" using \"%V\"",
1738 n, &name, &sn[i].name);
1739 return NGX_ERROR;
1740 }
1741
1742 /* match */
1743
1744 cscf = sn[i].server;
1745
1746 r->ncaptures = ncaptures;
1747 r->captures_data = host;
1748
1749 goto found;
1750 } 1727 }
1751 } 1728 }
1752 1729
1753 #endif 1730 #endif
1754 1731