Mercurial > hg > nginx
comparison src/http/modules/ngx_http_ssi_filter_module.c @ 1545:2d8fab47dd89
SSI echo encoding
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 27 Sep 2007 09:37:09 +0000 |
parents | e30e9de091b7 |
children | 4c43e25d11ea |
comparison
equal
deleted
inserted
replaced
1544:998c44b19e30 | 1545:2d8fab47dd89 |
---|---|
210 #define NGX_HTTP_SSI_INCLUDE_SET 3 | 210 #define NGX_HTTP_SSI_INCLUDE_SET 3 |
211 #define NGX_HTTP_SSI_INCLUDE_STUB 4 | 211 #define NGX_HTTP_SSI_INCLUDE_STUB 4 |
212 | 212 |
213 #define NGX_HTTP_SSI_ECHO_VAR 0 | 213 #define NGX_HTTP_SSI_ECHO_VAR 0 |
214 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 | 214 #define NGX_HTTP_SSI_ECHO_DEFAULT 1 |
215 #define NGX_HTTP_SSI_ECHO_ENCODING 2 | |
215 | 216 |
216 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 | 217 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0 |
217 #define NGX_HTTP_SSI_CONFIG_TIMEFMT 1 | 218 #define NGX_HTTP_SSI_CONFIG_TIMEFMT 1 |
218 | 219 |
219 #define NGX_HTTP_SSI_SET_VAR 0 | 220 #define NGX_HTTP_SSI_SET_VAR 0 |
235 | 236 |
236 | 237 |
237 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { | 238 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = { |
238 { ngx_string("var"), NGX_HTTP_SSI_ECHO_VAR, 1, 0 }, | 239 { ngx_string("var"), NGX_HTTP_SSI_ECHO_VAR, 1, 0 }, |
239 { ngx_string("default"), NGX_HTTP_SSI_ECHO_DEFAULT, 0, 0 }, | 240 { ngx_string("default"), NGX_HTTP_SSI_ECHO_DEFAULT, 0, 0 }, |
241 { ngx_string("encoding"), NGX_HTTP_SSI_ECHO_ENCODING, 0, 0 }, | |
240 { ngx_null_string, 0, 0, 0 } | 242 { ngx_null_string, 0, 0, 0 } |
241 }; | 243 }; |
242 | 244 |
243 | 245 |
244 static ngx_http_ssi_param_t ngx_http_ssi_config_params[] = { | 246 static ngx_http_ssi_param_t ngx_http_ssi_config_params[] = { |
353 | 355 |
354 | 356 |
355 ctx->value_len = slcf->value_len; | 357 ctx->value_len = slcf->value_len; |
356 ctx->last_out = &ctx->out; | 358 ctx->last_out = &ctx->out; |
357 | 359 |
360 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING; | |
358 ctx->output = 1; | 361 ctx->output = 1; |
359 | 362 |
360 ctx->params.elts = ctx->params_array; | 363 ctx->params.elts = ctx->params_array; |
361 ctx->params.size = sizeof(ngx_table_elt_t); | 364 ctx->params.size = sizeof(ngx_table_elt_t); |
362 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; | 365 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; |
2117 | 2120 |
2118 static ngx_int_t | 2121 static ngx_int_t |
2119 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, | 2122 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx, |
2120 ngx_str_t **params) | 2123 ngx_str_t **params) |
2121 { | 2124 { |
2125 u_char *p; | |
2126 uintptr_t len; | |
2122 ngx_int_t key; | 2127 ngx_int_t key; |
2123 ngx_uint_t i; | 2128 ngx_uint_t i; |
2124 ngx_buf_t *b; | 2129 ngx_buf_t *b; |
2125 ngx_str_t *var, *value, text; | 2130 ngx_str_t *var, *value, *enc, text; |
2126 ngx_chain_t *cl; | 2131 ngx_chain_t *cl; |
2127 ngx_http_variable_value_t *vv; | 2132 ngx_http_variable_value_t *vv; |
2128 | 2133 |
2129 var = params[NGX_HTTP_SSI_ECHO_VAR]; | 2134 var = params[NGX_HTTP_SSI_ECHO_VAR]; |
2130 | 2135 |
2166 | 2171 |
2167 } else { | 2172 } else { |
2168 if (value->len == 0) { | 2173 if (value->len == 0) { |
2169 return NGX_OK; | 2174 return NGX_OK; |
2170 } | 2175 } |
2176 } | |
2177 | |
2178 enc = params[NGX_HTTP_SSI_ECHO_ENCODING]; | |
2179 | |
2180 if (enc) { | |
2181 if (enc->len == 4 && ngx_strncmp(enc->data, "none", 4) == 0) { | |
2182 | |
2183 ctx->encoding = NGX_HTTP_SSI_NO_ENCODING; | |
2184 | |
2185 } else if (enc->len == 3 && ngx_strncmp(enc->data, "url", 3) == 0) { | |
2186 | |
2187 ctx->encoding = NGX_HTTP_SSI_URL_ENCODING; | |
2188 | |
2189 } else if (enc->len == 6 && ngx_strncmp(enc->data, "entity", 6) == 0) { | |
2190 | |
2191 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING; | |
2192 | |
2193 } else { | |
2194 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
2195 "unknown encoding \"%V\" in the \"echo\" command", | |
2196 enc); | |
2197 } | |
2198 } | |
2199 | |
2200 switch (ctx->encoding) { | |
2201 | |
2202 case NGX_HTTP_SSI_NO_ENCODING: | |
2203 break; | |
2204 | |
2205 case NGX_HTTP_SSI_URL_ENCODING: | |
2206 len = 2 * ngx_escape_uri(NULL, value->data, value->len, | |
2207 NGX_ESCAPE_HTML); | |
2208 | |
2209 if (len) { | |
2210 p = ngx_palloc(r->pool, value->len + len); | |
2211 if (p == NULL) { | |
2212 return NGX_HTTP_SSI_ERROR; | |
2213 } | |
2214 | |
2215 (void) ngx_escape_uri(p, value->data, value->len, NGX_ESCAPE_HTML); | |
2216 | |
2217 value->len += len; | |
2218 value->data = p; | |
2219 } | |
2220 | |
2221 break; | |
2222 | |
2223 case NGX_HTTP_SSI_ENTITY_ENCODING: | |
2224 len = ngx_escape_html(NULL, value->data, value->len); | |
2225 | |
2226 if (len) { | |
2227 p = ngx_palloc(r->pool, value->len + len); | |
2228 if (p == NULL) { | |
2229 return NGX_HTTP_SSI_ERROR; | |
2230 } | |
2231 | |
2232 (void) ngx_escape_html(p, value->data, value->len); | |
2233 | |
2234 value->len += len; | |
2235 value->data = p; | |
2236 } | |
2237 | |
2238 break; | |
2171 } | 2239 } |
2172 | 2240 |
2173 b = ngx_calloc_buf(r->pool); | 2241 b = ngx_calloc_buf(r->pool); |
2174 if (b == NULL) { | 2242 if (b == NULL) { |
2175 return NGX_HTTP_SSI_ERROR; | 2243 return NGX_HTTP_SSI_ERROR; |