Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 565 lines (478 sloc) 11.752 kB
911b447 Update from Google Code SVN
Evan Miller authored
1
72f60ce First commit.
Evan Miller authored
2 #line 1 "ngx_http_zip_parsers.rl"
911b447 Update from Google Code SVN
Evan Miller authored
3 /* Ragel Parser definitions for mod_zip64 */
72f60ce First commit.
Evan Miller authored
4
5 #include "ngx_http_zip_module.h"
6 #include "ngx_http_zip_parsers.h"
7
8 static void
9 ngx_http_zip_file_init(ngx_http_zip_file_t *parsing_file)
10 {
11 parsing_file->uri.data = NULL;
12 parsing_file->uri.len = 0;
13
14 parsing_file->args.data = NULL;
15 parsing_file->args.len = 0;
16
17 parsing_file->filename.data = NULL;
18 parsing_file->filename.len = 0;
46efeae @tony2001 add X-Archive-Charset and Unicode Path extra field
tony2001 authored
19
20 parsing_file->filename_utf8.data = NULL;
21 parsing_file->filename_utf8.len = 0;
72f60ce First commit.
Evan Miller authored
22
23 parsing_file->header_sent = 0;
24 parsing_file->trailer_sent = 0;
25
26 parsing_file->crc32 = 0;
27 parsing_file->size = 0;
911b447 Update from Google Code SVN
Evan Miller authored
28
29 parsing_file->missing_crc32 = 0;
30 parsing_file->need_zip64 = 0;
31 parsing_file->need_zip64_offset = 0;
32 }
33
a1fe308 @evanmiller Fix compile issue for LLVM
authored
34 static char
35 hex_char_value(unsigned char ch) {
911b447 Update from Google Code SVN
Evan Miller authored
36 if ('0' <= ch && ch <= '9')
37 return ch - '0';
38 if ('A' <= ch && ch <= 'F')
39 return ch - 'A' + 10;
40 if ('a' <= ch && ch <= 'f')
41 return ch - 'A' + 10;
42 return 0;
43 }
44
a1fe308 @evanmiller Fix compile issue for LLVM
authored
45 static size_t
46 destructive_url_decode_len(unsigned char* start, unsigned char* end)
911b447 Update from Google Code SVN
Evan Miller authored
47 {
48 unsigned char *read_pos = start, *write_pos = start;
49
50 for (; read_pos < end; read_pos++) {
51 unsigned char ch = *read_pos;
3c69ff5 @dup2 Fixed an issue with "+" in the filename
dup2 authored
52 if (ch == '+')
53 ch = ' ';
911b447 Update from Google Code SVN
Evan Miller authored
54 if (ch == '%' && (read_pos+2 < end)) {
55 ch = 16 * hex_char_value(*(read_pos+1)) + hex_char_value(*(read_pos+2));
56 read_pos += 2;
57 }
58 *(write_pos++) = ch;
59 }
60
61 return write_pos - start;
72f60ce First commit.
Evan Miller authored
62 }
63
911b447 Update from Google Code SVN
Evan Miller authored
64
72f60ce First commit.
Evan Miller authored
65 static ngx_int_t
66 ngx_http_zip_clean_range(ngx_http_zip_range_t *range,
67 int prefix, int suffix, ngx_http_zip_ctx_t *ctx)
68 {
69 if (suffix) {
70 range->end = ctx->archive_size;
71 range->start = ctx->archive_size - range->start;
72 } else if (prefix) {
73 range->end = ctx->archive_size;
74 } else {
75 range->end++;
76 /*
77 * Download Accelerator sends the last byte position
78 * that equals to the file length
79 */
80 if (range->end >= ctx->archive_size) {
81 range->end = ctx->archive_size;
82 }
83 }
84 if (range->start < 0) {
85 return NGX_ERROR;
86 }
87 if (range->start >= ctx->archive_size) {
88 return NGX_ERROR;
89 }
90 return NGX_OK;
91 }
92
93
667da70 @evanmiller Merge branch 'master' of https://github.com/tony2001/mod_zip into ton…
authored
94 #line 95 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
95 static const char _request_actions[] = {
96 0, 1, 1, 1, 2, 1, 3, 1,
97 4, 1, 5, 1, 6, 1, 7, 1,
98 8, 2, 0, 6
99 };
100
101 static const char _request_key_offsets[] = {
102 0, 0, 7, 8, 11, 14, 16, 18,
3d15211 @evanmiller Make final newline optional
authored
103 19, 26, 27, 28, 31
72f60ce First commit.
Evan Miller authored
104 };
105
106 static const char _request_trans_keys[] = {
107 45, 48, 57, 65, 70, 97, 102, 32,
108 32, 48, 57, 32, 48, 57, 32, 63,
3d15211 @evanmiller Make final newline optional
authored
109 32, 63, 32, 32, 48, 57, 65, 70,
110 97, 102, 32, 32, 0, 10, 13, 10,
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
111 13, 45, 48, 57, 65, 70, 97, 102,
112 0
72f60ce First commit.
Evan Miller authored
113 };
114
115 static const char _request_single_lengths[] = {
116 0, 1, 1, 1, 1, 2, 2, 1,
3d15211 @evanmiller Make final newline optional
authored
117 1, 1, 1, 3, 3
72f60ce First commit.
Evan Miller authored
118 };
119
120 static const char _request_range_lengths[] = {
121 0, 3, 0, 1, 1, 0, 0, 0,
3d15211 @evanmiller Make final newline optional
authored
122 3, 0, 0, 0, 3
72f60ce First commit.
Evan Miller authored
123 };
124
125 static const char _request_index_offsets[] = {
126 0, 0, 5, 7, 10, 13, 16, 19,
3d15211 @evanmiller Make final newline optional
authored
127 21, 26, 28, 30, 34
72f60ce First commit.
Evan Miller authored
128 };
129
130 static const char _request_indicies[] = {
131 0, 2, 2, 2, 1, 3, 1, 3,
132 4, 1, 5, 4, 1, 5, 1, 6,
3d15211 @evanmiller Make final newline optional
authored
133 8, 9, 7, 11, 10, 3, 12, 12,
134 12, 1, 1, 13, 15, 14, 1, 17,
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
135 17, 16, 18, 18, 0, 2, 2, 2,
136 1, 0
72f60ce First commit.
Evan Miller authored
137 };
138
139 static const char _request_trans_targs[] = {
3d15211 @evanmiller Make final newline optional
authored
140 2, 0, 8, 3, 4, 5, 6, 6,
141 7, 9, 11, 7, 8, 10, 10, 7,
142 11, 12, 12
72f60ce First commit.
Evan Miller authored
143 };
144
145 static const char _request_trans_actions[] = {
146 17, 0, 17, 0, 9, 0, 1, 0,
3d15211 @evanmiller Make final newline optional
authored
147 3, 3, 13, 0, 11, 5, 0, 7,
148 0, 15, 0
149 };
150
151 static const char _request_eof_actions[] = {
152 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 15, 0
72f60ce First commit.
Evan Miller authored
154 };
155
156 static const int request_start = 1;
157
158 static const int request_en_main = 1;
159
911b447 Update from Google Code SVN
Evan Miller authored
160
667da70 @evanmiller Merge branch 'master' of https://github.com/tony2001/mod_zip into ton…
authored
161 #line 94 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
162
163
164 ngx_int_t
165 ngx_http_zip_parse_request(ngx_http_zip_ctx_t *ctx)
166 {
167 int cs;
168 u_char *p = ctx->unparsed_request->data;
169 u_char *pe = ctx->unparsed_request->data + ctx->unparsed_request->len;
6f71b11 @evanmiller Fix compile error
authored
170 u_char *eof = ctx->unparsed_request->data + ctx->unparsed_request->len;
72f60ce First commit.
Evan Miller authored
171 ngx_http_zip_file_t *parsing_file = NULL;
172
173
9a261a8 @evanmiller Suppress compile warnings
authored
174 #line 175 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
175 {
176 cs = request_start;
177 }
178
9a261a8 @evanmiller Suppress compile warnings
authored
179 #line 180 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
180 {
181 int _klen;
182 unsigned int _trans;
183 const char *_acts;
184 unsigned int _nacts;
185 const char *_keys;
186
187 if ( p == pe )
188 goto _test_eof;
189 if ( cs == 0 )
190 goto _out;
191 _resume:
192 _keys = _request_trans_keys + _request_key_offsets[cs];
193 _trans = _request_index_offsets[cs];
194
195 _klen = _request_single_lengths[cs];
196 if ( _klen > 0 ) {
197 const char *_lower = _keys;
198 const char *_mid;
199 const char *_upper = _keys + _klen - 1;
200 while (1) {
201 if ( _upper < _lower )
202 break;
203
204 _mid = _lower + ((_upper-_lower) >> 1);
205 if ( (*p) < *_mid )
206 _upper = _mid - 1;
207 else if ( (*p) > *_mid )
208 _lower = _mid + 1;
209 else {
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
210 _trans += (unsigned int)(_mid - _keys);
72f60ce First commit.
Evan Miller authored
211 goto _match;
212 }
213 }
214 _keys += _klen;
215 _trans += _klen;
216 }
217
218 _klen = _request_range_lengths[cs];
219 if ( _klen > 0 ) {
220 const char *_lower = _keys;
221 const char *_mid;
222 const char *_upper = _keys + (_klen<<1) - 2;
223 while (1) {
224 if ( _upper < _lower )
225 break;
226
227 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
228 if ( (*p) < _mid[0] )
229 _upper = _mid - 2;
230 else if ( (*p) > _mid[1] )
231 _lower = _mid + 2;
232 else {
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
233 _trans += (unsigned int)((_mid - _keys)>>1);
72f60ce First commit.
Evan Miller authored
234 goto _match;
235 }
236 }
237 _trans += _klen;
238 }
239
240 _match:
241 _trans = _request_indicies[_trans];
242 cs = _request_trans_targs[_trans];
243
244 if ( _request_trans_actions[_trans] == 0 )
245 goto _again;
246
247 _acts = _request_actions + _request_trans_actions[_trans];
248 _nacts = (unsigned int) *_acts++;
249 while ( _nacts-- > 0 )
250 {
251 switch ( *_acts++ )
252 {
253 case 0:
6f71b11 @evanmiller Fix compile error
authored
254 #line 107 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
255 {
256 parsing_file = ngx_array_push(&ctx->files);
257 ngx_http_zip_file_init(parsing_file);
258
259 parsing_file->index = ctx->files.nelts - 1;
260 }
261 break;
262 case 1:
6f71b11 @evanmiller Fix compile error
authored
263 #line 114 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
264 {
265 parsing_file->uri.data = p;
266 parsing_file->uri.len = 1;
267 }
268 break;
269 case 2:
6f71b11 @evanmiller Fix compile error
authored
270 #line 119 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
271 {
911b447 Update from Google Code SVN
Evan Miller authored
272 parsing_file->uri.len = destructive_url_decode_len(parsing_file->uri.data, p);
72f60ce First commit.
Evan Miller authored
273 }
274 break;
275 case 3:
6f71b11 @evanmiller Fix compile error
authored
276 #line 122 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
277 {
278 parsing_file->args.data = p;
279 }
280 break;
281 case 4:
6f71b11 @evanmiller Fix compile error
authored
282 #line 125 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
283 {
284 parsing_file->args.len = p - parsing_file->args.data;
285 }
286 break;
287 case 5:
6f71b11 @evanmiller Fix compile error
authored
288 #line 128 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
289 {
290 parsing_file->size = parsing_file->size * 10 + ((*p) - '0');
291 }
292 break;
293 case 6:
6f71b11 @evanmiller Fix compile error
authored
294 #line 131 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
295 {
296 if ((*p) == '-') {
297 ctx->missing_crc32 = 1;
911b447 Update from Google Code SVN
Evan Miller authored
298 parsing_file->missing_crc32 = 1;
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
299 ngx_crc32_init(parsing_file->crc32);
72f60ce First commit.
Evan Miller authored
300 } else {
301 parsing_file->crc32 *= 16;
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
302 parsing_file->crc32 += ngx_hextoi(p, 1);
72f60ce First commit.
Evan Miller authored
303 }
304 }
305 break;
306 case 7:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
307 #line 141 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
308 {
309 parsing_file->filename.data = p;
310 }
311 break;
312 case 8:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
313 #line 144 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
314 {
315 parsing_file->filename.len = p - parsing_file->filename.data;
316 }
317 break;
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
318 #line 319 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
319 }
320 }
321
322 _again:
323 if ( cs == 0 )
324 goto _out;
325 if ( ++p != pe )
326 goto _resume;
327 _test_eof: {}
3d15211 @evanmiller Make final newline optional
authored
328 if ( p == eof )
329 {
330 const char *__acts = _request_actions + _request_eof_actions[cs];
331 unsigned int __nacts = (unsigned int) *__acts++;
332 while ( __nacts-- > 0 ) {
333 switch ( *__acts++ ) {
334 case 8:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
335 #line 144 "ngx_http_zip_parsers.rl"
3d15211 @evanmiller Make final newline optional
authored
336 {
337 parsing_file->filename.len = p - parsing_file->filename.data;
338 }
339 break;
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
340 #line 341 "ngx_http_zip_parsers.c"
3d15211 @evanmiller Make final newline optional
authored
341 }
342 }
343 }
344
72f60ce First commit.
Evan Miller authored
345 _out: {}
346 }
911b447 Update from Google Code SVN
Evan Miller authored
347
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
348 #line 162 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
349
350
9a261a8 @evanmiller Suppress compile warnings
authored
351 /* suppress warning */
352 (void)request_en_main;
353
4db5ed9 @evanmiller Fix compile error
authored
354 if (cs < 11) {
72f60ce First commit.
Evan Miller authored
355 return NGX_ERROR;
356 }
357
358 ctx->parsed = 1;
359
360 return NGX_OK;
361 }
362
363
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
364 #line 369 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
365 static const char _range_actions[] = {
366 0, 1, 0, 1, 1, 1, 2, 2,
367 0, 1, 2, 3, 1
368 };
369
370 static const char _range_key_offsets[] = {
371 0, 0, 1, 2, 3, 4, 5, 6,
372 9, 11, 14, 17
373 };
374
375 static const char _range_trans_keys[] = {
376 98, 121, 116, 101, 115, 61, 45, 48,
377 57, 48, 57, 45, 48, 57, 44, 48,
378 57, 44, 48, 57, 0
379 };
380
381 static const char _range_single_lengths[] = {
382 0, 1, 1, 1, 1, 1, 1, 1,
383 0, 1, 1, 1
384 };
385
386 static const char _range_range_lengths[] = {
387 0, 0, 0, 0, 0, 0, 0, 1,
388 1, 1, 1, 1
389 };
390
391 static const char _range_index_offsets[] = {
392 0, 0, 2, 4, 6, 8, 10, 12,
393 15, 17, 20, 23
394 };
395
396 static const char _range_trans_targs[] = {
397 2, 0, 3, 0, 4, 0, 5, 0,
398 6, 0, 7, 0, 8, 9, 0, 10,
399 0, 11, 9, 0, 7, 10, 0, 7,
400 11, 0, 0
401 };
402
403 static const char _range_trans_actions[] = {
404 0, 0, 0, 0, 0, 0, 0, 0,
405 0, 0, 0, 0, 1, 7, 0, 10,
406 0, 0, 3, 0, 0, 3, 0, 0,
407 5, 0, 0
408 };
409
410 static const int range_start = 1;
411
412 static const int range_en_main = 1;
413
911b447 Update from Google Code SVN
Evan Miller authored
414
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
415 #line 179 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
416
417
418 ngx_int_t
419 ngx_http_zip_parse_range(ngx_http_request_t *r, ngx_str_t *range_str, ngx_http_zip_ctx_t *ctx)
420 {
421 int cs, prefix = 0, suffix = 0;
422
423 ngx_http_zip_range_t *range = NULL;
424 u_char *p = range_str->data;
425 u_char *pe = range_str->data + range_str->len;
426
427
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
428 #line 433 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
429 {
430 cs = range_start;
431 }
432
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
433 #line 438 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
434 {
435 int _klen;
436 unsigned int _trans;
437 const char *_acts;
438 unsigned int _nacts;
439 const char *_keys;
440
441 if ( p == pe )
442 goto _test_eof;
443 if ( cs == 0 )
444 goto _out;
445 _resume:
446 _keys = _range_trans_keys + _range_key_offsets[cs];
447 _trans = _range_index_offsets[cs];
448
449 _klen = _range_single_lengths[cs];
450 if ( _klen > 0 ) {
451 const char *_lower = _keys;
452 const char *_mid;
453 const char *_upper = _keys + _klen - 1;
454 while (1) {
455 if ( _upper < _lower )
456 break;
457
458 _mid = _lower + ((_upper-_lower) >> 1);
459 if ( (*p) < *_mid )
460 _upper = _mid - 1;
461 else if ( (*p) > *_mid )
462 _lower = _mid + 1;
463 else {
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
464 _trans += (unsigned int)(_mid - _keys);
72f60ce First commit.
Evan Miller authored
465 goto _match;
466 }
467 }
468 _keys += _klen;
469 _trans += _klen;
470 }
471
472 _klen = _range_range_lengths[cs];
473 if ( _klen > 0 ) {
474 const char *_lower = _keys;
475 const char *_mid;
476 const char *_upper = _keys + (_klen<<1) - 2;
477 while (1) {
478 if ( _upper < _lower )
479 break;
480
481 _mid = _lower + (((_upper-_lower) >> 1) & ~1);
482 if ( (*p) < _mid[0] )
483 _upper = _mid - 2;
484 else if ( (*p) > _mid[1] )
485 _lower = _mid + 2;
486 else {
dce4dd4 @devgs Fix: allow one-character filenames
devgs authored
487 _trans += (unsigned int)((_mid - _keys)>>1);
72f60ce First commit.
Evan Miller authored
488 goto _match;
489 }
490 }
491 _trans += _klen;
492 }
493
494 _match:
495 cs = _range_trans_targs[_trans];
496
497 if ( _range_trans_actions[_trans] == 0 )
498 goto _again;
499
500 _acts = _range_actions + _range_trans_actions[_trans];
501 _nacts = (unsigned int) *_acts++;
502 while ( _nacts-- > 0 )
503 {
504 switch ( *_acts++ )
505 {
506 case 0:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
507 #line 191 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
508 {
509 if (range) {
510 if (ngx_http_zip_clean_range(range, prefix, suffix, ctx) == NGX_ERROR) {
511 return NGX_ERROR;
512 }
513 }
514 if ((range = ngx_array_push(&ctx->ranges)) == NULL) {
515 return NGX_ERROR;
516 }
517 range->start = 0; range->end = 0; range->boundary_sent = 0;
518 suffix = 0;
519 prefix = 1;
520 }
521 break;
522 case 1:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
523 #line 205 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
524 { range->start = range->start * 10 + ((*p) - '0'); }
525 break;
526 case 2:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
527 #line 207 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
528 { range->end = range->end * 10 + ((*p) - '0'); prefix = 0; }
529 break;
530 case 3:
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
531 #line 209 "ngx_http_zip_parsers.rl"
72f60ce First commit.
Evan Miller authored
532 { suffix = 1; }
533 break;
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
534 #line 539 "ngx_http_zip_parsers.c"
72f60ce First commit.
Evan Miller authored
535 }
536 }
537
538 _again:
539 if ( cs == 0 )
540 goto _out;
541 if ( ++p != pe )
542 goto _resume;
543 _test_eof: {}
544 _out: {}
545 }
911b447 Update from Google Code SVN
Evan Miller authored
546
4bffd6b @anthonyryan1 Use carton to install modules form cpan
anthonyryan1 authored
547 #line 222 "ngx_http_zip_parsers.rl"
9a261a8 @evanmiller Suppress compile warnings
authored
548
72f60ce First commit.
Evan Miller authored
549
9a261a8 @evanmiller Suppress compile warnings
authored
550 /* suppress warning */
551 (void)range_en_main;
72f60ce First commit.
Evan Miller authored
552
4db5ed9 @evanmiller Fix compile error
authored
553 if (cs < 10) {
72f60ce First commit.
Evan Miller authored
554 return NGX_ERROR;
555 }
556
557 if (range) {
558 if (ngx_http_zip_clean_range(range, prefix, suffix, ctx) == NGX_ERROR) {
559 return NGX_ERROR;
560 }
561 }
562
563 return NGX_OK;
564 }
Something went wrong with that request. Please try again.