28 #define HTTP_PARSER_VERSION_MAJOR 2
29 #define HTTP_PARSER_VERSION_MINOR 7
30 #define HTTP_PARSER_VERSION_PATCH 1
32 #include <sys/types.h>
33 #if defined(_WIN32) && !defined(__MINGW32__) && \
34 (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
37 typedef __int8 int8_t;
38 typedef unsigned __int8 uint8_t;
39 typedef __int16 int16_t;
40 typedef unsigned __int16 uint16_t;
41 typedef __int32 int32_t;
42 typedef unsigned __int32 uint32_t;
43 typedef __int64 int64_t;
44 typedef unsigned __int64 uint64_t;
52 #ifndef HTTP_PARSER_STRICT
53 # define HTTP_PARSER_STRICT 1
63 #ifndef HTTP_MAX_HEADER_SIZE
64 # define HTTP_MAX_HEADER_SIZE (80*1024)
94 #define HTTP_METHOD_MAP(XX) \
95 XX(0, DELETE, DELETE) \
101 XX(5, CONNECT, CONNECT) \
102 XX(6, OPTIONS, OPTIONS) \
103 XX(7, TRACE, TRACE) \
107 XX(10, MKCOL, MKCOL) \
109 XX(12, PROPFIND, PROPFIND) \
110 XX(13, PROPPATCH, PROPPATCH) \
111 XX(14, SEARCH, SEARCH) \
112 XX(15, UNLOCK, UNLOCK) \
114 XX(17, REBIND, REBIND) \
115 XX(18, UNBIND, UNBIND) \
118 XX(20, REPORT, REPORT) \
119 XX(21, MKACTIVITY, MKACTIVITY) \
120 XX(22, CHECKOUT, CHECKOUT) \
121 XX(23, MERGE, MERGE) \
123 XX(24, MSEARCH, M-SEARCH) \
124 XX(25, NOTIFY, NOTIFY) \
125 XX(26, SUBSCRIBE, SUBSCRIBE) \
126 XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
128 XX(28, PATCH, PATCH) \
129 XX(29, PURGE, PURGE) \
131 XX(30, MKCALENDAR, MKCALENDAR) \
134 XX(32, UNLINK, UNLINK) \
138 #define XX(num, name, string) HTTP_##name = num,
164 #define HTTP_ERRNO_MAP(XX) \
169 XX(CB_message_begin, "the on_message_begin callback failed") \
170 XX(CB_url, "the on_url callback failed") \
171 XX(CB_header_field, "the on_header_field callback failed") \
172 XX(CB_header_value, "the on_header_value callback failed") \
173 XX(CB_headers_complete, "the on_headers_complete callback failed") \
174 XX(CB_body, "the on_body callback failed") \
175 XX(CB_message_complete, "the on_message_complete callback failed") \
176 XX(CB_status, "the on_status callback failed") \
177 XX(CB_chunk_header, "the on_chunk_header callback failed") \
178 XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
181 XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
182 XX(HEADER_OVERFLOW, \
183 "too many header bytes seen; overflow detected") \
184 XX(CLOSED_CONNECTION, \
185 "data received after completed connection: close message") \
186 XX(INVALID_VERSION, "invalid HTTP version") \
187 XX(INVALID_STATUS, "invalid HTTP status code") \
188 XX(INVALID_METHOD, "invalid HTTP method") \
189 XX(INVALID_URL, "invalid URL") \
190 XX(INVALID_HOST, "invalid host") \
191 XX(INVALID_PORT, "invalid port") \
192 XX(INVALID_PATH, "invalid path") \
193 XX(INVALID_QUERY_STRING, "invalid query string") \
194 XX(INVALID_FRAGMENT, "invalid fragment") \
195 XX(LF_EXPECTED, "LF character expected") \
196 XX(INVALID_HEADER_TOKEN, "invalid character in header") \
197 XX(INVALID_CONTENT_LENGTH, \
198 "invalid character in content-length header") \
199 XX(UNEXPECTED_CONTENT_LENGTH, \
200 "unexpected content-length header") \
201 XX(INVALID_CHUNK_SIZE, \
202 "invalid character in chunk size header") \
203 XX(INVALID_CONSTANT, "invalid constant string") \
204 XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
205 XX(STRICT, "strict mode assertion failed") \
206 XX(PAUSED, "parser is paused") \
207 XX(UNKNOWN, "an unknown error occurred")
211 #define HTTP_ERRNO_GEN(n, s) HPE_##n,
215 #undef HTTP_ERRNO_GEN
219 #define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
uint32_t nread
Definition: http_parser.h:231
#define HTTP_ERRNO_MAP(XX)
Definition: http_parser.h:164
Definition: http_parser.h:222
unsigned int method
Definition: http_parser.h:238
flags
Definition: http_parser.h:148
Definition: http_parser.h:149
http_data_cb on_header_field
Definition: http_parser.h:257
void http_parser_settings_init(http_parser_settings *settings)
Definition: http_parser.cpp:2154
http_cb on_headers_complete
Definition: http_parser.h:259
unsigned short http_minor
Definition: http_parser.h:236
Definition: http_parser.h:272
uint16_t len
Definition: http_parser.h:295
Definition: http_parser.h:144
Definition: http_parser.h:150
Definition: http_parser.h:275
#define HTTP_METHOD_MAP(XX)
Definition: http_parser.h:94
Definition: http_parser.h:271
uint16_t field_set
Definition: http_parser.h:290
http_cb on_chunk_header
Definition: http_parser.h:265
const char * http_method_str(enum http_method m)
Definition: http_parser.cpp:2136
http_data_cb on_body
Definition: http_parser.h:260
unsigned int status_code
Definition: http_parser.h:237
Definition: http_parser.h:152
unsigned int header_state
Definition: http_parser.h:227
size_t http_parser_execute(http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
Definition: http_parser.cpp:631
http_data_cb on_url
Definition: http_parser.h:255
unsigned int index
Definition: http_parser.h:228
const char * http_errno_name(enum http_errno err)
Definition: http_parser.cpp:2160
int(* http_cb)(http_parser *)
Definition: http_parser.h:90
Definition: http_parser.h:276
Definition: http_parser.h:156
#define XX(num, name, string)
Definition: http_parser.h:138
int(* http_data_cb)(http_parser *, const char *at, size_t length)
Definition: http_parser.h:89
Definition: http_parser.h:278
void http_parser_init(http_parser *parser, enum http_parser_type t)
Definition: http_parser.cpp:2143
unsigned int lenient_http_headers
Definition: http_parser.h:229
int http_should_keep_alive(const http_parser *parser)
Definition: http_parser.cpp:2117
Definition: http_parser.h:253
uint64_t content_length
Definition: http_parser.h:232
void http_parser_pause(http_parser *parser, int paused)
Definition: http_parser.cpp:2445
Definition: http_parser.h:151
http_data_cb on_status
Definition: http_parser.h:256
unsigned short http_major
Definition: http_parser.h:235
int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u)
Definition: http_parser.cpp:2341
http_method
Definition: http_parser.h:136
Definition: http_parser.h:144
http_parser_type
Definition: http_parser.h:144
http_data_cb on_header_value
Definition: http_parser.h:258
#define HTTP_ERRNO_GEN(n, s)
Definition: http_parser.h:211
const char * http_errno_description(enum http_errno err)
Definition: http_parser.cpp:2166
Definition: http_parser.h:153
Definition: http_parser.h:273
void * data
Definition: http_parser.h:249
Definition: http_parser.h:277
http_cb on_chunk_complete
Definition: http_parser.h:266
Definition: http_parser.h:154
int http_body_is_final(const struct http_parser *parser)
Definition: http_parser.cpp:2459
Definition: http_parser.h:144
uint16_t off
Definition: http_parser.h:294
http_errno
Definition: http_parser.h:212
unsigned int upgrade
Definition: http_parser.h:246
state
Definition: http_parser.cpp:276
unsigned long http_parser_version(void)
Definition: http_parser.cpp:2464
Definition: http_parser.h:274
http_cb on_message_begin
Definition: http_parser.h:254
uint16_t port
Definition: http_parser.h:291
Definition: http_parser.h:155
struct http_parser_url::@1 field_data[UF_MAX]
unsigned int type
Definition: http_parser.h:224
http_parser_url_fields
Definition: http_parser.h:270
http_cb on_message_complete
Definition: http_parser.h:261
Definition: http_parser.h:289
void http_parser_url_init(struct http_parser_url *u)
Definition: http_parser.cpp:2336