11#ifndef INCLUDE_LLHTTP_H_
22#define INCLUDE_LLHTTP_H_
33
4- #define LLHTTP_VERSION_MAJOR 4
5- #define LLHTTP_VERSION_MINOR 1
6- #define LLHTTP_VERSION_PATCH 1
4+ #define LLHTTP_VERSION_MAJOR 6
5+ #define LLHTTP_VERSION_MINOR 0
6+ #define LLHTTP_VERSION_PATCH 2
77
88#ifndef LLHTTP_STRICT_MODE
99# define LLHTTP_STRICT_MODE 0
@@ -99,7 +99,8 @@ typedef enum llhttp_flags llhttp_flags_t;
9999
100100enum llhttp_lenient_flags {
101101 LENIENT_HEADERS = 0x1 ,
102- LENIENT_CHUNKED_LENGTH = 0x2
102+ LENIENT_CHUNKED_LENGTH = 0x2 ,
103+ LENIENT_KEEP_ALIVE = 0x4
103104};
104105typedef enum llhttp_lenient_flags llhttp_lenient_flags_t ;
105106
@@ -230,7 +231,12 @@ typedef enum llhttp_method llhttp_method_t;
230231 XX(31, LINK, LINK) \
231232 XX(32, UNLINK, UNLINK) \
232233 XX(33, SOURCE, SOURCE) \
233- XX(34, PRI, PRI) \
234+
235+
236+ #define RTSP_METHOD_MAP (XX ) \
237+ XX(1, GET, GET) \
238+ XX(3, POST, POST) \
239+ XX(6, OPTIONS, OPTIONS) \
234240 XX(35, DESCRIBE, DESCRIBE) \
235241 XX(36, ANNOUNCE, ANNOUNCE) \
236242 XX(37, SETUP, SETUP) \
@@ -244,6 +250,54 @@ typedef enum llhttp_method llhttp_method_t;
244250 XX(45, FLUSH, FLUSH) \
245251
246252
253+ #define HTTP_ALL_METHOD_MAP (XX ) \
254+ XX(0, DELETE, DELETE) \
255+ XX(1, GET, GET) \
256+ XX(2, HEAD, HEAD) \
257+ XX(3, POST, POST) \
258+ XX(4, PUT, PUT) \
259+ XX(5, CONNECT, CONNECT) \
260+ XX(6, OPTIONS, OPTIONS) \
261+ XX(7, TRACE, TRACE) \
262+ XX(8, COPY, COPY) \
263+ XX(9, LOCK, LOCK) \
264+ XX(10, MKCOL, MKCOL) \
265+ XX(11, MOVE, MOVE) \
266+ XX(12, PROPFIND, PROPFIND) \
267+ XX(13, PROPPATCH, PROPPATCH) \
268+ XX(14, SEARCH, SEARCH) \
269+ XX(15, UNLOCK, UNLOCK) \
270+ XX(16, BIND, BIND) \
271+ XX(17, REBIND, REBIND) \
272+ XX(18, UNBIND, UNBIND) \
273+ XX(19, ACL, ACL) \
274+ XX(20, REPORT, REPORT) \
275+ XX(21, MKACTIVITY, MKACTIVITY) \
276+ XX(22, CHECKOUT, CHECKOUT) \
277+ XX(23, MERGE, MERGE) \
278+ XX(24, MSEARCH, M-SEARCH) \
279+ XX(25, NOTIFY, NOTIFY) \
280+ XX(26, SUBSCRIBE, SUBSCRIBE) \
281+ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
282+ XX(28, PATCH, PATCH) \
283+ XX(29, PURGE, PURGE) \
284+ XX(30, MKCALENDAR, MKCALENDAR) \
285+ XX(31, LINK, LINK) \
286+ XX(32, UNLINK, UNLINK) \
287+ XX(33, SOURCE, SOURCE) \
288+ XX(34, PRI, PRI) \
289+ XX(35, DESCRIBE, DESCRIBE) \
290+ XX(36, ANNOUNCE, ANNOUNCE) \
291+ XX(37, SETUP, SETUP) \
292+ XX(38, PLAY, PLAY) \
293+ XX(39, PAUSE, PAUSE) \
294+ XX(40, TEARDOWN, TEARDOWN) \
295+ XX(41, GET_PARAMETER, GET_PARAMETER) \
296+ XX(42, SET_PARAMETER, SET_PARAMETER) \
297+ XX(43, REDIRECT, REDIRECT) \
298+ XX(44, RECORD, RECORD) \
299+ XX(45, FLUSH, FLUSH) \
300+
247301
248302#ifdef __cplusplus
249303} /* extern "C" */
@@ -257,6 +311,12 @@ extern "C" {
257311#endif
258312#include <stddef.h>
259313
314+ #if defined(__wasm__ )
315+ #define LLHTTP_EXPORT __attribute__((visibility("default")))
316+ #else
317+ #define LLHTTP_EXPORT
318+ #endif
319+
260320typedef llhttp__internal_t llhttp_t ;
261321typedef struct llhttp_settings_s llhttp_settings_t ;
262322
@@ -267,6 +327,7 @@ struct llhttp_settings_s {
267327 /* Possible return values 0, -1, `HPE_PAUSED` */
268328 llhttp_cb on_message_begin ;
269329
330+ /* Possible return values 0, -1, HPE_USER */
270331 llhttp_data_cb on_url ;
271332 llhttp_data_cb on_status ;
272333 llhttp_data_cb on_header_field ;
@@ -283,6 +344,7 @@ struct llhttp_settings_s {
283344 */
284345 llhttp_cb on_headers_complete ;
285346
347+ /* Possible return values 0, -1, HPE_USER */
286348 llhttp_data_cb on_body ;
287349
288350 /* Possible return values 0, -1, `HPE_PAUSED` */
@@ -295,6 +357,7 @@ struct llhttp_settings_s {
295357 llhttp_cb on_chunk_header ;
296358 llhttp_cb on_chunk_complete ;
297359
360+ /* Information-only callbacks, return value is ignored */
298361 llhttp_cb on_url_complete ;
299362 llhttp_cb on_status_complete ;
300363 llhttp_cb on_header_field_complete ;
@@ -307,15 +370,46 @@ struct llhttp_settings_s {
307370 * the `parser` here. In practice, `settings` has to be either a static
308371 * variable or be allocated with `malloc`, `new`, etc.
309372 */
373+ LLHTTP_EXPORT
310374void llhttp_init (llhttp_t * parser , llhttp_type_t type ,
311375 const llhttp_settings_t * settings );
312376
377+ #if defined(__wasm__ )
378+
379+ LLHTTP_EXPORT
380+ llhttp_t * llhttp_alloc (llhttp_type_t type );
381+
382+ LLHTTP_EXPORT
383+ void llhttp_free (llhttp_t * parser );
384+
385+ LLHTTP_EXPORT
386+ uint8_t llhttp_get_type (llhttp_t * parser );
387+
388+ LLHTTP_EXPORT
389+ uint8_t llhttp_get_http_major (llhttp_t * parser );
390+
391+ LLHTTP_EXPORT
392+ uint8_t llhttp_get_http_minor (llhttp_t * parser );
393+
394+ LLHTTP_EXPORT
395+ uint8_t llhttp_get_method (llhttp_t * parser );
396+
397+ LLHTTP_EXPORT
398+ int llhttp_get_status_code (llhttp_t * parser );
399+
400+ LLHTTP_EXPORT
401+ uint8_t llhttp_get_upgrade (llhttp_t * parser );
402+
403+ #endif // defined(__wasm__)
404+
313405/* Reset an already initialized parser back to the start state, preserving the
314406 * existing parser type, callback settings, user data, and lenient flags.
315407 */
408+ LLHTTP_EXPORT
316409void llhttp_reset (llhttp_t * parser );
317410
318411/* Initialize the settings object */
412+ LLHTTP_EXPORT
319413void llhttp_settings_init (llhttp_settings_t * settings );
320414
321415/* Parse full or partial request/response, invoking user callbacks along the
@@ -334,6 +428,7 @@ void llhttp_settings_init(llhttp_settings_t* settings);
334428 * to return the same error upon each successive call up until `llhttp_init()`
335429 * is called.
336430 */
431+ LLHTTP_EXPORT
337432llhttp_errno_t llhttp_execute (llhttp_t * parser , const char * data , size_t len );
338433
339434/* This method should be called when the other side has no further bytes to
@@ -344,16 +439,19 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
344439 * connection. This method will invoke `on_message_complete()` callback if the
345440 * request was terminated safely. Otherwise a error code would be returned.
346441 */
442+ LLHTTP_EXPORT
347443llhttp_errno_t llhttp_finish (llhttp_t * parser );
348444
349445/* Returns `1` if the incoming message is parsed until the last byte, and has
350446 * to be completed by calling `llhttp_finish()` on EOF
351447 */
448+ LLHTTP_EXPORT
352449int llhttp_message_needs_eof (const llhttp_t * parser );
353450
354451/* Returns `1` if there might be any other messages following the last that was
355452 * successfully parsed.
356453 */
454+ LLHTTP_EXPORT
357455int llhttp_should_keep_alive (const llhttp_t * parser );
358456
359457/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -362,50 +460,59 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
362460 * Important: do not call this from user callbacks! User callbacks must return
363461 * `HPE_PAUSED` if pausing is required.
364462 */
463+ LLHTTP_EXPORT
365464void llhttp_pause (llhttp_t * parser );
366465
367466/* Might be called to resume the execution after the pause in user's callback.
368467 * See `llhttp_execute()` above for details.
369468 *
370469 * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
371470 */
471+ LLHTTP_EXPORT
372472void llhttp_resume (llhttp_t * parser );
373473
374474/* Might be called to resume the execution after the pause in user's callback.
375475 * See `llhttp_execute()` above for details.
376476 *
377477 * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
378478 */
479+ LLHTTP_EXPORT
379480void llhttp_resume_after_upgrade (llhttp_t * parser );
380481
381482/* Returns the latest return error */
483+ LLHTTP_EXPORT
382484llhttp_errno_t llhttp_get_errno (const llhttp_t * parser );
383485
384486/* Returns the verbal explanation of the latest returned error.
385487 *
386488 * Note: User callback should set error reason when returning the error. See
387489 * `llhttp_set_error_reason()` for details.
388490 */
491+ LLHTTP_EXPORT
389492const char * llhttp_get_error_reason (const llhttp_t * parser );
390493
391494/* Assign verbal description to the returned error. Must be called in user
392495 * callbacks right before returning the errno.
393496 *
394497 * Note: `HPE_USER` error code might be useful in user callbacks.
395498 */
499+ LLHTTP_EXPORT
396500void llhttp_set_error_reason (llhttp_t * parser , const char * reason );
397501
398502/* Returns the pointer to the last parsed byte before the returned error. The
399503 * pointer is relative to the `data` argument of `llhttp_execute()`.
400504 *
401505 * Note: this method might be useful for counting the number of parsed bytes.
402506 */
507+ LLHTTP_EXPORT
403508const char * llhttp_get_error_pos (const llhttp_t * parser );
404509
405510/* Returns textual name of error code */
511+ LLHTTP_EXPORT
406512const char * llhttp_errno_name (llhttp_errno_t err );
407513
408514/* Returns textual name of HTTP method */
515+ LLHTTP_EXPORT
409516const char * llhttp_method_name (llhttp_method_t method );
410517
411518
@@ -418,6 +525,7 @@ const char* llhttp_method_name(llhttp_method_t method);
418525 *
419526 * **(USE AT YOUR OWN RISK)**
420527 */
528+ LLHTTP_EXPORT
421529void llhttp_set_lenient_headers (llhttp_t * parser , int enabled );
422530
423531
@@ -431,8 +539,23 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
431539 *
432540 * **(USE AT YOUR OWN RISK)**
433541 */
542+ LLHTTP_EXPORT
434543void llhttp_set_lenient_chunked_length (llhttp_t * parser , int enabled );
435544
545+
546+ /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
547+ * requests responses.
548+ *
549+ * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
550+ * the HTTP request/response after the request/response with `Connection: close`
551+ * and `Content-Length`. This is important to prevent cache poisoning attacks,
552+ * but might interact badly with outdated and insecure clients. With this flag
553+ * the extra request/response will be parsed normally.
554+ *
555+ * **(USE AT YOUR OWN RISK)**
556+ */
557+ void llhttp_set_lenient_keep_alive (llhttp_t * parser , int enabled );
558+
436559#ifdef __cplusplus
437560} /* extern "C" */
438561#endif
0 commit comments