Skip to content
This repository
Browse code

upgrade http_parser

  • Loading branch information...
commit 4624906e2a97ca1ccf9d3c2865dd2b0d99880650 1 parent 080fa54
ry ry authored
661 deps/http_parser/http_parser.c
... ... @@ -1,8 +1,6 @@
1 1 #line 1 "http_parser.rl"
2 2 /* Copyright (c) 2008, 2009 Ryan Dahl (ry@tinyclouds.org)
3   - *
4   - * Based on Zed Shaw's Mongrel.
5   - * Copyright (c) 2005 Zed A. Shaw
  3 + * Based on Zed Shaw's Mongrel, copyright (c) Zed A. Shaw
6 4 *
7 5 * All rights reserved.
8 6 *
@@ -26,7 +24,7 @@
26 24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 25 */
28 26 #include "http_parser.h"
29   -
  27 +#include <limits.h>
30 28 #include <assert.h>
31 29
32 30 static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
@@ -43,38 +41,50 @@ static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
43 41 #define MIN(a,b) (a < b ? a : b)
44 42 #define NULL (void*)(0)
45 43
  44 +#define MAX_FIELD_SIZE 80*1024
  45 +
46 46 #define REMAINING (pe - p)
47   -#define CALLBACK(FOR) \
48   - if (parser->FOR##_mark && parser->on_##FOR) { \
49   - callback_return_value = \
50   - parser->on_##FOR(parser, parser->FOR##_mark, p - parser->FOR##_mark); \
51   - }
  47 +#define CALLBACK(FOR) \
  48 +do { \
  49 + if (parser->FOR##_mark) { \
  50 + parser->FOR##_size += p - parser->FOR##_mark; \
  51 + if (parser->FOR##_size > MAX_FIELD_SIZE) { \
  52 + parser->buffer_overflow = TRUE; \
  53 + return 0; \
  54 + } \
  55 + if (parser->on_##FOR) { \
  56 + callback_return_value = parser->on_##FOR(parser, \
  57 + parser->FOR##_mark, \
  58 + p - parser->FOR##_mark); \
  59 + } \
  60 + } \
  61 +} while(0)
52 62
53   -#define RESET_PARSER(parser) \
54   - parser->chunk_size = 0; \
55   - parser->eating = 0; \
56   - parser->header_field_mark = NULL; \
57   - parser->header_value_mark = NULL; \
58   - parser->query_string_mark = NULL; \
59   - parser->path_mark = NULL; \
60   - parser->uri_mark = NULL; \
61   - parser->fragment_mark = NULL; \
62   - parser->status_code = 0; \
63   - parser->method = 0; \
64   - parser->transfer_encoding = HTTP_IDENTITY; \
65   - parser->version_major = 0; \
66   - parser->version_minor = 0; \
67   - parser->keep_alive = -1; \
68   - parser->content_length = 0; \
  63 +#define RESET_PARSER(parser) \
  64 + parser->chunk_size = 0; \
  65 + parser->eating = 0; \
  66 + parser->header_field_mark = NULL; \
  67 + parser->header_value_mark = NULL; \
  68 + parser->query_string_mark = NULL; \
  69 + parser->path_mark = NULL; \
  70 + parser->uri_mark = NULL; \
  71 + parser->fragment_mark = NULL; \
  72 + parser->status_code = 0; \
  73 + parser->method = 0; \
  74 + parser->transfer_encoding = HTTP_IDENTITY; \
  75 + parser->version_major = 0; \
  76 + parser->version_minor = 0; \
  77 + parser->keep_alive = -1; \
  78 + parser->content_length = 0; \
69 79 parser->body_read = 0;
70 80
71   -#define END_REQUEST \
72   -do { \
73   - if (parser->on_message_complete) { \
74   - callback_return_value = \
75   - parser->on_message_complete(parser); \
76   - } \
77   - RESET_PARSER(parser); \
  81 +#define END_REQUEST \
  82 +do { \
  83 + if (parser->on_message_complete) { \
  84 + callback_return_value = \
  85 + parser->on_message_complete(parser); \
  86 + } \
  87 + RESET_PARSER(parser); \
78 88 } while (0)
79 89
80 90 #define SKIP_BODY(nskip) \
@@ -98,11 +108,11 @@ do { \
98 108 } \
99 109 } while (0)
100 110
101   -#line 340 "http_parser.rl"
  111 +#line 382 "http_parser.rl"
102 112
103 113
104 114
105   -#line 106 "http_parser.c"
  115 +#line 116 "http_parser.c"
106 116 static const int http_parser_start = 1;
107 117 static const int http_parser_first_final = 267;
108 118 static const int http_parser_error = 0;
@@ -113,20 +123,21 @@ static const int http_parser_en_Requests = 269;
113 123 static const int http_parser_en_Responses = 270;
114 124 static const int http_parser_en_main = 1;
115 125
116   -#line 343 "http_parser.rl"
  126 +#line 385 "http_parser.rl"
