Mercurial > hg > nginx-vendor-0-5
comparison src/http/modules/ngx_http_ssi_filter_module.c @ 248:acd2ec3541cb NGINX_0_4_9
nginx 0.4.9
*) Feature: the "set" parameter in the "include" SSI command.
*) Feature: the ngx_http_perl_module now tests the nginx.pm module
version.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 13 Oct 2006 00:00:00 +0400 |
parents | b52bd034c577 |
children | fbf2b2f66c9f |
comparison
equal
deleted
inserted
replaced
247:fcca101509a4 | 248:acd2ec3541cb |
---|---|
76 static ngx_int_t ngx_http_ssi_evaluate_string(ngx_http_request_t *r, | 76 static ngx_int_t ngx_http_ssi_evaluate_string(ngx_http_request_t *r, |
77 ngx_http_ssi_ctx_t *ctx, ngx_str_t *text, ngx_uint_t flags); | 77 ngx_http_ssi_ctx_t *ctx, ngx_str_t *text, ngx_uint_t flags); |
78 | 78 |
79 static ngx_int_t ngx_http_ssi_include(ngx_http_request_t *r, | 79 static ngx_int_t ngx_http_ssi_include(ngx_http_request_t *r, |
80 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | 80 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
81 static ngx_int_t ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data, | |
82 ngx_int_t rc); | |
83 static ngx_int_t ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data, | |
84 ngx_int_t rc); | |
81 static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r, | 85 static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r, |
82 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | 86 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
83 static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r, | 87 static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r, |
84 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); | 88 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); |
85 static ngx_int_t ngx_http_ssi_set(ngx_http_request_t *r, | 89 static ngx_int_t ngx_http_ssi_set(ngx_http_request_t *r, |
195 | 199 |
196 | 200 |
197 static u_char ngx_http_ssi_string[] = "<!--"; | 201 static u_char ngx_http_ssi_string[] = "<!--"; |
198 | 202 |
199 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); | 203 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); |
204 static ngx_str_t ngx_http_ssi_null_string = ngx_null_string; | |
205 | |
200 | 206 |
201 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 | 207 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 |
202 #define NGX_HTTP_SSI_INCLUDE_FILE 1 | 208 #define NGX_HTTP_SSI_INCLUDE_FILE 1 |
203 #define NGX_HTTP_SSI_INCLUDE_WAIT 2 | 209 #define NGX_HTTP_SSI_INCLUDE_WAIT 2 |
204 #define NGX_HTTP_SSI_INCLUDE_STUB 3 | 210 #define NGX_HTTP_SSI_INCLUDE_SET 3 |
211 #define NGX_HTTP_SSI_INCLUDE_STUB 4 | |
205 | 212 |
206 #define NGX_HTTP_SSI_ECHO_VAR 0 | 213 #define NGX_HTTP_SSI_ECHO_VAR 0 |
207 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 | 214 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 |
208 | 215 |
209 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 | 216 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 |
219 | 226 |
220 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { | 227 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = { |
221 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, | 228 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 }, |
222 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, | 229 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 }, |
223 { ngx_string("wait"), NGX_HTTP_SSI_INCLUDE_WAIT, 0, 0 }, | 230 { ngx_string("wait"), NGX_HTTP_SSI_INCLUDE_WAIT, 0, 0 }, |
231 { ngx_string("set"), NGX_HTTP_SSI_INCLUDE_SET, 0, 0 }, | |
224 { ngx_string("stub"), NGX_HTTP_SSI_INCLUDE_STUB, 0, 0 }, | 232 { ngx_string("stub"), NGX_HTTP_SSI_INCLUDE_STUB, 0, 0 }, |
225 { ngx_null_string, 0, 0, 0 } | 233 { ngx_null_string, 0, 0, 0 } |
226 }; | 234 }; |
227 | 235 |
228 | 236 |
380 ngx_int_t rc; | 388 ngx_int_t rc; |
381 ngx_buf_t *b; | 389 ngx_buf_t *b; |
382 ngx_uint_t i, index; | 390 ngx_uint_t i, index; |
383 ngx_chain_t *cl, **ll; | 391 ngx_chain_t *cl, **ll; |
384 ngx_table_elt_t *param; | 392 ngx_table_elt_t *param; |
385 ngx_connection_t *c; | |
386 ngx_http_request_t *pr; | 393 ngx_http_request_t *pr; |
387 ngx_http_ssi_ctx_t *ctx, *mctx; | 394 ngx_http_ssi_ctx_t *ctx, *mctx; |
388 ngx_http_ssi_block_t *bl; | 395 ngx_http_ssi_block_t *bl; |
389 ngx_http_ssi_param_t *prm; | 396 ngx_http_ssi_param_t *prm; |
390 ngx_http_ssi_command_t *cmd; | 397 ngx_http_ssi_command_t *cmd; |
799 if (rc == NGX_ERROR) { | 806 if (rc == NGX_ERROR) { |
800 return NGX_ERROR; | 807 return NGX_ERROR; |
801 } | 808 } |
802 } | 809 } |
803 | 810 |
804 c = r->connection; | |
805 | |
806 rc = cmd->handler(r, ctx, params); | 811 rc = cmd->handler(r, ctx, params); |
807 | |
808 if (c->destroyed) { | |
809 return NGX_DONE; | |
810 } | |
811 | 812 |
812 if (rc == NGX_OK) { | 813 if (rc == NGX_OK) { |
813 continue; | 814 continue; |
814 } | 815 } |
815 | 816 |
816 if (rc == NGX_AGAIN) { | 817 if (rc == NGX_DONE || rc == NGX_AGAIN || rc == NGX_ERROR) { |
817 return NGX_AGAIN; | 818 return rc; |
818 } | |
819 | |
820 if (rc == NGX_ERROR) { | |
821 return NGX_ERROR; | |
822 } | 819 } |
823 } | 820 } |
824 | 821 |
825 | 822 |
826 /* rc == NGX_HTTP_SSI_ERROR */ | 823 /* rc == NGX_HTTP_SSI_ERROR */ |
1536 static ngx_str_t * | 1533 static ngx_str_t * |
1537 ngx_http_ssi_get_variable(ngx_http_request_t *r, ngx_str_t *name, | 1534 ngx_http_ssi_get_variable(ngx_http_request_t *r, ngx_str_t *name, |
1538 ngx_uint_t key) | 1535 ngx_uint_t key) |
1539 { | 1536 { |
1540 ngx_uint_t i; | 1537 ngx_uint_t i; |
1538 ngx_list_part_t *part; | |
1541 ngx_http_ssi_var_t *var; | 1539 ngx_http_ssi_var_t *var; |
1542 ngx_http_ssi_ctx_t *ctx; | 1540 ngx_http_ssi_ctx_t *ctx; |
1543 | 1541 |
1544 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | 1542 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); |
1545 | 1543 |
1546 if (ctx->variables == NULL) { | 1544 if (ctx->variables == NULL) { |
1547 return NULL; | 1545 return NULL; |
1548 } | 1546 } |
1549 | 1547 |
1550 var = ctx->variables->elts; | 1548 part = &ctx->variables->part; |
1551 for (i = 0; i < ctx->variables->nelts; i++) { | 1549 var = part->elts; |
1550 | |
1551 for (i = 0; /* void */ ; i++) { | |
1552 | |
1553 if (i >= part->nelts) { | |
1554 if (part->next == NULL) { | |
1555 break; | |
1556 } | |
1557 | |
1558 part = part->next; | |
1559 var = part->elts; | |
1560 i = 0; | |
1561 } | |
1562 | |
1552 if (name->len != var[i].name.len) { | 1563 if (name->len != var[i].name.len) { |
1553 continue; | 1564 continue; |
1554 } | 1565 } |
1555 | 1566 |
1556 if (key != var[i].key) { | 1567 if (key != var[i].key) { |
1691 | 1702 |
1692 if (bracket) { | 1703 if (bracket) { |
1693 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1704 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1694 "the closing bracket in \"%V\" " | 1705 "the closing bracket in \"%V\" " |
1695 "variable is missing", &var); | 1706 "variable is missing", &var); |
1696 return NGX_ERROR; | 1707 return NGX_HTTP_SSI_ERROR; |
1697 } | 1708 } |
1698 | 1709 |
1699 if (var.len == 0) { | 1710 if (var.len == 0) { |
1700 goto invalid_variable; | 1711 goto invalid_variable; |
1701 } | 1712 } |
1818 invalid_variable: | 1829 invalid_variable: |
1819 | 1830 |
1820 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1831 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1821 "invalid variable name in \"%V\"", text); | 1832 "invalid variable name in \"%V\"", text); |
1822 | 1833 |
1823 return NGX_ERROR; | 1834 return NGX_HTTP_SSI_ERROR; |
1824 } | 1835 } |
1825 | 1836 |
1826 | 1837 |
1827 static ngx_int_t | 1838 static ngx_int_t |
1828 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 1839 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
1829 ngx_str_t **params) | 1840 ngx_str_t **params) |
1830 { | 1841 { |
1831 ngx_int_t rc; | 1842 ngx_int_t rc, key; |
1832 ngx_str_t *uri, *file, *wait, *stub, args; | 1843 ngx_str_t *uri, *file, *wait, *set, *stub, args; |
1833 ngx_buf_t *b; | 1844 ngx_buf_t *b; |
1834 ngx_uint_t flags, i; | 1845 ngx_uint_t flags, i; |
1835 ngx_chain_t *out, *cl, *tl, **ll; | 1846 ngx_chain_t *cl, *tl, **ll; |
1836 ngx_http_request_t *sr; | 1847 ngx_http_request_t *sr; |
1837 ngx_http_ssi_ctx_t *mctx; | 1848 ngx_http_ssi_var_t *var; |
1838 ngx_http_ssi_block_t *bl; | 1849 ngx_http_ssi_ctx_t *mctx; |
1850 ngx_http_ssi_block_t *bl; | |
1851 ngx_http_post_subrequest_t *psr; | |
1839 | 1852 |
1840 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; | 1853 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL]; |
1841 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; | 1854 file = params[NGX_HTTP_SSI_INCLUDE_FILE]; |
1842 wait = params[NGX_HTTP_SSI_INCLUDE_WAIT]; | 1855 wait = params[NGX_HTTP_SSI_INCLUDE_WAIT]; |
1856 set = params[NGX_HTTP_SSI_INCLUDE_SET]; | |
1843 stub = params[NGX_HTTP_SSI_INCLUDE_STUB]; | 1857 stub = params[NGX_HTTP_SSI_INCLUDE_STUB]; |
1844 | 1858 |
1845 if (uri && file) { | 1859 if (uri && file) { |
1846 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1860 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1847 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", | 1861 "inlcusion may be either virtual=\"%V\" or file=\"%V\"", |
1850 } | 1864 } |
1851 | 1865 |
1852 if (uri == NULL && file == NULL) { | 1866 if (uri == NULL && file == NULL) { |
1853 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1867 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1854 "no parameter in \"include\" SSI command"); | 1868 "no parameter in \"include\" SSI command"); |
1869 return NGX_HTTP_SSI_ERROR; | |
1870 } | |
1871 | |
1872 if (set && stub) { | |
1873 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1874 "\"set\" and \"stub\" may not be used together " | |
1875 "in \"include\" SSI command"); | |
1855 return NGX_HTTP_SSI_ERROR; | 1876 return NGX_HTTP_SSI_ERROR; |
1856 } | 1877 } |
1857 | 1878 |
1858 if (wait) { | 1879 if (wait) { |
1859 if (uri == NULL) { | 1880 if (uri == NULL) { |
1876 | 1897 |
1877 if (uri == NULL) { | 1898 if (uri == NULL) { |
1878 uri = file; | 1899 uri = file; |
1879 } | 1900 } |
1880 | 1901 |
1881 if (ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX) | 1902 rc = ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX); |
1882 != NGX_OK) | 1903 |
1883 { | 1904 if (rc != NGX_OK) { |
1884 return NGX_HTTP_SSI_ERROR; | 1905 return rc; |
1885 } | 1906 } |
1886 | 1907 |
1887 args.len = 0; | 1908 args.len = 0; |
1888 args.data = NULL; | 1909 args.data = NULL; |
1889 flags = 0; | 1910 flags = 0; |
1893 | 1914 |
1894 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { | 1915 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) { |
1895 return NGX_HTTP_SSI_ERROR; | 1916 return NGX_HTTP_SSI_ERROR; |
1896 } | 1917 } |
1897 | 1918 |
1898 out = NULL; | 1919 psr = NULL; |
1920 | |
1921 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
1899 | 1922 |
1900 if (stub) { | 1923 if (stub) { |
1901 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | |
1902 | |
1903 if (mctx->blocks) { | 1924 if (mctx->blocks) { |
1904 bl = mctx->blocks->elts; | 1925 bl = mctx->blocks->elts; |
1905 for (i = 0; i < mctx->blocks->nelts; i++) { | 1926 for (i = 0; i < mctx->blocks->nelts; i++) { |
1906 if (stub->len == bl[i].name.len | 1927 if (stub->len == bl[i].name.len |
1907 && ngx_strncmp(stub->data, bl[i].name.data, stub->len) == 0) | 1928 && ngx_strncmp(stub->data, bl[i].name.data, stub->len) == 0) |
1915 "\"stub\"=\"%V\" for \"include\" not found", stub); | 1936 "\"stub\"=\"%V\" for \"include\" not found", stub); |
1916 return NGX_HTTP_SSI_ERROR; | 1937 return NGX_HTTP_SSI_ERROR; |
1917 | 1938 |
1918 found: | 1939 found: |
1919 | 1940 |
1941 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t)); | |
1942 if (psr == NULL) { | |
1943 return NGX_ERROR; | |
1944 } | |
1945 | |
1946 psr->handler = ngx_http_ssi_stub_output; | |
1947 | |
1920 if (bl[i].count++) { | 1948 if (bl[i].count++) { |
1921 | 1949 |
1922 ll = &out; | 1950 ll = (ngx_chain_t **) &psr->data; |
1923 | 1951 |
1924 for (tl = bl[i].bufs; tl; tl = tl->next) { | 1952 for (tl = bl[i].bufs; tl; tl = tl->next) { |
1925 | 1953 |
1926 if (ctx->free) { | 1954 if (ctx->free) { |
1927 cl = ctx->free; | 1955 cl = ctx->free; |
1950 cl->next = NULL; | 1978 cl->next = NULL; |
1951 ll = &cl->next; | 1979 ll = &cl->next; |
1952 } | 1980 } |
1953 | 1981 |
1954 } else { | 1982 } else { |
1955 out = bl[i].bufs; | 1983 psr->data = bl[i].bufs; |
1956 } | 1984 } |
1957 } | 1985 } |
1958 | 1986 |
1959 rc = ngx_http_subrequest(r, uri, &args, &sr, out, flags); | 1987 if (set) { |
1988 key = 0; | |
1989 | |
1990 for (i = 0; i < set->len; i++) { | |
1991 set->data[i] = ngx_tolower(set->data[i]); | |
1992 key = ngx_hash(key, set->data[i]); | |
1993 } | |
1994 | |
1995 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t)); | |
1996 if (psr == NULL) { | |
1997 return NGX_ERROR; | |
1998 } | |
1999 | |
2000 psr->handler = ngx_http_ssi_set_variable; | |
2001 psr->data = ngx_http_ssi_get_variable(r, set, key); | |
2002 | |
2003 if (psr->data == NULL) { | |
2004 | |
2005 if (mctx->variables == NULL) { | |
2006 mctx->variables = ngx_list_create(r->pool, 4, | |
2007 sizeof(ngx_http_ssi_var_t)); | |
2008 if (mctx->variables == NULL) { | |
2009 return NGX_ERROR; | |
2010 } | |
2011 } | |
2012 | |
2013 var = ngx_list_push(mctx->variables); | |
2014 if (var == NULL) { | |
2015 return NGX_ERROR; | |
2016 } | |
2017 | |
2018 var->name = *set; | |
2019 var->key = key; | |
2020 var->value = ngx_http_ssi_null_string; | |
2021 psr->data = &var->value; | |
2022 } | |
2023 | |
2024 flags |= NGX_HTTP_SUBREQUEST_IN_MEMORY; | |
2025 } | |
2026 | |
2027 rc = ngx_http_subrequest(r, uri, &args, &sr, psr, flags); | |
2028 | |
2029 if (rc == NGX_DONE) { | |
2030 return NGX_DONE; | |
2031 } | |
1960 | 2032 |
1961 if (rc == NGX_ERROR) { | 2033 if (rc == NGX_ERROR) { |
1962 return NGX_HTTP_SSI_ERROR; | 2034 return NGX_HTTP_SSI_ERROR; |
1963 } | 2035 } |
1964 | 2036 |
1965 if (wait == NULL) { | 2037 if (wait == NULL && set == NULL) { |
1966 return NGX_OK; | 2038 return NGX_OK; |
1967 } | 2039 } |
1968 | 2040 |
1969 if (rc == NGX_AGAIN) { | 2041 if (rc == NGX_AGAIN) { |
1970 if (ctx->wait == NULL) { | 2042 if (ctx->wait == NULL) { |
1972 | 2044 |
1973 } else { | 2045 } else { |
1974 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 2046 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1975 "only one subrequest may be waited at the same time"); | 2047 "only one subrequest may be waited at the same time"); |
1976 } | 2048 } |
2049 } | |
2050 | |
2051 return rc; | |
2052 } | |
2053 | |
2054 | |
2055 static ngx_int_t | |
2056 ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data, ngx_int_t rc) | |
2057 { | |
2058 ngx_chain_t *out; | |
2059 | |
2060 if (rc == NGX_ERROR || r->connection->error || r->request_output) { | |
2061 return rc; | |
2062 } | |
2063 | |
2064 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2065 "ssi stub output: \"%V?%V\"", &r->uri, &r->args); | |
2066 | |
2067 out = data; | |
2068 | |
2069 if (!r->header_sent) { | |
2070 if (ngx_http_set_content_type(r) == NGX_ERROR) { | |
2071 return NGX_ERROR; | |
2072 } | |
2073 | |
2074 if (ngx_http_send_header(r) == NGX_ERROR) { | |
2075 return NGX_ERROR; | |
2076 } | |
2077 } | |
2078 | |
2079 return ngx_http_output_filter(r, out); | |
2080 } | |
2081 | |
2082 | |
2083 static ngx_int_t | |
2084 ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data, ngx_int_t rc) | |
2085 { | |
2086 ngx_str_t *value = data; | |
2087 | |
2088 if (r->upstream) { | |
2089 value->len = r->upstream->buffer.last - r->upstream->buffer.pos; | |
2090 value->data = r->upstream->buffer.pos; | |
1977 } | 2091 } |
1978 | 2092 |
1979 return rc; | 2093 return rc; |
1980 } | 2094 } |
1981 | 2095 |
2088 | 2202 |
2089 static ngx_int_t | 2203 static ngx_int_t |
2090 ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 2204 ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
2091 ngx_str_t **params) | 2205 ngx_str_t **params) |
2092 { | 2206 { |
2093 ngx_int_t key; | 2207 ngx_int_t key, rc; |
2094 ngx_uint_t i; | 2208 ngx_uint_t i; |
2095 ngx_str_t *name, *value, *vv; | 2209 ngx_str_t *name, *value, *vv; |
2096 ngx_http_ssi_var_t *var; | 2210 ngx_http_ssi_var_t *var; |
2097 ngx_http_ssi_ctx_t *mctx; | 2211 ngx_http_ssi_ctx_t *mctx; |
2098 | 2212 |
2099 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); | 2213 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module); |
2100 | 2214 |
2101 if (mctx->variables == NULL) { | 2215 if (mctx->variables == NULL) { |
2102 mctx->variables = ngx_array_create(r->pool, 4, | 2216 mctx->variables = ngx_list_create(r->pool, 4, |
2103 sizeof(ngx_http_ssi_var_t)); | 2217 sizeof(ngx_http_ssi_var_t)); |
2104 if (mctx->variables == NULL) { | 2218 if (mctx->variables == NULL) { |
2105 return NGX_HTTP_SSI_ERROR; | 2219 return NGX_ERROR; |
2106 } | 2220 } |
2107 } | 2221 } |
2108 | 2222 |
2109 name = params[NGX_HTTP_SSI_SET_VAR]; | 2223 name = params[NGX_HTTP_SSI_SET_VAR]; |
2110 value = params[NGX_HTTP_SSI_SET_VALUE]; | 2224 value = params[NGX_HTTP_SSI_SET_VALUE]; |
2111 | 2225 |
2112 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2226 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2113 "ssi set \"%V\" \"%V\"", name, value); | 2227 "ssi set \"%V\" \"%V\"", name, value); |
2114 | 2228 |
2115 if (ngx_http_ssi_evaluate_string(r, ctx, value, 0) != NGX_OK) { | 2229 rc = ngx_http_ssi_evaluate_string(r, ctx, value, 0); |
2116 return NGX_HTTP_SSI_ERROR; | 2230 |
2231 if (rc != NGX_OK) { | |
2232 return rc; | |
2117 } | 2233 } |
2118 | 2234 |
2119 key = 0; | 2235 key = 0; |
2120 | 2236 |
2121 for (i = 0; i < name->len; i++) { | 2237 for (i = 0; i < name->len; i++) { |
2128 if (vv) { | 2244 if (vv) { |
2129 *vv = *value; | 2245 *vv = *value; |
2130 return NGX_OK; | 2246 return NGX_OK; |
2131 } | 2247 } |
2132 | 2248 |
2133 var = ngx_array_push(mctx->variables); | 2249 var = ngx_list_push(mctx->variables); |
2134 if (var == NULL) { | 2250 if (var == NULL) { |
2135 return NGX_HTTP_SSI_ERROR; | 2251 return NGX_ERROR; |
2136 } | 2252 } |
2137 | 2253 |
2138 var->name = *name; | 2254 var->name = *name; |
2139 var->key = key; | 2255 var->key = key; |
2140 var->value = *value; | 2256 var->value = *value; |
2207 flags = (p == last) ? NGX_HTTP_SSI_EXPR_TEST : 0; | 2323 flags = (p == last) ? NGX_HTTP_SSI_EXPR_TEST : 0; |
2208 | 2324 |
2209 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2325 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2210 "left: \"%V\"", &left); | 2326 "left: \"%V\"", &left); |
2211 | 2327 |
2212 if (ngx_http_ssi_evaluate_string(r, ctx, &left, flags) != NGX_OK) { | 2328 rc = ngx_http_ssi_evaluate_string(r, ctx, &left, flags); |
2213 return NGX_HTTP_SSI_ERROR; | 2329 |
2330 if (rc != NGX_OK) { | |
2331 return rc; | |
2214 } | 2332 } |
2215 | 2333 |
2216 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2334 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2217 "evaluted left: \"%V\"", &left); | 2335 "evaluted left: \"%V\"", &left); |
2218 | 2336 |
2269 right.data = p; | 2387 right.data = p; |
2270 | 2388 |
2271 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2389 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2272 "right: \"%V\"", &right); | 2390 "right: \"%V\"", &right); |
2273 | 2391 |
2274 if (ngx_http_ssi_evaluate_string(r, ctx, &right, flags) != NGX_OK) { | 2392 rc = ngx_http_ssi_evaluate_string(r, ctx, &right, flags); |
2275 return NGX_HTTP_SSI_ERROR; | 2393 |
2394 if (rc != NGX_OK) { | |
2395 return rc; | |
2276 } | 2396 } |
2277 | 2397 |
2278 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2398 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2279 "evaluted right: \"%V\"", &right); | 2399 "evaluted right: \"%V\"", &right); |
2280 | 2400 |