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