comparison src/http/modules/ngx_http_ssi_filter.c @ 127:4cbe22f9907f

nginx-0.0.1-2003-08-07-10:07:49 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 07 Aug 2003 06:07:49 +0000
parents fcc79370b9a8
children 1947c683490f
comparison
equal deleted inserted replaced
126:fcc79370b9a8 127:4cbe22f9907f
35 35
36 static int (*next_header_filter) (ngx_http_request_t *r); 36 static int (*next_header_filter) (ngx_http_request_t *r);
37 static int (*next_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); 37 static int (*next_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
38 38
39 39
40 static comment_string = "<!--";
41
42
40 static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 43 static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
41 { 44 {
42 45
43 } 46 }
44 47
45 48
46 static int ngx_http_ssi_parse() 49
50
51
52
53 static int ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
54 ngx_hunk_t *h)
47 { 55 {
48 56 int looked, state;
49 ctx 57 char *p;
50 58 ngx_hunk_t *temp;
51 new_hunk = 1; 59 ngx_chain_t chain;
60
52 looked = ctx->looked; 61 looked = ctx->looked;
53 state = ctx->state; 62 state = ctx->state;
54 63 p = h->pos;
55 64
56 while (p < h->last) { 65 while (p < h->last) {
57 ch = *p++; 66 ch = *p++;
58 67
59 switch (state) { 68 switch (state) {
60 69
61 case ssi_start_state: 70 case ssi_start_state:
62 71
63 if (new_hunk) { 72 if (ctx->new_hunk) {
73
64 if (looked) { 74 if (looked) {
65 send looked hunk 75 ngx_test_null(temp, ngx_calloc_hunk(r->pool), NGX_ERROR);
66 } 76 temp->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
67 new_hunk = 0; 77 temp->pos = comment_string;
78 temp->last = comment_string + looked;
79
80 chain.hunk = temp;
81 chain.next = NULL;
82
83 if (next_body_filter(r, &chain) == NGX_ERROR) {
84 return NGX_ERROR;
85 }
86 }
87
88 ctx->new_hunk = 0;
68 } 89 }
69 90
70 /* tight loop */ 91 /* tight loop */
71 for ( ;; ) { 92 for ( ;; ) {
72 93
75 looked = 1; 96 looked = 1;
76 break; 97 break;
77 } 98 }
78 99
79 if (p < h->last) { 100 if (p < h->last) {
80 state = ssi_start_state; 101 ctx->state = ssi_start_state;
81 looked = 0; 102 ctx->looked = 0;
82 break; 103 return NGX_HTTP_SSI_DONE;
83 } 104 }
84 105
85 ch = *p++; 106 ch = *p++;
86 } 107 }
87 108
173 case '\t': 194 case '\t':
174 break; 195 break;
175 196
176 default: 197 default:
177 ngx_test_null(ctx->command.data, 198 ngx_test_null(ctx->command.data,
178 ngx_palloc(r->pool, NGX_SSI_COMMAND_LEN), 199 ngx_palloc(r->pool, NGX_HTTP_SSI_COMMAND_LEN),
179 NGX_ERROR); 200 NGX_ERROR);
180 ctx->command.data[0] = ch; 201 ctx->command.data[0] = ch;
181 ctx->command.len = 1; 202 ctx->command.len = 1;
182 state = ssi_command_state; 203 state = ssi_command_state;
183 break; 204 break;
184 } 205 }
185 206
186 break; 207 break;
187 208
188 case ssi_command_state: 209 case ssi_command_state:
189 if ((ch >= 'a' && ch =< 'z') || (ch >= 'A' && ch <= 'Z') 210 switch (ch) {
190 || (ch == '_') || (ch >= '0' && ch <= '9')) 211 case ' ':
191 { 212 case CR:
213 case LF:
214 case '\t':
215 ctx->command.data[ctx->command.len] = 0;
216 state = ssi_preparam_state;
217 break;
218
219 default:
220 if (ctx->command.len >= NGX_HTTP_SSI_COMMAND_LEN) {
221 return NGX_HTTP_SSI_INVALID_COMMAND;
222 }
223
192 ctx->command.data[ctx->command.len++] = ch; 224 ctx->command.data[ctx->command.len++] = ch;
193 225 }
194 } else if (ch == ' ' || ch == CR || ch == LF || ch == '\t') { 226
195 state = ssi_postcommand_state; 227 break;
196 228
197 #if 0 229 case ssi_preparam_state:
198 } else if (ch == '=') { 230 switch (ch) {
199 state = ssi_preexpression_state; 231 case ' ':
200 #endif 232 case CR:
201 233 case LF:
202 } else { 234 case '\t':
203 return NGX_SSI_PARSE_INVALID_COMMAND; 235 break;
204 } 236
205 237 case '-':
206 break; 238 state = ssi_comment_end0_state;
207 239 break;
208 case ssi_postcommand_state: 240
209 switch (ch) { 241 default:
210 case ' ': 242 ngx_test_null(param, ngx_push_array(&ctx->params), NGX_ERROR);
211 case CR: 243
212 case LF: 244 ngx_test_null(param->name.data,
213 case '\t': 245 ngx_palloc(r->pool, NGX_HTTP_SSI_PARAM_LEN),
246 NGX_ERROR);
247 param->name.data[0] = ch;
248 param->name.len = 1;
249
250 ngx_test_null(param->value.data,
251 ngx_palloc(r->pool, NGX_HTTP_SSI_VALUE_LEN),
252 NGX_ERROR);
253 param->value.len = 0;
254
255 state = ssi_param_state;
256 break;
257 }
258
259 break;
260
261 case ssi_param_state:
262 switch (ch) {
263 case ' ':
264 case CR:
265 case LF:
266 case '\t':
267 ctx->param.data[ctx->param.len] = 0;
268 state = ssi_preequal_state;
214 break; 269 break;
215 270
216 case '=': 271 case '=':
217 state = ssi_preexpression_state; 272 ctx->param.data[ctx->param.len] = 0;
218 break; 273 state = ssi_prevalue_state;
219 274 break;
220 default: 275
221 return NGX_SSI_PARSE_INVALID_PARAM; 276 default:
222 } 277 if (ctx->param.len >= NGX_HTTP_SSI_PARAM_LEN) {
223 278 return NGX_HTTP_SSI_INVALID_PARAM;
224 break; 279 }
225 280
226 case ssi_preexpression_state: 281 ctx->param.data[ctx->param.len++] = ch;
282 }
283
284 break;
285
286 case ssi_preequal_state:
287 switch (ch) {
288 case ' ':
289 case CR:
290 case LF:
291 case '\t':
292 break;
293
294 case '=':
295 state = ssi_prevalue_state;
296 break;
297
298 default:
299 return NGX_HTTP_SSI_PARSE_INVALID_PARAM;
300 }
301
302 break;
303
304 case ssi_prevalue_state:
227 switch (ch) { 305 switch (ch) {
228 case ' ': 306 case ' ':
229 case CR: 307 case CR:
230 case LF: 308 case LF:
231 case '\t': 309 case '\t':
232 break; 310 break;
233 311
234 case '"': 312 case '"':
235 state = ssi_expression_state; 313 state = ssi_value_state;
236 break; 314 break;
237 315
238 default: 316 default:
239 return NGX_SSI_PARSE_INVALID_PARAM; 317 return NGX_HTTP_SSI_PARSE_INVALID_PARAM;
240 } 318 }
241 319
242 break; 320 break;
243 321
244 case ssi_expression_state: 322 case ssi_value_state:
245 switch (ch) { 323 switch (ch) {
246 case '\': 324 case '\':
247 state = ssi_quote_state; 325 state = ssi_quote_state;
248 break; 326 break;
249 327
250 case '"': 328 case '"':
251 state = ssi_expression_state; 329 state = ssi_postvalue_state;
252 break; 330 break;
253 331
254 default: 332 default:
255 return NGX_SSI_PARSE_INVALID_PARAM; 333 return NGX_SSI_PARSE_INVALID_PARAM;
256 } 334 }
266 } 344 }
267 345
268 ctx->state = state; 346 ctx->state = state;
269 ctx->looked = looked; 347 ctx->looked = looked;
270 348
271 send hunk (size - looked); 349 return NGX_HTTP_SSI_DONE;
272
273 return;
274 } 350 }
275 351
276 352
277 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle) 353 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle)
278 { 354 {