46
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
660
|
4 * Copyright (C) Nginx, Inc.
|
46
|
5 */
|
|
6
|
|
7
|
|
8 #include <ngx_config.h>
|
|
9 #include <ngx_core.h>
|
|
10 #include <ngx_http.h>
|
|
11
|
102
|
12 #define NGX_HTTP_SSI_ERROR 1
|
|
13
|
|
14 #define NGX_HTTP_SSI_DATE_LEN 2048
|
|
15
|
|
16 #define NGX_HTTP_SSI_ADD_PREFIX 1
|
178
|
17 #define NGX_HTTP_SSI_ADD_ZERO 2
|
58
|
18
|
46
|
19
|
|
20 typedef struct {
|
146
|
21 ngx_flag_t enable;
|
|
22 ngx_flag_t silent_errors;
|
|
23 ngx_flag_t ignore_recycled_buffers;
|
|
24
|
394
|
25 ngx_hash_t types;
|
146
|
26
|
|
27 size_t min_file_chunk;
|
|
28 size_t value_len;
|
394
|
29
|
|
30 ngx_array_t *types_keys;
|
146
|
31 } ngx_http_ssi_loc_conf_t;
|
102
|
32
|
|
33
|
|
34 typedef struct {
|
146
|
35 ngx_str_t name;
|
160
|
36 ngx_uint_t key;
|
146
|
37 ngx_str_t value;
|
|
38 } ngx_http_ssi_var_t;
|
46
|
39
|
|
40
|
216
|
41 typedef struct {
|
|
42 ngx_str_t name;
|
|
43 ngx_chain_t *bufs;
|
|
44 ngx_uint_t count;
|
|
45 } ngx_http_ssi_block_t;
|
|
46
|
|
47
|
46
|
48 typedef enum {
|
|
49 ssi_start_state = 0,
|
|
50 ssi_tag_state,
|
|
51 ssi_comment0_state,
|
|
52 ssi_comment1_state,
|
|
53 ssi_sharp_state,
|
|
54 ssi_precommand_state,
|
|
55 ssi_command_state,
|
|
56 ssi_preparam_state,
|
|
57 ssi_param_state,
|
|
58 ssi_preequal_state,
|
|
59 ssi_prevalue_state,
|
|
60 ssi_double_quoted_value_state,
|
|
61 ssi_quoted_value_state,
|
|
62 ssi_quoted_symbol_state,
|
|
63 ssi_postparam_state,
|
|
64 ssi_comment_end0_state,
|
|
65 ssi_comment_end1_state,
|
|
66 ssi_error_state,
|
|
67 ssi_error_end0_state,
|
|
68 ssi_error_end1_state
|
|
69 } ngx_http_ssi_state_e;
|
|
70
|
|
71
|
58
|
72 static ngx_int_t ngx_http_ssi_output(ngx_http_request_t *r,
|
|
73 ngx_http_ssi_ctx_t *ctx);
|
586
|
74 static void ngx_http_ssi_buffered(ngx_http_request_t *r,
|
|
75 ngx_http_ssi_ctx_t *ctx);
|
46
|
76 static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r,
|
|
77 ngx_http_ssi_ctx_t *ctx);
|
102
|
78 static ngx_str_t *ngx_http_ssi_get_variable(ngx_http_request_t *r,
|
160
|
79 ngx_str_t *name, ngx_uint_t key);
|
102
|
80 static ngx_int_t ngx_http_ssi_evaluate_string(ngx_http_request_t *r,
|
|
81 ngx_http_ssi_ctx_t *ctx, ngx_str_t *text, ngx_uint_t flags);
|
656
|
82 static ngx_int_t ngx_http_ssi_regex_match(ngx_http_request_t *r,
|
|
83 ngx_str_t *pattern, ngx_str_t *str);
|
102
|
84
|
|
85 static ngx_int_t ngx_http_ssi_include(ngx_http_request_t *r,
|
|
86 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
248
|
87 static ngx_int_t ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data,
|
|
88 ngx_int_t rc);
|
|
89 static ngx_int_t ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data,
|
|
90 ngx_int_t rc);
|
46
|
91 static ngx_int_t ngx_http_ssi_echo(ngx_http_request_t *r,
|
|
92 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
58
|
93 static ngx_int_t ngx_http_ssi_config(ngx_http_request_t *r,
|
|
94 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
102
|
95 static ngx_int_t ngx_http_ssi_set(ngx_http_request_t *r,
|
58
|
96 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
|
97 static ngx_int_t ngx_http_ssi_if(ngx_http_request_t *r,
|
|
98 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
|
99 static ngx_int_t ngx_http_ssi_else(ngx_http_request_t *r,
|
|
100 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
|
101 static ngx_int_t ngx_http_ssi_endif(ngx_http_request_t *r,
|
|
102 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
216
|
103 static ngx_int_t ngx_http_ssi_block(ngx_http_request_t *r,
|
|
104 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
|
105 static ngx_int_t ngx_http_ssi_endblock(ngx_http_request_t *r,
|
|
106 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
|
46
|
107
|
122
|
108 static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
|
380
|
109 ngx_http_variable_value_t *v, uintptr_t gmt);
|
58
|
110
|
146
|
111 static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf);
|
|
112 static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf);
|
|
113 static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf);
|
296
|
114 static void *ngx_http_ssi_create_loc_conf(ngx_conf_t *cf);
|
|
115 static char *ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf,
|
46
|
116 void *parent, void *child);
|
230
|
117 static ngx_int_t ngx_http_ssi_filter_init(ngx_conf_t *cf);
|
46
|
118
|
|
119
|
|
120 static ngx_command_t ngx_http_ssi_filter_commands[] = {
|
|
121
|
|
122 { ngx_string("ssi"),
|
230
|
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
|
124 |NGX_CONF_FLAG,
|
46
|
125 ngx_conf_set_flag_slot,
|
|
126 NGX_HTTP_LOC_CONF_OFFSET,
|
146
|
127 offsetof(ngx_http_ssi_loc_conf_t, enable),
|
46
|
128 NULL },
|
|
129
|
|
130 { ngx_string("ssi_silent_errors"),
|
|
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
132 ngx_conf_set_flag_slot,
|
|
133 NGX_HTTP_LOC_CONF_OFFSET,
|
146
|
134 offsetof(ngx_http_ssi_loc_conf_t, silent_errors),
|
46
|
135 NULL },
|
|
136
|
58
|
137 { ngx_string("ssi_ignore_recycled_buffers"),
|
|
138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
139 ngx_conf_set_flag_slot,
|
|
140 NGX_HTTP_LOC_CONF_OFFSET,
|
146
|
141 offsetof(ngx_http_ssi_loc_conf_t, ignore_recycled_buffers),
|
58
|
142 NULL },
|
|
143
|
46
|
144 { ngx_string("ssi_min_file_chunk"),
|
648
|
145 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
46
|
146 ngx_conf_set_size_slot,
|
|
147 NGX_HTTP_LOC_CONF_OFFSET,
|
146
|
148 offsetof(ngx_http_ssi_loc_conf_t, min_file_chunk),
|
46
|
149 NULL },
|
|
150
|
138
|
151 { ngx_string("ssi_value_length"),
|
648
|
152 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
138
|
153 ngx_conf_set_size_slot,
|
|
154 NGX_HTTP_LOC_CONF_OFFSET,
|
146
|
155 offsetof(ngx_http_ssi_loc_conf_t, value_len),
|
138
|
156 NULL },
|
|
157
|
76
|
158 { ngx_string("ssi_types"),
|
|
159 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
394
|
160 ngx_http_types_slot,
|
76
|
161 NGX_HTTP_LOC_CONF_OFFSET,
|
394
|
162 offsetof(ngx_http_ssi_loc_conf_t, types_keys),
|
|
163 &ngx_http_html_default_types[0] },
|
76
|
164
|
46
|
165 ngx_null_command
|
|
166 };
|
|
167
|
|
168
|
126
|
169
|
46
|
170 static ngx_http_module_t ngx_http_ssi_filter_module_ctx = {
|
146
|
171 ngx_http_ssi_preconfiguration, /* preconfiguration */
|
230
|
172 ngx_http_ssi_filter_init, /* postconfiguration */
|
46
|
173
|
146
|
174 ngx_http_ssi_create_main_conf, /* create main configuration */
|
|
175 ngx_http_ssi_init_main_conf, /* init main configuration */
|
46
|
176
|
|
177 NULL, /* create server configuration */
|
|
178 NULL, /* merge server configuration */
|
|
179
|
296
|
180 ngx_http_ssi_create_loc_conf, /* create location configuration */
|
|
181 ngx_http_ssi_merge_loc_conf /* merge location configuration */
|
126
|
182 };
|
46
|
183
|
|
184
|
|
185 ngx_module_t ngx_http_ssi_filter_module = {
|
58
|
186 NGX_MODULE_V1,
|
46
|
187 &ngx_http_ssi_filter_module_ctx, /* module context */
|
|
188 ngx_http_ssi_filter_commands, /* module directives */
|
|
189 NGX_HTTP_MODULE, /* module type */
|
90
|
190 NULL, /* init master */
|
230
|
191 NULL, /* init module */
|
90
|
192 NULL, /* init process */
|
|
193 NULL, /* init thread */
|
|
194 NULL, /* exit thread */
|
|
195 NULL, /* exit process */
|
|
196 NULL, /* exit master */
|
|
197 NGX_MODULE_V1_PADDING
|
46
|
198 };
|
|
199
|
|
200
|
118
|
201 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
|
202 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
|
46
|
203
|
|
204
|
|
205 static u_char ngx_http_ssi_string[] = "<!--";
|
|
206
|
|
207 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)");
|
248
|
208 static ngx_str_t ngx_http_ssi_null_string = ngx_null_string;
|
|
209
|
46
|
210
|
102
|
211 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0
|
|
212 #define NGX_HTTP_SSI_INCLUDE_FILE 1
|
194
|
213 #define NGX_HTTP_SSI_INCLUDE_WAIT 2
|
248
|
214 #define NGX_HTTP_SSI_INCLUDE_SET 3
|
|
215 #define NGX_HTTP_SSI_INCLUDE_STUB 4
|
46
|
216
|
58
|
217 #define NGX_HTTP_SSI_ECHO_VAR 0
|
|
218 #define NGX_HTTP_SSI_ECHO_DEFAULT 1
|
340
|
219 #define NGX_HTTP_SSI_ECHO_ENCODING 2
|
58
|
220
|
96
|
221 #define NGX_HTTP_SSI_CONFIG_ERRMSG 0
|
|
222 #define NGX_HTTP_SSI_CONFIG_TIMEFMT 1
|
58
|
223
|
102
|
224 #define NGX_HTTP_SSI_SET_VAR 0
|
|
225 #define NGX_HTTP_SSI_SET_VALUE 1
|
58
|
226
|
|
227 #define NGX_HTTP_SSI_IF_EXPR 0
|
|
228
|
216
|
229 #define NGX_HTTP_SSI_BLOCK_NAME 0
|
|
230
|
46
|
231
|
102
|
232 static ngx_http_ssi_param_t ngx_http_ssi_include_params[] = {
|
146
|
233 { ngx_string("virtual"), NGX_HTTP_SSI_INCLUDE_VIRTUAL, 0, 0 },
|
|
234 { ngx_string("file"), NGX_HTTP_SSI_INCLUDE_FILE, 0, 0 },
|
194
|
235 { ngx_string("wait"), NGX_HTTP_SSI_INCLUDE_WAIT, 0, 0 },
|
248
|
236 { ngx_string("set"), NGX_HTTP_SSI_INCLUDE_SET, 0, 0 },
|
216
|
237 { ngx_string("stub"), NGX_HTTP_SSI_INCLUDE_STUB, 0, 0 },
|
146
|
238 { ngx_null_string, 0, 0, 0 }
|
102
|
239 };
|
|
240
|
|
241
|
46
|
242 static ngx_http_ssi_param_t ngx_http_ssi_echo_params[] = {
|
146
|
243 { ngx_string("var"), NGX_HTTP_SSI_ECHO_VAR, 1, 0 },
|
|
244 { ngx_string("default"), NGX_HTTP_SSI_ECHO_DEFAULT, 0, 0 },
|
340
|
245 { ngx_string("encoding"), NGX_HTTP_SSI_ECHO_ENCODING, 0, 0 },
|
146
|
246 { ngx_null_string, 0, 0, 0 }
|
46
|
247 };
|
|
248
|
58
|
249
|
|
250 static ngx_http_ssi_param_t ngx_http_ssi_config_params[] = {
|
146
|
251 { ngx_string("errmsg"), NGX_HTTP_SSI_CONFIG_ERRMSG, 0, 0 },
|
|
252 { ngx_string("timefmt"), NGX_HTTP_SSI_CONFIG_TIMEFMT, 0, 0 },
|
|
253 { ngx_null_string, 0, 0, 0 }
|
58
|
254 };
|
|
255
|
|
256
|
102
|
257 static ngx_http_ssi_param_t ngx_http_ssi_set_params[] = {
|
146
|
258 { ngx_string("var"), NGX_HTTP_SSI_SET_VAR, 1, 0 },
|
|
259 { ngx_string("value"), NGX_HTTP_SSI_SET_VALUE, 1, 0 },
|
|
260 { ngx_null_string, 0, 0, 0 }
|
102
|
261 };
|
|
262
|
|
263
|
58
|
264 static ngx_http_ssi_param_t ngx_http_ssi_if_params[] = {
|
146
|
265 { ngx_string("expr"), NGX_HTTP_SSI_IF_EXPR, 1, 0 },
|
|
266 { ngx_null_string, 0, 0, 0 }
|
58
|
267 };
|
|
268
|
|
269
|
216
|
270 static ngx_http_ssi_param_t ngx_http_ssi_block_params[] = {
|
|
271 { ngx_string("name"), NGX_HTTP_SSI_BLOCK_NAME, 1, 0 },
|
|
272 { ngx_null_string, 0, 0, 0 }
|
|
273 };
|
|
274
|
|
275
|
58
|
276 static ngx_http_ssi_param_t ngx_http_ssi_no_params[] = {
|
146
|
277 { ngx_null_string, 0, 0, 0 }
|
58
|
278 };
|
|
279
|
46
|
280
|
|
281 static ngx_http_ssi_command_t ngx_http_ssi_commands[] = {
|
102
|
282 { ngx_string("include"), ngx_http_ssi_include,
|
216
|
283 ngx_http_ssi_include_params, 0, 0, 1 },
|
|
284 { ngx_string("echo"), ngx_http_ssi_echo,
|
|
285 ngx_http_ssi_echo_params, 0, 0, 0 },
|
58
|
286 { ngx_string("config"), ngx_http_ssi_config,
|
216
|
287 ngx_http_ssi_config_params, 0, 0, 0 },
|
|
288 { ngx_string("set"), ngx_http_ssi_set, ngx_http_ssi_set_params, 0, 0, 0 },
|
|
289
|
|
290 { ngx_string("if"), ngx_http_ssi_if, ngx_http_ssi_if_params, 0, 0, 0 },
|
178
|
291 { ngx_string("elif"), ngx_http_ssi_if, ngx_http_ssi_if_params,
|
216
|
292 NGX_HTTP_SSI_COND_IF, 0, 0 },
|
178
|
293 { ngx_string("else"), ngx_http_ssi_else, ngx_http_ssi_no_params,
|
216
|
294 NGX_HTTP_SSI_COND_IF, 0, 0 },
|
178
|
295 { ngx_string("endif"), ngx_http_ssi_endif, ngx_http_ssi_no_params,
|
216
|
296 NGX_HTTP_SSI_COND_ELSE, 0, 0 },
|
|
297
|
|
298 { ngx_string("block"), ngx_http_ssi_block,
|
|
299 ngx_http_ssi_block_params, 0, 0, 0 },
|
|
300 { ngx_string("endblock"), ngx_http_ssi_endblock,
|
|
301 ngx_http_ssi_no_params, 0, 1, 0 },
|
|
302
|
|
303 { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
46
|
304 };
|
|
305
|
|
306
|
58
|
307 static ngx_http_variable_t ngx_http_ssi_vars[] = {
|
|
308
|
186
|
309 { ngx_string("date_local"), NULL, ngx_http_ssi_date_gmt_local_variable, 0,
|
340
|
310 NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
58
|
311
|
186
|
312 { ngx_string("date_gmt"), NULL, ngx_http_ssi_date_gmt_local_variable, 1,
|
340
|
313 NGX_HTTP_VAR_NOCACHEABLE, 0 },
|
58
|
314
|
186
|
315 { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
58
|
316 };
|
|
317
|
|
318
|
|
319
|
46
|
320 static ngx_int_t
|
|
321 ngx_http_ssi_header_filter(ngx_http_request_t *r)
|
|
322 {
|
146
|
323 ngx_http_ssi_ctx_t *ctx;
|
|
324 ngx_http_ssi_loc_conf_t *slcf;
|
|
325
|
|
326 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
|
|
327
|
|
328 if (!slcf->enable
|
394
|
329 || r->headers_out.content_length_n == 0
|
|
330 || ngx_http_test_content_type(r, &slcf->types) == NULL)
|
46
|
331 {
|
|
332 return ngx_http_next_header_filter(r);
|
|
333 }
|
|
334
|
48
|
335 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
|
|
336 if (ctx == NULL) {
|
46
|
337 return NGX_ERROR;
|
|
338 }
|
|
339
|
|
340 ngx_http_set_ctx(r, ctx, ngx_http_ssi_filter_module);
|
|
341
|
|
342
|
146
|
343 ctx->value_len = slcf->value_len;
|
46
|
344 ctx->last_out = &ctx->out;
|
|
345
|
340
|
346 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING;
|
58
|
347 ctx->output = 1;
|
|
348
|
46
|
349 ctx->params.elts = ctx->params_array;
|
|
350 ctx->params.size = sizeof(ngx_table_elt_t);
|
|
351 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N;
|
|
352 ctx->params.pool = r->pool;
|
|
353
|
570
|
354 ngx_str_set(&ctx->timefmt, "%A, %d-%b-%Y %H:%M:%S %Z");
|
|
355 ngx_str_set(&ctx->errmsg,
|
|
356 "[an error occurred while processing the directive]");
|
96
|
357
|
46
|
358 r->filter_need_in_memory = 1;
|
|
359
|
146
|
360 if (r == r->main) {
|
126
|
361 ngx_http_clear_content_length(r);
|
|
362 ngx_http_clear_last_modified(r);
|
510
|
363 ngx_http_clear_accept_ranges(r);
|
680
|
364 ngx_http_clear_etag(r);
|
58
|
365 }
|
|
366
|
46
|
367 return ngx_http_next_header_filter(r);
|
|
368 }
|
|
369
|
|
370
|
|
371 static ngx_int_t
|
|
372 ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
373 {
|
216
|
374 size_t len;
|
146
|
375 ngx_int_t rc;
|
|
376 ngx_buf_t *b;
|
|
377 ngx_uint_t i, index;
|
216
|
378 ngx_chain_t *cl, **ll;
|
146
|
379 ngx_table_elt_t *param;
|
216
|
380 ngx_http_ssi_ctx_t *ctx, *mctx;
|
|
381 ngx_http_ssi_block_t *bl;
|
146
|
382 ngx_http_ssi_param_t *prm;
|
|
383 ngx_http_ssi_command_t *cmd;
|
|
384 ngx_http_ssi_loc_conf_t *slcf;
|
|
385 ngx_http_ssi_main_conf_t *smcf;
|
148
|
386 ngx_str_t *params[NGX_HTTP_SSI_MAX_PARAMS + 1];
|
46
|
387
|
|
388 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
|
|
389
|
194
|
390 if (ctx == NULL
|
|
391 || (in == NULL
|
|
392 && ctx->buf == NULL
|
|
393 && ctx->in == NULL
|
|
394 && ctx->busy == NULL))
|
|
395 {
|
46
|
396 return ngx_http_next_body_filter(r, in);
|
|
397 }
|
|
398
|
|
399 /* add the incoming chain to the chain ctx->in */
|
|
400
|
|
401 if (in) {
|
454
|
402 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) {
|
46
|
403 return NGX_ERROR;
|
|
404 }
|
|
405 }
|
|
406
|
426
|
407 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
408 "http ssi filter \"%V?%V\"", &r->uri, &r->args);
|
|
409
|
194
|
410 if (ctx->wait) {
|
426
|
411
|
|
412 if (r != r->connection->data) {
|
|
413 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
414 "http ssi filter wait \"%V?%V\" non-active",
|
|
415 &ctx->wait->uri, &ctx->wait->args);
|
|
416
|
194
|
417 return NGX_AGAIN;
|
|
418 }
|
|
419
|
426
|
420 if (ctx->wait->done) {
|
|
421 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
422 "http ssi filter wait \"%V?%V\" done",
|
|
423 &ctx->wait->uri, &ctx->wait->args);
|
|
424
|
244
|
425 ctx->wait = NULL;
|
426
|
426
|
|
427 } else {
|
|
428 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
429 "http ssi filter wait \"%V?%V\"",
|
|
430 &ctx->wait->uri, &ctx->wait->args);
|
|
431
|
|
432 return ngx_http_next_body_filter(r, NULL);
|
244
|
433 }
|
194
|
434 }
|
|
435
|
146
|
436 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
|
46
|
437
|
48
|
438 while (ctx->in || ctx->buf) {
|
46
|
439
|
582
|
440 if (ctx->buf == NULL) {
|
48
|
441 ctx->buf = ctx->in->buf;
|
|
442 ctx->in = ctx->in->next;
|
|
443 ctx->pos = ctx->buf->pos;
|
|
444 }
|
46
|
445
|
|
446 if (ctx->state == ssi_start_state) {
|
|
447 ctx->copy_start = ctx->pos;
|
|
448 ctx->copy_end = ctx->pos;
|
|
449 }
|
|
450
|
48
|
451 b = NULL;
|
|
452
|
46
|
453 while (ctx->pos < ctx->buf->last) {
|
|
454
|
|
455 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
456 "saved: %d state: %d", ctx->saved, ctx->state);
|
|
457
|
|
458 rc = ngx_http_ssi_parse(r, ctx);
|
|
459
|
|
460 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
461 "parse: %d, looked: %d %p-%p",
|
|
462 rc, ctx->looked, ctx->copy_start, ctx->copy_end);
|
|
463
|
|
464 if (rc == NGX_ERROR) {
|
|
465 return rc;
|
|
466 }
|
|
467
|
|
468 if (ctx->copy_start != ctx->copy_end) {
|
|
469
|
58
|
470 if (ctx->output) {
|
|
471
|
|
472 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
473 "saved: %d", ctx->saved);
|
|
474
|
|
475 if (ctx->saved) {
|
|
476
|
|
477 if (ctx->free) {
|
|
478 cl = ctx->free;
|
|
479 ctx->free = ctx->free->next;
|
|
480 b = cl->buf;
|
|
481 ngx_memzero(b, sizeof(ngx_buf_t));
|
46
|
482
|
58
|
483 } else {
|
|
484 b = ngx_calloc_buf(r->pool);
|
|
485 if (b == NULL) {
|
|
486 return NGX_ERROR;
|
|
487 }
|
|
488
|
|
489 cl = ngx_alloc_chain_link(r->pool);
|
|
490 if (cl == NULL) {
|
|
491 return NGX_ERROR;
|
|
492 }
|
|
493
|
|
494 cl->buf = b;
|
|
495 }
|
|
496
|
|
497 b->memory = 1;
|
|
498 b->pos = ngx_http_ssi_string;
|
|
499 b->last = ngx_http_ssi_string + ctx->saved;
|
|
500
|
|
501 *ctx->last_out = cl;
|
|
502 ctx->last_out = &cl->next;
|
|
503
|
|
504 ctx->saved = 0;
|
|
505 }
|
48
|
506
|
|
507 if (ctx->free) {
|
|
508 cl = ctx->free;
|
|
509 ctx->free = ctx->free->next;
|
|
510 b = cl->buf;
|
|
511
|
|
512 } else {
|
58
|
513 b = ngx_alloc_buf(r->pool);
|
48
|
514 if (b == NULL) {
|
|
515 return NGX_ERROR;
|
|
516 }
|
|
517
|
|
518 cl = ngx_alloc_chain_link(r->pool);
|
|
519 if (cl == NULL) {
|
|
520 return NGX_ERROR;
|
|
521 }
|
|
522
|
|
523 cl->buf = b;
|
46
|
524 }
|
|
525
|
58
|
526 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
|
|
527
|
62
|
528 b->pos = ctx->copy_start;
|
|
529 b->last = ctx->copy_end;
|
|
530 b->shadow = NULL;
|
58
|
531 b->last_buf = 0;
|
|
532 b->recycled = 0;
|
46
|
533
|
58
|
534 if (b->in_file) {
|
146
|
535 if (slcf->min_file_chunk < (size_t) (b->last - b->pos))
|
58
|
536 {
|
386
|
537 b->file_last = b->file_pos
|
|
538 + (b->last - ctx->buf->pos);
|
|
539 b->file_pos += b->pos - ctx->buf->pos;
|
58
|
540
|
|
541 } else {
|
|
542 b->in_file = 0;
|
|
543 }
|
|
544 }
|
|
545
|
|
546 cl->next = NULL;
|
46
|
547 *ctx->last_out = cl;
|
|
548 ctx->last_out = &cl->next;
|
|
549
|
58
|
550 } else {
|
216
|
551 if (ctx->block
|
|
552 && ctx->saved + (ctx->copy_end - ctx->copy_start))
|
|
553 {
|
|
554 b = ngx_create_temp_buf(r->pool,
|
|
555 ctx->saved + (ctx->copy_end - ctx->copy_start));
|
|
556
|
|
557 if (b == NULL) {
|
|
558 return NGX_ERROR;
|
|
559 }
|
|
560
|
|
561 if (ctx->saved) {
|
|
562 b->last = ngx_cpymem(b->pos, ngx_http_ssi_string,
|
|
563 ctx->saved);
|
|
564 }
|
|
565
|
|
566 b->last = ngx_cpymem(b->last, ctx->copy_start,
|
|
567 ctx->copy_end - ctx->copy_start);
|
|
568
|
|
569 cl = ngx_alloc_chain_link(r->pool);
|
|
570 if (cl == NULL) {
|
|
571 return NGX_ERROR;
|
|
572 }
|
|
573
|
|
574 cl->buf = b;
|
|
575 cl->next = NULL;
|
|
576
|
|
577 b = NULL;
|
|
578
|
|
579 mctx = ngx_http_get_module_ctx(r->main,
|
|
580 ngx_http_ssi_filter_module);
|
|
581 bl = mctx->blocks->elts;
|
|
582 for (ll = &bl[mctx->blocks->nelts - 1].bufs;
|
|
583 *ll;
|
|
584 ll = &(*ll)->next)
|
|
585 {
|
|
586 /* void */
|
|
587 }
|
|
588
|
|
589 *ll = cl;
|
|
590 }
|
|
591
|
46
|
592 ctx->saved = 0;
|
|
593 }
|
|
594 }
|
|
595
|
|
596 if (ctx->state == ssi_start_state) {
|
|
597 ctx->copy_start = ctx->pos;
|
|
598 ctx->copy_end = ctx->pos;
|
|
599
|
|
600 } else {
|
|
601 ctx->copy_start = NULL;
|
|
602 ctx->copy_end = NULL;
|
|
603 }
|
|
604
|
|
605 if (rc == NGX_AGAIN) {
|
|
606 continue;
|
|
607 }
|
|
608
|
|
609
|
122
|
610 b = NULL;
|
|
611
|
46
|
612 if (rc == NGX_OK) {
|
|
613
|
146
|
614 smcf = ngx_http_get_module_main_conf(r,
|
|
615 ngx_http_ssi_filter_module);
|
|
616
|
|
617 cmd = ngx_hash_find(&smcf->hash, ctx->key, ctx->command.data,
|
|
618 ctx->command.len);
|
|
619
|
|
620 if (cmd == NULL) {
|
|
621 if (ctx->output) {
|
|
622 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
623 "invalid SSI command: \"%V\"",
|
|
624 &ctx->command);
|
|
625 goto ssi_error;
|
46
|
626 }
|
|
627
|
146
|
628 continue;
|
46
|
629 }
|
|
630
|
216
|
631 if (!ctx->output && !cmd->block) {
|
|
632
|
|
633 if (ctx->block) {
|
|
634
|
|
635 /* reconstruct the SSI command text */
|
|
636
|
|
637 len = 5 + ctx->command.len + 4;
|
|
638
|
|
639 param = ctx->params.elts;
|
|
640 for (i = 0; i < ctx->params.nelts; i++) {
|
|
641 len += 1 + param[i].key.len + 2
|
|
642 + param[i].value.len + 1;
|
|
643 }
|
|
644
|
|
645 b = ngx_create_temp_buf(r->pool, len);
|
|
646
|
|
647 if (b == NULL) {
|
|
648 return NGX_ERROR;
|
|
649 }
|
|
650
|
|
651 cl = ngx_alloc_chain_link(r->pool);
|
|
652 if (cl == NULL) {
|
|
653 return NGX_ERROR;
|
|
654 }
|
|
655
|
|
656 cl->buf = b;
|
|
657 cl->next = NULL;
|
|
658
|
|
659 *b->last++ = '<';
|
|
660 *b->last++ = '!';
|
|
661 *b->last++ = '-';
|
|
662 *b->last++ = '-';
|
|
663 *b->last++ = '#';
|
|
664
|
|
665 b->last = ngx_cpymem(b->last, ctx->command.data,
|
|
666 ctx->command.len);
|
|
667
|
|
668 for (i = 0; i < ctx->params.nelts; i++) {
|
|
669 *b->last++ = ' ';
|
|
670 b->last = ngx_cpymem(b->last, param[i].key.data,
|
|
671 param[i].key.len);
|
|
672 *b->last++ = '=';
|
|
673 *b->last++ = '"';
|
|
674 b->last = ngx_cpymem(b->last, param[i].value.data,
|
|
675 param[i].value.len);
|
|
676 *b->last++ = '"';
|
|
677 }
|
|
678
|
|
679 *b->last++ = ' ';
|
|
680 *b->last++ = '-';
|
|
681 *b->last++ = '-';
|
|
682 *b->last++ = '>';
|
|
683
|
|
684 mctx = ngx_http_get_module_ctx(r->main,
|
|
685 ngx_http_ssi_filter_module);
|
|
686 bl = mctx->blocks->elts;
|
|
687 for (ll = &bl[mctx->blocks->nelts - 1].bufs;
|
|
688 *ll;
|
|
689 ll = &(*ll)->next)
|
|
690 {
|
|
691 /* void */
|
|
692 }
|
|
693
|
|
694 *ll = cl;
|
|
695
|
|
696 b = NULL;
|
|
697
|
|
698 continue;
|
|
699 }
|
|
700
|
|
701 if (cmd->conditional == 0) {
|
|
702 continue;
|
|
703 }
|
58
|
704 }
|
|
705
|
656
|
706 if (cmd->conditional
|
|
707 && (ctx->conditional == 0
|
|
708 || ctx->conditional > cmd->conditional))
|
|
709 {
|
|
710 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
711 "invalid context of SSI command: \"%V\"",
|
|
712 &ctx->command);
|
|
713 goto ssi_error;
|
|
714 }
|
|
715
|
146
|
716 if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) {
|
|
717 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
670
|
718 "too many SSI command parameters: \"%V\"",
|
146
|
719 &ctx->command);
|
|
720 goto ssi_error;
|
|
721 }
|
|
722
|
46
|
723 ngx_memzero(params,
|
148
|
724 (NGX_HTTP_SSI_MAX_PARAMS + 1) * sizeof(ngx_str_t *));
|
46
|
725
|
|
726 param = ctx->params.elts;
|
|
727
|
|
728 for (i = 0; i < ctx->params.nelts; i++) {
|
|
729
|
|
730 for (prm = cmd->params; prm->name.len; prm++) {
|
|
731
|
|
732 if (param[i].key.len != prm->name.len
|
|
733 || ngx_strncmp(param[i].key.data, prm->name.data,
|
|
734 prm->name.len) != 0)
|
|
735 {
|
|
736 continue;
|
|
737 }
|
|
738
|
146
|
739 if (!prm->multiple) {
|
|
740 if (params[prm->index]) {
|
|
741 ngx_log_error(NGX_LOG_ERR,
|
|
742 r->connection->log, 0,
|
|
743 "duplicate \"%V\" parameter "
|
|
744 "in \"%V\" SSI command",
|
|
745 ¶m[i].key, &ctx->command);
|
|
746
|
|
747 goto ssi_error;
|
|
748 }
|
|
749
|
|
750 params[prm->index] = ¶m[i].value;
|
|
751
|
|
752 break;
|
46
|
753 }
|
|
754
|
146
|
755 for (index = prm->index; params[index]; index++) {
|
|
756 /* void */
|
|
757 }
|
|
758
|
|
759 params[index] = ¶m[i].value;
|
46
|
760
|
|
761 break;
|
|
762 }
|
|
763
|
|
764 if (prm->name.len == 0) {
|
|
765 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
766 "invalid parameter name: \"%V\" "
|
|
767 "in \"%V\" SSI command",
|
|
768 ¶m[i].key, &ctx->command);
|
|
769
|
|
770 goto ssi_error;
|
|
771 }
|
|
772 }
|
|
773
|
|
774 for (prm = cmd->params; prm->name.len; prm++) {
|
|
775 if (prm->mandatory && params[prm->index] == 0) {
|
|
776 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
777 "mandatory \"%V\" parameter is absent "
|
|
778 "in \"%V\" SSI command",
|
|
779 &prm->name, &ctx->command);
|
|
780
|
|
781 goto ssi_error;
|
|
782 }
|
|
783 }
|
|
784
|
426
|
785 if (cmd->flush && ctx->out) {
|
|
786
|
|
787 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
788 "ssi flush");
|
|
789
|
|
790 if (ngx_http_ssi_output(r, ctx) == NGX_ERROR) {
|
58
|
791 return NGX_ERROR;
|
|
792 }
|
|
793 }
|
|
794
|
118
|
795 rc = cmd->handler(r, ctx, params);
|
|
796
|
|
797 if (rc == NGX_OK) {
|
46
|
798 continue;
|
|
799 }
|
132
|
800
|
248
|
801 if (rc == NGX_DONE || rc == NGX_AGAIN || rc == NGX_ERROR) {
|
586
|
802 ngx_http_ssi_buffered(r, ctx);
|
248
|
803 return rc;
|
132
|
804 }
|
46
|
805 }
|
|
806
|
|
807
|
|
808 /* rc == NGX_HTTP_SSI_ERROR */
|
|
809
|
48
|
810 ssi_error:
|
46
|
811
|
146
|
812 if (slcf->silent_errors) {
|
46
|
813 continue;
|
|
814 }
|
|
815
|
48
|
816 if (ctx->free) {
|
|
817 cl = ctx->free;
|
|
818 ctx->free = ctx->free->next;
|
|
819 b = cl->buf;
|
|
820 ngx_memzero(b, sizeof(ngx_buf_t));
|
|
821
|
|
822 } else {
|
|
823 b = ngx_calloc_buf(r->pool);
|
|
824 if (b == NULL) {
|
|
825 return NGX_ERROR;
|
|
826 }
|
|
827
|
|
828 cl = ngx_alloc_chain_link(r->pool);
|
|
829 if (cl == NULL) {
|
|
830 return NGX_ERROR;
|
|
831 }
|
|
832
|
|
833 cl->buf = b;
|
46
|
834 }
|
|
835
|
|
836 b->memory = 1;
|
96
|
837 b->pos = ctx->errmsg.data;
|
|
838 b->last = ctx->errmsg.data + ctx->errmsg.len;
|
46
|
839
|
|
840 cl->next = NULL;
|
|
841 *ctx->last_out = cl;
|
|
842 ctx->last_out = &cl->next;
|
|
843
|
|
844 continue;
|
|
845 }
|
|
846
|
236
|
847 if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) {
|
48
|
848 if (b == NULL) {
|
|
849 if (ctx->free) {
|
|
850 cl = ctx->free;
|
|
851 ctx->free = ctx->free->next;
|
|
852 b = cl->buf;
|
|
853 ngx_memzero(b, sizeof(ngx_buf_t));
|
|
854
|
|
855 } else {
|
|
856 b = ngx_calloc_buf(r->pool);
|
|
857 if (b == NULL) {
|
|
858 return NGX_ERROR;
|
|
859 }
|
46
|
860
|
48
|
861 cl = ngx_alloc_chain_link(r->pool);
|
|
862 if (cl == NULL) {
|
|
863 return NGX_ERROR;
|
|
864 }
|
|
865
|
|
866 cl->buf = b;
|
|
867 }
|
|
868
|
58
|
869 b->sync = 1;
|
|
870
|
48
|
871 cl->next = NULL;
|
|
872 *ctx->last_out = cl;
|
|
873 ctx->last_out = &cl->next;
|
|
874 }
|
|
875
|
|
876 b->last_buf = ctx->buf->last_buf;
|
|
877 b->shadow = ctx->buf;
|
58
|
878
|
146
|
879 if (slcf->ignore_recycled_buffers == 0) {
|
58
|
880 b->recycled = ctx->buf->recycled;
|
|
881 }
|
46
|
882 }
|
|
883
|
48
|
884 ctx->buf = NULL;
|
|
885
|
46
|
886 ctx->saved = ctx->looked;
|
|
887 }
|
|
888
|
48
|
889 if (ctx->out == NULL && ctx->busy == NULL) {
|
46
|
890 return NGX_OK;
|
|
891 }
|
|
892
|
58
|
893 return ngx_http_ssi_output(r, ctx);
|
|
894 }
|
|
895
|
|
896
|
|
897 static ngx_int_t
|
|
898 ngx_http_ssi_output(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx)
|
|
899 {
|
|
900 ngx_int_t rc;
|
|
901 ngx_buf_t *b;
|
|
902 ngx_chain_t *cl;
|
|
903
|
190
|
904 #if 1
|
|
905 b = NULL;
|
|
906 for (cl = ctx->out; cl; cl = cl->next) {
|
192
|
907 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
908 "ssi out: %p %p", cl->buf, cl->buf->pos);
|
190
|
909 if (cl->buf == b) {
|
|
910 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
911 "the same buf was used in ssi");
|
|
912 ngx_debug_point();
|
|
913 return NGX_ERROR;
|
|
914 }
|
|
915 b = cl->buf;
|
|
916 }
|
|
917 #endif
|
|
918
|
46
|
919 rc = ngx_http_next_body_filter(r, ctx->out);
|
|
920
|
48
|
921 if (ctx->busy == NULL) {
|
|
922 ctx->busy = ctx->out;
|
|
923
|
|
924 } else {
|
|
925 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ }
|
|
926 cl->next = ctx->out;
|
|
927 }
|
|
928
|
46
|
929 ctx->out = NULL;
|
|
930 ctx->last_out = &ctx->out;
|
|
931
|
48
|
932 while (ctx->busy) {
|
|
933
|
206
|
934 cl = ctx->busy;
|
|
935 b = cl->buf;
|
48
|
936
|
|
937 if (ngx_buf_size(b) != 0) {
|
|
938 break;
|
|
939 }
|
|
940
|
|
941 if (b->shadow) {
|
|
942 b->shadow->pos = b->shadow->last;
|
|
943 }
|
|
944
|
|
945 ctx->busy = cl->next;
|
194
|
946
|
|
947 if (ngx_buf_in_memory(b) || b->in_file) {
|
|
948 /* add data bufs only to the free buf chain */
|
|
949
|
|
950 cl->next = ctx->free;
|
|
951 ctx->free = cl;
|
|
952 }
|
48
|
953 }
|
|
954
|
586
|
955 ngx_http_ssi_buffered(r, ctx);
|
|
956
|
|
957 return rc;
|
|
958 }
|
|
959
|
|
960
|
|
961 static void
|
|
962 ngx_http_ssi_buffered(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx)
|
|
963 {
|
254
|
964 if (ctx->in || ctx->buf) {
|
|
965 r->buffered |= NGX_HTTP_SSI_BUFFERED;
|
|
966
|
|
967 } else {
|
|
968 r->buffered &= ~NGX_HTTP_SSI_BUFFERED;
|
|
969 }
|
46
|
970 }
|
|
971
|
|
972
|
|
973 static ngx_int_t
|
|
974 ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx)
|
|
975 {
|
158
|
976 u_char *p, *value, *last, *copy_end, ch;
|
46
|
977 size_t looked;
|
|
978 ngx_http_ssi_state_e state;
|
|
979
|
|
980 state = ctx->state;
|
|
981 looked = ctx->looked;
|
|
982 last = ctx->buf->last;
|
|
983 copy_end = ctx->copy_end;
|
|
984
|
|
985 for (p = ctx->pos; p < last; p++) {
|
|
986
|
|
987 ch = *p;
|
|
988
|
|
989 if (state == ssi_start_state) {
|
|
990
|
|
991 /* the tight loop */
|
|
992
|
48
|
993 for ( ;; ) {
|
|
994 if (ch == '<') {
|
|
995 copy_end = p;
|
|
996 looked = 1;
|
|
997 state = ssi_tag_state;
|
|
998
|
|
999 goto tag_started;
|
46
|
1000 }
|
|
1001
|
48
|
1002 if (++p == last) {
|
|
1003 break;
|
|
1004 }
|
46
|
1005
|
48
|
1006 ch = *p;
|
46
|
1007 }
|
|
1008
|
314
|
1009 ctx->state = state;
|
46
|
1010 ctx->pos = p;
|
|
1011 ctx->looked = looked;
|
|
1012 ctx->copy_end = p;
|
|
1013
|
|
1014 if (ctx->copy_start == NULL) {
|
|
1015 ctx->copy_start = ctx->buf->pos;
|
|
1016 }
|
|
1017
|
|
1018 return NGX_AGAIN;
|
|
1019
|
48
|
1020 tag_started:
|
|
1021
|
46
|
1022 continue;
|
|
1023 }
|
|
1024
|
|
1025 switch (state) {
|
|
1026
|
|
1027 case ssi_start_state:
|
|
1028 break;
|
|
1029
|
|
1030 case ssi_tag_state:
|
|
1031 switch (ch) {
|
|
1032 case '!':
|
|
1033 looked = 2;
|
|
1034 state = ssi_comment0_state;
|
|
1035 break;
|
|
1036
|
|
1037 case '<':
|
|
1038 copy_end = p;
|
|
1039 break;
|
|
1040
|
|
1041 default:
|
|
1042 copy_end = p;
|
|
1043 looked = 0;
|
|
1044 state = ssi_start_state;
|
|
1045 break;
|
|
1046 }
|
|
1047
|
|
1048 break;
|
|
1049
|
|
1050 case ssi_comment0_state:
|
|
1051 switch (ch) {
|
|
1052 case '-':
|
|
1053 looked = 3;
|
|
1054 state = ssi_comment1_state;
|
|
1055 break;
|
|
1056
|
|
1057 case '<':
|
|
1058 copy_end = p;
|
|
1059 looked = 1;
|
|
1060 state = ssi_tag_state;
|
|
1061 break;
|
|
1062
|
|
1063 default:
|
|
1064 copy_end = p;
|
|
1065 looked = 0;
|
|
1066 state = ssi_start_state;
|
|
1067 break;
|
|
1068 }
|
|
1069
|
|
1070 break;
|
|
1071
|
|
1072 case ssi_comment1_state:
|
|
1073 switch (ch) {
|
|
1074 case '-':
|
|
1075 looked = 4;
|
|
1076 state = ssi_sharp_state;
|
|
1077 break;
|
|
1078
|
|
1079 case '<':
|
|
1080 copy_end = p;
|
|
1081 looked = 1;
|
|
1082 state = ssi_tag_state;
|
|
1083 break;
|
|
1084
|
|
1085 default:
|
|
1086 copy_end = p;
|
|
1087 looked = 0;
|
|
1088 state = ssi_start_state;
|
|
1089 break;
|
|
1090 }
|
|
1091
|
|
1092 break;
|
|
1093
|
|
1094 case ssi_sharp_state:
|
|
1095 switch (ch) {
|
|
1096 case '#':
|
208
|
1097 if (p - ctx->pos < 4) {
|
|
1098 ctx->saved = 0;
|
|
1099 }
|
46
|
1100 looked = 0;
|
|
1101 state = ssi_precommand_state;
|
|
1102 break;
|
|
1103
|
|
1104 case '<':
|
|
1105 copy_end = p;
|
|
1106 looked = 1;
|
|
1107 state = ssi_tag_state;
|
|
1108 break;
|
|
1109
|
|
1110 default:
|
|
1111 copy_end = p;
|
|
1112 looked = 0;
|
|
1113 state = ssi_start_state;
|
|
1114 break;
|
|
1115 }
|
|
1116
|
|
1117 break;
|
|
1118
|
|
1119 case ssi_precommand_state:
|
|
1120 switch (ch) {
|
|
1121 case ' ':
|
|
1122 case CR:
|
|
1123 case LF:
|
|
1124 case '\t':
|
|
1125 break;
|
|
1126
|
|
1127 default:
|
|
1128 ctx->command.len = 1;
|
382
|
1129 ctx->command.data = ngx_pnalloc(r->pool,
|
|
1130 NGX_HTTP_SSI_COMMAND_LEN);
|
46
|
1131 if (ctx->command.data == NULL) {
|
|
1132 return NGX_ERROR;
|
|
1133 }
|
|
1134
|
|
1135 ctx->command.data[0] = ch;
|
158
|
1136
|
146
|
1137 ctx->key = 0;
|
|
1138 ctx->key = ngx_hash(ctx->key, ch);
|
|
1139
|
46
|
1140 ctx->params.nelts = 0;
|
178
|
1141
|
46
|
1142 state = ssi_command_state;
|
|
1143 break;
|
|
1144 }
|
|
1145
|
|
1146 break;
|
|
1147
|
|
1148 case ssi_command_state:
|
|
1149 switch (ch) {
|
|
1150 case ' ':
|
|
1151 case CR:
|
|
1152 case LF:
|
|
1153 case '\t':
|
|
1154 state = ssi_preparam_state;
|
|
1155 break;
|
|
1156
|
|
1157 case '-':
|
|
1158 state = ssi_comment_end0_state;
|
|
1159 break;
|
|
1160
|
|
1161 default:
|
|
1162 if (ctx->command.len == NGX_HTTP_SSI_COMMAND_LEN) {
|
|
1163 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
158
|
1164 "the \"%V%c...\" SSI command is too long",
|
|
1165 &ctx->command, ch);
|
46
|
1166
|
|
1167 state = ssi_error_state;
|
|
1168 break;
|
|
1169 }
|
158
|
1170
|
|
1171 ctx->command.data[ctx->command.len++] = ch;
|
|
1172 ctx->key = ngx_hash(ctx->key, ch);
|
46
|
1173 }
|
|
1174
|
|
1175 break;
|
|
1176
|
|
1177 case ssi_preparam_state:
|
|
1178 switch (ch) {
|
|
1179 case ' ':
|
|
1180 case CR:
|
|
1181 case LF:
|
|
1182 case '\t':
|
|
1183 break;
|
|
1184
|
|
1185 case '-':
|
|
1186 state = ssi_comment_end0_state;
|
|
1187 break;
|
|
1188
|
|
1189 default:
|
48
|
1190 ctx->param = ngx_array_push(&ctx->params);
|
|
1191 if (ctx->param == NULL) {
|
46
|
1192 return NGX_ERROR;
|
|
1193 }
|
|
1194
|
|
1195 ctx->param->key.len = 1;
|
382
|
1196 ctx->param->key.data = ngx_pnalloc(r->pool,
|
|
1197 NGX_HTTP_SSI_PARAM_LEN);
|
46
|
1198 if (ctx->param->key.data == NULL) {
|
|
1199 return NGX_ERROR;
|
|
1200 }
|
|
1201
|
|
1202 ctx->param->key.data[0] = ch;
|
|
1203
|
|
1204 ctx->param->value.len = 0;
|
158
|
1205
|
|
1206 if (ctx->value_buf == NULL) {
|
382
|
1207 ctx->param->value.data = ngx_pnalloc(r->pool,
|
666
|
1208 ctx->value_len + 1);
|
158
|
1209 if (ctx->param->value.data == NULL) {
|
|
1210 return NGX_ERROR;
|
|
1211 }
|
|
1212
|
|
1213 } else {
|
|
1214 ctx->param->value.data = ctx->value_buf;
|
46
|
1215 }
|
|
1216
|
|
1217 state = ssi_param_state;
|
|
1218 break;
|
|
1219 }
|
|
1220
|
|
1221 break;
|
|
1222
|
|
1223 case ssi_param_state:
|
|
1224 switch (ch) {
|
|
1225 case ' ':
|
|
1226 case CR:
|
|
1227 case LF:
|
|
1228 case '\t':
|
|
1229 state = ssi_preequal_state;
|
|
1230 break;
|
|
1231
|
|
1232 case '=':
|
|
1233 state = ssi_prevalue_state;
|
|
1234 break;
|
|
1235
|
|
1236 case '-':
|
|
1237 state = ssi_error_end0_state;
|
|
1238
|
|
1239 ctx->param->key.data[ctx->param->key.len++] = ch;
|
|
1240 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1241 "invalid \"%V\" parameter in \"%V\" SSI command",
|
|
1242 &ctx->param->key, &ctx->command);
|
|
1243 break;
|
|
1244
|
|
1245 default:
|
|
1246 if (ctx->param->key.len == NGX_HTTP_SSI_PARAM_LEN) {
|
|
1247 state = ssi_error_state;
|
|
1248 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
158
|
1249 "too long \"%V%c...\" parameter in "
|
46
|
1250 "\"%V\" SSI command",
|
158
|
1251 &ctx->param->key, ch, &ctx->command);
|
46
|
1252 break;
|
|
1253 }
|
158
|
1254
|
|
1255 ctx->param->key.data[ctx->param->key.len++] = ch;
|
46
|
1256 }
|
|
1257
|
|
1258 break;
|
|
1259
|
|
1260 case ssi_preequal_state:
|
|
1261 switch (ch) {
|
|
1262 case ' ':
|
|
1263 case CR:
|
|
1264 case LF:
|
|
1265 case '\t':
|
|
1266 break;
|
|
1267
|
|
1268 case '=':
|
|
1269 state = ssi_prevalue_state;
|
|
1270 break;
|
|
1271
|
|
1272 default:
|
|
1273 if (ch == '-') {
|
|
1274 state = ssi_error_end0_state;
|
|
1275 } else {
|
|
1276 state = ssi_error_state;
|
|
1277 }
|
|
1278
|
|
1279 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1280 "unexpected \"%c\" symbol after \"%V\" "
|
|
1281 "parameter in \"%V\" SSI command",
|
|
1282 ch, &ctx->param->key, &ctx->command);
|
|
1283 break;
|
|
1284 }
|
|
1285
|
|
1286 break;
|
|
1287
|
|
1288 case ssi_prevalue_state:
|
|
1289 switch (ch) {
|
|
1290 case ' ':
|
|
1291 case CR:
|
|
1292 case LF:
|
|
1293 case '\t':
|
|
1294 break;
|
|
1295
|
|
1296 case '"':
|
|
1297 state = ssi_double_quoted_value_state;
|
|
1298 break;
|
|
1299
|
|
1300 case '\'':
|
|
1301 state = ssi_quoted_value_state;
|
|
1302 break;
|
|
1303
|
|
1304 default:
|
|
1305 if (ch == '-') {
|
|
1306 state = ssi_error_end0_state;
|
|
1307 } else {
|
|
1308 state = ssi_error_state;
|
|
1309 }
|
|
1310
|
|
1311 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1312 "unexpected \"%c\" symbol before value of "
|
|
1313 "\"%V\" parameter in \"%V\" SSI command",
|
|
1314 ch, &ctx->param->key, &ctx->command);
|
|
1315 break;
|
|
1316 }
|
|
1317
|
|
1318 break;
|
|
1319
|
|
1320 case ssi_double_quoted_value_state:
|
|
1321 switch (ch) {
|
108
|
1322 case '"':
|
|
1323 state = ssi_postparam_state;
|
|
1324 break;
|
|
1325
|
46
|
1326 case '\\':
|
|
1327 ctx->saved_state = ssi_double_quoted_value_state;
|
|
1328 state = ssi_quoted_symbol_state;
|
108
|
1329
|
|
1330 /* fall through */
|
46
|
1331
|
|
1332 default:
|
|
1333 if (ctx->param->value.len == ctx->value_len) {
|
|
1334 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
158
|
1335 "too long \"%V%c...\" value of \"%V\" "
|
|
1336 "parameter in \"%V\" SSI command",
|
|
1337 &ctx->param->value, ch, &ctx->param->key,
|
46
|
1338 &ctx->command);
|
|
1339 state = ssi_error_state;
|
|
1340 break;
|
|
1341 }
|
158
|
1342
|
|
1343 ctx->param->value.data[ctx->param->value.len++] = ch;
|
46
|
1344 }
|
|
1345
|
|
1346 break;
|
|
1347
|
|
1348 case ssi_quoted_value_state:
|
|
1349 switch (ch) {
|
108
|
1350 case '\'':
|
|
1351 state = ssi_postparam_state;
|
|
1352 break;
|
|
1353
|
46
|
1354 case '\\':
|
|
1355 ctx->saved_state = ssi_quoted_value_state;
|
|
1356 state = ssi_quoted_symbol_state;
|
108
|
1357
|
|
1358 /* fall through */
|
46
|
1359
|
|
1360 default:
|
|
1361 if (ctx->param->value.len == ctx->value_len) {
|
|
1362 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
158
|
1363 "too long \"%V%c...\" value of \"%V\" "
|
|
1364 "parameter in \"%V\" SSI command",
|
|
1365 &ctx->param->value, ch, &ctx->param->key,
|
46
|
1366 &ctx->command);
|
|
1367 state = ssi_error_state;
|
|
1368 break;
|
|
1369 }
|
158
|
1370
|
|
1371 ctx->param->value.data[ctx->param->value.len++] = ch;
|
46
|
1372 }
|
|
1373
|
|
1374 break;
|
|
1375
|
|
1376 case ssi_quoted_symbol_state:
|
108
|
1377 state = ctx->saved_state;
|
|
1378
|
666
|
1379 if (ctx->param->value.len == ctx->value_len) {
|
|
1380 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1381 "too long \"%V%c...\" value of \"%V\" "
|
|
1382 "parameter in \"%V\" SSI command",
|
|
1383 &ctx->param->value, ch, &ctx->param->key,
|
|
1384 &ctx->command);
|
|
1385 state = ssi_error_state;
|
|
1386 break;
|
|
1387 }
|
|
1388
|
46
|
1389 ctx->param->value.data[ctx->param->value.len++] = ch;
|
|
1390
|
|
1391 break;
|
|
1392
|
|
1393 case ssi_postparam_state:
|
158
|
1394
|
200
|
1395 if (ctx->param->value.len + 1 < ctx->value_len / 2) {
|
382
|
1396 value = ngx_pnalloc(r->pool, ctx->param->value.len + 1);
|
158
|
1397 if (value == NULL) {
|
|
1398 return NGX_ERROR;
|
|
1399 }
|
|
1400
|
|
1401 ngx_memcpy(value, ctx->param->value.data,
|
|
1402 ctx->param->value.len);
|
|
1403
|
|
1404 ctx->value_buf = ctx->param->value.data;
|
|
1405 ctx->param->value.data = value;
|
|
1406
|
|
1407 } else {
|
|
1408 ctx->value_buf = NULL;
|
|
1409 }
|
|
1410
|
46
|
1411 switch (ch) {
|
|
1412 case ' ':
|
|
1413 case CR:
|
|
1414 case LF:
|
|
1415 case '\t':
|
|
1416 state = ssi_preparam_state;
|
|
1417 break;
|
|
1418
|
|
1419 case '-':
|
|
1420 state = ssi_comment_end0_state;
|
|
1421 break;
|
|
1422
|
|
1423 default:
|
|
1424 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1425 "unexpected \"%c\" symbol after \"%V\" value "
|
|
1426 "of \"%V\" parameter in \"%V\" SSI command",
|
|
1427 ch, &ctx->param->value, &ctx->param->key,
|
|
1428 &ctx->command);
|
|
1429 state = ssi_error_state;
|
|
1430 break;
|
|
1431 }
|
|
1432
|
|
1433 break;
|
|
1434
|
|
1435 case ssi_comment_end0_state:
|
|
1436 switch (ch) {
|
|
1437 case '-':
|
|
1438 state = ssi_comment_end1_state;
|
|
1439 break;
|
|
1440
|
|
1441 default:
|
|
1442 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1443 "unexpected \"%c\" symbol in \"%V\" SSI command",
|
|
1444 ch, &ctx->command);
|
|
1445 state = ssi_error_state;
|
|
1446 break;
|
|
1447 }
|
|
1448
|
|
1449 break;
|
|
1450
|
|
1451 case ssi_comment_end1_state:
|
|
1452 switch (ch) {
|
|
1453 case '>':
|
|
1454 ctx->state = ssi_start_state;
|
|
1455 ctx->pos = p + 1;
|
|
1456 ctx->looked = looked;
|
|
1457 ctx->copy_end = copy_end;
|
|
1458
|
|
1459 if (ctx->copy_start == NULL && copy_end) {
|
|
1460 ctx->copy_start = ctx->buf->pos;
|
|
1461 }
|
|
1462
|
|
1463 return NGX_OK;
|
|
1464
|
|
1465 default:
|
|
1466 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1467 "unexpected \"%c\" symbol in \"%V\" SSI command",
|
|
1468 ch, &ctx->command);
|
|
1469 state = ssi_error_state;
|
|
1470 break;
|
|
1471 }
|
|
1472
|
|
1473 break;
|
|
1474
|
|
1475 case ssi_error_state:
|
|
1476 switch (ch) {
|
|
1477 case '-':
|
|
1478 state = ssi_error_end0_state;
|
|
1479 break;
|
|
1480
|
|
1481 default:
|
|
1482 break;
|
|
1483 }
|
|
1484
|
|
1485 break;
|
|
1486
|
|
1487 case ssi_error_end0_state:
|
|
1488 switch (ch) {
|
|
1489 case '-':
|
|
1490 state = ssi_error_end1_state;
|
|
1491 break;
|
|
1492
|
|
1493 default:
|
|
1494 state = ssi_error_state;
|
|
1495 break;
|
|
1496 }
|
|
1497
|
|
1498 break;
|
|
1499
|
|
1500 case ssi_error_end1_state:
|
|
1501 switch (ch) {
|
|
1502 case '>':
|
|
1503 ctx->state = ssi_start_state;
|
|
1504 ctx->pos = p + 1;
|
|
1505 ctx->looked = looked;
|
|
1506 ctx->copy_end = copy_end;
|
|
1507
|
|
1508 if (ctx->copy_start == NULL && copy_end) {
|
|
1509 ctx->copy_start = ctx->buf->pos;
|
|
1510 }
|
|
1511
|
|
1512 return NGX_HTTP_SSI_ERROR;
|
|
1513
|
|
1514 default:
|
|
1515 state = ssi_error_state;
|
|
1516 break;
|
|
1517 }
|
|
1518
|
|
1519 break;
|
|
1520 }
|
|
1521 }
|
|
1522
|
|
1523 ctx->state = state;
|
|
1524 ctx->pos = p;
|
|
1525 ctx->looked = looked;
|
|
1526
|
|
1527 ctx->copy_end = (state == ssi_start_state) ? p : copy_end;
|
|
1528
|
|
1529 if (ctx->copy_start == NULL && ctx->copy_end) {
|
|
1530 ctx->copy_start = ctx->buf->pos;
|
|
1531 }
|
|
1532
|
|
1533 return NGX_AGAIN;
|
|
1534 }
|
|
1535
|
|
1536
|
102
|
1537 static ngx_str_t *
|
160
|
1538 ngx_http_ssi_get_variable(ngx_http_request_t *r, ngx_str_t *name,
|
|
1539 ngx_uint_t key)
|
102
|
1540 {
|
|
1541 ngx_uint_t i;
|
248
|
1542 ngx_list_part_t *part;
|
102
|
1543 ngx_http_ssi_var_t *var;
|
|
1544 ngx_http_ssi_ctx_t *ctx;
|
|
1545
|
|
1546 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);
|
|
1547
|
656
|
1548 #if (NGX_PCRE)
|
|
1549 {
|
|
1550 ngx_str_t *value;
|
|
1551
|
|
1552 if (key >= '0' && key <= '9') {
|
|
1553 i = key - '0';
|
|
1554
|
|
1555 if (i < ctx->ncaptures) {
|
|
1556 value = ngx_palloc(r->pool, sizeof(ngx_str_t));
|
|
1557 if (value == NULL) {
|
|
1558 return NULL;
|
|
1559 }
|
|
1560
|
|
1561 i *= 2;
|
|
1562
|
|
1563 value->data = ctx->captures_data + ctx->captures[i];
|
|
1564 value->len = ctx->captures[i + 1] - ctx->captures[i];
|
|
1565
|
|
1566 return value;
|
|
1567 }
|
|
1568 }
|
|
1569 }
|
|
1570 #endif
|
|
1571
|
216
|
1572 if (ctx->variables == NULL) {
|
|
1573 return NULL;
|
|
1574 }
|
|
1575
|
248
|
1576 part = &ctx->variables->part;
|
|
1577 var = part->elts;
|
|
1578
|
|
1579 for (i = 0; /* void */ ; i++) {
|
|
1580
|
|
1581 if (i >= part->nelts) {
|
|
1582 if (part->next == NULL) {
|
|
1583 break;
|
|
1584 }
|
250
|
1585
|
248
|
1586 part = part->next;
|
|
1587 var = part->elts;
|
|
1588 i = 0;
|
|
1589 }
|
|
1590
|
102
|
1591 if (name->len != var[i].name.len) {
|
|
1592 continue;
|
|
1593 }
|
|
1594
|
160
|
1595 if (key != var[i].key) {
|
|
1596 continue;
|
|
1597 }
|
|
1598
|
|
1599 if (ngx_strncmp(name->data, var[i].name.data, name->len) == 0) {
|
102
|
1600 return &var[i].value;
|
|
1601 }
|
|
1602 }
|
|
1603
|
|
1604 return NULL;
|
|
1605 }
|
|
1606
|
|
1607
|
|
1608 static ngx_int_t
|
|
1609 ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
1610 ngx_str_t *text, ngx_uint_t flags)
|
|
1611 {
|
122
|
1612 u_char ch, *p, **value, *data, *part_data;
|
|
1613 size_t *size, len, prefix, part_len;
|
|
1614 ngx_str_t var, *val;
|
160
|
1615 ngx_int_t key;
|
392
|
1616 ngx_uint_t i, n, bracket, quoted;
|
102
|
1617 ngx_array_t lengths, values;
|
|
1618 ngx_http_variable_value_t *vv;
|
|
1619
|
|
1620 n = ngx_http_script_variables_count(text);
|
|
1621
|
|
1622 if (n == 0) {
|
|
1623
|
206
|
1624 data = text->data;
|
|
1625 p = data;
|
|
1626
|
|
1627 if ((flags & NGX_HTTP_SSI_ADD_PREFIX) && text->data[0] != '/') {
|
|
1628
|
102
|
1629 for (prefix = r->uri.len; prefix; prefix--) {
|
|
1630 if (r->uri.data[prefix - 1] == '/') {
|
|
1631 break;
|
|
1632 }
|
|
1633 }
|
|
1634
|
|
1635 if (prefix) {
|
|
1636 len = prefix + text->len;
|
|
1637
|
382
|
1638 data = ngx_pnalloc(r->pool, len);
|
102
|
1639 if (data == NULL) {
|
|
1640 return NGX_ERROR;
|
|
1641 }
|
|
1642
|
122
|
1643 p = ngx_copy(data, r->uri.data, prefix);
|
102
|
1644 }
|
|
1645 }
|
|
1646
|
206
|
1647 quoted = 0;
|
|
1648
|
378
|
1649 for (i = 0; i < text->len; i++) {
|
206
|
1650 ch = text->data[i];
|
|
1651
|
|
1652 if (!quoted) {
|
|
1653
|
|
1654 if (ch == '\\') {
|
|
1655 quoted = 1;
|
|
1656 continue;
|
|
1657 }
|
|
1658
|
|
1659 } else {
|
|
1660 quoted = 0;
|
|
1661
|
|
1662 if (ch != '\\' && ch != '\'' && ch != '"' && ch != '$') {
|
|
1663 *p++ = '\\';
|
|
1664 }
|
|
1665 }
|
|
1666
|
|
1667 *p++ = ch;
|
|
1668 }
|
|
1669
|
|
1670 text->len = p - data;
|
|
1671 text->data = data;
|
|
1672
|
102
|
1673 return NGX_OK;
|
|
1674 }
|
|
1675
|
|
1676 if (ngx_array_init(&lengths, r->pool, 8, sizeof(size_t *)) != NGX_OK) {
|
|
1677 return NGX_ERROR;
|
|
1678 }
|
|
1679
|
|
1680 if (ngx_array_init(&values, r->pool, 8, sizeof(u_char *)) != NGX_OK) {
|
|
1681 return NGX_ERROR;
|
|
1682 }
|
|
1683
|
|
1684 len = 0;
|
|
1685 i = 0;
|
|
1686
|
|
1687 while (i < text->len) {
|
|
1688
|
|
1689 if (text->data[i] == '$') {
|
|
1690
|
|
1691 var.len = 0;
|
|
1692
|
|
1693 if (++i == text->len) {
|
|
1694 goto invalid_variable;
|
|
1695 }
|
|
1696
|
|
1697 if (text->data[i] == '{') {
|
|
1698 bracket = 1;
|
|
1699
|
|
1700 if (++i == text->len) {
|
|
1701 goto invalid_variable;
|
|
1702 }
|
|
1703
|
|
1704 var.data = &text->data[i];
|
|
1705
|
|
1706 } else {
|
|
1707 bracket = 0;
|
|
1708 var.data = &text->data[i];
|
|
1709 }
|
|
1710
|
|
1711 for ( /* void */ ; i < text->len; i++, var.len++) {
|
|
1712 ch = text->data[i];
|
|
1713
|
|
1714 if (ch == '}' && bracket) {
|
|
1715 i++;
|
|
1716 bracket = 0;
|
|
1717 break;
|
|
1718 }
|
|
1719
|
|
1720 if ((ch >= 'A' && ch <= 'Z')
|
|
1721 || (ch >= 'a' && ch <= 'z')
|
|
1722 || (ch >= '0' && ch <= '9')
|
|
1723 || ch == '_')
|
|
1724 {
|
|
1725 continue;
|
|
1726 }
|
|
1727
|
|
1728 break;
|
|
1729 }
|
|
1730
|
|
1731 if (bracket) {
|
|
1732 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1733 "the closing bracket in \"%V\" "
|
|
1734 "variable is missing", &var);
|
248
|
1735 return NGX_HTTP_SSI_ERROR;
|
102
|
1736 }
|
|
1737
|
126
|
1738 if (var.len == 0) {
|
102
|
1739 goto invalid_variable;
|
|
1740 }
|
|
1741
|
392
|
1742 key = ngx_hash_strlow(var.data, var.data, var.len);
|
102
|
1743
|
160
|
1744 val = ngx_http_ssi_get_variable(r, &var, key);
|
102
|
1745
|
|
1746 if (val == NULL) {
|
568
|
1747 vv = ngx_http_get_variable(r, &var, key);
|
102
|
1748 if (vv == NULL) {
|
|
1749 return NGX_ERROR;
|
|
1750 }
|
|
1751
|
122
|
1752 if (vv->not_found) {
|
102
|
1753 continue;
|
|
1754 }
|
|
1755
|
122
|
1756 part_data = vv->data;
|
|
1757 part_len = vv->len;
|
102
|
1758
|
|
1759 } else {
|
122
|
1760 part_data = val->data;
|
|
1761 part_len = val->len;
|
102
|
1762 }
|
|
1763
|
|
1764 } else {
|
122
|
1765 part_data = &text->data[i];
|
200
|
1766 quoted = 0;
|
122
|
1767
|
|
1768 for (p = part_data; i < text->len; i++) {
|
108
|
1769 ch = text->data[i];
|
|
1770
|
200
|
1771 if (!quoted) {
|
|
1772
|
|
1773 if (ch == '\\') {
|
|
1774 quoted = 1;
|
|
1775 continue;
|
|
1776 }
|
|
1777
|
|
1778 if (ch == '$') {
|
108
|
1779 break;
|
|
1780 }
|
|
1781
|
200
|
1782 } else {
|
|
1783 quoted = 0;
|
|
1784
|
|
1785 if (ch != '\\' && ch != '\'' && ch != '"' && ch != '$') {
|
|
1786 *p++ = '\\';
|
|
1787 }
|
108
|
1788 }
|
|
1789
|
|
1790 *p++ = ch;
|
102
|
1791 }
|
108
|
1792
|
122
|
1793 part_len = p - part_data;
|
102
|
1794 }
|
|
1795
|
122
|
1796 len += part_len;
|
102
|
1797
|
|
1798 size = ngx_array_push(&lengths);
|
|
1799 if (size == NULL) {
|
|
1800 return NGX_ERROR;
|
|
1801 }
|
|
1802
|
122
|
1803 *size = part_len;
|
102
|
1804
|
|
1805 value = ngx_array_push(&values);
|
|
1806 if (value == NULL) {
|
|
1807 return NGX_ERROR;
|
|
1808 }
|
|
1809
|
122
|
1810 *value = part_data;
|
102
|
1811 }
|
|
1812
|
|
1813 prefix = 0;
|
|
1814
|
|
1815 size = lengths.elts;
|
|
1816 value = values.elts;
|
|
1817
|
|
1818 if (flags & NGX_HTTP_SSI_ADD_PREFIX) {
|
|
1819 for (i = 0; i < values.nelts; i++) {
|
|
1820 if (size[i] != 0) {
|
|
1821 if (*value[i] != '/') {
|
|
1822 for (prefix = r->uri.len; prefix; prefix--) {
|
|
1823 if (r->uri.data[prefix - 1] == '/') {
|
|
1824 len += prefix;
|
|
1825 break;
|
|
1826 }
|
|
1827 }
|
|
1828 }
|
|
1829
|
|
1830 break;
|
|
1831 }
|
|
1832 }
|
|
1833 }
|
|
1834
|
382
|
1835 p = ngx_pnalloc(r->pool, len + ((flags & NGX_HTTP_SSI_ADD_ZERO) ? 1 : 0));
|
102
|
1836 if (p == NULL) {
|
|
1837 return NGX_ERROR;
|
|
1838 }
|
|
1839
|
|
1840 text->len = len;
|
|
1841 text->data = p;
|
|
1842
|
122
|
1843 p = ngx_copy(p, r->uri.data, prefix);
|
102
|
1844
|
|
1845 for (i = 0; i < values.nelts; i++) {
|
122
|
1846 p = ngx_copy(p, value[i], size[i]);
|
102
|
1847 }
|
|
1848
|
|
1849 return NGX_OK;
|
|
1850
|
|
1851 invalid_variable:
|
|
1852
|
|
1853 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1854 "invalid variable name in \"%V\"", text);
|
|
1855
|
248
|
1856 return NGX_HTTP_SSI_ERROR;
|
102
|
1857 }
|
|
1858
|
|
1859
|
|
1860 static ngx_int_t
|
656
|
1861 ngx_http_ssi_regex_match(ngx_http_request_t *r, ngx_str_t *pattern,
|
|
1862 ngx_str_t *str)
|
|
1863 {
|
|
1864 #if (NGX_PCRE)
|
|
1865 int rc, *captures;
|
|
1866 u_char *p, errstr[NGX_MAX_CONF_ERRSTR];
|
|
1867 size_t size;
|
|
1868 ngx_int_t key;
|
|
1869 ngx_str_t *vv, name, value;
|
|
1870 ngx_uint_t i, n;
|
|
1871 ngx_http_ssi_ctx_t *ctx;
|
|
1872 ngx_http_ssi_var_t *var;
|
|
1873 ngx_regex_compile_t rgc;
|
|
1874
|
|
1875 ngx_memzero(&rgc, sizeof(ngx_regex_compile_t));
|
|
1876
|
|
1877 rgc.pattern = *pattern;
|
|
1878 rgc.pool = r->pool;
|
|
1879 rgc.err.len = NGX_MAX_CONF_ERRSTR;
|
|
1880 rgc.err.data = errstr;
|
|
1881
|
|
1882 if (ngx_regex_compile(&rgc) != NGX_OK) {
|
|
1883 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%V", &rgc.err);
|
|
1884 return NGX_HTTP_SSI_ERROR;
|
|
1885 }
|
|
1886
|
|
1887 n = (rgc.captures + 1) * 3;
|
|
1888
|
|
1889 captures = ngx_palloc(r->pool, n * sizeof(int));
|
|
1890 if (captures == NULL) {
|
|
1891 return NGX_ERROR;
|
|
1892 }
|
|
1893
|
|
1894 rc = ngx_regex_exec(rgc.regex, str, captures, n);
|
|
1895
|
|
1896 if (rc < NGX_REGEX_NO_MATCHED) {
|
|
1897 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1898 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
|
|
1899 rc, str, pattern);
|
|
1900 return NGX_HTTP_SSI_ERROR;
|
|
1901 }
|
|
1902
|
|
1903 if (rc == NGX_REGEX_NO_MATCHED) {
|
|
1904 return NGX_DECLINED;
|
|
1905 }
|
|
1906
|
|
1907 ctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);
|
|
1908
|
|
1909 ctx->ncaptures = rc;
|
|
1910 ctx->captures = captures;
|
|
1911 ctx->captures_data = str->data;
|
|
1912
|
|
1913 if (rgc.named_captures > 0) {
|
|
1914
|
|
1915 if (ctx->variables == NULL) {
|
|
1916 ctx->variables = ngx_list_create(r->pool, 4,
|
|
1917 sizeof(ngx_http_ssi_var_t));
|
|
1918 if (ctx->variables == NULL) {
|
|
1919 return NGX_ERROR;
|
|
1920 }
|
|
1921 }
|
|
1922
|
|
1923 size = rgc.name_size;
|
|
1924 p = rgc.names;
|
|
1925
|
|
1926 for (i = 0; i < (ngx_uint_t) rgc.named_captures; i++, p += size) {
|
|
1927
|
|
1928 name.data = &p[2];
|
|
1929 name.len = ngx_strlen(name.data);
|
|
1930
|
|
1931 n = 2 * ((p[0] << 8) + p[1]);
|
|
1932
|
|
1933 value.data = &str->data[captures[n]];
|
|
1934 value.len = captures[n + 1] - captures[n];
|
|
1935
|
|
1936 key = ngx_hash_strlow(name.data, name.data, name.len);
|
|
1937
|
|
1938 vv = ngx_http_ssi_get_variable(r, &name, key);
|
|
1939
|
|
1940 if (vv) {
|
|
1941 *vv = value;
|
|
1942 continue;
|
|
1943 }
|
|
1944
|
|
1945 var = ngx_list_push(ctx->variables);
|
|
1946 if (var == NULL) {
|
|
1947 return NGX_ERROR;
|
|
1948 }
|
|
1949
|
|
1950 var->name = name;
|
|
1951 var->key = key;
|
|
1952 var->value = value;
|
|
1953 }
|
|
1954 }
|
|
1955
|
|
1956 return NGX_OK;
|
|
1957
|
|
1958 #else
|
|
1959
|
|
1960 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
|
1961 "the using of the regex \"%V\" in SSI requires PCRE library",
|
|
1962 pattern);
|
|
1963 return NGX_HTTP_SSI_ERROR;
|
|
1964
|
|
1965 #endif
|
|
1966 }
|
|
1967
|
|
1968
|
|
1969 static ngx_int_t
|
102
|
1970 ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
1971 ngx_str_t **params)
|
|
1972 {
|
342
|
1973 u_char *dst, *src;
|
|
1974 size_t len;
|
248
|
1975 ngx_int_t rc, key;
|
|
1976 ngx_str_t *uri, *file, *wait, *set, *stub, args;
|
|
1977 ngx_buf_t *b;
|
|
1978 ngx_uint_t flags, i;
|
250
|
1979 ngx_chain_t *cl, *tl, **ll, *out;
|
248
|
1980 ngx_http_request_t *sr;
|
|
1981 ngx_http_ssi_var_t *var;
|
|
1982 ngx_http_ssi_ctx_t *mctx;
|
|
1983 ngx_http_ssi_block_t *bl;
|
|
1984 ngx_http_post_subrequest_t *psr;
|
102
|
1985
|
|
1986 uri = params[NGX_HTTP_SSI_INCLUDE_VIRTUAL];
|
|
1987 file = params[NGX_HTTP_SSI_INCLUDE_FILE];
|
194
|
1988 wait = params[NGX_HTTP_SSI_INCLUDE_WAIT];
|
248
|
1989 set = params[NGX_HTTP_SSI_INCLUDE_SET];
|
216
|
1990 stub = params[NGX_HTTP_SSI_INCLUDE_STUB];
|
102
|
1991
|
|
1992 if (uri && file) {
|
|
1993 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
1994 "inlcusion may be either virtual=\"%V\" or file=\"%V\"",
|
|
1995 uri, file);
|
|
1996 return NGX_HTTP_SSI_ERROR;
|
|
1997 }
|
|
1998
|
|
1999 if (uri == NULL && file == NULL) {
|
|
2000 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2001 "no parameter in \"include\" SSI command");
|
|
2002 return NGX_HTTP_SSI_ERROR;
|
|
2003 }
|
|
2004
|
248
|
2005 if (set && stub) {
|
|
2006 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
672
|
2007 "\"set\" and \"stub\" cannot be used together "
|
248
|
2008 "in \"include\" SSI command");
|
|
2009 return NGX_HTTP_SSI_ERROR;
|
|
2010 }
|
|
2011
|
194
|
2012 if (wait) {
|
|
2013 if (uri == NULL) {
|
|
2014 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
672
|
2015 "\"wait\" cannot be used with file=\"%V\"", file);
|
194
|
2016 return NGX_HTTP_SSI_ERROR;
|
|
2017 }
|
|
2018
|
286
|
2019 if (wait->len == 2
|
|
2020 && ngx_strncasecmp(wait->data, (u_char *) "no", 2) == 0)
|
|
2021 {
|
194
|
2022 wait = NULL;
|
|
2023
|
286
|
2024 } else if (wait->len != 3
|
|
2025 || ngx_strncasecmp(wait->data, (u_char *) "yes", 3) != 0)
|
194
|
2026 {
|
|
2027 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2028 "invalid value \"%V\" in the \"wait\" parameter",
|
216
|
2029 wait);
|
194
|
2030 return NGX_HTTP_SSI_ERROR;
|
|
2031 }
|
|
2032 }
|
|
2033
|
102
|
2034 if (uri == NULL) {
|
|
2035 uri = file;
|
434
|
2036 wait = (ngx_str_t *) -1;
|
102
|
2037 }
|
|
2038
|
248
|
2039 rc = ngx_http_ssi_evaluate_string(r, ctx, uri, NGX_HTTP_SSI_ADD_PREFIX);
|
|
2040
|
|
2041 if (rc != NGX_OK) {
|
|
2042 return rc;
|
102
|
2043 }
|
|
2044
|
342
|
2045 dst = uri->data;
|
|
2046 src = uri->data;
|
|
2047
|
|
2048 ngx_unescape_uri(&dst, &src, uri->len, NGX_UNESCAPE_URI);
|
|
2049
|
|
2050 len = (uri->data + uri->len) - src;
|
|
2051 if (len) {
|
620
|
2052 dst = ngx_movemem(dst, src, len);
|
342
|
2053 }
|
|
2054
|
|
2055 uri->len = dst - uri->data;
|
|
2056
|
|
2057 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2058 "ssi include: \"%V\"", uri);
|
|
2059
|
570
|
2060 ngx_str_null(&args);
|
530
|
2061 flags = NGX_HTTP_LOG_UNSAFE;
|
122
|
2062
|
|
2063 if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {
|
|
2064 return NGX_HTTP_SSI_ERROR;
|
102
|
2065 }
|
|
2066
|
248
|
2067 psr = NULL;
|
|
2068
|
|
2069 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);
|
216
|
2070
|
|
2071 if (stub) {
|
|
2072 if (mctx->blocks) {
|
|
2073 bl = mctx->blocks->elts;
|
|
2074 for (i = 0; i < mctx->blocks->nelts; i++) {
|
|
2075 if (stub->len == bl[i].name.len
|
|
2076 && ngx_strncmp(stub->data, bl[i].name.data, stub->len) == 0)
|
|
2077 {
|
|
2078 goto found;
|
|
2079 }
|
|
2080 }
|
|
2081 }
|
|
2082
|
|
2083 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2084 "\"stub\"=\"%V\" for \"include\" not found", stub);
|
|
2085 return NGX_HTTP_SSI_ERROR;
|
|
2086
|
|
2087 found:
|
|
2088
|
248
|
2089 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
|
|
2090 if (psr == NULL) {
|
|
2091 return NGX_ERROR;
|
|
2092 }
|
|
2093
|
|
2094 psr->handler = ngx_http_ssi_stub_output;
|
|
2095
|
216
|
2096 if (bl[i].count++) {
|
|
2097
|
366
|
2098 out = NULL;
|
250
|
2099 ll = &out;
|
216
|
2100
|
|
2101 for (tl = bl[i].bufs; tl; tl = tl->next) {
|
|
2102
|
|
2103 if (ctx->free) {
|
|
2104 cl = ctx->free;
|
|
2105 ctx->free = ctx->free->next;
|
|
2106 b = cl->buf;
|
|
2107
|
|
2108 } else {
|
|
2109 b = ngx_alloc_buf(r->pool);
|
|
2110 if (b == NULL) {
|
|
2111 return NGX_ERROR;
|
|
2112 }
|
|
2113
|
|
2114 cl = ngx_alloc_chain_link(r->pool);
|
|
2115 if (cl == NULL) {
|
|
2116 return NGX_ERROR;
|
|
2117 }
|
|
2118
|
|
2119 cl->buf = b;
|
|
2120 }
|
|
2121
|
|
2122 ngx_memcpy(b, tl->buf, sizeof(ngx_buf_t));
|
|
2123
|
|
2124 b->pos = b->start;
|
|
2125
|
|
2126 *ll = cl;
|
|
2127 cl->next = NULL;
|
|
2128 ll = &cl->next;
|
|
2129 }
|
|
2130
|
250
|
2131 psr->data = out;
|
|
2132
|
216
|
2133 } else {
|
248
|
2134 psr->data = bl[i].bufs;
|
216
|
2135 }
|
|
2136 }
|
|
2137
|
426
|
2138 if (wait) {
|
|
2139 flags |= NGX_HTTP_SUBREQUEST_WAITED;
|
|
2140 }
|
|
2141
|
248
|
2142 if (set) {
|
392
|
2143 key = ngx_hash_strlow(set->data, set->data, set->len);
|
248
|
2144
|
|
2145 psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
|
|
2146 if (psr == NULL) {
|
|
2147 return NGX_ERROR;
|
|
2148 }
|
|
2149
|
|
2150 psr->handler = ngx_http_ssi_set_variable;
|
|
2151 psr->data = ngx_http_ssi_get_variable(r, set, key);
|
|
2152
|
|
2153 if (psr->data == NULL) {
|
|
2154
|
|
2155 if (mctx->variables == NULL) {
|
|
2156 mctx->variables = ngx_list_create(r->pool, 4,
|
|
2157 sizeof(ngx_http_ssi_var_t));
|
|
2158 if (mctx->variables == NULL) {
|
|
2159 return NGX_ERROR;
|
|
2160 }
|
|
2161 }
|
|
2162
|
|
2163 var = ngx_list_push(mctx->variables);
|
|
2164 if (var == NULL) {
|
|
2165 return NGX_ERROR;
|
|
2166 }
|
|
2167
|
|
2168 var->name = *set;
|
|
2169 var->key = key;
|
|
2170 var->value = ngx_http_ssi_null_string;
|
|
2171 psr->data = &var->value;
|
|
2172 }
|
|
2173
|
426
|
2174 flags |= NGX_HTTP_SUBREQUEST_IN_MEMORY|NGX_HTTP_SUBREQUEST_WAITED;
|
248
|
2175 }
|
|
2176
|
426
|
2177 if (ngx_http_subrequest(r, uri, &args, &sr, psr, flags) != NGX_OK) {
|
102
|
2178 return NGX_HTTP_SSI_ERROR;
|
|
2179 }
|
|
2180
|
248
|
2181 if (wait == NULL && set == NULL) {
|
194
|
2182 return NGX_OK;
|
|
2183 }
|
|
2184
|
426
|
2185 if (ctx->wait == NULL) {
|
|
2186 ctx->wait = sr;
|
|
2187
|
|
2188 return NGX_AGAIN;
|
|
2189
|
|
2190 } else {
|
|
2191 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
672
|
2192 "can only wait for one subrequest at a time");
|
194
|
2193 }
|
|
2194
|
426
|
2195 return NGX_OK;
|
102
|
2196 }
|
|
2197
|
|
2198
|
46
|
2199 static ngx_int_t
|
248
|
2200 ngx_http_ssi_stub_output(ngx_http_request_t *r, void *data, ngx_int_t rc)
|
|
2201 {
|
|
2202 ngx_chain_t *out;
|
|
2203
|
|
2204 if (rc == NGX_ERROR || r->connection->error || r->request_output) {
|
|
2205 return rc;
|
|
2206 }
|
|
2207
|
|
2208 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2209 "ssi stub output: \"%V?%V\"", &r->uri, &r->args);
|
|
2210
|
|
2211 out = data;
|
|
2212
|
|
2213 if (!r->header_sent) {
|
564
|
2214 r->headers_out.content_type_len =
|
|
2215 r->parent->headers_out.content_type_len;
|
|
2216 r->headers_out.content_type = r->parent->headers_out.content_type;
|
248
|
2217
|
|
2218 if (ngx_http_send_header(r) == NGX_ERROR) {
|
|
2219 return NGX_ERROR;
|
|
2220 }
|
|
2221 }
|
|
2222
|
|
2223 return ngx_http_output_filter(r, out);
|
|
2224 }
|
|
2225
|
|
2226
|
|
2227 static ngx_int_t
|
|
2228 ngx_http_ssi_set_variable(ngx_http_request_t *r, void *data, ngx_int_t rc)
|
|
2229 {
|
|
2230 ngx_str_t *value = data;
|
|
2231
|
|
2232 if (r->upstream) {
|
|
2233 value->len = r->upstream->buffer.last - r->upstream->buffer.pos;
|
|
2234 value->data = r->upstream->buffer.pos;
|
|
2235 }
|
|
2236
|
|
2237 return rc;
|
|
2238 }
|
|
2239
|
|
2240
|
|
2241 static ngx_int_t
|
46
|
2242 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2243 ngx_str_t **params)
|
|
2244 {
|
340
|
2245 u_char *p;
|
|
2246 uintptr_t len;
|
160
|
2247 ngx_int_t key;
|
48
|
2248 ngx_buf_t *b;
|
340
|
2249 ngx_str_t *var, *value, *enc, text;
|
48
|
2250 ngx_chain_t *cl;
|
50
|
2251 ngx_http_variable_value_t *vv;
|
46
|
2252
|
|
2253 var = params[NGX_HTTP_SSI_ECHO_VAR];
|
|
2254
|
192
|
2255 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2256 "ssi echo \"%V\"", var);
|
|
2257
|
392
|
2258 key = ngx_hash_strlow(var->data, var->data, var->len);
|
160
|
2259
|
|
2260 value = ngx_http_ssi_get_variable(r, var, key);
|
102
|
2261
|
|
2262 if (value == NULL) {
|
568
|
2263 vv = ngx_http_get_variable(r, var, key);
|
102
|
2264
|
|
2265 if (vv == NULL) {
|
|
2266 return NGX_HTTP_SSI_ERROR;
|
|
2267 }
|
|
2268
|
122
|
2269 if (!vv->not_found) {
|
|
2270 text.data = vv->data;
|
|
2271 text.len = vv->len;
|
|
2272 value = &text;
|
102
|
2273 }
|
50
|
2274 }
|
46
|
2275
|
102
|
2276 if (value == NULL) {
|
48
|
2277 value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
|
|
2278
|
|
2279 if (value == NULL) {
|
|
2280 value = &ngx_http_ssi_none;
|
|
2281
|
|
2282 } else if (value->len == 0) {
|
|
2283 return NGX_OK;
|
|
2284 }
|
|
2285
|
|
2286 } else {
|
|
2287 if (value->len == 0) {
|
|
2288 return NGX_OK;
|
|
2289 }
|
|
2290 }
|
|
2291
|
340
|
2292 enc = params[NGX_HTTP_SSI_ECHO_ENCODING];
|
|
2293
|
|
2294 if (enc) {
|
|
2295 if (enc->len == 4 && ngx_strncmp(enc->data, "none", 4) == 0) {
|
|
2296
|
|
2297 ctx->encoding = NGX_HTTP_SSI_NO_ENCODING;
|
|
2298
|
|
2299 } else if (enc->len == 3 && ngx_strncmp(enc->data, "url", 3) == 0) {
|
|
2300
|
|
2301 ctx->encoding = NGX_HTTP_SSI_URL_ENCODING;
|
|
2302
|
|
2303 } else if (enc->len == 6 && ngx_strncmp(enc->data, "entity", 6) == 0) {
|
|
2304
|
|
2305 ctx->encoding = NGX_HTTP_SSI_ENTITY_ENCODING;
|
|
2306
|
|
2307 } else {
|
|
2308 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2309 "unknown encoding \"%V\" in the \"echo\" command",
|
|
2310 enc);
|
|
2311 }
|
|
2312 }
|
|
2313
|
568
|
2314 p = value->data;
|
|
2315
|
340
|
2316 switch (ctx->encoding) {
|
|
2317
|
|
2318 case NGX_HTTP_SSI_URL_ENCODING:
|
|
2319 len = 2 * ngx_escape_uri(NULL, value->data, value->len,
|
|
2320 NGX_ESCAPE_HTML);
|
|
2321
|
|
2322 if (len) {
|
382
|
2323 p = ngx_pnalloc(r->pool, value->len + len);
|
340
|
2324 if (p == NULL) {
|
|
2325 return NGX_HTTP_SSI_ERROR;
|
|
2326 }
|
|
2327
|
|
2328 (void) ngx_escape_uri(p, value->data, value->len, NGX_ESCAPE_HTML);
|
|
2329 }
|
|
2330
|
568
|
2331 len += value->len;
|
340
|
2332 break;
|
|
2333
|
|
2334 case NGX_HTTP_SSI_ENTITY_ENCODING:
|
|
2335 len = ngx_escape_html(NULL, value->data, value->len);
|
|
2336
|
|
2337 if (len) {
|
382
|
2338 p = ngx_pnalloc(r->pool, value->len + len);
|
340
|
2339 if (p == NULL) {
|
|
2340 return NGX_HTTP_SSI_ERROR;
|
|
2341 }
|
|
2342
|
|
2343 (void) ngx_escape_html(p, value->data, value->len);
|
|
2344 }
|
|
2345
|
568
|
2346 len += value->len;
|
|
2347 break;
|
|
2348
|
|
2349 default: /* NGX_HTTP_SSI_NO_ENCODING */
|
|
2350 len = value->len;
|
340
|
2351 break;
|
|
2352 }
|
|
2353
|
48
|
2354 b = ngx_calloc_buf(r->pool);
|
|
2355 if (b == NULL) {
|
|
2356 return NGX_HTTP_SSI_ERROR;
|
|
2357 }
|
|
2358
|
|
2359 cl = ngx_alloc_chain_link(r->pool);
|
|
2360 if (cl == NULL) {
|
46
|
2361 return NGX_HTTP_SSI_ERROR;
|
|
2362 }
|
|
2363
|
|
2364 b->memory = 1;
|
568
|
2365 b->pos = p;
|
|
2366 b->last = p + len;
|
46
|
2367
|
|
2368 cl->buf = b;
|
|
2369 cl->next = NULL;
|
|
2370 *ctx->last_out = cl;
|
|
2371 ctx->last_out = &cl->next;
|
|
2372
|
|
2373 return NGX_OK;
|
|
2374 }
|
|
2375
|
|
2376
|
58
|
2377 static ngx_int_t
|
|
2378 ngx_http_ssi_config(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2379 ngx_str_t **params)
|
|
2380 {
|
|
2381 ngx_str_t *value;
|
|
2382
|
|
2383 value = params[NGX_HTTP_SSI_CONFIG_TIMEFMT];
|
|
2384
|
|
2385 if (value) {
|
138
|
2386 ctx->timefmt.len = value->len;
|
382
|
2387 ctx->timefmt.data = ngx_pnalloc(r->pool, value->len + 1);
|
138
|
2388 if (ctx->timefmt.data == NULL) {
|
|
2389 return NGX_HTTP_SSI_ERROR;
|
|
2390 }
|
|
2391
|
|
2392 ngx_cpystrn(ctx->timefmt.data, value->data, value->len + 1);
|
58
|
2393 }
|
|
2394
|
96
|
2395 value = params[NGX_HTTP_SSI_CONFIG_ERRMSG];
|
|
2396
|
|
2397 if (value) {
|
|
2398 ctx->errmsg = *value;
|
|
2399 }
|
|
2400
|
58
|
2401 return NGX_OK;
|
|
2402 }
|
|
2403
|
|
2404
|
|
2405 static ngx_int_t
|
102
|
2406 ngx_http_ssi_set(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
58
|
2407 ngx_str_t **params)
|
|
2408 {
|
248
|
2409 ngx_int_t key, rc;
|
102
|
2410 ngx_str_t *name, *value, *vv;
|
|
2411 ngx_http_ssi_var_t *var;
|
|
2412 ngx_http_ssi_ctx_t *mctx;
|
|
2413
|
|
2414 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);
|
|
2415
|
216
|
2416 if (mctx->variables == NULL) {
|
248
|
2417 mctx->variables = ngx_list_create(r->pool, 4,
|
|
2418 sizeof(ngx_http_ssi_var_t));
|
216
|
2419 if (mctx->variables == NULL) {
|
248
|
2420 return NGX_ERROR;
|
58
|
2421 }
|
|
2422 }
|
|
2423
|
102
|
2424 name = params[NGX_HTTP_SSI_SET_VAR];
|
|
2425 value = params[NGX_HTTP_SSI_SET_VALUE];
|
|
2426
|
192
|
2427 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2428 "ssi set \"%V\" \"%V\"", name, value);
|
|
2429
|
248
|
2430 rc = ngx_http_ssi_evaluate_string(r, ctx, value, 0);
|
|
2431
|
|
2432 if (rc != NGX_OK) {
|
|
2433 return rc;
|
58
|
2434 }
|
|
2435
|
392
|
2436 key = ngx_hash_strlow(name->data, name->data, name->len);
|
160
|
2437
|
|
2438 vv = ngx_http_ssi_get_variable(r, name, key);
|
102
|
2439
|
|
2440 if (vv) {
|
|
2441 *vv = *value;
|
|
2442 return NGX_OK;
|
|
2443 }
|
|
2444
|
248
|
2445 var = ngx_list_push(mctx->variables);
|
102
|
2446 if (var == NULL) {
|
248
|
2447 return NGX_ERROR;
|
102
|
2448 }
|
|
2449
|
|
2450 var->name = *name;
|
160
|
2451 var->key = key;
|
102
|
2452 var->value = *value;
|
|
2453
|
|
2454 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2455 "set: \"%V\"=\"%V\"", name, value);
|
|
2456
|
58
|
2457 return NGX_OK;
|
|
2458 }
|
|
2459
|
|
2460
|
|
2461 static ngx_int_t
|
|
2462 ngx_http_ssi_if(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2463 ngx_str_t **params)
|
|
2464 {
|
102
|
2465 u_char *p, *last;
|
|
2466 ngx_str_t *expr, left, right;
|
|
2467 ngx_int_t rc;
|
178
|
2468 ngx_uint_t negative, noregex, flags;
|
58
|
2469
|
178
|
2470 if (ctx->command.len == 2) {
|
|
2471 if (ctx->conditional) {
|
|
2472 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2473 "the \"if\" command inside the \"if\" command");
|
|
2474 return NGX_HTTP_SSI_ERROR;
|
|
2475 }
|
|
2476 }
|
|
2477
|
|
2478 if (ctx->output_chosen) {
|
|
2479 ctx->output = 0;
|
|
2480 return NGX_OK;
|
|
2481 }
|
|
2482
|
58
|
2483 expr = params[NGX_HTTP_SSI_IF_EXPR];
|
|
2484
|
192
|
2485 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2486 "ssi if expr=\"%V\"", expr);
|
|
2487
|
102
|
2488 left.data = expr->data;
|
100
|
2489 last = expr->data + expr->len;
|
|
2490
|
102
|
2491 for (p = left.data; p < last; p++) {
|
100
|
2492 if (*p >= 'A' && *p <= 'Z') {
|
|
2493 *p |= 0x20;
|
|
2494 continue;
|
|
2495 }
|
58
|
2496
|
102
|
2497 if ((*p >= 'a' && *p <= 'z')
|
|
2498 || (*p >= '0' && *p <= '9')
|
122
|
2499 || *p == '$' || *p == '{' || *p == '}' || *p == '_'
|
|
2500 || *p == '"' || *p == '\'')
|
102
|
2501 {
|
100
|
2502 continue;
|
|
2503 }
|
|
2504
|
|
2505 break;
|
|
2506 }
|
|
2507
|
102
|
2508 left.len = p - left.data;
|
100
|
2509
|
|
2510 while (p < last && *p == ' ') {
|
|
2511 p++;
|
58
|
2512 }
|
|
2513
|
568
|
2514 flags = 0;
|
184
|
2515
|
102
|
2516 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2517 "left: \"%V\"", &left);
|
|
2518
|
248
|
2519 rc = ngx_http_ssi_evaluate_string(r, ctx, &left, flags);
|
|
2520
|
|
2521 if (rc != NGX_OK) {
|
|
2522 return rc;
|
58
|
2523 }
|
|
2524
|
102
|
2525 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2526 "evaluted left: \"%V\"", &left);
|
|
2527
|
100
|
2528 if (p == last) {
|
102
|
2529 if (left.len) {
|
100
|
2530 ctx->output = 1;
|
178
|
2531 ctx->output_chosen = 1;
|
100
|
2532
|
|
2533 } else {
|
|
2534 ctx->output = 0;
|
|
2535 }
|
|
2536
|
178
|
2537 ctx->conditional = NGX_HTTP_SSI_COND_IF;
|
|
2538
|
100
|
2539 return NGX_OK;
|
|
2540 }
|
|
2541
|
|
2542 if (p < last && *p == '=') {
|
|
2543 negative = 0;
|
|
2544 p++;
|
|
2545
|
|
2546 } else if (p + 1 < last && *p == '!' && *(p + 1) == '=') {
|
|
2547 negative = 1;
|
|
2548 p += 2;
|
|
2549
|
|
2550 } else {
|
|
2551 goto invalid_expression;
|
|
2552 }
|
|
2553
|
|
2554 while (p < last && *p == ' ') {
|
|
2555 p++;
|
|
2556 }
|
|
2557
|
300
|
2558 if (p < last - 1 && *p == '/') {
|
100
|
2559 if (*(last - 1) != '/') {
|
|
2560 goto invalid_expression;
|
|
2561 }
|
|
2562
|
|
2563 noregex = 0;
|
178
|
2564 flags = NGX_HTTP_SSI_ADD_ZERO;
|
100
|
2565 last--;
|
274
|
2566 p++;
|
100
|
2567
|
|
2568 } else {
|
|
2569 noregex = 1;
|
178
|
2570 flags = 0;
|
|
2571
|
|
2572 if (p < last - 1 && p[0] == '\\' && p[1] == '/') {
|
200
|
2573 p++;
|
178
|
2574 }
|
100
|
2575 }
|
|
2576
|
|
2577 right.len = last - p;
|
|
2578 right.data = p;
|
|
2579
|
102
|
2580 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2581 "right: \"%V\"", &right);
|
|
2582
|
248
|
2583 rc = ngx_http_ssi_evaluate_string(r, ctx, &right, flags);
|
|
2584
|
|
2585 if (rc != NGX_OK) {
|
|
2586 return rc;
|
100
|
2587 }
|
|
2588
|
102
|
2589 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2590 "evaluted right: \"%V\"", &right);
|
100
|
2591
|
|
2592 if (noregex) {
|
|
2593 if (left.len != right.len) {
|
|
2594 rc = -1;
|
|
2595
|
|
2596 } else {
|
|
2597 rc = ngx_strncmp(left.data, right.data, right.len);
|
|
2598 }
|
|
2599
|
|
2600 } else {
|
|
2601 right.data[right.len] = '\0';
|
|
2602
|
656
|
2603 rc = ngx_http_ssi_regex_match(r, &right, &left);
|
|
2604
|
|
2605 if (rc == NGX_OK) {
|
|
2606 rc = 0;
|
|
2607 } else if (rc == NGX_DECLINED) {
|
|
2608 rc = -1;
|
|
2609 } else {
|
|
2610 return rc;
|
100
|
2611 }
|
|
2612 }
|
|
2613
|
|
2614 if ((rc == 0 && !negative) || (rc != 0 && negative)) {
|
58
|
2615 ctx->output = 1;
|
178
|
2616 ctx->output_chosen = 1;
|
58
|
2617
|
|
2618 } else {
|
|
2619 ctx->output = 0;
|
|
2620 }
|
|
2621
|
178
|
2622 ctx->conditional = NGX_HTTP_SSI_COND_IF;
|
|
2623
|
58
|
2624 return NGX_OK;
|
100
|
2625
|
|
2626 invalid_expression:
|
|
2627
|
|
2628 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
2629 "invalid expression in \"%V\"", expr);
|
|
2630
|
|
2631 return NGX_HTTP_SSI_ERROR;
|
58
|
2632 }
|
|
2633
|
|
2634
|
|
2635 static ngx_int_t
|
|
2636 ngx_http_ssi_else(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2637 ngx_str_t **params)
|
|
2638 {
|
192
|
2639 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2640 "ssi else");
|
|
2641
|
178
|
2642 if (ctx->output_chosen) {
|
|
2643 ctx->output = 0;
|
|
2644 } else {
|
|
2645 ctx->output = 1;
|
|
2646 }
|
|
2647
|
|
2648 ctx->conditional = NGX_HTTP_SSI_COND_ELSE;
|
58
|
2649
|
|
2650 return NGX_OK;
|
|
2651 }
|
|
2652
|
|
2653
|
|
2654 static ngx_int_t
|
|
2655 ngx_http_ssi_endif(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2656 ngx_str_t **params)
|
|
2657 {
|
192
|
2658 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2659 "ssi endif");
|
|
2660
|
58
|
2661 ctx->output = 1;
|
178
|
2662 ctx->output_chosen = 0;
|
|
2663 ctx->conditional = 0;
|
58
|
2664
|
|
2665 return NGX_OK;
|
|
2666 }
|
|
2667
|
|
2668
|
122
|
2669 static ngx_int_t
|
216
|
2670 ngx_http_ssi_block(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2671 ngx_str_t **params)
|
|
2672 {
|
|
2673 ngx_http_ssi_ctx_t *mctx;
|
|
2674 ngx_http_ssi_block_t *bl;
|
|
2675
|
|
2676 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2677 "ssi block");
|
|
2678
|
|
2679 mctx = ngx_http_get_module_ctx(r->main, ngx_http_ssi_filter_module);
|
|
2680
|
|
2681 if (mctx->blocks == NULL) {
|
|
2682 mctx->blocks = ngx_array_create(r->pool, 4,
|
|
2683 sizeof(ngx_http_ssi_block_t));
|
|
2684 if (mctx->blocks == NULL) {
|
|
2685 return NGX_HTTP_SSI_ERROR;
|
|
2686 }
|
|
2687 }
|
|
2688
|
|
2689 bl = ngx_array_push(mctx->blocks);
|
|
2690 if (bl == NULL) {
|
|
2691 return NGX_HTTP_SSI_ERROR;
|
|
2692 }
|
|
2693
|
|
2694 bl->name = *params[NGX_HTTP_SSI_BLOCK_NAME];
|
|
2695 bl->bufs = NULL;
|
|
2696 bl->count = 0;
|
|
2697
|
|
2698 ctx->output = 0;
|
|
2699 ctx->block = 1;
|
|
2700
|
|
2701 return NGX_OK;
|
|
2702 }
|
|
2703
|
|
2704
|
|
2705 static ngx_int_t
|
|
2706 ngx_http_ssi_endblock(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|
2707 ngx_str_t **params)
|
|
2708 {
|
|
2709 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
2710 "ssi endblock");
|
|
2711
|
|
2712 ctx->output = 1;
|
|
2713 ctx->block = 0;
|
|
2714
|
|
2715 return NGX_OK;
|
|
2716 }
|
|
2717
|
|
2718
|
|
2719 static ngx_int_t
|
122
|
2720 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
|
380
|
2721 ngx_http_variable_value_t *v, uintptr_t gmt)
|
58
|
2722 {
|
122
|
2723 ngx_http_ssi_ctx_t *ctx;
|
|
2724 ngx_time_t *tp;
|
|
2725 struct tm tm;
|
|
2726 char buf[NGX_HTTP_SSI_DATE_LEN];
|
|
2727
|
126
|
2728 v->valid = 1;
|
340
|
2729 v->no_cacheable = 0;
|
122
|
2730 v->not_found = 0;
|
58
|
2731
|
112
|
2732 tp = ngx_timeofday();
|
|
2733
|
58
|
2734 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
|
|
2735
|
340
|
2736 if (ctx == NULL
|
|
2737 || (ctx->timefmt.len == sizeof("%s") - 1
|
|
2738 && ctx->timefmt.data[0] == '%' && ctx->timefmt.data[1] == 's'))
|
58
|
2739 {
|
382
|
2740 v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN);
|
122
|
2741 if (v->data == NULL) {
|
|
2742 return NGX_ERROR;
|
58
|
2743 }
|
|
2744
|
564
|
2745 v->len = ngx_sprintf(v->data, "%T", tp->sec) - v->data;
|
206
|
2746
|
122
|
2747 return NGX_OK;
|
58
|
2748 }
|
|
2749
|
|
2750 if (gmt) {
|
112
|
2751 ngx_libc_gmtime(tp->sec, &tm);
|
58
|
2752 } else {
|
112
|
2753 ngx_libc_localtime(tp->sec, &tm);
|
58
|
2754 }
|
|
2755
|
122
|
2756 v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN,
|
|
2757 (char *) ctx->timefmt.data, &tm);
|
|
2758 if (v->len == 0) {
|
|
2759 return NGX_ERROR;
|
58
|
2760 }
|
|
2761
|
382
|
2762 v->data = ngx_pnalloc(r->pool, v->len);
|
122
|
2763 if (v->data == NULL) {
|
|
2764 return NGX_ERROR;
|
58
|
2765 }
|
|
2766
|
122
|
2767 ngx_memcpy(v->data, buf, v->len);
|
|
2768
|
|
2769 return NGX_OK;
|
58
|
2770 }
|
|
2771
|
|
2772
|
|
2773 static ngx_int_t
|
146
|
2774 ngx_http_ssi_preconfiguration(ngx_conf_t *cf)
|
58
|
2775 {
|
146
|
2776 ngx_int_t rc;
|
|
2777 ngx_http_variable_t *var, *v;
|
|
2778 ngx_http_ssi_command_t *cmd;
|
|
2779 ngx_http_ssi_main_conf_t *smcf;
|
58
|
2780
|
|
2781 for (v = ngx_http_ssi_vars; v->name.len; v++) {
|
|
2782 var = ngx_http_add_variable(cf, &v->name, v->flags);
|
|
2783 if (var == NULL) {
|
|
2784 return NGX_ERROR;
|
|
2785 }
|
|
2786
|
186
|
2787 var->get_handler = v->get_handler;
|
58
|
2788 var->data = v->data;
|
|
2789 }
|
|
2790
|
146
|
2791 smcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_ssi_filter_module);
|
|
2792
|
|
2793 for (cmd = ngx_http_ssi_commands; cmd->name.len; cmd++) {
|
|
2794 rc = ngx_hash_add_key(&smcf->commands, &cmd->name, cmd,
|
|
2795 NGX_HASH_READONLY_KEY);
|
|
2796
|
|
2797 if (rc == NGX_OK) {
|
|
2798 continue;
|
|
2799 }
|
|
2800
|
|
2801 if (rc == NGX_BUSY) {
|
|
2802 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
2803 "conflicting SSI command \"%V\"", &cmd->name);
|
|
2804 }
|
|
2805
|
|
2806 return NGX_ERROR;
|
|
2807 }
|
|
2808
|
126
|
2809 return NGX_OK;
|
58
|
2810 }
|
|
2811
|
|
2812
|
46
|
2813 static void *
|
146
|
2814 ngx_http_ssi_create_main_conf(ngx_conf_t *cf)
|
|
2815 {
|
|
2816 ngx_http_ssi_main_conf_t *smcf;
|
|
2817
|
|
2818 smcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_main_conf_t));
|
|
2819 if (smcf == NULL) {
|
496
|
2820 return NULL;
|
146
|
2821 }
|
|
2822
|
|
2823 smcf->commands.pool = cf->pool;
|
|
2824 smcf->commands.temp_pool = cf->temp_pool;
|
|
2825
|
|
2826 if (ngx_hash_keys_array_init(&smcf->commands, NGX_HASH_SMALL) != NGX_OK) {
|
496
|
2827 return NULL;
|
146
|
2828 }
|
|
2829
|
|
2830 return smcf;
|
|
2831 }
|
|
2832
|
|
2833
|
|
2834 static char *
|
|
2835 ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf)
|
|
2836 {
|
|
2837 ngx_http_ssi_main_conf_t *smcf = conf;
|
|
2838
|
|
2839 ngx_hash_init_t hash;
|
|
2840
|
|
2841 hash.hash = &smcf->hash;
|
|
2842 hash.key = ngx_hash_key;
|
|
2843 hash.max_size = 1024;
|
|
2844 hash.bucket_size = ngx_cacheline_size;
|
|
2845 hash.name = "ssi_command_hash";
|
|
2846 hash.pool = cf->pool;
|
|
2847 hash.temp_pool = NULL;
|
|
2848
|
|
2849 if (ngx_hash_init(&hash, smcf->commands.keys.elts,
|
|
2850 smcf->commands.keys.nelts)
|
|
2851 != NGX_OK)
|
|
2852 {
|
|
2853 return NGX_CONF_ERROR;
|
|
2854 }
|
|
2855
|
|
2856 return NGX_CONF_OK;
|
|
2857 }
|
|
2858
|
|
2859
|
|
2860 static void *
|
296
|
2861 ngx_http_ssi_create_loc_conf(ngx_conf_t *cf)
|
46
|
2862 {
|
146
|
2863 ngx_http_ssi_loc_conf_t *slcf;
|
|
2864
|
|
2865 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_loc_conf_t));
|
|
2866 if (slcf == NULL) {
|
496
|
2867 return NULL;
|
46
|
2868 }
|
|
2869
|
76
|
2870 /*
|
|
2871 * set by ngx_pcalloc():
|
|
2872 *
|
394
|
2873 * conf->types = { NULL };
|
|
2874 * conf->types_keys = NULL;
|
76
|
2875 */
|
|
2876
|
146
|
2877 slcf->enable = NGX_CONF_UNSET;
|
|
2878 slcf->silent_errors = NGX_CONF_UNSET;
|
|
2879 slcf->ignore_recycled_buffers = NGX_CONF_UNSET;
|
|
2880
|
|
2881 slcf->min_file_chunk = NGX_CONF_UNSET_SIZE;
|
|
2882 slcf->value_len = NGX_CONF_UNSET_SIZE;
|
|
2883
|
|
2884 return slcf;
|
46
|
2885 }
|
|
2886
|
|
2887
|
|
2888 static char *
|
296
|
2889 ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
46
|
2890 {
|
146
|
2891 ngx_http_ssi_loc_conf_t *prev = parent;
|
|
2892 ngx_http_ssi_loc_conf_t *conf = child;
|
46
|
2893
|
|
2894 ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
|
2895 ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0);
|
58
|
2896 ngx_conf_merge_value(conf->ignore_recycled_buffers,
|
|
2897 prev->ignore_recycled_buffers, 0);
|
46
|
2898
|
|
2899 ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024);
|
666
|
2900 ngx_conf_merge_size_value(conf->value_len, prev->value_len, 255);
|
46
|
2901
|
554
|
2902 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
|
|
2903 &prev->types_keys, &prev->types,
|
394
|
2904 ngx_http_html_default_types)
|
|
2905 != NGX_OK)
|
|
2906 {
|
|
2907 return NGX_CONF_ERROR;
|
76
|
2908 }
|
|
2909
|
46
|
2910 return NGX_CONF_OK;
|
|
2911 }
|
|
2912
|
|
2913
|
|
2914 static ngx_int_t
|
230
|
2915 ngx_http_ssi_filter_init(ngx_conf_t *cf)
|
46
|
2916 {
|
|
2917 ngx_http_next_header_filter = ngx_http_top_header_filter;
|
|
2918 ngx_http_top_header_filter = ngx_http_ssi_header_filter;
|
|
2919
|
|
2920 ngx_http_next_body_filter = ngx_http_top_body_filter;
|
|
2921 ngx_http_top_body_filter = ngx_http_ssi_body_filter;
|
|
2922
|
|
2923 return NGX_OK;
|
|
2924 }
|