Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_ssi_filter_module.c @ 178:87699398f955 NGINX_0_3_36
nginx 0.3.36
*) Feature: the ngx_http_addition_filter_module.
*) Feature: the "proxy_pass" and "fastcgi_pass" directives may be used
inside the "if" block.
*) Feature: the "proxy_ignore_client_abort" and
"fastcgi_ignore_client_abort" directives.
*) Feature: the "$request_completion" variable.
*) Feature: the ngx_http_perl_module supports the $r->request_method
and $r->remote_addr.
*) Feature: the ngx_http_ssi_module supports the "elif" command.
*) Bugfix: the "\/" string in the expression of the "if" command of the
ngx_http_ssi_module was treated incorrectly.
*) Bugfix: in the regular expressions in the "if" command of the
ngx_http_ssi_module.
*) Bugfix: if the relative path was specified in the
"client_body_temp_path", "proxy_temp_path", "fastcgi_temp_path", and
"perl_modules" directives, then the directory was used relatively to
a current path but not to a server prefix.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 05 Apr 2006 00:00:00 +0400 |
parents | 73e8476f9142 |
children | 71ff1e2b484a |
comparison
equal
deleted
inserted
replaced
177:4a3ddd758222 | 178:87699398f955 |
---|---|
11 #define NGX_HTTP_SSI_ERROR 1 | 11 #define NGX_HTTP_SSI_ERROR 1 |
12 | 12 |
13 #define NGX_HTTP_SSI_DATE_LEN 2048 | 13 #define NGX_HTTP_SSI_DATE_LEN 2048 |
14 | 14 |
15 #define NGX_HTTP_SSI_ADD_PREFIX 1 | 15 #define NGX_HTTP_SSI_ADD_PREFIX 1 |
16 #define NGX_HTTP_SSI_ADD_ZERO 2 | |
16 | 17 |
17 | 18 |
18 typedef struct { | 19 typedef struct { |
19 ngx_flag_t enable; | 20 ngx_flag_t enable; |
20 ngx_flag_t silent_errors; | 21 ngx_flag_t silent_errors; |
245 { ngx_string("config"), ngx_http_ssi_config, | 246 { ngx_string("config"), ngx_http_ssi_config, |
246 ngx_http_ssi_config_params, 0, 0 }, | 247 ngx_http_ssi_config_params, 0, 0 }, |
247 { ngx_string("set"), ngx_http_ssi_set, ngx_http_ssi_set_params, 0, 0 }, | 248 { ngx_string("set"), ngx_http_ssi_set, ngx_http_ssi_set_params, 0, 0 }, |
248 | 249 |
249 { ngx_string("if"), ngx_http_ssi_if, ngx_http_ssi_if_params, 0, 0 }, | 250 { ngx_string("if"), ngx_http_ssi_if, ngx_http_ssi_if_params, 0, 0 }, |
250 { ngx_string("else"), ngx_http_ssi_else, ngx_http_ssi_no_params, 1, 0 }, | 251 { ngx_string("elif"), ngx_http_ssi_if, ngx_http_ssi_if_params, |
251 { ngx_string("endif"), ngx_http_ssi_endif, ngx_http_ssi_no_params, 1, 0 }, | 252 NGX_HTTP_SSI_COND_IF, 0 }, |
253 { ngx_string("else"), ngx_http_ssi_else, ngx_http_ssi_no_params, | |
254 NGX_HTTP_SSI_COND_IF, 0 }, | |
255 { ngx_string("endif"), ngx_http_ssi_endif, ngx_http_ssi_no_params, | |
256 NGX_HTTP_SSI_COND_ELSE, 0 }, | |
252 | 257 |
253 { ngx_null_string, NULL, NULL, 0, 0 } | 258 { ngx_null_string, NULL, NULL, 0, 0 } |
254 }; | 259 }; |
255 | 260 |
256 | 261 |
521 } | 526 } |
522 | 527 |
523 continue; | 528 continue; |
524 } | 529 } |
525 | 530 |
526 if (!ctx->output && !cmd->conditional) { | 531 if (cmd->conditional |
532 && (ctx->conditional == 0 | |
533 || ctx->conditional > cmd->conditional)) | |
534 { | |
535 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
536 "invalid context of SSI command: \"%V\"", | |
537 &ctx->command); | |
538 goto ssi_error; | |
539 } | |
540 | |
541 if (!ctx->output && cmd->conditional == 0) { | |
527 continue; | 542 continue; |
528 } | 543 } |
529 | 544 |
530 if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) { | 545 if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) { |
531 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 546 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
924 | 939 |
925 ctx->key = 0; | 940 ctx->key = 0; |
926 ctx->key = ngx_hash(ctx->key, ch); | 941 ctx->key = ngx_hash(ctx->key, ch); |
927 | 942 |
928 ctx->params.nelts = 0; | 943 ctx->params.nelts = 0; |
944 | |
929 state = ssi_command_state; | 945 state = ssi_command_state; |
930 break; | 946 break; |
931 } | 947 } |
932 | 948 |
933 break; | 949 break; |
1563 break; | 1579 break; |
1564 } | 1580 } |
1565 } | 1581 } |
1566 } | 1582 } |
1567 | 1583 |
1568 p = ngx_palloc(r->pool, len); | 1584 p = ngx_palloc(r->pool, len + ((flags & NGX_HTTP_SSI_ADD_ZERO) ? 1 : 0)); |
1569 if (p == NULL) { | 1585 if (p == NULL) { |
1570 return NGX_ERROR; | 1586 return NGX_ERROR; |
1571 } | 1587 } |
1572 | 1588 |
1573 text->len = len; | 1589 text->len = len; |
1807 ngx_str_t **params) | 1823 ngx_str_t **params) |
1808 { | 1824 { |
1809 u_char *p, *last; | 1825 u_char *p, *last; |
1810 ngx_str_t *expr, left, right; | 1826 ngx_str_t *expr, left, right; |
1811 ngx_int_t rc; | 1827 ngx_int_t rc; |
1812 ngx_uint_t negative, noregex; | 1828 ngx_uint_t negative, noregex, flags; |
1813 #if (NGX_PCRE) | 1829 #if (NGX_PCRE) |
1814 ngx_str_t err; | 1830 ngx_str_t err; |
1815 ngx_regex_t *regex; | 1831 ngx_regex_t *regex; |
1816 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 1832 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
1817 #endif | 1833 #endif |
1834 | |
1835 if (ctx->command.len == 2) { | |
1836 if (ctx->conditional) { | |
1837 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1838 "the \"if\" command inside the \"if\" command"); | |
1839 return NGX_HTTP_SSI_ERROR; | |
1840 } | |
1841 } | |
1842 | |
1843 if (ctx->output_chosen) { | |
1844 ctx->output = 0; | |
1845 return NGX_OK; | |
1846 } | |
1818 | 1847 |
1819 expr = params[NGX_HTTP_SSI_IF_EXPR]; | 1848 expr = params[NGX_HTTP_SSI_IF_EXPR]; |
1820 | 1849 |
1821 left.data = expr->data; | 1850 left.data = expr->data; |
1822 last = expr->data + expr->len; | 1851 last = expr->data + expr->len; |
1855 "evaluted left: \"%V\"", &left); | 1884 "evaluted left: \"%V\"", &left); |
1856 | 1885 |
1857 if (p == last) { | 1886 if (p == last) { |
1858 if (left.len) { | 1887 if (left.len) { |
1859 ctx->output = 1; | 1888 ctx->output = 1; |
1889 ctx->output_chosen = 1; | |
1860 | 1890 |
1861 } else { | 1891 } else { |
1862 ctx->output = 0; | 1892 ctx->output = 0; |
1863 } | 1893 } |
1894 | |
1895 ctx->conditional = NGX_HTTP_SSI_COND_IF; | |
1864 | 1896 |
1865 return NGX_OK; | 1897 return NGX_OK; |
1866 } | 1898 } |
1867 | 1899 |
1868 if (p < last && *p == '=') { | 1900 if (p < last && *p == '=') { |
1885 if (*(last - 1) != '/') { | 1917 if (*(last - 1) != '/') { |
1886 goto invalid_expression; | 1918 goto invalid_expression; |
1887 } | 1919 } |
1888 | 1920 |
1889 noregex = 0; | 1921 noregex = 0; |
1922 flags = NGX_HTTP_SSI_ADD_ZERO; | |
1890 last--; | 1923 last--; |
1891 p++; | 1924 p++; |
1892 | 1925 |
1893 } else { | 1926 } else { |
1894 noregex = 1; | 1927 noregex = 1; |
1928 flags = 0; | |
1929 | |
1930 if (p < last - 1 && p[0] == '\\' && p[1] == '/') { | |
1931 p++; | |
1932 } | |
1895 } | 1933 } |
1896 | 1934 |
1897 right.len = last - p; | 1935 right.len = last - p; |
1898 right.data = p; | 1936 right.data = p; |
1899 | 1937 |
1900 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1938 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1901 "right: \"%V\"", &right); | 1939 "right: \"%V\"", &right); |
1902 | 1940 |
1903 if (ngx_http_ssi_evaluate_string(r, ctx, &right, 0) != NGX_OK) { | 1941 if (ngx_http_ssi_evaluate_string(r, ctx, &right, flags) != NGX_OK) { |
1904 return NGX_HTTP_SSI_ERROR; | 1942 return NGX_HTTP_SSI_ERROR; |
1905 } | 1943 } |
1906 | 1944 |
1907 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1945 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1908 "evaluted right: \"%V\"", &right); | 1946 "evaluted right: \"%V\"", &right); |
1946 #endif | 1984 #endif |
1947 } | 1985 } |
1948 | 1986 |
1949 if ((rc == 0 && !negative) || (rc != 0 && negative)) { | 1987 if ((rc == 0 && !negative) || (rc != 0 && negative)) { |
1950 ctx->output = 1; | 1988 ctx->output = 1; |
1989 ctx->output_chosen = 1; | |
1951 | 1990 |
1952 } else { | 1991 } else { |
1953 ctx->output = 0; | 1992 ctx->output = 0; |
1954 } | 1993 } |
1994 | |
1995 ctx->conditional = NGX_HTTP_SSI_COND_IF; | |
1955 | 1996 |
1956 return NGX_OK; | 1997 return NGX_OK; |
1957 | 1998 |
1958 invalid_expression: | 1999 invalid_expression: |
1959 | 2000 |
1966 | 2007 |
1967 static ngx_int_t | 2008 static ngx_int_t |
1968 ngx_http_ssi_else(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 2009 ngx_http_ssi_else(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
1969 ngx_str_t **params) | 2010 ngx_str_t **params) |
1970 { | 2011 { |
1971 ctx->output = !ctx->output; | 2012 if (ctx->output_chosen) { |
2013 ctx->output = 0; | |
2014 } else { | |
2015 ctx->output = 1; | |
2016 } | |
2017 | |
2018 ctx->conditional = NGX_HTTP_SSI_COND_ELSE; | |
1972 | 2019 |
1973 return NGX_OK; | 2020 return NGX_OK; |
1974 } | 2021 } |
1975 | 2022 |
1976 | 2023 |
1977 static ngx_int_t | 2024 static ngx_int_t |
1978 ngx_http_ssi_endif(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 2025 ngx_http_ssi_endif(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
1979 ngx_str_t **params) | 2026 ngx_str_t **params) |
1980 { | 2027 { |
1981 ctx->output = 1; | 2028 ctx->output = 1; |
2029 ctx->output_chosen = 0; | |
2030 ctx->conditional = 0; | |
1982 | 2031 |
1983 return NGX_OK; | 2032 return NGX_OK; |
1984 } | 2033 } |
1985 | 2034 |
1986 | 2035 |