117 127
118 128 void
119 129 http_parser_init (http_parser *parser, enum http_parser_type type)
120 130 {
121 131 int cs = 0;
122 132
123   -#line 124 "http_parser.c"
  133 +#line 134 "http_parser.c"
124 134 {
125 135 cs = http_parser_start;
126 136 }
127   -#line 349 "http_parser.rl"
  137 +#line 391 "http_parser.rl"
128 138 parser->cs = cs;
129 139 parser->type = type;
  140 + parser->buffer_overflow = 0;
130 141
131 142 parser->on_message_begin = NULL;
132 143 parser->on_path = NULL;
@@ -167,7 +178,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
167 178 if (parser->uri_mark) parser->uri_mark = buffer;
168 179
169 180
170   -#line 171 "http_parser.c"
  181 +#line 182 "http_parser.c"
171 182 {
172 183 if ( p == pe )
173 184 goto _test_eof;
@@ -460,7 +471,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
460 471 case 1:
461 472 goto tr0;
462 473 tr0:
463   -#line 331 "http_parser.rl"
  474 +#line 373 "http_parser.rl"
464 475 {
465 476 p--;
466 477 if (parser->type == HTTP_REQUEST) {
@@ -474,7 +485,7 @@ case 1:
474 485 if ( ++p == pe )
475 486 goto _test_eof267;
476 487 case 267:
477   -#line 478 "http_parser.c"
  488 +#line 489 "http_parser.c"
478 489 goto st0;
479 490 st0:
480 491 cs = 0;
@@ -495,7 +506,7 @@ case 2:
495 506 goto tr3;
496 507 goto st0;
497 508 tr1:
498   -#line 186 "http_parser.rl"
  509 +#line 229 "http_parser.rl"
499 510 {
500 511 parser->chunk_size *= 16;
501 512 parser->chunk_size += unhex[(int)*p];
@@ -505,7 +516,7 @@ case 2:
505 516 if ( ++p == pe )
506 517 goto _test_eof3;
507 518 case 3:
508   -#line 509 "http_parser.c"
  519 +#line 520 "http_parser.c"
509 520 switch( (*p) ) {
510 521 case 13: goto st4;
511 522 case 48: goto tr1;
@@ -564,7 +575,7 @@ case 6:
564 575 goto st0;
565 576 tr9:
566 577 cs = 268;
567   -#line 203 "http_parser.rl"
  578 +#line 246 "http_parser.rl"
568 579 {
569 580 END_REQUEST;
570 581 if (parser->type == HTTP_REQUEST) {
@@ -578,7 +589,7 @@ case 6:
578 589 if ( ++p == pe )
579 590 goto _test_eof268;
580 591 case 268:
581   -#line 582 "http_parser.c"
  592 +#line 593 "http_parser.c"
582 593 goto st0;
583 594 st7:
584 595 if ( ++p == pe )
@@ -616,7 +627,7 @@ case 8:
616 627 goto st4;
617 628 goto st8;
618 629 tr3:
619   -#line 186 "http_parser.rl"
  630 +#line 229 "http_parser.rl"
620 631 {
621 632 parser->chunk_size *= 16;
622 633 parser->chunk_size += unhex[(int)*p];
@@ -626,7 +637,7 @@ case 8:
626 637 if ( ++p == pe )
627 638 goto _test_eof9;
628 639 case 9:
629   -#line 630 "http_parser.c"
  640 +#line 641 "http_parser.c"
630 641 switch( (*p) ) {
631 642 case 13: goto st10;
632 643 case 59: goto st14;
@@ -653,7 +664,7 @@ case 10:
653 664 case 11:
654 665 goto tr14;
655 666 tr14:
656   -#line 191 "http_parser.rl"
  667 +#line 234 "http_parser.rl"
657 668 {
658 669 SKIP_BODY(MIN(parser->chunk_size, REMAINING));
659 670 if (callback_return_value != 0) {p++; cs = 12; goto _out;}
@@ -670,7 +681,7 @@ case 11:
670 681 if ( ++p == pe )
671 682 goto _test_eof12;
672 683 case 12:
673   -#line 674 "http_parser.c"
  684 +#line 685 "http_parser.c"
674 685 if ( (*p) == 13 )
675 686 goto st13;
676 687 goto st0;
@@ -863,14 +874,14 @@ case 19:
863 874 goto st0;
864 875 tr45:
865 876 cs = 269;
866   -#line 146 "http_parser.rl"
  877 +#line 185 "http_parser.rl"
867 878 {
868 879 if(parser->on_headers_complete) {
869 880 callback_return_value = parser->on_headers_complete(parser);
870 881 if (callback_return_value != 0) {p++; goto _out;}
871 882 }
872 883 }
873   -#line 212 "http_parser.rl"
  884 +#line 255 "http_parser.rl"
874 885 {
875 886 if (parser->transfer_encoding == HTTP_CHUNKED) {
876 887 cs = 2;
@@ -893,7 +904,7 @@ case 19:
893 904 if ( ++p == pe )
894 905 goto _test_eof269;
895 906 case 269:
896   -#line 897 "http_parser.c"
  907 +#line 908 "http_parser.c"
897 908 switch( (*p) ) {
898 909 case 67: goto tr311;
899 910 case 68: goto tr312;
@@ -908,7 +919,7 @@ case 269:
908 919 }
909 920 goto st0;
910 921 tr311:
911   -#line 153 "http_parser.rl"
  922 +#line 192 "http_parser.rl"
912 923 {
913 924 if(parser->on_message_begin) {
914 925 callback_return_value = parser->on_message_begin(parser);
@@ -920,7 +931,7 @@ case 269:
920 931 if ( ++p == pe )
921 932 goto _test_eof20;
922 933 case 20:
923   -#line 924 "http_parser.c"
  934 +#line 935 "http_parser.c"
924 935 if ( (*p) == 79 )
925 936 goto st21;
926 937 goto st0;
@@ -946,66 +957,66 @@ case 23:
946 957 goto tr24;
947 958 goto st0;
948 959 tr24:
949   -#line 256 "http_parser.rl"
  960 +#line 298 "http_parser.rl"
950 961 { parser->method = HTTP_COPY; }
951 962 goto st24;
952 963 tr154:
953   -#line 257 "http_parser.rl"
  964 +#line 299 "http_parser.rl"
954 965 { parser->method = HTTP_DELETE; }
955 966 goto st24;
956 967 tr157:
957   -#line 258 "http_parser.rl"
  968 +#line 300 "http_parser.rl"
958 969 { parser->method = HTTP_GET; }
959 970 goto st24;
960 971 tr161:
961   -#line 259 "http_parser.rl"
  972 +#line 301 "http_parser.rl"
962 973 { parser->method = HTTP_HEAD; }
963 974 goto st24;
964 975 tr165:
965   -#line 260 "http_parser.rl"
  976 +#line 302 "http_parser.rl"
966 977 { parser->method = HTTP_LOCK; }
967 978 goto st24;
968 979 tr171:
969   -#line 261 "http_parser.rl"
  980 +#line 303 "http_parser.rl"
970 981 { parser->method = HTTP_MKCOL; }
971 982 goto st24;
972 983 tr174:
973   -#line 262 "http_parser.rl"
  984 +#line 304 "http_parser.rl"
974 985 { parser->method = HTTP_MOVE; }
975 986 goto st24;
976 987 tr181:
977   -#line 263 "http_parser.rl"
  988 +#line 305 "http_parser.rl"
978 989 { parser->method = HTTP_OPTIONS; }
979 990 goto st24;
980 991 tr187:
981   -#line 264 "http_parser.rl"
  992 +#line 306 "http_parser.rl"
982 993 { parser->method = HTTP_POST; }
983 994 goto st24;
984 995 tr195:
985   -#line 265 "http_parser.rl"
  996 +#line 307 "http_parser.rl"
986 997 { parser->method = HTTP_PROPFIND; }
987 998 goto st24;
988 999 tr200:
989   -#line 266 "http_parser.rl"
  1000 +#line 308 "http_parser.rl"
990 1001 { parser->method = HTTP_PROPPATCH; }
991 1002 goto st24;
992 1003 tr202:
993   -#line 267 "http_parser.rl"
  1004 +#line 309 "http_parser.rl"
994 1005 { parser->method = HTTP_PUT; }
995 1006 goto st24;
996 1007 tr207:
997   -#line 268 "http_parser.rl"
  1008 +#line 310 "http_parser.rl"
998 1009 { parser->method = HTTP_TRACE; }
999 1010 goto st24;
1000 1011 tr213:
1001   -#line 269 "http_parser.rl"
  1012 +#line 311 "http_parser.rl"
1002 1013 { parser->method = HTTP_UNLOCK; }
1003 1014 goto st24;
1004 1015 st24:
1005 1016 if ( ++p == pe )
1006 1017 goto _test_eof24;
1007 1018 case 24:
1008   -#line 1009 "http_parser.c"
  1019 +#line 1020 "http_parser.c"
1009 1020 switch( (*p) ) {
1010 1021 case 42: goto tr25;
1011 1022 case 43: goto tr26;
@@ -1022,94 +1033,112 @@ case 24:
1022 1033 goto tr26;
1023 1034 goto st0;
1024 1035 tr25:
1025   -#line 108 "http_parser.rl"
1026   - { parser->uri_mark = p; }
  1036 +#line 138 "http_parser.rl"
  1037 + {
  1038 + parser->uri_mark = p;
  1039 + parser->uri_size = 0;
  1040 + }
1027 1041 goto st25;
1028 1042 st25:
1029 1043 if ( ++p == pe )
1030 1044 goto _test_eof25;
1031 1045 case 25:
1032   -#line 1033 "http_parser.c"
  1046 +#line 1047 "http_parser.c"
1033 1047 switch( (*p) ) {
1034 1048 case 32: goto tr29;
1035 1049 case 35: goto tr30;
1036 1050 }
1037 1051 goto st0;
1038 1052 tr29:
1039   -#line 122 "http_parser.rl"
  1053 +#line 157 "http_parser.rl"
1040 1054 {
1041 1055 CALLBACK(uri);
1042 1056 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1043 1057 parser->uri_mark = NULL;
  1058 + parser->uri_size = 0;
1044 1059 }
1045 1060 goto st26;
1046 1061 tr124:
1047   -#line 105 "http_parser.rl"
1048   - { parser->fragment_mark = p; }
1049   -#line 128 "http_parser.rl"
  1062 +#line 123 "http_parser.rl"
  1063 + {
  1064 + parser->fragment_mark = p;
  1065 + parser->fragment_size = 0;
  1066 + }
  1067 +#line 164 "http_parser.rl"
1050 1068 {
1051 1069 CALLBACK(fragment);
1052 1070 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1053 1071 parser->fragment_mark = NULL;
  1072 + parser->fragment_size = 0;
1054 1073 }
1055 1074 goto st26;
1056 1075 tr127:
1057   -#line 128 "http_parser.rl"
  1076 +#line 164 "http_parser.rl"
1058 1077 {
1059 1078 CALLBACK(fragment);
1060 1079 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1061 1080 parser->fragment_mark = NULL;
  1081 + parser->fragment_size = 0;
1062 1082 }
1063 1083 goto st26;
1064 1084 tr135:
1065   -#line 140 "http_parser.rl"
  1085 +#line 178 "http_parser.rl"
1066 1086 {
1067 1087 CALLBACK(path);
1068 1088 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1069 1089 parser->path_mark = NULL;
  1090 + parser->path_size = 0;
1070 1091 }
1071   -#line 122 "http_parser.rl"
  1092 +#line 157 "http_parser.rl"
1072 1093 {
1073 1094 CALLBACK(uri);
1074 1095 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1075 1096 parser->uri_mark = NULL;
  1097 + parser->uri_size = 0;
1076 1098 }
1077 1099 goto st26;
1078 1100 tr141:
1079   -#line 106 "http_parser.rl"
1080   - { parser->query_string_mark = p; }
1081   -#line 134 "http_parser.rl"
  1101 +#line 128 "http_parser.rl"
  1102 + {
  1103 + parser->query_string_mark = p;
  1104 + parser->query_string_size = 0;
  1105 + }
  1106 +#line 171 "http_parser.rl"
1082 1107 {
1083 1108 CALLBACK(query_string);
1084 1109 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1085 1110 parser->query_string_mark = NULL;
  1111 + parser->query_string_size = 0;
1086 1112 }
1087   -#line 122 "http_parser.rl"
  1113 +#line 157 "http_parser.rl"
1088 1114 {
1089 1115 CALLBACK(uri);
1090 1116 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1091 1117 parser->uri_mark = NULL;
  1118 + parser->uri_size = 0;
1092 1119 }
1093 1120 goto st26;
1094 1121 tr145:
1095   -#line 134 "http_parser.rl"
  1122 +#line 171 "http_parser.rl"
1096 1123 {
1097 1124 CALLBACK(query_string);
1098 1125 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1099 1126 parser->query_string_mark = NULL;
  1127 + parser->query_string_size = 0;
1100 1128 }
1101   -#line 122 "http_parser.rl"
  1129 +#line 157 "http_parser.rl"
1102 1130 {
1103 1131 CALLBACK(uri);
1104 1132 if (callback_return_value != 0) {p++; cs = 26; goto _out;}
1105 1133 parser->uri_mark = NULL;
  1134 + parser->uri_size = 0;
1106 1135 }
1107 1136 goto st26;
1108 1137 st26:
1109 1138 if ( ++p == pe )
1110 1139 goto _test_eof26;
1111 1140 case 26:
1112   -#line 1113 "http_parser.c"
  1141 +#line 1142 "http_parser.c"
1113 1142 if ( (*p) == 72 )
1114 1143 goto st27;
1115 1144 goto st0;
@@ -1149,7 +1178,7 @@ case 31:
1149 1178 goto tr36;
1150 1179 goto st0;
1151 1180 tr36:
1152   -#line 176 "http_parser.rl"
  1181 +#line 219 "http_parser.rl"
1153 1182 {
1154 1183 parser->version_major *= 10;
1155 1184 parser->version_major += *p - '0';
@@ -1159,11 +1188,9 @@ case 31:
1159 1188 if ( ++p == pe )
1160 1189 goto _test_eof32;
1161 1190 case 32:
1162   -#line 1163 "http_parser.c"
  1191 +#line 1192 "http_parser.c"
1163 1192 if ( (*p) == 46 )
1164 1193 goto st33;
1165   - if ( 48 <= (*p) && (*p) <= 57 )
1166   - goto tr36;
1167 1194 goto st0;
1168 1195 st33:
1169 1196 if ( ++p == pe )
@@ -1173,7 +1200,7 @@ case 33:
1173 1200 goto tr38;
1174 1201 goto st0;
1175 1202 tr38:
1176   -#line 181 "http_parser.rl"
  1203 +#line 224 "http_parser.rl"
1177 1204 {
1178 1205 parser->version_minor *= 10;
1179 1206 parser->version_minor += *p - '0';
@@ -1183,65 +1210,71 @@ case 33:
1183 1210 if ( ++p == pe )
1184 1211 goto _test_eof34;
1185 1212 case 34:
1186   -#line 1187 "http_parser.c"
  1213 +#line 1214 "http_parser.c"
1187 1214 if ( (*p) == 13 )
1188 1215 goto st35;
1189   - if ( 48 <= (*p) && (*p) <= 57 )
1190   - goto tr38;
1191 1216 goto st0;
1192 1217 tr49:
1193   -#line 104 "http_parser.rl"
1194   - { parser->header_value_mark = p; }
1195   -#line 116 "http_parser.rl"
  1218 +#line 118 "http_parser.rl"
  1219 + {
  1220 + parser->header_value_mark = p;
  1221 + parser->header_value_size = 0;
  1222 + }
  1223 +#line 150 "http_parser.rl"
1196 1224 {
1197 1225 CALLBACK(header_value);
1198 1226 if (callback_return_value != 0) {p++; cs = 35; goto _out;}
1199 1227 parser->header_value_mark = NULL;
  1228 + parser->header_value_size = 0;
1200 1229 }
1201 1230 goto st35;
1202 1231 tr52:
1203   -#line 116 "http_parser.rl"
  1232 +#line 150 "http_parser.rl"
1204 1233 {
1205 1234 CALLBACK(header_value);
1206 1235 if (callback_return_value != 0) {p++; cs = 35; goto _out;}
1207 1236 parser->header_value_mark = NULL;
  1237 + parser->header_value_size = 0;
1208 1238 }
1209 1239 goto st35;
1210 1240 tr71:
1211   -#line 174 "http_parser.rl"
  1241 +#line 217 "http_parser.rl"
1212 1242 { parser->keep_alive = FALSE; }
1213   -#line 116 "http_parser.rl"
  1243 +#line 150 "http_parser.rl"
1214 1244 {
1215 1245 CALLBACK(header_value);
1216 1246 if (callback_return_value != 0) {p++; cs = 35; goto _out;}
1217 1247 parser->header_value_mark = NULL;
  1248 + parser->header_value_size = 0;
1218 1249 }
1219 1250 goto st35;
1220 1251 tr81:
1221   -#line 173 "http_parser.rl"
  1252 +#line 216 "http_parser.rl"
1222 1253 { parser->keep_alive = TRUE; }
1223   -#line 116 "http_parser.rl"
  1254 +#line 150 "http_parser.rl"
1224 1255 {
1225 1256 CALLBACK(header_value);
1226 1257 if (callback_return_value != 0) {p++; cs = 35; goto _out;}
1227 1258 parser->header_value_mark = NULL;
  1259 + parser->header_value_size = 0;
1228 1260 }
1229 1261 goto st35;
1230 1262 tr122:
1231   -#line 170 "http_parser.rl"
  1263 +#line 213 "http_parser.rl"
1232 1264 { parser->transfer_encoding = HTTP_IDENTITY; }
1233   -#line 116 "http_parser.rl"
  1265 +#line 150 "http_parser.rl"
1234 1266 {
1235 1267 CALLBACK(header_value);
1236 1268 if (callback_return_value != 0) {p++; cs = 35; goto _out;}
1237 1269 parser->header_value_mark = NULL;
  1270 + parser->header_value_size = 0;
1238 1271 }
1239 1272 goto st35;
1240 1273 st35:
1241 1274 if ( ++p == pe )
1242 1275 goto _test_eof35;
1243 1276 case 35:
1244   -#line 1245 "http_parser.c"
  1277 +#line 1278 "http_parser.c"
1245 1278 if ( (*p) == 10 )
1246 1279 goto st36;
1247 1280 goto st0;
@@ -1285,14 +1318,17 @@ case 37:
1285 1318 goto tr45;
1286 1319 goto st0;
1287 1320 tr42:
1288   -#line 103 "http_parser.rl"
1289   - { parser->header_field_mark = p; }
  1321 +#line 113 "http_parser.rl"
  1322 + {
  1323 + parser->header_field_mark = p;
  1324 + parser->header_field_size = 0;
  1325 + }
1290 1326 goto st38;
1291 1327 st38:
1292 1328 if ( ++p == pe )
1293 1329 goto _test_eof38;
1294 1330 case 38:
1295   -#line 1296 "http_parser.c"
  1331 +#line 1332 "http_parser.c"
1296 1332 switch( (*p) ) {
1297 1333 case 33: goto st38;
1298 1334 case 58: goto tr47;
@@ -1318,44 +1354,51 @@ case 38:
1318 1354 goto st38;
1319 1355 goto st0;
1320 1356 tr47:
1321   -#line 110 "http_parser.rl"
  1357 +#line 143 "http_parser.rl"
1322 1358 {
1323 1359 CALLBACK(header_field);
1324 1360 if (callback_return_value != 0) {p++; cs = 39; goto _out;}
1325 1361 parser->header_field_mark = NULL;
  1362 + parser->header_field_size = 0;
1326 1363 }
1327 1364 goto st39;
1328 1365 st39:
1329 1366 if ( ++p == pe )
1330 1367 goto _test_eof39;
1331 1368 case 39:
1332   -#line 1333 "http_parser.c"
  1369 +#line 1370 "http_parser.c"
1333 1370 switch( (*p) ) {
1334 1371 case 13: goto tr49;
1335 1372 case 32: goto st39;
1336 1373 }
1337 1374 goto tr48;
1338 1375 tr48:
1339   -#line 104 "http_parser.rl"
1340   - { parser->header_value_mark = p; }
  1376 +#line 118 "http_parser.rl"
  1377 + {
  1378 + parser->header_value_mark = p;
  1379 + parser->header_value_size = 0;
  1380 + }
1341 1381 goto st40;
1342 1382 st40:
1343 1383 if ( ++p == pe )
1344 1384 goto _test_eof40;
1345 1385 case 40:
1346   -#line 1347 "http_parser.c"
  1386 +#line 1387 "http_parser.c"
1347 1387 if ( (*p) == 13 )
1348 1388 goto tr52;
1349 1389 goto st40;
1350 1390 tr43:
1351   -#line 103 "http_parser.rl"
1352   - { parser->header_field_mark = p; }
  1391 +#line 113 "http_parser.rl"
  1392 + {
  1393 + parser->header_field_mark = p;
  1394 + parser->header_field_size = 0;
  1395 + }
1353 1396 goto st41;
1354 1397 st41:
1355 1398 if ( ++p == pe )
1356 1399 goto _test_eof41;
1357 1400 case 41:
1358   -#line 1359 "http_parser.c"
  1401 +#line 1402 "http_parser.c"
1359 1402 switch( (*p) ) {
1360 1403 case 33: goto st38;
1361 1404 case 58: goto tr47;
@@ -1653,18 +1696,19 @@ case 50:
1653 1696 goto st38;
1654 1697 goto st0;
1655 1698 tr63:
1656   -#line 110 "http_parser.rl"
  1699 +#line 143 "http_parser.rl"
1657 1700 {
1658 1701 CALLBACK(header_field);
1659 1702 if (callback_return_value != 0) {p++; cs = 51; goto _out;}
1660 1703 parser->header_field_mark = NULL;
  1704 + parser->header_field_size = 0;
1661 1705 }
1662 1706 goto st51;
1663 1707 st51:
1664 1708 if ( ++p == pe )
1665 1709 goto _test_eof51;
1666 1710 case 51:
1667   -#line 1668 "http_parser.c"
  1711 +#line 1712 "http_parser.c"
1668 1712 switch( (*p) ) {
1669 1713 case 13: goto tr49;
1670 1714 case 32: goto st51;
@@ -1675,14 +1719,17 @@ case 51:
1675 1719 }
1676 1720 goto tr48;
1677 1721 tr65:
1678   -#line 104 "http_parser.rl"
1679   - { parser->header_value_mark = p; }
  1722 +#line 118 "http_parser.rl"
  1723 + {
  1724 + parser->header_value_mark = p;
  1725 + parser->header_value_size = 0;
  1726 + }
1680 1727 goto st52;
1681 1728 st52:
1682 1729 if ( ++p == pe )
1683 1730 goto _test_eof52;
1684 1731 case 52:
1685   -#line 1686 "http_parser.c"
  1732 +#line 1733 "http_parser.c"
1686 1733 switch( (*p) ) {
1687 1734 case 13: goto tr52;
1688 1735 case 76: goto st53;
@@ -1727,14 +1774,17 @@ case 56:
1727 1774 goto tr71;
1728 1775 goto st40;
1729 1776 tr66:
1730   -#line 104 "http_parser.rl"
1731   - { parser->header_value_mark = p; }
  1777 +#line 118 "http_parser.rl"
  1778 + {
  1779 + parser->header_value_mark = p;
  1780 + parser->header_value_size = 0;
  1781 + }
1732 1782 goto st57;
1733 1783 st57:
1734 1784 if ( ++p == pe )
1735 1785 goto _test_eof57;
1736 1786 case 57:
1737   -#line 1738 "http_parser.c"
  1787 +#line 1788 "http_parser.c"
1738 1788 switch( (*p) ) {
1739 1789 case 13: goto tr52;
1740 1790 case 69: goto st58;
@@ -2153,18 +2203,19 @@ case 77:
2153 2203 goto st38;
2154 2204 goto st0;
2155 2205 tr92:
2156   -#line 110 "http_parser.rl"
  2206 +#line 143 "http_parser.rl"
2157 2207 {
2158 2208 CALLBACK(header_field);
2159 2209 if (callback_return_value != 0) {p++; cs = 78; goto _out;}
2160 2210 parser->header_field_mark = NULL;
  2211 + parser->header_field_size = 0;
2161 2212 }
2162 2213 goto st78;
2163 2214 st78:
2164 2215 if ( ++p == pe )
2165 2216 goto _test_eof78;
2166 2217 case 78:
2167   -#line 2168 "http_parser.c"
  2218 +#line 2219 "http_parser.c"
2168 2219 switch( (*p) ) {
2169 2220 case 13: goto tr49;
2170 2221 case 32: goto st78;
@@ -2173,17 +2224,28 @@ case 78:
2173 2224 goto tr94;
2174 2225 goto tr48;
2175 2226 tr94:
2176   -#line 160 "http_parser.rl"
  2227 +#line 199 "http_parser.rl"
2177 2228 {
  2229 + if (parser->content_length > INT_MAX) {
  2230 + parser->buffer_overflow = TRUE;
  2231 + return 0;
  2232 + }
2178 2233 parser->content_length *= 10;
2179 2234 parser->content_length += *p - '0';
2180 2235 }
2181   -#line 104 "http_parser.rl"
2182   - { parser->header_value_mark = p; }
  2236 +#line 118 "http_parser.rl"
  2237 + {
  2238 + parser->header_value_mark = p;
  2239 + parser->header_value_size = 0;
  2240 + }
2183 2241 goto st79;
2184 2242 tr95:
2185   -#line 160 "http_parser.rl"
  2243 +#line 199 "http_parser.rl"
2186 2244 {
  2245 + if (parser->content_length > INT_MAX) {
  2246 + parser->buffer_overflow = TRUE;
  2247 + return 0;
  2248 + }
2187 2249 parser->content_length *= 10;
2188 2250 parser->content_length += *p - '0';
2189 2251 }
@@ -2192,21 +2254,24 @@ case 78:
2192 2254 if ( ++p == pe )
2193 2255 goto _test_eof79;
2194 2256 case 79:
2195   -#line 2196 "http_parser.c"
  2257 +#line 2258 "http_parser.c"
2196 2258 if ( (*p) == 13 )
2197 2259 goto tr52;
2198 2260 if ( 48 <= (*p) && (*p) <= 57 )
2199 2261 goto tr95;
2200 2262 goto st40;
2201 2263 tr44:
2202   -#line 103 "http_parser.rl"
2203   - { parser->header_field_mark = p; }
  2264 +#line 113 "http_parser.rl"
  2265 + {
  2266 + parser->header_field_mark = p;
  2267 + parser->header_field_size = 0;
  2268 + }
2204 2269 goto st80;
2205 2270 st80:
2206 2271 if ( ++p == pe )
2207 2272 goto _test_eof80;
2208 2273 case 80:
2209   -#line 2210 "http_parser.c"
  2274 +#line 2275 "http_parser.c"
2210 2275 switch( (*p) ) {
2211 2276 case 33: goto st38;
2212 2277 case 58: goto tr47;
@@ -2709,20 +2774,21 @@ case 96:
2709 2774 goto st38;
2710 2775 goto st0;
2711 2776 tr112:
2712   -#line 171 "http_parser.rl"
  2777 +#line 214 "http_parser.rl"
2713 2778 { parser->transfer_encoding = HTTP_CHUNKED; }
2714   -#line 110 "http_parser.rl"
  2779 +#line 143 "http_parser.rl"
2715 2780 {
2716 2781 CALLBACK(header_field);
2717 2782 if (callback_return_value != 0) {p++; cs = 97; goto _out;}
2718 2783 parser->header_field_mark = NULL;
  2784 + parser->header_field_size = 0;
2719 2785 }
2720 2786 goto st97;
2721 2787 st97:
2722 2788 if ( ++p == pe )
2723 2789 goto _test_eof97;
2724 2790 case 97:
2725   -#line 2726 "http_parser.c"
  2791 +#line 2792 "http_parser.c"
2726 2792 switch( (*p) ) {
2727 2793 case 13: goto tr49;
2728 2794 case 32: goto st97;
@@ -2730,14 +2796,17 @@ case 97:
2730 2796 }
2731 2797 goto tr48;
2732 2798 tr114:
2733   -#line 104 "http_parser.rl"
2734   - { parser->header_value_mark = p; }
  2799 +#line 118 "http_parser.rl"
  2800 + {
  2801 + parser->header_value_mark = p;
  2802 + parser->header_value_size = 0;
  2803 + }
2735 2804 goto st98;
2736 2805 st98:
2737 2806 if ( ++p == pe )
2738 2807 goto _test_eof98;
2739 2808 case 98:
2740   -#line 2741 "http_parser.c"
  2809 +#line 2810 "http_parser.c"
2741 2810 switch( (*p) ) {
2742 2811 case 13: goto tr52;
2743 2812 case 100: goto st99;
@@ -2805,62 +2874,72 @@ case 105:
2805 2874 goto tr122;
2806 2875 goto st40;
2807 2876 tr30:
2808   -#line 122 "http_parser.rl"
  2877 +#line 157 "http_parser.rl"
2809 2878 {
2810 2879 CALLBACK(uri);
2811 2880 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2812 2881 parser->uri_mark = NULL;
  2882 + parser->uri_size = 0;
2813 2883 }
2814 2884 goto st106;
2815 2885 tr136:
2816   -#line 140 "http_parser.rl"
  2886 +#line 178 "http_parser.rl"
2817 2887 {
2818 2888 CALLBACK(path);
2819 2889 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2820 2890 parser->path_mark = NULL;
  2891 + parser->path_size = 0;
2821 2892 }
2822   -#line 122 "http_parser.rl"
  2893 +#line 157 "http_parser.rl"
2823 2894 {
2824 2895 CALLBACK(uri);
2825 2896 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2826 2897 parser->uri_mark = NULL;
  2898 + parser->uri_size = 0;
2827 2899 }
2828 2900 goto st106;
2829 2901 tr142:
2830   -#line 106 "http_parser.rl"
2831   - { parser->query_string_mark = p; }
2832   -#line 134 "http_parser.rl"
  2902 +#line 128 "http_parser.rl"
  2903 + {
  2904 + parser->query_string_mark = p;
  2905 + parser->query_string_size = 0;
  2906 + }
  2907 +#line 171 "http_parser.rl"
2833 2908 {
2834 2909 CALLBACK(query_string);
2835 2910 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2836 2911 parser->query_string_mark = NULL;
  2912 + parser->query_string_size = 0;
2837 2913 }
2838   -#line 122 "http_parser.rl"
  2914 +#line 157 "http_parser.rl"
2839 2915 {
2840 2916 CALLBACK(uri);
2841 2917 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2842 2918 parser->uri_mark = NULL;
  2919 + parser->uri_size = 0;
2843 2920 }
2844 2921 goto st106;
2845 2922 tr146:
2846   -#line 134 "http_parser.rl"
  2923 +#line 171 "http_parser.rl"
2847 2924 {
2848 2925 CALLBACK(query_string);
2849 2926 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2850 2927 parser->query_string_mark = NULL;
  2928 + parser->query_string_size = 0;
2851 2929 }
2852   -#line 122 "http_parser.rl"
  2930 +#line 157 "http_parser.rl"
2853 2931 {
2854 2932 CALLBACK(uri);
2855 2933 if (callback_return_value != 0) {p++; cs = 106; goto _out;}
2856 2934 parser->uri_mark = NULL;
  2935 + parser->uri_size = 0;
2857 2936 }
2858 2937 goto st106;
2859 2938 st106:
2860 2939 if ( ++p == pe )
2861 2940 goto _test_eof106;
2862 2941 case 106:
2863   -#line 2864 "http_parser.c"
  2942 +#line 2943 "http_parser.c"
2864 2943 switch( (*p) ) {
2865 2944 case 32: goto tr124;
2866 2945 case 37: goto tr125;
@@ -2875,14 +2954,17 @@ case 106:
2875 2954 goto st0;
2876 2955 goto tr123;
2877 2956 tr123:
2878   -#line 105 "http_parser.rl"
2879   - { parser->fragment_mark = p; }
  2957 +#line 123 "http_parser.rl"
  2958 + {
  2959 + parser->fragment_mark = p;
  2960 + parser->fragment_size = 0;
  2961 + }
2880 2962 goto st107;
2881 2963 st107:
2882 2964 if ( ++p == pe )
2883 2965 goto _test_eof107;
2884 2966 case 107:
2885   -#line 2886 "http_parser.c"
  2967 +#line 2968 "http_parser.c"
2886 2968 switch( (*p) ) {
2887 2969 case 32: goto tr127;
2888 2970 case 37: goto st108;
@@ -2897,14 +2979,17 @@ case 107:
2897 2979 goto st0;
2898 2980 goto st107;
2899 2981 tr125:
2900   -#line 105 "http_parser.rl"
2901   - { parser->fragment_mark = p; }
  2982 +#line 123 "http_parser.rl"
  2983 + {
  2984 + parser->fragment_mark = p;
  2985 + parser->fragment_size = 0;
  2986 + }
2902 2987 goto st108;
2903 2988 st108:
2904 2989 if ( ++p == pe )
2905 2990 goto _test_eof108;
2906 2991 case 108:
2907   -#line 2908 "http_parser.c"
  2992 +#line 2993 "http_parser.c"
2908 2993 if ( (*p) < 65 ) {
2909 2994 if ( 48 <= (*p) && (*p) <= 57 )
2910 2995 goto st109;
@@ -2928,14 +3013,17 @@ case 109:
2928 3013 goto st107;
2929 3014 goto st0;
2930 3015 tr26:
2931   -#line 108 "http_parser.rl"
2932   - { parser->uri_mark = p; }
  3016 +#line 138 "http_parser.rl"
  3017 + {
  3018 + parser->uri_mark = p;
  3019 + parser->uri_size = 0;
  3020 + }
2933 3021 goto st110;
2934 3022 st110:
2935 3023 if ( ++p == pe )
2936 3024 goto _test_eof110;
2937 3025 case 110:
2938   -#line 2939 "http_parser.c"
  3026 +#line 3027 "http_parser.c"
2939 3027 switch( (*p) ) {
2940 3028 case 43: goto st110;
2941 3029 case 58: goto st111;
@@ -2953,14 +3041,17 @@ case 110:
2953 3041 goto st110;
2954 3042 goto st0;
2955 3043 tr28:
2956   -#line 108 "http_parser.rl"
2957   - { parser->uri_mark = p; }
  3044 +#line 138 "http_parser.rl"
  3045 + {
  3046 + parser->uri_mark = p;
  3047 + parser->uri_size = 0;
  3048 + }
2958 3049 goto st111;
2959 3050 st111:
2960 3051 if ( ++p == pe )
2961 3052 goto _test_eof111;
2962 3053 case 111:
2963   -#line 2964 "http_parser.c"
  3054 +#line 3055 "http_parser.c"
2964 3055 switch( (*p) ) {
2965 3056 case 32: goto tr29;
2966 3057 case 34: goto st0;
@@ -3000,16 +3091,22 @@ case 113:
3000 3091 goto st111;
3001 3092 goto st0;
3002 3093 tr27:
3003   -#line 108 "http_parser.rl"
3004   - { parser->uri_mark = p; }
3005   -#line 107 "http_parser.rl"
3006   - { parser->path_mark = p; }
  3094 +#line 138 "http_parser.rl"
  3095 + {
  3096 + parser->uri_mark = p;
  3097 + parser->uri_size = 0;
  3098 + }
  3099 +#line 133 "http_parser.rl"
  3100 + {
  3101 + parser->path_mark = p;
  3102 + parser->path_size = 0;
  3103 + }
3007 3104 goto st114;
3008 3105 st114:
3009 3106 if ( ++p == pe )
3010 3107 goto _test_eof114;
3011 3108 case 114:
3012   -#line 3013 "http_parser.c"
  3109 +#line 3110 "http_parser.c"
3013 3110 switch( (*p) ) {
3014 3111 case 32: goto tr135;
3015 3112 case 34: goto st0;
@@ -3050,18 +3147,19 @@ case 116:
3050 3147 goto st114;
3051 3148 goto st0;
3052 3149 tr138:
3053   -#line 140 "http_parser.rl"
  3150 +#line 178 "http_parser.rl"
3054 3151 {
3055 3152 CALLBACK(path);
3056 3153 if (callback_return_value != 0) {p++; cs = 117; goto _out;}
3057 3154 parser->path_mark = NULL;
  3155 + parser->path_size = 0;
3058 3156 }
3059 3157 goto st117;
3060 3158 st117:
3061 3159 if ( ++p == pe )
3062 3160 goto _test_eof117;
3063 3161 case 117:
3064   -#line 3065 "http_parser.c"
  3162 +#line 3163 "http_parser.c"
3065 3163 switch( (*p) ) {
3066 3164 case 32: goto tr141;
3067 3165 case 34: goto st0;
@@ -3075,14 +3173,17 @@ case 117:
3075 3173 goto st0;
3076 3174 goto tr140;
3077 3175 tr140:
3078   -#line 106 "http_parser.rl"
3079   - { parser->query_string_mark = p; }
  3176 +#line 128 "http_parser.rl"
  3177 + {
  3178 + parser->query_string_mark = p;
  3179 + parser->query_string_size = 0;
  3180 + }
3080 3181 goto st118;
3081 3182 st118:
3082 3183 if ( ++p == pe )
3083 3184 goto _test_eof118;
3084 3185 case 118:
3085   -#line 3086 "http_parser.c"
  3186 +#line 3187 "http_parser.c"
3086 3187 switch( (*p) ) {
3087 3188 case 32: goto tr145;
3088 3189 case 34: goto st0;
@@ -3096,14 +3197,17 @@ case 118:
3096 3197 goto st0;
3097 3198 goto st118;
3098 3199 tr143:
3099   -#line 106 "http_parser.rl"
3100   - { parser->query_string_mark = p; }
  3200 +#line 128 "http_parser.rl"
  3201 + {
  3202 + parser->query_string_mark = p;
  3203 + parser->query_string_size = 0;
  3204 + }
3101 3205 goto st119;
3102 3206 st119:
3103 3207 if ( ++p == pe )
3104 3208 goto _test_eof119;
3105 3209 case 119:
3106   -#line 3107 "http_parser.c"
  3210 +#line 3211 "http_parser.c"
3107 3211 if ( (*p) < 65 ) {
3108 3212 if ( 48 <= (*p) && (*p) <= 57 )
3109 3213 goto st120;
@@ -3127,7 +3231,7 @@ case 120:
3127 3231 goto st118;
3128 3232 goto st0;
3129 3233 tr312:
3130   -#line 153 "http_parser.rl"
  3234 +#line 192 "http_parser.rl"
3131 3235 {
3132 3236 if(parser->on_message_begin) {
3133 3237 callback_return_value = parser->on_message_begin(parser);
@@ -3139,7 +3243,7 @@ case 120:
3139 3243