comparison src/http/modules/ngx_http_ssi_filter.c @ 126:fcc79370b9a8

nginx-0.0.1-2003-08-06-18:43:50 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 06 Aug 2003 14:43:50 +0000
parents 885ffb8cc32a
children 4cbe22f9907f
comparison
equal deleted inserted replaced
125:885ffb8cc32a 126:fcc79370b9a8
41 { 41 {
42 42
43 } 43 }
44 44
45 45
46 static void ngx_http_ssi_parse() 46 static int ngx_http_ssi_parse()
47 { 47 {
48 for ( ) { 48
49 ctx
50
51 new_hunk = 1;
52 looked = ctx->looked;
53 state = ctx->state;
54
55
56 while (p < h->last) {
57 ch = *p++;
58
49 switch (state) { 59 switch (state) {
60
50 case ssi_start_state: 61 case ssi_start_state:
51 62
63 if (new_hunk) {
64 if (looked) {
65 send looked hunk
66 }
67 new_hunk = 0;
68 }
69
52 /* tight loop */ 70 /* tight loop */
53 while (p < h->last) { 71 for ( ;; ) {
54 if (*p++ == '<') { 72
55 state = ssi_comment_state; 73 if (ch == '<') {
56 length = 1; 74 state = ssi_tag_state;
75 looked = 1;
57 break; 76 break;
58 } 77 }
59 } 78
60 79 if (p < h->last) {
61 /* fall through */ 80 state = ssi_start_state;
62 81 looked = 0;
63 case ssi_comment_state: 82 break;
64 break; 83 }
65 84
85 ch = *p++;
86 }
87
88 break;
89
90 case ssi_tag_state:
91 switch (ch) {
92 case '!':
93 state = ssi_comment0_state;
94 looked = 2;
95 break;
96
97 case '<':
98 break;
99
100 default:
101 state = ssi_start_state;
102 looked = 0;
103 break;
104 }
105
106 break;
107
108 case ssi_comment0_state:
109 switch (ch) {
110 case '-':
111 state = ssi_comment1_state;
112 looked = 3;
113 break;
114
115 case '<':
116 state = ssi_tag_state;
117 looked = 1;
118 break;
119
120 default:
121 state = ssi_start_state;
122 looked = 0;
123 break;
124 }
125
126 break;
127
128 case ssi_comment1_state:
129 switch (ch) {
130 case '-':
131 state = ssi_sharp_state;
132 looked = 4;
133 break;
134
135 case '<':
136 state = ssi_tag_state;
137 looked = 1;
138 break;
139
140 default:
141 state = ssi_start_state;
142 looked = 0;
143 break;
144 }
145
146 break;
147
148 case ssi_sharp_state:
149 switch (ch) {
150 case '#':
151 state = ssi_precommand_state;
152 looked = 0;
153 break;
154
155 case '<':
156 state = ssi_tag_state;
157 looked = 1;
158 break;
159
160 default:
161 state = ssi_start_state;
162 looked = 0;
163 break;
164 }
165
166 break;
167
168 case ssi_precommand_state:
169 switch (ch) {
170 case ' ':
171 case CR:
172 case LF:
173 case '\t':
174 break;
175
176 default:
177 ngx_test_null(ctx->command.data,
178 ngx_palloc(r->pool, NGX_SSI_COMMAND_LEN),
179 NGX_ERROR);
180 ctx->command.data[0] = ch;
181 ctx->command.len = 1;
182 state = ssi_command_state;
183 break;
184 }
185
186 break;
187
188 case ssi_command_state:
189 if ((ch >= 'a' && ch =< 'z') || (ch >= 'A' && ch <= 'Z')
190 || (ch == '_') || (ch >= '0' && ch <= '9'))
191 {
192 ctx->command.data[ctx->command.len++] = ch;
193
194 } else if (ch == ' ' || ch == CR || ch == LF || ch == '\t') {
195 state = ssi_postcommand_state;
196
197 #if 0
198 } else if (ch == '=') {
199 state = ssi_preexpression_state;
200 #endif
201
202 } else {
203 return NGX_SSI_PARSE_INVALID_COMMAND;
204 }
205
206 break;
207
208 case ssi_postcommand_state:
209 switch (ch) {
210 case ' ':
211 case CR:
212 case LF:
213 case '\t':
214 break;
215
216 case '=':
217 state = ssi_preexpression_state;
218 break;
219
220 default:
221 return NGX_SSI_PARSE_INVALID_PARAM;
222 }
223
224 break;
225
226 case ssi_preexpression_state:
227 switch (ch) {
228 case ' ':
229 case CR:
230 case LF:
231 case '\t':
232 break;
233
234 case '"':
235 state = ssi_expression_state;
236 break;
237
238 default:
239 return NGX_SSI_PARSE_INVALID_PARAM;
240 }
241
242 break;
243
244 case ssi_expression_state:
245 switch (ch) {
246 case '\':
247 state = ssi_quote_state;
248 break;
249
250 case '"':
251 state = ssi_expression_state;
252 break;
253
254 default:
255 return NGX_SSI_PARSE_INVALID_PARAM;
256 }
257
258 break;
259
260 case ssi_quote_state:
261 state = ssi_expression_state;
262
263 break;
264
265 }
66 } 266 }
267
268 ctx->state = state;
269 ctx->looked = looked;
270
271 send hunk (size - looked);
272
273 return;
67 } 274 }
68 275
69 276
70 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle) 277 static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle)
71 { 278 {