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