Exchange the Mongrel parser with the Mongrel2 parser because of licensing issues
[mistral.git] / http11_parser.c
blob870dda40c3bb4514fc54050f622bc3e415328f05
2 #line 1 "http11_parser.rl"
3 /**
5 * Copyright (c) 2010, Zed A. Shaw and Mongrel2 Project Contributors.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * * Neither the name of the Mongrel2 Project, Zed A. Shaw, nor the names
20 * of its contributors may be used to endorse or promote products
21 * derived from this software without specific prior written
22 * permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "http11_parser.h"
38 #include <stdio.h>
39 #include <assert.h>
40 #include <stdlib.h>
41 #include <ctype.h>
42 #include <string.h>
44 #define LEN(AT, FPC) (FPC - buffer - parser->AT)
45 #define MARK(M,FPC) (parser->M = (FPC) - buffer)
46 #define PTR_TO(F) (buffer + parser->F)
48 /** Machine **/
51 #line 165 "http11_parser.rl"
54 /** Data **/
56 #line 57 "http11_parser.c"
57 static const int http_parser_start = 1;
58 static const int http_parser_first_final = 60;
59 static const int http_parser_error = 0;
61 static const int http_parser_en_main = 1;
64 #line 169 "http11_parser.rl"
66 static int apply_element(http_parser *parser, int type, const char *begin, const char *end, int max_length)
68 int len = (int)(end-begin);
69 if(len > max_length) {
70 return(0);
72 if(parser->on_element)
73 parser->on_element(parser->data, type, begin, len);
74 return(1);
79 int http_parser_init(http_parser *parser) {
80 int cs = 0;
82 #line 83 "http11_parser.c"
84 cs = http_parser_start;
87 #line 186 "http11_parser.rl"
88 parser->cs = cs;
89 parser->body_start = 0;
90 parser->content_len = 0;
91 parser->mark = 0;
92 parser->nread = 0;
93 parser->field_len = 0;
94 parser->field_start = 0;
96 return(1);
99 /** exec **/
100 size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len, size_t off)
102 if(len == 0) return 0;
104 const char *p, *pe;
105 int cs = parser->cs;
107 assert(off <= len && "offset past end of buffer");
109 p = buffer+off;
110 pe = buffer+len;
112 assert(pe - p == (int)len - (int)off && "pointers aren't same distance");
115 #line 116 "http11_parser.c"
117 if ( p == pe )
118 goto _test_eof;
119 switch ( cs )
121 case 1:
122 switch( (*p) ) {
123 case 36: goto tr0;
124 case 95: goto tr0;
126 if ( (*p) < 48 ) {
127 if ( 45 <= (*p) && (*p) <= 46 )
128 goto tr0;
129 } else if ( (*p) > 57 ) {
130 if ( 65 <= (*p) && (*p) <= 90 )
131 goto tr0;
132 } else
133 goto tr0;
134 goto st0;
135 st0:
136 cs = 0;
137 goto _out;
138 tr0:
139 #line 52 "http11_parser.rl"
140 {MARK(mark, p); }
141 goto st2;
142 st2:
143 if ( ++p == pe )
144 goto _test_eof2;
145 case 2:
146 #line 147 "http11_parser.c"
147 switch( (*p) ) {
148 case 32: goto tr2;
149 case 36: goto st41;
150 case 95: goto st41;
152 if ( (*p) < 48 ) {
153 if ( 45 <= (*p) && (*p) <= 46 )
154 goto st41;
155 } else if ( (*p) > 57 ) {
156 if ( 65 <= (*p) && (*p) <= 90 )
157 goto st41;
158 } else
159 goto st41;
160 goto st0;
161 tr2:
162 #line 94 "http11_parser.rl"
164 if(!apply_element(parser, REQUEST_METHOD, PTR_TO(mark), p, 1024))
165 {p++; cs = 3; goto _out;}
167 goto st3;
168 st3:
169 if ( ++p == pe )
170 goto _test_eof3;
171 case 3:
172 #line 173 "http11_parser.c"
173 switch( (*p) ) {
174 case 42: goto tr4;
175 case 47: goto tr5;
176 case 104: goto tr6;
178 goto st0;
179 tr4:
180 #line 52 "http11_parser.rl"
181 {MARK(mark, p); }
182 goto st4;
183 st4:
184 if ( ++p == pe )
185 goto _test_eof4;
186 case 4:
187 #line 188 "http11_parser.c"
188 switch( (*p) ) {
189 case 32: goto tr7;
190 case 35: goto tr8;
192 goto st0;
193 tr7:
194 #line 99 "http11_parser.rl"
196 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
197 {p++; cs = 5; goto _out;}
199 goto st5;
200 tr33:
201 #line 52 "http11_parser.rl"
202 {MARK(mark, p); }
203 #line 79 "http11_parser.rl"
205 if(!apply_element(parser, FRAGMENT, PTR_TO(mark), p, 10*1024))
206 {p++; cs = 5; goto _out;}
208 goto st5;
209 tr36:
210 #line 79 "http11_parser.rl"
212 if(!apply_element(parser, FRAGMENT, PTR_TO(mark), p, 10*1024))
213 {p++; cs = 5; goto _out;}
215 goto st5;
216 tr40:
217 #line 89 "http11_parser.rl"
219 if(!apply_element(parser, REQUEST_PATH, PTR_TO(mark), p, 1024))
220 {p++; cs = 5; goto _out;}
222 #line 99 "http11_parser.rl"
224 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
225 {p++; cs = 5; goto _out;}
227 goto st5;
228 tr51:
229 #line 104 "http11_parser.rl"
230 {MARK(query_start, p); }
231 #line 106 "http11_parser.rl"
233 if(!apply_element(parser, QUERY_STRING, PTR_TO(query_start), p, 10*1024))
234 {p++; cs = 5; goto _out;}
236 #line 99 "http11_parser.rl"
238 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
239 {p++; cs = 5; goto _out;}
241 goto st5;
242 tr55:
243 #line 106 "http11_parser.rl"
245 if(!apply_element(parser, QUERY_STRING, PTR_TO(query_start), p, 10*1024))
246 {p++; cs = 5; goto _out;}
248 #line 99 "http11_parser.rl"
250 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
251 {p++; cs = 5; goto _out;}
253 goto st5;
254 st5:
255 if ( ++p == pe )
256 goto _test_eof5;
257 case 5:
258 #line 259 "http11_parser.c"
259 if ( (*p) == 72 )
260 goto tr9;
261 goto st0;
262 tr9:
263 #line 52 "http11_parser.rl"
264 {MARK(mark, p); }
265 goto st6;
266 st6:
267 if ( ++p == pe )
268 goto _test_eof6;
269 case 6:
270 #line 271 "http11_parser.c"
271 if ( (*p) == 84 )
272 goto st7;
273 goto st0;
274 st7:
275 if ( ++p == pe )
276 goto _test_eof7;
277 case 7:
278 if ( (*p) == 84 )
279 goto st8;
280 goto st0;
281 st8:
282 if ( ++p == pe )
283 goto _test_eof8;
284 case 8:
285 if ( (*p) == 80 )
286 goto st9;
287 goto st0;
288 st9:
289 if ( ++p == pe )
290 goto _test_eof9;
291 case 9:
292 if ( (*p) == 47 )
293 goto st10;
294 goto st0;
295 st10:
296 if ( ++p == pe )
297 goto _test_eof10;
298 case 10:
299 if ( (*p) == 49 )
300 goto st11;
301 goto st0;
302 st11:
303 if ( ++p == pe )
304 goto _test_eof11;
305 case 11:
306 if ( (*p) == 46 )
307 goto st12;
308 goto st0;
309 st12:
310 if ( ++p == pe )
311 goto _test_eof12;
312 case 12:
313 if ( 48 <= (*p) && (*p) <= 49 )
314 goto st13;
315 goto st0;
316 st13:
317 if ( ++p == pe )
318 goto _test_eof13;
319 case 13:
320 switch( (*p) ) {
321 case 10: goto tr17;
322 case 13: goto tr18;
324 goto st0;
325 tr17:
326 #line 84 "http11_parser.rl"
328 if(!apply_element(parser, HTTP_VERSION, PTR_TO(mark), p, 10))
329 {p++; cs = 14; goto _out;}
331 goto st14;
332 tr25:
333 #line 60 "http11_parser.rl"
334 { MARK(mark, p); }
335 #line 62 "http11_parser.rl"
337 if(parser->http_field != NULL) {
338 parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
341 goto st14;
342 tr29:
343 #line 62 "http11_parser.rl"
345 if(parser->http_field != NULL) {
346 parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
349 goto st14;
350 st14:
351 if ( ++p == pe )
352 goto _test_eof14;
353 case 14:
354 #line 355 "http11_parser.c"
355 switch( (*p) ) {
356 case 10: goto tr19;
357 case 13: goto st15;
358 case 33: goto tr21;
359 case 124: goto tr21;
360 case 126: goto tr21;
362 if ( (*p) < 45 ) {
363 if ( (*p) > 39 ) {
364 if ( 42 <= (*p) && (*p) <= 43 )
365 goto tr21;
366 } else if ( (*p) >= 35 )
367 goto tr21;
368 } else if ( (*p) > 46 ) {
369 if ( (*p) < 65 ) {
370 if ( 48 <= (*p) && (*p) <= 57 )
371 goto tr21;
372 } else if ( (*p) > 90 ) {
373 if ( 94 <= (*p) && (*p) <= 122 )
374 goto tr21;
375 } else
376 goto tr21;
377 } else
378 goto tr21;
379 goto st0;
380 tr19:
381 #line 111 "http11_parser.rl"
383 parser->body_start = p - buffer + 1;
384 {p++; cs = 60; goto _out;}
386 goto st60;
387 st60:
388 if ( ++p == pe )
389 goto _test_eof60;
390 case 60:
391 #line 392 "http11_parser.c"
392 goto st0;
393 st15:
394 if ( ++p == pe )
395 goto _test_eof15;
396 case 15:
397 if ( (*p) == 10 )
398 goto tr19;
399 goto st0;
400 tr21:
401 #line 55 "http11_parser.rl"
402 { MARK(field_start, p); }
403 goto st16;
404 st16:
405 if ( ++p == pe )
406 goto _test_eof16;
407 case 16:
408 #line 409 "http11_parser.c"
409 switch( (*p) ) {
410 case 33: goto st16;
411 case 58: goto tr23;
412 case 124: goto st16;
413 case 126: goto st16;
415 if ( (*p) < 45 ) {
416 if ( (*p) > 39 ) {
417 if ( 42 <= (*p) && (*p) <= 43 )
418 goto st16;
419 } else if ( (*p) >= 35 )
420 goto st16;
421 } else if ( (*p) > 46 ) {
422 if ( (*p) < 65 ) {
423 if ( 48 <= (*p) && (*p) <= 57 )
424 goto st16;
425 } else if ( (*p) > 90 ) {
426 if ( 94 <= (*p) && (*p) <= 122 )
427 goto st16;
428 } else
429 goto st16;
430 } else
431 goto st16;
432 goto st0;
433 tr23:
434 #line 56 "http11_parser.rl"
436 parser->field_len = LEN(field_start, p);
438 goto st17;
439 tr27:
440 #line 60 "http11_parser.rl"
441 { MARK(mark, p); }
442 goto st17;
443 st17:
444 if ( ++p == pe )
445 goto _test_eof17;
446 case 17:
447 #line 448 "http11_parser.c"
448 switch( (*p) ) {
449 case 10: goto tr25;
450 case 13: goto tr26;
451 case 32: goto tr27;
453 goto tr24;
454 tr24:
455 #line 60 "http11_parser.rl"
456 { MARK(mark, p); }
457 goto st18;
458 st18:
459 if ( ++p == pe )
460 goto _test_eof18;
461 case 18:
462 #line 463 "http11_parser.c"
463 switch( (*p) ) {
464 case 10: goto tr29;
465 case 13: goto tr30;
467 goto st18;
468 tr18:
469 #line 84 "http11_parser.rl"
471 if(!apply_element(parser, HTTP_VERSION, PTR_TO(mark), p, 10))
472 {p++; cs = 19; goto _out;}
474 goto st19;
475 tr26:
476 #line 60 "http11_parser.rl"
477 { MARK(mark, p); }
478 #line 62 "http11_parser.rl"
480 if(parser->http_field != NULL) {
481 parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
484 goto st19;
485 tr30:
486 #line 62 "http11_parser.rl"
488 if(parser->http_field != NULL) {
489 parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
492 goto st19;
493 st19:
494 if ( ++p == pe )
495 goto _test_eof19;
496 case 19:
497 #line 498 "http11_parser.c"
498 if ( (*p) == 10 )
499 goto st14;
500 goto st0;
501 tr8:
502 #line 99 "http11_parser.rl"
504 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
505 {p++; cs = 20; goto _out;}
507 goto st20;
508 tr41:
509 #line 89 "http11_parser.rl"
511 if(!apply_element(parser, REQUEST_PATH, PTR_TO(mark), p, 1024))
512 {p++; cs = 20; goto _out;}
514 #line 99 "http11_parser.rl"
516 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
517 {p++; cs = 20; goto _out;}
519 goto st20;
520 tr52:
521 #line 104 "http11_parser.rl"
522 {MARK(query_start, p); }
523 #line 106 "http11_parser.rl"
525 if(!apply_element(parser, QUERY_STRING, PTR_TO(query_start), p, 10*1024))
526 {p++; cs = 20; goto _out;}
528 #line 99 "http11_parser.rl"
530 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
531 {p++; cs = 20; goto _out;}
533 goto st20;
534 tr56:
535 #line 106 "http11_parser.rl"
537 if(!apply_element(parser, QUERY_STRING, PTR_TO(query_start), p, 10*1024))
538 {p++; cs = 20; goto _out;}
540 #line 99 "http11_parser.rl"
542 if(!apply_element(parser, REQUEST_URI, PTR_TO(mark), p, 12*1024))
543 {p++; cs = 20; goto _out;}
545 goto st20;
546 st20:
547 if ( ++p == pe )
548 goto _test_eof20;
549 case 20:
550 #line 551 "http11_parser.c"
551 switch( (*p) ) {
552 case 32: goto tr33;
553 case 37: goto tr34;
554 case 60: goto st0;
555 case 62: goto st0;
556 case 127: goto st0;
558 if ( (*p) > 31 ) {
559 if ( 34 <= (*p) && (*p) <= 35 )
560 goto st0;
561 } else if ( (*p) >= 0 )
562 goto st0;
563 goto tr32;
564 tr32:
565 #line 52 "http11_parser.rl"
566 {MARK(mark, p); }
567 goto st21;
568 st21:
569 if ( ++p == pe )
570 goto _test_eof21;
571 case 21:
572 #line 573 "http11_parser.c"
573 switch( (*p) ) {
574 case 32: goto tr36;
575 case 37: goto st22;
576 case 60: goto st0;
577 case 62: goto st0;
578 case 127: goto st0;
580 if ( (*p) > 31 ) {
581 if ( 34 <= (*p) && (*p) <= 35 )
582 goto st0;
583 } else if ( (*p) >= 0 )
584 goto st0;
585 goto st21;
586 tr34:
587 #line 52 "http11_parser.rl"
588 {MARK(mark, p); }
589 goto st22;
590 st22:
591 if ( ++p == pe )
592 goto _test_eof22;
593 case 22:
594 #line 595 "http11_parser.c"
595 if ( (*p) < 65 ) {
596 if ( 48 <= (*p) && (*p) <= 57 )
597 goto st23;
598 } else if ( (*p) > 70 ) {
599 if ( 97 <= (*p) && (*p) <= 102 )
600 goto st23;
601 } else
602 goto st23;
603 goto st0;
604 st23:
605 if ( ++p == pe )
606 goto _test_eof23;
607 case 23:
608 if ( (*p) < 65 ) {
609 if ( 48 <= (*p) && (*p) <= 57 )
610 goto st21;
611 } else if ( (*p) > 70 ) {
612 if ( 97 <= (*p) && (*p) <= 102 )
613 goto st21;
614 } else
615 goto st21;
616 goto st0;
617 tr5:
618 #line 52 "http11_parser.rl"
619 {MARK(mark, p); }
620 goto st24;
621 st24:
622 if ( ++p == pe )
623 goto _test_eof24;
624 case 24:
625 #line 626 "http11_parser.c"
626 switch( (*p) ) {
627 case 32: goto tr40;
628 case 34: goto st0;
629 case 35: goto tr41;
630 case 37: goto st25;
631 case 59: goto tr43;
632 case 60: goto st0;
633 case 62: goto st0;
634 case 63: goto tr44;
635 case 127: goto st0;
637 if ( 0 <= (*p) && (*p) <= 31 )
638 goto st0;
639 goto st24;
640 st25:
641 if ( ++p == pe )
642 goto _test_eof25;
643 case 25:
644 if ( (*p) < 65 ) {
645 if ( 48 <= (*p) && (*p) <= 57 )
646 goto st26;
647 } else if ( (*p) > 70 ) {
648 if ( 97 <= (*p) && (*p) <= 102 )
649 goto st26;
650 } else
651 goto st26;
652 goto st0;
653 st26:
654 if ( ++p == pe )
655 goto _test_eof26;
656 case 26:
657 if ( (*p) < 65 ) {
658 if ( 48 <= (*p) && (*p) <= 57 )
659 goto st24;
660 } else if ( (*p) > 70 ) {
661 if ( 97 <= (*p) && (*p) <= 102 )
662 goto st24;
663 } else
664 goto st24;
665 goto st0;
666 tr43:
667 #line 89 "http11_parser.rl"
669 if(!apply_element(parser, REQUEST_PATH, PTR_TO(mark), p, 1024))
670 {p++; cs = 27; goto _out;}
672 goto st27;
673 st27:
674 if ( ++p == pe )
675 goto _test_eof27;
676 case 27:
677 #line 678 "http11_parser.c"
678 switch( (*p) ) {
679 case 32: goto tr7;
680 case 34: goto st0;
681 case 35: goto tr8;
682 case 37: goto st28;
683 case 60: goto st0;
684 case 62: goto st0;
685 case 63: goto st30;
686 case 127: goto st0;
688 if ( 0 <= (*p) && (*p) <= 31 )
689 goto st0;
690 goto st27;
691 st28:
692 if ( ++p == pe )
693 goto _test_eof28;
694 case 28:
695 if ( (*p) < 65 ) {
696 if ( 48 <= (*p) && (*p) <= 57 )
697 goto st29;
698 } else if ( (*p) > 70 ) {
699 if ( 97 <= (*p) && (*p) <= 102 )
700 goto st29;
701 } else
702 goto st29;
703 goto st0;
704 st29:
705 if ( ++p == pe )
706 goto _test_eof29;
707 case 29:
708 if ( (*p) < 65 ) {
709 if ( 48 <= (*p) && (*p) <= 57 )
710 goto st27;
711 } else if ( (*p) > 70 ) {
712 if ( 97 <= (*p) && (*p) <= 102 )
713 goto st27;
714 } else
715 goto st27;
716 goto st0;
717 tr44:
718 #line 89 "http11_parser.rl"
720 if(!apply_element(parser, REQUEST_PATH, PTR_TO(mark), p, 1024))
721 {p++; cs = 30; goto _out;}
723 goto st30;
724 st30:
725 if ( ++p == pe )
726 goto _test_eof30;
727 case 30:
728 #line 729 "http11_parser.c"
729 switch( (*p) ) {
730 case 32: goto tr51;
731 case 34: goto st0;
732 case 35: goto tr52;
733 case 37: goto tr53;
734 case 60: goto st0;
735 case 62: goto st0;
736 case 127: goto st0;
738 if ( 0 <= (*p) && (*p) <= 31 )
739 goto st0;
740 goto tr50;
741 tr50:
742 #line 104 "http11_parser.rl"
743 {MARK(query_start, p); }
744 goto st31;
745 st31:
746 if ( ++p == pe )
747 goto _test_eof31;
748 case 31:
749 #line 750 "http11_parser.c"
750 switch( (*p) ) {
751 case 32: goto tr55;
752 case 34: goto st0;
753 case 35: goto tr56;
754 case 37: goto st32;
755 case 60: goto st0;
756 case 62: goto st0;
757 case 127: goto st0;
759 if ( 0 <= (*p) && (*p) <= 31 )
760 goto st0;
761 goto st31;
762 tr53:
763 #line 104 "http11_parser.rl"
764 {MARK(query_start, p); }
765 goto st32;
766 st32:
767 if ( ++p == pe )
768 goto _test_eof32;
769 case 32:
770 #line 771 "http11_parser.c"
771 if ( (*p) < 65 ) {
772 if ( 48 <= (*p) && (*p) <= 57 )
773 goto st33;
774 } else if ( (*p) > 70 ) {
775 if ( 97 <= (*p) && (*p) <= 102 )
776 goto st33;
777 } else
778 goto st33;
779 goto st0;
780 st33:
781 if ( ++p == pe )
782 goto _test_eof33;
783 case 33:
784 if ( (*p) < 65 ) {
785 if ( 48 <= (*p) && (*p) <= 57 )
786 goto st31;
787 } else if ( (*p) > 70 ) {
788 if ( 97 <= (*p) && (*p) <= 102 )
789 goto st31;
790 } else
791 goto st31;
792 goto st0;
793 tr6:
794 #line 52 "http11_parser.rl"
795 {MARK(mark, p); }
796 goto st34;
797 st34:
798 if ( ++p == pe )
799 goto _test_eof34;
800 case 34:
801 #line 802 "http11_parser.c"
802 if ( (*p) == 116 )
803 goto st35;
804 goto st0;
805 st35:
806 if ( ++p == pe )
807 goto _test_eof35;
808 case 35:
809 if ( (*p) == 116 )
810 goto st36;
811 goto st0;
812 st36:
813 if ( ++p == pe )
814 goto _test_eof36;
815 case 36:
816 if ( (*p) == 112 )
817 goto st37;
818 goto st0;
819 st37:
820 if ( ++p == pe )
821 goto _test_eof37;
822 case 37:
823 if ( (*p) == 58 )
824 goto st38;
825 goto st0;
826 st38:
827 if ( ++p == pe )
828 goto _test_eof38;
829 case 38:
830 switch( (*p) ) {
831 case 32: goto tr7;
832 case 34: goto st0;
833 case 35: goto tr8;
834 case 37: goto st39;
835 case 60: goto st0;
836 case 62: goto st0;
837 case 127: goto st0;
839 if ( 0 <= (*p) && (*p) <= 31 )
840 goto st0;
841 goto st38;
842 st39:
843 if ( ++p == pe )
844 goto _test_eof39;
845 case 39:
846 if ( (*p) < 65 ) {
847 if ( 48 <= (*p) && (*p) <= 57 )
848 goto st40;
849 } else if ( (*p) > 70 ) {
850 if ( 97 <= (*p) && (*p) <= 102 )
851 goto st40;
852 } else
853 goto st40;
854 goto st0;
855 st40:
856 if ( ++p == pe )
857 goto _test_eof40;
858 case 40:
859 if ( (*p) < 65 ) {
860 if ( 48 <= (*p) && (*p) <= 57 )
861 goto st38;
862 } else if ( (*p) > 70 ) {
863 if ( 97 <= (*p) && (*p) <= 102 )
864 goto st38;
865 } else
866 goto st38;
867 goto st0;
868 st41:
869 if ( ++p == pe )
870 goto _test_eof41;
871 case 41:
872 switch( (*p) ) {
873 case 32: goto tr2;
874 case 36: goto st42;
875 case 95: goto st42;
877 if ( (*p) < 48 ) {
878 if ( 45 <= (*p) && (*p) <= 46 )
879 goto st42;
880 } else if ( (*p) > 57 ) {
881 if ( 65 <= (*p) && (*p) <= 90 )
882 goto st42;
883 } else
884 goto st42;
885 goto st0;
886 st42:
887 if ( ++p == pe )
888 goto _test_eof42;
889 case 42:
890 switch( (*p) ) {
891 case 32: goto tr2;
892 case 36: goto st43;
893 case 95: goto st43;
895 if ( (*p) < 48 ) {
896 if ( 45 <= (*p) && (*p) <= 46 )
897 goto st43;
898 } else if ( (*p) > 57 ) {
899 if ( 65 <= (*p) && (*p) <= 90 )
900 goto st43;
901 } else
902 goto st43;
903 goto st0;
904 st43:
905 if ( ++p == pe )
906 goto _test_eof43;
907 case 43:
908 switch( (*p) ) {
909 case 32: goto tr2;
910 case 36: goto st44;
911 case 95: goto st44;
913 if ( (*p) < 48 ) {
914 if ( 45 <= (*p) && (*p) <= 46 )
915 goto st44;
916 } else if ( (*p) > 57 ) {
917 if ( 65 <= (*p) && (*p) <= 90 )
918 goto st44;
919 } else
920 goto st44;
921 goto st0;
922 st44:
923 if ( ++p == pe )
924 goto _test_eof44;
925 case 44:
926 switch( (*p) ) {
927 case 32: goto tr2;
928 case 36: goto st45;
929 case 95: goto st45;
931 if ( (*p) < 48 ) {
932 if ( 45 <= (*p) && (*p) <= 46 )
933 goto st45;
934 } else if ( (*p) > 57 ) {
935 if ( 65 <= (*p) && (*p) <= 90 )
936 goto st45;
937 } else
938 goto st45;
939 goto st0;
940 st45:
941 if ( ++p == pe )
942 goto _test_eof45;
943 case 45:
944 switch( (*p) ) {
945 case 32: goto tr2;
946 case 36: goto st46;
947 case 95: goto st46;
949 if ( (*p) < 48 ) {
950 if ( 45 <= (*p) && (*p) <= 46 )
951 goto st46;
952 } else if ( (*p) > 57 ) {
953 if ( 65 <= (*p) && (*p) <= 90 )
954 goto st46;
955 } else
956 goto st46;
957 goto st0;
958 st46:
959 if ( ++p == pe )
960 goto _test_eof46;
961 case 46:
962 switch( (*p) ) {
963 case 32: goto tr2;
964 case 36: goto st47;
965 case 95: goto st47;
967 if ( (*p) < 48 ) {
968 if ( 45 <= (*p) && (*p) <= 46 )
969 goto st47;
970 } else if ( (*p) > 57 ) {
971 if ( 65 <= (*p) && (*p) <= 90 )
972 goto st47;
973 } else
974 goto st47;
975 goto st0;
976 st47:
977 if ( ++p == pe )
978 goto _test_eof47;
979 case 47:
980 switch( (*p) ) {
981 case 32: goto tr2;
982 case 36: goto st48;
983 case 95: goto st48;
985 if ( (*p) < 48 ) {
986 if ( 45 <= (*p) && (*p) <= 46 )
987 goto st48;
988 } else if ( (*p) > 57 ) {
989 if ( 65 <= (*p) && (*p) <= 90 )
990 goto st48;
991 } else
992 goto st48;
993 goto st0;
994 st48:
995 if ( ++p == pe )
996 goto _test_eof48;
997 case 48:
998 switch( (*p) ) {
999 case 32: goto tr2;
1000 case 36: goto st49;
1001 case 95: goto st49;
1003 if ( (*p) < 48 ) {
1004 if ( 45 <= (*p) && (*p) <= 46 )
1005 goto st49;
1006 } else if ( (*p) > 57 ) {
1007 if ( 65 <= (*p) && (*p) <= 90 )
1008 goto st49;
1009 } else
1010 goto st49;
1011 goto st0;
1012 st49:
1013 if ( ++p == pe )
1014 goto _test_eof49;
1015 case 49:
1016 switch( (*p) ) {
1017 case 32: goto tr2;
1018 case 36: goto st50;
1019 case 95: goto st50;
1021 if ( (*p) < 48 ) {
1022 if ( 45 <= (*p) && (*p) <= 46 )
1023 goto st50;
1024 } else if ( (*p) > 57 ) {
1025 if ( 65 <= (*p) && (*p) <= 90 )
1026 goto st50;
1027 } else
1028 goto st50;
1029 goto st0;
1030 st50:
1031 if ( ++p == pe )
1032 goto _test_eof50;
1033 case 50:
1034 switch( (*p) ) {
1035 case 32: goto tr2;
1036 case 36: goto st51;
1037 case 95: goto st51;
1039 if ( (*p) < 48 ) {
1040 if ( 45 <= (*p) && (*p) <= 46 )
1041 goto st51;
1042 } else if ( (*p) > 57 ) {
1043 if ( 65 <= (*p) && (*p) <= 90 )
1044 goto st51;
1045 } else
1046 goto st51;
1047 goto st0;
1048 st51:
1049 if ( ++p == pe )
1050 goto _test_eof51;
1051 case 51:
1052 switch( (*p) ) {
1053 case 32: goto tr2;
1054 case 36: goto st52;
1055 case 95: goto st52;
1057 if ( (*p) < 48 ) {
1058 if ( 45 <= (*p) && (*p) <= 46 )
1059 goto st52;
1060 } else if ( (*p) > 57 ) {
1061 if ( 65 <= (*p) && (*p) <= 90 )
1062 goto st52;
1063 } else
1064 goto st52;
1065 goto st0;
1066 st52:
1067 if ( ++p == pe )
1068 goto _test_eof52;
1069 case 52:
1070 switch( (*p) ) {
1071 case 32: goto tr2;
1072 case 36: goto st53;
1073 case 95: goto st53;
1075 if ( (*p) < 48 ) {
1076 if ( 45 <= (*p) && (*p) <= 46 )
1077 goto st53;
1078 } else if ( (*p) > 57 ) {
1079 if ( 65 <= (*p) && (*p) <= 90 )
1080 goto st53;
1081 } else
1082 goto st53;
1083 goto st0;
1084 st53:
1085 if ( ++p == pe )
1086 goto _test_eof53;
1087 case 53:
1088 switch( (*p) ) {
1089 case 32: goto tr2;
1090 case 36: goto st54;
1091 case 95: goto st54;
1093 if ( (*p) < 48 ) {
1094 if ( 45 <= (*p) && (*p) <= 46 )
1095 goto st54;
1096 } else if ( (*p) > 57 ) {
1097 if ( 65 <= (*p) && (*p) <= 90 )
1098 goto st54;
1099 } else
1100 goto st54;
1101 goto st0;
1102 st54:
1103 if ( ++p == pe )
1104 goto _test_eof54;
1105 case 54:
1106 switch( (*p) ) {
1107 case 32: goto tr2;
1108 case 36: goto st55;
1109 case 95: goto st55;
1111 if ( (*p) < 48 ) {
1112 if ( 45 <= (*p) && (*p) <= 46 )
1113 goto st55;
1114 } else if ( (*p) > 57 ) {
1115 if ( 65 <= (*p) && (*p) <= 90 )
1116 goto st55;
1117 } else
1118 goto st55;
1119 goto st0;
1120 st55:
1121 if ( ++p == pe )
1122 goto _test_eof55;
1123 case 55:
1124 switch( (*p) ) {
1125 case 32: goto tr2;
1126 case 36: goto st56;
1127 case 95: goto st56;
1129 if ( (*p) < 48 ) {
1130 if ( 45 <= (*p) && (*p) <= 46 )
1131 goto st56;
1132 } else if ( (*p) > 57 ) {
1133 if ( 65 <= (*p) && (*p) <= 90 )
1134 goto st56;
1135 } else
1136 goto st56;
1137 goto st0;
1138 st56:
1139 if ( ++p == pe )
1140 goto _test_eof56;
1141 case 56:
1142 switch( (*p) ) {
1143 case 32: goto tr2;
1144 case 36: goto st57;
1145 case 95: goto st57;
1147 if ( (*p) < 48 ) {
1148 if ( 45 <= (*p) && (*p) <= 46 )
1149 goto st57;
1150 } else if ( (*p) > 57 ) {
1151 if ( 65 <= (*p) && (*p) <= 90 )
1152 goto st57;
1153 } else
1154 goto st57;
1155 goto st0;
1156 st57:
1157 if ( ++p == pe )
1158 goto _test_eof57;
1159 case 57:
1160 switch( (*p) ) {
1161 case 32: goto tr2;
1162 case 36: goto st58;
1163 case 95: goto st58;
1165 if ( (*p) < 48 ) {
1166 if ( 45 <= (*p) && (*p) <= 46 )
1167 goto st58;
1168 } else if ( (*p) > 57 ) {
1169 if ( 65 <= (*p) && (*p) <= 90 )
1170 goto st58;
1171 } else
1172 goto st58;
1173 goto st0;
1174 st58:
1175 if ( ++p == pe )
1176 goto _test_eof58;
1177 case 58:
1178 switch( (*p) ) {
1179 case 32: goto tr2;
1180 case 36: goto st59;
1181 case 95: goto st59;
1183 if ( (*p) < 48 ) {
1184 if ( 45 <= (*p) && (*p) <= 46 )
1185 goto st59;
1186 } else if ( (*p) > 57 ) {
1187 if ( 65 <= (*p) && (*p) <= 90 )
1188 goto st59;
1189 } else
1190 goto st59;
1191 goto st0;
1192 st59:
1193 if ( ++p == pe )
1194 goto _test_eof59;
1195 case 59:
1196 if ( (*p) == 32 )
1197 goto tr2;
1198 goto st0;
1200 _test_eof2: cs = 2; goto _test_eof;
1201 _test_eof3: cs = 3; goto _test_eof;
1202 _test_eof4: cs = 4; goto _test_eof;
1203 _test_eof5: cs = 5; goto _test_eof;
1204 _test_eof6: cs = 6; goto _test_eof;
1205 _test_eof7: cs = 7; goto _test_eof;
1206 _test_eof8: cs = 8; goto _test_eof;
1207 _test_eof9: cs = 9; goto _test_eof;
1208 _test_eof10: cs = 10; goto _test_eof;
1209 _test_eof11: cs = 11; goto _test_eof;
1210 _test_eof12: cs = 12; goto _test_eof;
1211 _test_eof13: cs = 13; goto _test_eof;
1212 _test_eof14: cs = 14; goto _test_eof;
1213 _test_eof60: cs = 60; goto _test_eof;
1214 _test_eof15: cs = 15; goto _test_eof;
1215 _test_eof16: cs = 16; goto _test_eof;
1216 _test_eof17: cs = 17; goto _test_eof;
1217 _test_eof18: cs = 18; goto _test_eof;
1218 _test_eof19: cs = 19; goto _test_eof;
1219 _test_eof20: cs = 20; goto _test_eof;
1220 _test_eof21: cs = 21; goto _test_eof;
1221 _test_eof22: cs = 22; goto _test_eof;
1222 _test_eof23: cs = 23; goto _test_eof;
1223 _test_eof24: cs = 24; goto _test_eof;
1224 _test_eof25: cs = 25; goto _test_eof;
1225 _test_eof26: cs = 26; goto _test_eof;
1226 _test_eof27: cs = 27; goto _test_eof;
1227 _test_eof28: cs = 28; goto _test_eof;
1228 _test_eof29: cs = 29; goto _test_eof;
1229 _test_eof30: cs = 30; goto _test_eof;
1230 _test_eof31: cs = 31; goto _test_eof;
1231 _test_eof32: cs = 32; goto _test_eof;
1232 _test_eof33: cs = 33; goto _test_eof;
1233 _test_eof34: cs = 34; goto _test_eof;
1234 _test_eof35: cs = 35; goto _test_eof;
1235 _test_eof36: cs = 36; goto _test_eof;
1236 _test_eof37: cs = 37; goto _test_eof;
1237 _test_eof38: cs = 38; goto _test_eof;
1238 _test_eof39: cs = 39; goto _test_eof;
1239 _test_eof40: cs = 40; goto _test_eof;
1240 _test_eof41: cs = 41; goto _test_eof;
1241 _test_eof42: cs = 42; goto _test_eof;
1242 _test_eof43: cs = 43; goto _test_eof;
1243 _test_eof44: cs = 44; goto _test_eof;
1244 _test_eof45: cs = 45; goto _test_eof;
1245 _test_eof46: cs = 46; goto _test_eof;
1246 _test_eof47: cs = 47; goto _test_eof;
1247 _test_eof48: cs = 48; goto _test_eof;
1248 _test_eof49: cs = 49; goto _test_eof;
1249 _test_eof50: cs = 50; goto _test_eof;
1250 _test_eof51: cs = 51; goto _test_eof;
1251 _test_eof52: cs = 52; goto _test_eof;
1252 _test_eof53: cs = 53; goto _test_eof;
1253 _test_eof54: cs = 54; goto _test_eof;
1254 _test_eof55: cs = 55; goto _test_eof;
1255 _test_eof56: cs = 56; goto _test_eof;
1256 _test_eof57: cs = 57; goto _test_eof;
1257 _test_eof58: cs = 58; goto _test_eof;
1258 _test_eof59: cs = 59; goto _test_eof;
1260 _test_eof: {}
1261 _out: {}
1264 #line 213 "http11_parser.rl"
1266 assert(p <= pe && "Buffer overflow after parsing.");
1268 if (!http_parser_has_error(parser)) {
1269 parser->cs = cs;
1272 parser->nread += p - (buffer + off);
1274 assert(parser->nread <= len && "nread longer than length");
1275 assert(parser->body_start <= len && "body starts after buffer end");
1276 assert(parser->mark < len && "mark is after buffer end");
1277 assert(parser->field_len <= len && "field has length longer than whole buffer");
1278 assert(parser->field_start < len && "field starts after buffer end");
1280 return(parser->nread);
1283 int http_parser_finish(http_parser *parser)
1285 if (http_parser_has_error(parser) ) {
1286 return -1;
1287 } else if (http_parser_is_finished(parser) ) {
1288 return 1;
1289 } else {
1290 return 0;
1294 int http_parser_has_error(http_parser *parser) {
1295 return parser->cs == http_parser_error;
1298 int http_parser_is_finished(http_parser *parser) {
1299 return parser->cs >= http_parser_first_final;