#line 1 "parser.rl" /** * Copyright (c) 2005 Zed A. Shaw * You can redistribute it and/or modify it under the same terms as Ruby. */ #include "parser.h" #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define LEN(AT, FPC) (FPC - buffer - parser->AT) #define MARK(M,FPC) (parser->M = (FPC) - buffer) #define PTR_TO(F) (buffer + parser->F) /** machine **/ #line 139 "parser.rl" /** Data **/ #line 25 "parser.c" static const char _http_parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 14, 2, 0, 3, 2, 0, 6, 2, 0, 7, 2, 3, 0, 2, 3, 4, 2, 9, 11, 2, 13, 11, 3, 12, 13, 11 }; static const short _http_parser_key_offsets[] = { 0, 0, 8, 17, 27, 29, 30, 31, 32, 33, 34, 36, 39, 41, 44, 45, 63, 64, 82, 86, 89, 94, 99, 104, 109, 114, 119, 123, 130, 135, 140, 145, 150, 155, 159, 165, 170, 175, 180, 185, 189, 209, 229, 249, 269, 289, 309, 327, 349, 369, 389, 409, 429, 449, 467, 473, 493, 513, 533, 550, 570, 590, 610, 630, 650, 670, 688, 710, 730, 750, 770, 790, 810, 828, 834, 839, 859, 879, 899, 917, 919, 920, 929, 938, 944, 950, 960, 969, 975, 981, 992, 998, 1004, 1014, 1020, 1026, 1035, 1044, 1050, 1056, 1065, 1074, 1083, 1092, 1101, 1110, 1119, 1128, 1137, 1146, 1155, 1164, 1173, 1182, 1191, 1200, 1209, 1218, 1219 }; static const char _http_parser_trans_keys[] = { 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 42, 43, 47, 58, 45, 57, 65, 90, 97, 122, 32, 35, 72, 84, 84, 80, 47, 48, 57, 46, 48, 57, 48, 57, 13, 48, 57, 10, 13, 33, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, 33, 58, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 13, 32, 67, 99, 13, 67, 99, 13, 67, 79, 99, 111, 13, 67, 78, 99, 110, 13, 67, 84, 99, 116, 13, 67, 69, 99, 101, 13, 67, 78, 99, 110, 13, 67, 84, 99, 116, 13, 45, 67, 99, 13, 67, 76, 84, 99, 108, 116, 13, 67, 69, 99, 101, 13, 67, 78, 99, 110, 13, 67, 71, 99, 103, 13, 67, 84, 99, 116, 13, 67, 72, 99, 104, 13, 58, 67, 99, 13, 32, 67, 99, 48, 57, 13, 67, 99, 48, 57, 13, 67, 89, 99, 121, 13, 67, 80, 99, 112, 13, 67, 69, 99, 101, 13, 58, 67, 99, 33, 58, 67, 79, 99, 111, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 45, 46, 58, 67, 99, 124, 126, 35, 39, 42, 43, 48, 57, 65, 90, 94, 122, 33, 58, 67, 76, 84, 99, 108, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 71, 99, 103, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 72, 99, 104, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 13, 32, 67, 99, 48, 57, 33, 58, 67, 89, 99, 121, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 80, 99, 112, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 79, 99, 111, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 45, 46, 58, 67, 99, 124, 126, 35, 39, 42, 43, 48, 57, 65, 90, 94, 122, 33, 58, 67, 76, 84, 99, 108, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 78, 99, 110, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 71, 99, 103, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 84, 99, 116, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 72, 99, 104, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 13, 32, 67, 99, 48, 57, 13, 67, 99, 48, 57, 33, 58, 67, 89, 99, 121, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 80, 99, 112, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 69, 99, 101, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 33, 58, 67, 99, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 13, 32, 13, 32, 37, 60, 62, 127, 0, 31, 34, 35, 32, 37, 60, 62, 127, 0, 31, 34, 35, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 43, 58, 45, 46, 48, 57, 65, 90, 97, 122, 32, 34, 35, 37, 60, 62, 127, 0, 31, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 32, 34, 35, 37, 59, 60, 62, 63, 127, 0, 31, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 32, 34, 35, 37, 60, 62, 63, 127, 0, 31, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 32, 34, 35, 37, 60, 62, 127, 0, 31, 32, 34, 35, 37, 60, 62, 127, 0, 31, 48, 57, 65, 70, 97, 102, 48, 57, 65, 70, 97, 102, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 0 }; static const char _http_parser_single_lengths[] = { 0, 2, 3, 4, 2, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 6, 1, 6, 4, 3, 5, 5, 5, 5, 5, 5, 4, 7, 5, 5, 5, 5, 5, 4, 4, 3, 5, 5, 5, 4, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 6, 4, 8, 8, 8, 5, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 6, 4, 3, 8, 8, 8, 6, 2, 1, 5, 5, 0, 0, 2, 7, 0, 0, 9, 0, 0, 8, 0, 0, 7, 7, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0 }; static const char _http_parser_range_lengths[] = { 0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 6, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 6, 6, 1, 1, 6, 6, 6, 6, 0, 0, 2, 2, 3, 3, 4, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0 }; static const short _http_parser_index_offsets[] = { 0, 0, 6, 13, 21, 24, 26, 28, 30, 32, 34, 36, 39, 41, 44, 46, 59, 61, 74, 79, 83, 89, 95, 101, 107, 113, 119, 124, 132, 138, 144, 150, 156, 162, 167, 173, 178, 184, 190, 196, 201, 216, 231, 246, 261, 276, 291, 305, 322, 337, 352, 367, 382, 397, 410, 416, 431, 446, 461, 473, 488, 503, 518, 533, 548, 563, 577, 594, 609, 624, 639, 654, 669, 682, 688, 693, 708, 723, 738, 751, 754, 756, 764, 772, 776, 780, 787, 796, 800, 804, 815, 819, 823, 833, 837, 841, 850, 859, 863, 867, 874, 881, 888, 895, 902, 909, 916, 923, 930, 937, 944, 951, 958, 965, 972, 979, 986, 993, 995 }; static const unsigned char _http_parser_indicies[] = { 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 1, 4, 5, 6, 7, 5, 5, 5, 1, 8, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 15, 1, 17, 1, 18, 17, 1, 19, 1, 20, 21, 22, 22, 21, 21, 21, 21, 21, 21, 21, 21, 1, 23, 1, 24, 25, 26, 26, 24, 24, 24, 24, 24, 24, 24, 24, 1, 28, 29, 30, 30, 27, 32, 33, 33, 31, 32, 33, 34, 33, 34, 31, 32, 33, 35, 33, 35, 31, 32, 33, 36, 33, 36, 31, 32, 33, 37, 33, 37, 31, 32, 33, 38, 33, 38, 31, 32, 33, 39, 33, 39, 31, 32, 40, 33, 33, 31, 32, 33, 41, 42, 33, 41, 42, 31, 32, 33, 43, 33, 43, 31, 32, 33, 44, 33, 44, 31, 32, 33, 45, 33, 45, 31, 32, 33, 46, 33, 46, 31, 32, 33, 47, 33, 47, 31, 32, 48, 33, 33, 31, 32, 48, 33, 33, 49, 31, 1, 33, 33, 50, 31, 32, 33, 51, 33, 51, 31, 32, 33, 52, 33, 52, 31, 32, 33, 53, 33, 53, 31, 32, 1, 33, 33, 31, 24, 25, 26, 54, 26, 54, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 55, 26, 55, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 56, 26, 56, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 57, 26, 57, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 58, 26, 58, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 59, 26, 59, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 60, 24, 25, 26, 26, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 61, 62, 26, 61, 62, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 63, 26, 63, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 64, 26, 64, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 65, 26, 65, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 66, 26, 66, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 67, 26, 67, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 68, 26, 26, 24, 24, 24, 24, 24, 24, 24, 24, 1, 28, 69, 30, 30, 70, 27, 24, 25, 26, 71, 26, 71, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 72, 26, 72, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 73, 26, 73, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 26, 26, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 74, 26, 74, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 75, 26, 75, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 76, 26, 76, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 77, 26, 77, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 78, 26, 78, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 79, 26, 79, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 80, 24, 25, 26, 26, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 81, 82, 26, 81, 82, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 83, 26, 83, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 84, 26, 84, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 85, 26, 85, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 86, 26, 86, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 87, 26, 87, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 88, 26, 26, 24, 24, 24, 24, 24, 24, 24, 24, 1, 28, 89, 30, 30, 90, 27, 91, 33, 33, 92, 31, 24, 25, 26, 93, 26, 93, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 94, 26, 94, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 25, 26, 95, 26, 95, 24, 24, 24, 24, 24, 24, 24, 24, 1, 24, 96, 26, 26, 24, 24, 24, 24, 24, 24, 24, 24, 1, 98, 99, 97, 101, 100, 103, 104, 1, 1, 1, 1, 1, 102, 106, 107, 1, 1, 1, 1, 1, 105, 108, 108, 108, 1, 105, 105, 105, 1, 109, 110, 109, 109, 109, 109, 1, 8, 1, 9, 111, 1, 1, 1, 1, 110, 112, 112, 112, 1, 110, 110, 110, 1, 114, 1, 115, 116, 117, 1, 1, 118, 1, 1, 113, 119, 119, 119, 1, 113, 113, 113, 1, 8, 1, 9, 121, 1, 1, 122, 1, 1, 120, 123, 123, 123, 1, 120, 120, 120, 1, 125, 1, 126, 127, 1, 1, 1, 1, 124, 129, 1, 130, 131, 1, 1, 1, 1, 128, 132, 132, 132, 1, 128, 128, 128, 1, 2, 133, 133, 133, 133, 133, 1, 2, 134, 134, 134, 134, 134, 1, 2, 135, 135, 135, 135, 135, 1, 2, 136, 136, 136, 136, 136, 1, 2, 137, 137, 137, 137, 137, 1, 2, 138, 138, 138, 138, 138, 1, 2, 139, 139, 139, 139, 139, 1, 2, 140, 140, 140, 140, 140, 1, 2, 141, 141, 141, 141, 141, 1, 2, 142, 142, 142, 142, 142, 1, 2, 143, 143, 143, 143, 143, 1, 2, 144, 144, 144, 144, 144, 1, 2, 145, 145, 145, 145, 145, 1, 2, 146, 146, 146, 146, 146, 1, 2, 147, 147, 147, 147, 147, 1, 2, 148, 148, 148, 148, 148, 1, 2, 149, 149, 149, 149, 149, 1, 2, 150, 150, 150, 150, 150, 1, 2, 1, 1, 0 }; static const char _http_parser_trans_targs[] = { 2, 0, 3, 99, 4, 85, 89, 86, 5, 81, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 59, 118, 17, 18, 40, 19, 14, 18, 20, 19, 14, 20, 21, 22, 23, 24, 25, 26, 27, 28, 36, 29, 30, 31, 32, 33, 34, 35, 35, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 55, 49, 50, 51, 52, 53, 54, 54, 35, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 75, 68, 69, 70, 71, 72, 73, 73, 74, 14, 74, 76, 77, 78, 79, 80, 14, 79, 80, 14, 82, 5, 83, 82, 5, 83, 84, 85, 86, 87, 88, 89, 5, 81, 90, 92, 95, 91, 92, 93, 95, 94, 96, 5, 81, 97, 96, 5, 81, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117 }; static const char _http_parser_trans_actions[] = { 1, 0, 21, 0, 1, 1, 1, 1, 23, 23, 1, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 3, 3, 27, 0, 5, 0, 7, 41, 7, 7, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 29, 11, 0, 0, 0, 0, 0, 1, 32, 1, 0, 13, 1, 35, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 44, 44, 0, 19, 19, 0, 0, 0, 0, 0, 25, 50, 50, 25, 0, 47, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const int http_parser_start = 1; static const int http_parser_first_final = 118; static const int http_parser_error = 0; static const int http_parser_en_main = 1; #line 143 "parser.rl" /* returns TRUE if applied, FALSE if there was an error */ static int apply_element(http_parser *parser, int type, const char *begin, const char *end, int max_length) { int len = (int)(end-begin); if(len > max_length) { parser->overflow_error = TRUE; return FALSE; } if(parser->on_element) parser->on_element(parser->data, type, begin, len); return TRUE; } static void set_content_length(http_parser *parser, const char *at, int length) { /* atoi_length - why isn't this in the statndard library? i hate c */ assert(parser->content_length == 0); int i, mult; for(mult=1, i=length-1; i>=0; i--, mult*=10) parser->content_length += (at[i] - '0') * mult; } void http_parser_init(http_parser *parser) { int cs = 0; #line 469 "parser.c" { cs = http_parser_start; } #line 169 "parser.rl" parser->cs = cs; parser->overflow_error = FALSE; parser->body_start = 0; parser->content_length = 0; parser->mark = 0; parser->nread = 0; parser->field_len = 0; parser->field_start = 0; parser->data = NULL; parser->http_field = NULL; } /** exec **/ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len, size_t off) { const char *p, *pe; int cs = parser->cs; assert(off <= len && "offset past end of buffer"); p = buffer+off; pe = buffer+len; /* Ragel 6 does not require this */ // assert(*pe == '\0' && "pointer does not end on NUL"); assert(pe - p == len - off && "pointers aren't same distance"); #line 502 "parser.c" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _keys = _http_parser_trans_keys + _http_parser_key_offsets[cs]; _trans = _http_parser_index_offsets[cs]; _klen = _http_parser_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _http_parser_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += ((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _http_parser_indicies[_trans]; cs = _http_parser_trans_targs[_trans]; if ( _http_parser_trans_actions[_trans] == 0 ) goto _again; _acts = _http_parser_actions + _http_parser_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 21 "parser.rl" {MARK(mark, p); } break; case 1: #line 23 "parser.rl" { MARK(field_start, p); } break; case 2: #line 24 "parser.rl" { parser->field_len = LEN(field_start, p); if(parser->field_len > 256) { parser->overflow_error = TRUE; {p++; goto _out; } } } break; case 3: #line 32 "parser.rl" { MARK(mark, p); } break; case 4: #line 33 "parser.rl" { if(LEN(mark, p) > 80 * 1024) { parser->overflow_error = TRUE; {p++; goto _out; } } if(parser->http_field != NULL) { parser->http_field(parser->data, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p)); } } break; case 5: #line 40 "parser.rl" { if(!apply_element(parser, MONGREL_CONTENT_LENGTH, PTR_TO(mark), p, 20)) {p++; goto _out; } set_content_length(parser, PTR_TO(mark), LEN(mark, p)); } break; case 6: #line 46 "parser.rl" { if(!apply_element(parser, MONGREL_CONTENT_TYPE, PTR_TO(mark), p, 10*1024)) {p++; goto _out; } } break; case 7: #line 51 "parser.rl" { if(!apply_element(parser, MONGREL_FRAGMENT, PTR_TO(mark), p, 10*1024)) {p++; goto _out; } } break; case 8: #line 56 "parser.rl" { if(!apply_element(parser, MONGREL_HTTP_VERSION, PTR_TO(mark), p, 10)) {p++; goto _out; } } break; case 9: #line 61 "parser.rl" { if(!apply_element(parser, MONGREL_REQUEST_PATH, PTR_TO(mark), p, 1024)) {p++; goto _out; } } break; case 10: #line 66 "parser.rl" { if(!apply_element(parser, MONGREL_REQUEST_METHOD, PTR_TO(mark), p, 1024)) {p++; goto _out; } } break; case 11: #line 71 "parser.rl" { if(!apply_element(parser, MONGREL_REQUEST_URI, PTR_TO(mark), p, 12*1024)) {p++; goto _out; } } break; case 12: #line 76 "parser.rl" {MARK(query_start, p); } break; case 13: #line 77 "parser.rl" { if(!apply_element(parser, MONGREL_QUERY_STRING, PTR_TO(query_start), p, 10*1024)) {p++; goto _out; } } break; case 14: #line 82 "parser.rl" { parser->body_start = p - buffer + 1; {p++; goto _out; } } break; #line 675 "parser.c" } } _again: if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} _out: {} } #line 197 "parser.rl" parser->cs = cs; parser->nread += p - (buffer + off); assert(p <= pe && "buffer overflow after parsing execute"); assert(parser->nread <= len && "nread longer than length"); assert(parser->body_start <= len && "body starts after buffer end"); assert(parser->mark < len && "mark is after buffer end"); assert(parser->field_len <= len && "field has length longer than whole buffer"); assert(parser->field_start < len && "field starts after buffer end"); if(parser->nread > 1024 * (80 + 32)) parser->overflow_error = TRUE; /* Ragel 6 does not use write eof; no need for this if(parser->body_start) { // final \r\n combo encountered so stop right here parser->nread++; %% write eof; } */ return(parser->nread); } int http_parser_finish(http_parser *parser) { if (http_parser_has_error(parser)) return -1; else if (http_parser_is_finished(parser)) return 1; else return 0; } int http_parser_has_error(http_parser *parser) { return parser->cs == http_parser_error || parser->overflow_error; } int http_parser_is_finished(http_parser *parser) { return parser->cs >= http_parser_first_final; }