11cb0ef41Sopenharmony_ci#ifndef INCLUDE_LLHTTP_H_ 21cb0ef41Sopenharmony_ci#define INCLUDE_LLHTTP_H_ 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci#define LLHTTP_VERSION_MAJOR 6 51cb0ef41Sopenharmony_ci#define LLHTTP_VERSION_MINOR 1 61cb0ef41Sopenharmony_ci#define LLHTTP_VERSION_PATCH 1 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#ifndef LLHTTP_STRICT_MODE 91cb0ef41Sopenharmony_ci# define LLHTTP_STRICT_MODE 0 101cb0ef41Sopenharmony_ci#endif 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci#ifndef INCLUDE_LLHTTP_ITSELF_H_ 131cb0ef41Sopenharmony_ci#define INCLUDE_LLHTTP_ITSELF_H_ 141cb0ef41Sopenharmony_ci#ifdef __cplusplus 151cb0ef41Sopenharmony_ciextern "C" { 161cb0ef41Sopenharmony_ci#endif 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#include <stdint.h> 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_citypedef struct llhttp__internal_s llhttp__internal_t; 211cb0ef41Sopenharmony_cistruct llhttp__internal_s { 221cb0ef41Sopenharmony_ci int32_t _index; 231cb0ef41Sopenharmony_ci void* _span_pos0; 241cb0ef41Sopenharmony_ci void* _span_cb0; 251cb0ef41Sopenharmony_ci int32_t error; 261cb0ef41Sopenharmony_ci const char* reason; 271cb0ef41Sopenharmony_ci const char* error_pos; 281cb0ef41Sopenharmony_ci void* data; 291cb0ef41Sopenharmony_ci void* _current; 301cb0ef41Sopenharmony_ci uint64_t content_length; 311cb0ef41Sopenharmony_ci uint8_t type; 321cb0ef41Sopenharmony_ci uint8_t method; 331cb0ef41Sopenharmony_ci uint8_t http_major; 341cb0ef41Sopenharmony_ci uint8_t http_minor; 351cb0ef41Sopenharmony_ci uint8_t header_state; 361cb0ef41Sopenharmony_ci uint8_t lenient_flags; 371cb0ef41Sopenharmony_ci uint8_t upgrade; 381cb0ef41Sopenharmony_ci uint8_t finish; 391cb0ef41Sopenharmony_ci uint16_t flags; 401cb0ef41Sopenharmony_ci uint16_t status_code; 411cb0ef41Sopenharmony_ci void* settings; 421cb0ef41Sopenharmony_ci}; 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciint llhttp__internal_init(llhttp__internal_t* s); 451cb0ef41Sopenharmony_ciint llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci#ifdef __cplusplus 481cb0ef41Sopenharmony_ci} /* extern "C" */ 491cb0ef41Sopenharmony_ci#endif 501cb0ef41Sopenharmony_ci#endif /* INCLUDE_LLHTTP_ITSELF_H_ */ 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci#ifndef LLLLHTTP_C_HEADERS_ 531cb0ef41Sopenharmony_ci#define LLLLHTTP_C_HEADERS_ 541cb0ef41Sopenharmony_ci#ifdef __cplusplus 551cb0ef41Sopenharmony_ciextern "C" { 561cb0ef41Sopenharmony_ci#endif 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_cienum llhttp_errno { 591cb0ef41Sopenharmony_ci HPE_OK = 0, 601cb0ef41Sopenharmony_ci HPE_INTERNAL = 1, 611cb0ef41Sopenharmony_ci HPE_STRICT = 2, 621cb0ef41Sopenharmony_ci HPE_CR_EXPECTED = 25, 631cb0ef41Sopenharmony_ci HPE_LF_EXPECTED = 3, 641cb0ef41Sopenharmony_ci HPE_UNEXPECTED_CONTENT_LENGTH = 4, 651cb0ef41Sopenharmony_ci HPE_CLOSED_CONNECTION = 5, 661cb0ef41Sopenharmony_ci HPE_INVALID_METHOD = 6, 671cb0ef41Sopenharmony_ci HPE_INVALID_URL = 7, 681cb0ef41Sopenharmony_ci HPE_INVALID_CONSTANT = 8, 691cb0ef41Sopenharmony_ci HPE_INVALID_VERSION = 9, 701cb0ef41Sopenharmony_ci HPE_INVALID_HEADER_TOKEN = 10, 711cb0ef41Sopenharmony_ci HPE_INVALID_CONTENT_LENGTH = 11, 721cb0ef41Sopenharmony_ci HPE_INVALID_CHUNK_SIZE = 12, 731cb0ef41Sopenharmony_ci HPE_INVALID_STATUS = 13, 741cb0ef41Sopenharmony_ci HPE_INVALID_EOF_STATE = 14, 751cb0ef41Sopenharmony_ci HPE_INVALID_TRANSFER_ENCODING = 15, 761cb0ef41Sopenharmony_ci HPE_CB_MESSAGE_BEGIN = 16, 771cb0ef41Sopenharmony_ci HPE_CB_HEADERS_COMPLETE = 17, 781cb0ef41Sopenharmony_ci HPE_CB_MESSAGE_COMPLETE = 18, 791cb0ef41Sopenharmony_ci HPE_CB_CHUNK_HEADER = 19, 801cb0ef41Sopenharmony_ci HPE_CB_CHUNK_COMPLETE = 20, 811cb0ef41Sopenharmony_ci HPE_PAUSED = 21, 821cb0ef41Sopenharmony_ci HPE_PAUSED_UPGRADE = 22, 831cb0ef41Sopenharmony_ci HPE_PAUSED_H2_UPGRADE = 23, 841cb0ef41Sopenharmony_ci HPE_USER = 24 851cb0ef41Sopenharmony_ci}; 861cb0ef41Sopenharmony_citypedef enum llhttp_errno llhttp_errno_t; 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_cienum llhttp_flags { 891cb0ef41Sopenharmony_ci F_CONNECTION_KEEP_ALIVE = 0x1, 901cb0ef41Sopenharmony_ci F_CONNECTION_CLOSE = 0x2, 911cb0ef41Sopenharmony_ci F_CONNECTION_UPGRADE = 0x4, 921cb0ef41Sopenharmony_ci F_CHUNKED = 0x8, 931cb0ef41Sopenharmony_ci F_UPGRADE = 0x10, 941cb0ef41Sopenharmony_ci F_CONTENT_LENGTH = 0x20, 951cb0ef41Sopenharmony_ci F_SKIPBODY = 0x40, 961cb0ef41Sopenharmony_ci F_TRAILING = 0x80, 971cb0ef41Sopenharmony_ci F_TRANSFER_ENCODING = 0x200 981cb0ef41Sopenharmony_ci}; 991cb0ef41Sopenharmony_citypedef enum llhttp_flags llhttp_flags_t; 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_cienum llhttp_lenient_flags { 1021cb0ef41Sopenharmony_ci LENIENT_HEADERS = 0x1, 1031cb0ef41Sopenharmony_ci LENIENT_CHUNKED_LENGTH = 0x2, 1041cb0ef41Sopenharmony_ci LENIENT_KEEP_ALIVE = 0x4, 1051cb0ef41Sopenharmony_ci LENIENT_TRANSFER_ENCODING = 0x8, 1061cb0ef41Sopenharmony_ci LENIENT_VERSION = 0x10 1071cb0ef41Sopenharmony_ci}; 1081cb0ef41Sopenharmony_citypedef enum llhttp_lenient_flags llhttp_lenient_flags_t; 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_cienum llhttp_type { 1111cb0ef41Sopenharmony_ci HTTP_BOTH = 0, 1121cb0ef41Sopenharmony_ci HTTP_REQUEST = 1, 1131cb0ef41Sopenharmony_ci HTTP_RESPONSE = 2 1141cb0ef41Sopenharmony_ci}; 1151cb0ef41Sopenharmony_citypedef enum llhttp_type llhttp_type_t; 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_cienum llhttp_finish { 1181cb0ef41Sopenharmony_ci HTTP_FINISH_SAFE = 0, 1191cb0ef41Sopenharmony_ci HTTP_FINISH_SAFE_WITH_CB = 1, 1201cb0ef41Sopenharmony_ci HTTP_FINISH_UNSAFE = 2 1211cb0ef41Sopenharmony_ci}; 1221cb0ef41Sopenharmony_citypedef enum llhttp_finish llhttp_finish_t; 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_cienum llhttp_method { 1251cb0ef41Sopenharmony_ci HTTP_DELETE = 0, 1261cb0ef41Sopenharmony_ci HTTP_GET = 1, 1271cb0ef41Sopenharmony_ci HTTP_HEAD = 2, 1281cb0ef41Sopenharmony_ci HTTP_POST = 3, 1291cb0ef41Sopenharmony_ci HTTP_PUT = 4, 1301cb0ef41Sopenharmony_ci HTTP_CONNECT = 5, 1311cb0ef41Sopenharmony_ci HTTP_OPTIONS = 6, 1321cb0ef41Sopenharmony_ci HTTP_TRACE = 7, 1331cb0ef41Sopenharmony_ci HTTP_COPY = 8, 1341cb0ef41Sopenharmony_ci HTTP_LOCK = 9, 1351cb0ef41Sopenharmony_ci HTTP_MKCOL = 10, 1361cb0ef41Sopenharmony_ci HTTP_MOVE = 11, 1371cb0ef41Sopenharmony_ci HTTP_PROPFIND = 12, 1381cb0ef41Sopenharmony_ci HTTP_PROPPATCH = 13, 1391cb0ef41Sopenharmony_ci HTTP_SEARCH = 14, 1401cb0ef41Sopenharmony_ci HTTP_UNLOCK = 15, 1411cb0ef41Sopenharmony_ci HTTP_BIND = 16, 1421cb0ef41Sopenharmony_ci HTTP_REBIND = 17, 1431cb0ef41Sopenharmony_ci HTTP_UNBIND = 18, 1441cb0ef41Sopenharmony_ci HTTP_ACL = 19, 1451cb0ef41Sopenharmony_ci HTTP_REPORT = 20, 1461cb0ef41Sopenharmony_ci HTTP_MKACTIVITY = 21, 1471cb0ef41Sopenharmony_ci HTTP_CHECKOUT = 22, 1481cb0ef41Sopenharmony_ci HTTP_MERGE = 23, 1491cb0ef41Sopenharmony_ci HTTP_MSEARCH = 24, 1501cb0ef41Sopenharmony_ci HTTP_NOTIFY = 25, 1511cb0ef41Sopenharmony_ci HTTP_SUBSCRIBE = 26, 1521cb0ef41Sopenharmony_ci HTTP_UNSUBSCRIBE = 27, 1531cb0ef41Sopenharmony_ci HTTP_PATCH = 28, 1541cb0ef41Sopenharmony_ci HTTP_PURGE = 29, 1551cb0ef41Sopenharmony_ci HTTP_MKCALENDAR = 30, 1561cb0ef41Sopenharmony_ci HTTP_LINK = 31, 1571cb0ef41Sopenharmony_ci HTTP_UNLINK = 32, 1581cb0ef41Sopenharmony_ci HTTP_SOURCE = 33, 1591cb0ef41Sopenharmony_ci HTTP_PRI = 34, 1601cb0ef41Sopenharmony_ci HTTP_DESCRIBE = 35, 1611cb0ef41Sopenharmony_ci HTTP_ANNOUNCE = 36, 1621cb0ef41Sopenharmony_ci HTTP_SETUP = 37, 1631cb0ef41Sopenharmony_ci HTTP_PLAY = 38, 1641cb0ef41Sopenharmony_ci HTTP_PAUSE = 39, 1651cb0ef41Sopenharmony_ci HTTP_TEARDOWN = 40, 1661cb0ef41Sopenharmony_ci HTTP_GET_PARAMETER = 41, 1671cb0ef41Sopenharmony_ci HTTP_SET_PARAMETER = 42, 1681cb0ef41Sopenharmony_ci HTTP_REDIRECT = 43, 1691cb0ef41Sopenharmony_ci HTTP_RECORD = 44, 1701cb0ef41Sopenharmony_ci HTTP_FLUSH = 45 1711cb0ef41Sopenharmony_ci}; 1721cb0ef41Sopenharmony_citypedef enum llhttp_method llhttp_method_t; 1731cb0ef41Sopenharmony_ci 1741cb0ef41Sopenharmony_ci#define HTTP_ERRNO_MAP(XX) \ 1751cb0ef41Sopenharmony_ci XX(0, OK, OK) \ 1761cb0ef41Sopenharmony_ci XX(1, INTERNAL, INTERNAL) \ 1771cb0ef41Sopenharmony_ci XX(2, STRICT, STRICT) \ 1781cb0ef41Sopenharmony_ci XX(25, CR_EXPECTED, CR_EXPECTED) \ 1791cb0ef41Sopenharmony_ci XX(3, LF_EXPECTED, LF_EXPECTED) \ 1801cb0ef41Sopenharmony_ci XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \ 1811cb0ef41Sopenharmony_ci XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \ 1821cb0ef41Sopenharmony_ci XX(6, INVALID_METHOD, INVALID_METHOD) \ 1831cb0ef41Sopenharmony_ci XX(7, INVALID_URL, INVALID_URL) \ 1841cb0ef41Sopenharmony_ci XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \ 1851cb0ef41Sopenharmony_ci XX(9, INVALID_VERSION, INVALID_VERSION) \ 1861cb0ef41Sopenharmony_ci XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \ 1871cb0ef41Sopenharmony_ci XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \ 1881cb0ef41Sopenharmony_ci XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \ 1891cb0ef41Sopenharmony_ci XX(13, INVALID_STATUS, INVALID_STATUS) \ 1901cb0ef41Sopenharmony_ci XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \ 1911cb0ef41Sopenharmony_ci XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \ 1921cb0ef41Sopenharmony_ci XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \ 1931cb0ef41Sopenharmony_ci XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \ 1941cb0ef41Sopenharmony_ci XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \ 1951cb0ef41Sopenharmony_ci XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \ 1961cb0ef41Sopenharmony_ci XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \ 1971cb0ef41Sopenharmony_ci XX(21, PAUSED, PAUSED) \ 1981cb0ef41Sopenharmony_ci XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \ 1991cb0ef41Sopenharmony_ci XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \ 2001cb0ef41Sopenharmony_ci XX(24, USER, USER) \ 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ci#define HTTP_METHOD_MAP(XX) \ 2041cb0ef41Sopenharmony_ci XX(0, DELETE, DELETE) \ 2051cb0ef41Sopenharmony_ci XX(1, GET, GET) \ 2061cb0ef41Sopenharmony_ci XX(2, HEAD, HEAD) \ 2071cb0ef41Sopenharmony_ci XX(3, POST, POST) \ 2081cb0ef41Sopenharmony_ci XX(4, PUT, PUT) \ 2091cb0ef41Sopenharmony_ci XX(5, CONNECT, CONNECT) \ 2101cb0ef41Sopenharmony_ci XX(6, OPTIONS, OPTIONS) \ 2111cb0ef41Sopenharmony_ci XX(7, TRACE, TRACE) \ 2121cb0ef41Sopenharmony_ci XX(8, COPY, COPY) \ 2131cb0ef41Sopenharmony_ci XX(9, LOCK, LOCK) \ 2141cb0ef41Sopenharmony_ci XX(10, MKCOL, MKCOL) \ 2151cb0ef41Sopenharmony_ci XX(11, MOVE, MOVE) \ 2161cb0ef41Sopenharmony_ci XX(12, PROPFIND, PROPFIND) \ 2171cb0ef41Sopenharmony_ci XX(13, PROPPATCH, PROPPATCH) \ 2181cb0ef41Sopenharmony_ci XX(14, SEARCH, SEARCH) \ 2191cb0ef41Sopenharmony_ci XX(15, UNLOCK, UNLOCK) \ 2201cb0ef41Sopenharmony_ci XX(16, BIND, BIND) \ 2211cb0ef41Sopenharmony_ci XX(17, REBIND, REBIND) \ 2221cb0ef41Sopenharmony_ci XX(18, UNBIND, UNBIND) \ 2231cb0ef41Sopenharmony_ci XX(19, ACL, ACL) \ 2241cb0ef41Sopenharmony_ci XX(20, REPORT, REPORT) \ 2251cb0ef41Sopenharmony_ci XX(21, MKACTIVITY, MKACTIVITY) \ 2261cb0ef41Sopenharmony_ci XX(22, CHECKOUT, CHECKOUT) \ 2271cb0ef41Sopenharmony_ci XX(23, MERGE, MERGE) \ 2281cb0ef41Sopenharmony_ci XX(24, MSEARCH, M-SEARCH) \ 2291cb0ef41Sopenharmony_ci XX(25, NOTIFY, NOTIFY) \ 2301cb0ef41Sopenharmony_ci XX(26, SUBSCRIBE, SUBSCRIBE) \ 2311cb0ef41Sopenharmony_ci XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ 2321cb0ef41Sopenharmony_ci XX(28, PATCH, PATCH) \ 2331cb0ef41Sopenharmony_ci XX(29, PURGE, PURGE) \ 2341cb0ef41Sopenharmony_ci XX(30, MKCALENDAR, MKCALENDAR) \ 2351cb0ef41Sopenharmony_ci XX(31, LINK, LINK) \ 2361cb0ef41Sopenharmony_ci XX(32, UNLINK, UNLINK) \ 2371cb0ef41Sopenharmony_ci XX(33, SOURCE, SOURCE) \ 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_ci#define RTSP_METHOD_MAP(XX) \ 2411cb0ef41Sopenharmony_ci XX(1, GET, GET) \ 2421cb0ef41Sopenharmony_ci XX(3, POST, POST) \ 2431cb0ef41Sopenharmony_ci XX(6, OPTIONS, OPTIONS) \ 2441cb0ef41Sopenharmony_ci XX(35, DESCRIBE, DESCRIBE) \ 2451cb0ef41Sopenharmony_ci XX(36, ANNOUNCE, ANNOUNCE) \ 2461cb0ef41Sopenharmony_ci XX(37, SETUP, SETUP) \ 2471cb0ef41Sopenharmony_ci XX(38, PLAY, PLAY) \ 2481cb0ef41Sopenharmony_ci XX(39, PAUSE, PAUSE) \ 2491cb0ef41Sopenharmony_ci XX(40, TEARDOWN, TEARDOWN) \ 2501cb0ef41Sopenharmony_ci XX(41, GET_PARAMETER, GET_PARAMETER) \ 2511cb0ef41Sopenharmony_ci XX(42, SET_PARAMETER, SET_PARAMETER) \ 2521cb0ef41Sopenharmony_ci XX(43, REDIRECT, REDIRECT) \ 2531cb0ef41Sopenharmony_ci XX(44, RECORD, RECORD) \ 2541cb0ef41Sopenharmony_ci XX(45, FLUSH, FLUSH) \ 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ci#define HTTP_ALL_METHOD_MAP(XX) \ 2581cb0ef41Sopenharmony_ci XX(0, DELETE, DELETE) \ 2591cb0ef41Sopenharmony_ci XX(1, GET, GET) \ 2601cb0ef41Sopenharmony_ci XX(2, HEAD, HEAD) \ 2611cb0ef41Sopenharmony_ci XX(3, POST, POST) \ 2621cb0ef41Sopenharmony_ci XX(4, PUT, PUT) \ 2631cb0ef41Sopenharmony_ci XX(5, CONNECT, CONNECT) \ 2641cb0ef41Sopenharmony_ci XX(6, OPTIONS, OPTIONS) \ 2651cb0ef41Sopenharmony_ci XX(7, TRACE, TRACE) \ 2661cb0ef41Sopenharmony_ci XX(8, COPY, COPY) \ 2671cb0ef41Sopenharmony_ci XX(9, LOCK, LOCK) \ 2681cb0ef41Sopenharmony_ci XX(10, MKCOL, MKCOL) \ 2691cb0ef41Sopenharmony_ci XX(11, MOVE, MOVE) \ 2701cb0ef41Sopenharmony_ci XX(12, PROPFIND, PROPFIND) \ 2711cb0ef41Sopenharmony_ci XX(13, PROPPATCH, PROPPATCH) \ 2721cb0ef41Sopenharmony_ci XX(14, SEARCH, SEARCH) \ 2731cb0ef41Sopenharmony_ci XX(15, UNLOCK, UNLOCK) \ 2741cb0ef41Sopenharmony_ci XX(16, BIND, BIND) \ 2751cb0ef41Sopenharmony_ci XX(17, REBIND, REBIND) \ 2761cb0ef41Sopenharmony_ci XX(18, UNBIND, UNBIND) \ 2771cb0ef41Sopenharmony_ci XX(19, ACL, ACL) \ 2781cb0ef41Sopenharmony_ci XX(20, REPORT, REPORT) \ 2791cb0ef41Sopenharmony_ci XX(21, MKACTIVITY, MKACTIVITY) \ 2801cb0ef41Sopenharmony_ci XX(22, CHECKOUT, CHECKOUT) \ 2811cb0ef41Sopenharmony_ci XX(23, MERGE, MERGE) \ 2821cb0ef41Sopenharmony_ci XX(24, MSEARCH, M-SEARCH) \ 2831cb0ef41Sopenharmony_ci XX(25, NOTIFY, NOTIFY) \ 2841cb0ef41Sopenharmony_ci XX(26, SUBSCRIBE, SUBSCRIBE) \ 2851cb0ef41Sopenharmony_ci XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ 2861cb0ef41Sopenharmony_ci XX(28, PATCH, PATCH) \ 2871cb0ef41Sopenharmony_ci XX(29, PURGE, PURGE) \ 2881cb0ef41Sopenharmony_ci XX(30, MKCALENDAR, MKCALENDAR) \ 2891cb0ef41Sopenharmony_ci XX(31, LINK, LINK) \ 2901cb0ef41Sopenharmony_ci XX(32, UNLINK, UNLINK) \ 2911cb0ef41Sopenharmony_ci XX(33, SOURCE, SOURCE) \ 2921cb0ef41Sopenharmony_ci XX(34, PRI, PRI) \ 2931cb0ef41Sopenharmony_ci XX(35, DESCRIBE, DESCRIBE) \ 2941cb0ef41Sopenharmony_ci XX(36, ANNOUNCE, ANNOUNCE) \ 2951cb0ef41Sopenharmony_ci XX(37, SETUP, SETUP) \ 2961cb0ef41Sopenharmony_ci XX(38, PLAY, PLAY) \ 2971cb0ef41Sopenharmony_ci XX(39, PAUSE, PAUSE) \ 2981cb0ef41Sopenharmony_ci XX(40, TEARDOWN, TEARDOWN) \ 2991cb0ef41Sopenharmony_ci XX(41, GET_PARAMETER, GET_PARAMETER) \ 3001cb0ef41Sopenharmony_ci XX(42, SET_PARAMETER, SET_PARAMETER) \ 3011cb0ef41Sopenharmony_ci XX(43, REDIRECT, REDIRECT) \ 3021cb0ef41Sopenharmony_ci XX(44, RECORD, RECORD) \ 3031cb0ef41Sopenharmony_ci XX(45, FLUSH, FLUSH) \ 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_ci#ifdef __cplusplus 3071cb0ef41Sopenharmony_ci} /* extern "C" */ 3081cb0ef41Sopenharmony_ci#endif 3091cb0ef41Sopenharmony_ci#endif /* LLLLHTTP_C_HEADERS_ */ 3101cb0ef41Sopenharmony_ci 3111cb0ef41Sopenharmony_ci#ifndef INCLUDE_LLHTTP_API_H_ 3121cb0ef41Sopenharmony_ci#define INCLUDE_LLHTTP_API_H_ 3131cb0ef41Sopenharmony_ci#ifdef __cplusplus 3141cb0ef41Sopenharmony_ciextern "C" { 3151cb0ef41Sopenharmony_ci#endif 3161cb0ef41Sopenharmony_ci#include <stddef.h> 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci#if defined(__wasm__) 3191cb0ef41Sopenharmony_ci#define LLHTTP_EXPORT __attribute__((visibility("default"))) 3201cb0ef41Sopenharmony_ci#else 3211cb0ef41Sopenharmony_ci#define LLHTTP_EXPORT 3221cb0ef41Sopenharmony_ci#endif 3231cb0ef41Sopenharmony_ci 3241cb0ef41Sopenharmony_citypedef llhttp__internal_t llhttp_t; 3251cb0ef41Sopenharmony_citypedef struct llhttp_settings_s llhttp_settings_t; 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_citypedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length); 3281cb0ef41Sopenharmony_citypedef int (*llhttp_cb)(llhttp_t*); 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_cistruct llhttp_settings_s { 3311cb0ef41Sopenharmony_ci /* Possible return values 0, -1, `HPE_PAUSED` */ 3321cb0ef41Sopenharmony_ci llhttp_cb on_message_begin; 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_ci /* Possible return values 0, -1, HPE_USER */ 3351cb0ef41Sopenharmony_ci llhttp_data_cb on_url; 3361cb0ef41Sopenharmony_ci llhttp_data_cb on_status; 3371cb0ef41Sopenharmony_ci llhttp_data_cb on_header_field; 3381cb0ef41Sopenharmony_ci llhttp_data_cb on_header_value; 3391cb0ef41Sopenharmony_ci 3401cb0ef41Sopenharmony_ci /* Possible return values: 3411cb0ef41Sopenharmony_ci * 0 - Proceed normally 3421cb0ef41Sopenharmony_ci * 1 - Assume that request/response has no body, and proceed to parsing the 3431cb0ef41Sopenharmony_ci * next message 3441cb0ef41Sopenharmony_ci * 2 - Assume absence of body (as above) and make `llhttp_execute()` return 3451cb0ef41Sopenharmony_ci * `HPE_PAUSED_UPGRADE` 3461cb0ef41Sopenharmony_ci * -1 - Error 3471cb0ef41Sopenharmony_ci * `HPE_PAUSED` 3481cb0ef41Sopenharmony_ci */ 3491cb0ef41Sopenharmony_ci llhttp_cb on_headers_complete; 3501cb0ef41Sopenharmony_ci 3511cb0ef41Sopenharmony_ci /* Possible return values 0, -1, HPE_USER */ 3521cb0ef41Sopenharmony_ci llhttp_data_cb on_chunk_parameters; 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ci /* Possible return values 0, -1, HPE_USER */ 3551cb0ef41Sopenharmony_ci llhttp_data_cb on_body; 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_ci /* Possible return values 0, -1, `HPE_PAUSED` */ 3581cb0ef41Sopenharmony_ci llhttp_cb on_message_complete; 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci /* When on_chunk_header is called, the current chunk length is stored 3611cb0ef41Sopenharmony_ci * in parser->content_length. 3621cb0ef41Sopenharmony_ci * Possible return values 0, -1, `HPE_PAUSED` 3631cb0ef41Sopenharmony_ci */ 3641cb0ef41Sopenharmony_ci llhttp_cb on_chunk_header; 3651cb0ef41Sopenharmony_ci llhttp_cb on_chunk_complete; 3661cb0ef41Sopenharmony_ci 3671cb0ef41Sopenharmony_ci /* Information-only callbacks, return value is ignored */ 3681cb0ef41Sopenharmony_ci llhttp_cb on_url_complete; 3691cb0ef41Sopenharmony_ci llhttp_cb on_status_complete; 3701cb0ef41Sopenharmony_ci llhttp_cb on_header_field_complete; 3711cb0ef41Sopenharmony_ci llhttp_cb on_header_value_complete; 3721cb0ef41Sopenharmony_ci}; 3731cb0ef41Sopenharmony_ci 3741cb0ef41Sopenharmony_ci/* Initialize the parser with specific type and user settings. 3751cb0ef41Sopenharmony_ci * 3761cb0ef41Sopenharmony_ci * NOTE: lifetime of `settings` has to be at least the same as the lifetime of 3771cb0ef41Sopenharmony_ci * the `parser` here. In practice, `settings` has to be either a static 3781cb0ef41Sopenharmony_ci * variable or be allocated with `malloc`, `new`, etc. 3791cb0ef41Sopenharmony_ci */ 3801cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3811cb0ef41Sopenharmony_civoid llhttp_init(llhttp_t* parser, llhttp_type_t type, 3821cb0ef41Sopenharmony_ci const llhttp_settings_t* settings); 3831cb0ef41Sopenharmony_ci 3841cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3851cb0ef41Sopenharmony_cillhttp_t* llhttp_alloc(llhttp_type_t type); 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3881cb0ef41Sopenharmony_civoid llhttp_free(llhttp_t* parser); 3891cb0ef41Sopenharmony_ci 3901cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3911cb0ef41Sopenharmony_ciuint8_t llhttp_get_type(llhttp_t* parser); 3921cb0ef41Sopenharmony_ci 3931cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3941cb0ef41Sopenharmony_ciuint8_t llhttp_get_http_major(llhttp_t* parser); 3951cb0ef41Sopenharmony_ci 3961cb0ef41Sopenharmony_ciLLHTTP_EXPORT 3971cb0ef41Sopenharmony_ciuint8_t llhttp_get_http_minor(llhttp_t* parser); 3981cb0ef41Sopenharmony_ci 3991cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4001cb0ef41Sopenharmony_ciuint8_t llhttp_get_method(llhttp_t* parser); 4011cb0ef41Sopenharmony_ci 4021cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4031cb0ef41Sopenharmony_ciint llhttp_get_status_code(llhttp_t* parser); 4041cb0ef41Sopenharmony_ci 4051cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4061cb0ef41Sopenharmony_ciuint8_t llhttp_get_upgrade(llhttp_t* parser); 4071cb0ef41Sopenharmony_ci 4081cb0ef41Sopenharmony_ci/* Reset an already initialized parser back to the start state, preserving the 4091cb0ef41Sopenharmony_ci * existing parser type, callback settings, user data, and lenient flags. 4101cb0ef41Sopenharmony_ci */ 4111cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4121cb0ef41Sopenharmony_civoid llhttp_reset(llhttp_t* parser); 4131cb0ef41Sopenharmony_ci 4141cb0ef41Sopenharmony_ci/* Initialize the settings object */ 4151cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4161cb0ef41Sopenharmony_civoid llhttp_settings_init(llhttp_settings_t* settings); 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ci/* Parse full or partial request/response, invoking user callbacks along the 4191cb0ef41Sopenharmony_ci * way. 4201cb0ef41Sopenharmony_ci * 4211cb0ef41Sopenharmony_ci * If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing 4221cb0ef41Sopenharmony_ci * interrupts, and such errno is returned from `llhttp_execute()`. If 4231cb0ef41Sopenharmony_ci * `HPE_PAUSED` was used as a errno, the execution can be resumed with 4241cb0ef41Sopenharmony_ci * `llhttp_resume()` call. 4251cb0ef41Sopenharmony_ci * 4261cb0ef41Sopenharmony_ci * In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE` 4271cb0ef41Sopenharmony_ci * is returned after fully parsing the request/response. If the user wishes to 4281cb0ef41Sopenharmony_ci * continue parsing, they need to invoke `llhttp_resume_after_upgrade()`. 4291cb0ef41Sopenharmony_ci * 4301cb0ef41Sopenharmony_ci * NOTE: if this function ever returns a non-pause type error, it will continue 4311cb0ef41Sopenharmony_ci * to return the same error upon each successive call up until `llhttp_init()` 4321cb0ef41Sopenharmony_ci * is called. 4331cb0ef41Sopenharmony_ci */ 4341cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4351cb0ef41Sopenharmony_cillhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len); 4361cb0ef41Sopenharmony_ci 4371cb0ef41Sopenharmony_ci/* This method should be called when the other side has no further bytes to 4381cb0ef41Sopenharmony_ci * send (e.g. shutdown of readable side of the TCP connection.) 4391cb0ef41Sopenharmony_ci * 4401cb0ef41Sopenharmony_ci * Requests without `Content-Length` and other messages might require treating 4411cb0ef41Sopenharmony_ci * all incoming bytes as the part of the body, up to the last byte of the 4421cb0ef41Sopenharmony_ci * connection. This method will invoke `on_message_complete()` callback if the 4431cb0ef41Sopenharmony_ci * request was terminated safely. Otherwise a error code would be returned. 4441cb0ef41Sopenharmony_ci */ 4451cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4461cb0ef41Sopenharmony_cillhttp_errno_t llhttp_finish(llhttp_t* parser); 4471cb0ef41Sopenharmony_ci 4481cb0ef41Sopenharmony_ci/* Returns `1` if the incoming message is parsed until the last byte, and has 4491cb0ef41Sopenharmony_ci * to be completed by calling `llhttp_finish()` on EOF 4501cb0ef41Sopenharmony_ci */ 4511cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4521cb0ef41Sopenharmony_ciint llhttp_message_needs_eof(const llhttp_t* parser); 4531cb0ef41Sopenharmony_ci 4541cb0ef41Sopenharmony_ci/* Returns `1` if there might be any other messages following the last that was 4551cb0ef41Sopenharmony_ci * successfully parsed. 4561cb0ef41Sopenharmony_ci */ 4571cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4581cb0ef41Sopenharmony_ciint llhttp_should_keep_alive(const llhttp_t* parser); 4591cb0ef41Sopenharmony_ci 4601cb0ef41Sopenharmony_ci/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set 4611cb0ef41Sopenharmony_ci * appropriate error reason. 4621cb0ef41Sopenharmony_ci * 4631cb0ef41Sopenharmony_ci * Important: do not call this from user callbacks! User callbacks must return 4641cb0ef41Sopenharmony_ci * `HPE_PAUSED` if pausing is required. 4651cb0ef41Sopenharmony_ci */ 4661cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4671cb0ef41Sopenharmony_civoid llhttp_pause(llhttp_t* parser); 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci/* Might be called to resume the execution after the pause in user's callback. 4701cb0ef41Sopenharmony_ci * See `llhttp_execute()` above for details. 4711cb0ef41Sopenharmony_ci * 4721cb0ef41Sopenharmony_ci * Call this only if `llhttp_execute()` returns `HPE_PAUSED`. 4731cb0ef41Sopenharmony_ci */ 4741cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4751cb0ef41Sopenharmony_civoid llhttp_resume(llhttp_t* parser); 4761cb0ef41Sopenharmony_ci 4771cb0ef41Sopenharmony_ci/* Might be called to resume the execution after the pause in user's callback. 4781cb0ef41Sopenharmony_ci * See `llhttp_execute()` above for details. 4791cb0ef41Sopenharmony_ci * 4801cb0ef41Sopenharmony_ci * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE` 4811cb0ef41Sopenharmony_ci */ 4821cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4831cb0ef41Sopenharmony_civoid llhttp_resume_after_upgrade(llhttp_t* parser); 4841cb0ef41Sopenharmony_ci 4851cb0ef41Sopenharmony_ci/* Returns the latest return error */ 4861cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4871cb0ef41Sopenharmony_cillhttp_errno_t llhttp_get_errno(const llhttp_t* parser); 4881cb0ef41Sopenharmony_ci 4891cb0ef41Sopenharmony_ci/* Returns the verbal explanation of the latest returned error. 4901cb0ef41Sopenharmony_ci * 4911cb0ef41Sopenharmony_ci * Note: User callback should set error reason when returning the error. See 4921cb0ef41Sopenharmony_ci * `llhttp_set_error_reason()` for details. 4931cb0ef41Sopenharmony_ci */ 4941cb0ef41Sopenharmony_ciLLHTTP_EXPORT 4951cb0ef41Sopenharmony_ciconst char* llhttp_get_error_reason(const llhttp_t* parser); 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ci/* Assign verbal description to the returned error. Must be called in user 4981cb0ef41Sopenharmony_ci * callbacks right before returning the errno. 4991cb0ef41Sopenharmony_ci * 5001cb0ef41Sopenharmony_ci * Note: `HPE_USER` error code might be useful in user callbacks. 5011cb0ef41Sopenharmony_ci */ 5021cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5031cb0ef41Sopenharmony_civoid llhttp_set_error_reason(llhttp_t* parser, const char* reason); 5041cb0ef41Sopenharmony_ci 5051cb0ef41Sopenharmony_ci/* Returns the pointer to the last parsed byte before the returned error. The 5061cb0ef41Sopenharmony_ci * pointer is relative to the `data` argument of `llhttp_execute()`. 5071cb0ef41Sopenharmony_ci * 5081cb0ef41Sopenharmony_ci * Note: this method might be useful for counting the number of parsed bytes. 5091cb0ef41Sopenharmony_ci */ 5101cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5111cb0ef41Sopenharmony_ciconst char* llhttp_get_error_pos(const llhttp_t* parser); 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_ci/* Returns textual name of error code */ 5141cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5151cb0ef41Sopenharmony_ciconst char* llhttp_errno_name(llhttp_errno_t err); 5161cb0ef41Sopenharmony_ci 5171cb0ef41Sopenharmony_ci/* Returns textual name of HTTP method */ 5181cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5191cb0ef41Sopenharmony_ciconst char* llhttp_method_name(llhttp_method_t method); 5201cb0ef41Sopenharmony_ci 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci/* Enables/disables lenient header value parsing (disabled by default). 5231cb0ef41Sopenharmony_ci * 5241cb0ef41Sopenharmony_ci * Lenient parsing disables header value token checks, extending llhttp's 5251cb0ef41Sopenharmony_ci * protocol support to highly non-compliant clients/server. No 5261cb0ef41Sopenharmony_ci * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when 5271cb0ef41Sopenharmony_ci * lenient parsing is "on". 5281cb0ef41Sopenharmony_ci * 5291cb0ef41Sopenharmony_ci * **(USE AT YOUR OWN RISK)** 5301cb0ef41Sopenharmony_ci */ 5311cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5321cb0ef41Sopenharmony_civoid llhttp_set_lenient_headers(llhttp_t* parser, int enabled); 5331cb0ef41Sopenharmony_ci 5341cb0ef41Sopenharmony_ci 5351cb0ef41Sopenharmony_ci/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and 5361cb0ef41Sopenharmony_ci * `Content-Length` headers (disabled by default). 5371cb0ef41Sopenharmony_ci * 5381cb0ef41Sopenharmony_ci * Normally `llhttp` would error when `Transfer-Encoding` is present in 5391cb0ef41Sopenharmony_ci * conjunction with `Content-Length`. This error is important to prevent HTTP 5401cb0ef41Sopenharmony_ci * request smuggling, but may be less desirable for small number of cases 5411cb0ef41Sopenharmony_ci * involving legacy servers. 5421cb0ef41Sopenharmony_ci * 5431cb0ef41Sopenharmony_ci * **(USE AT YOUR OWN RISK)** 5441cb0ef41Sopenharmony_ci */ 5451cb0ef41Sopenharmony_ciLLHTTP_EXPORT 5461cb0ef41Sopenharmony_civoid llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled); 5471cb0ef41Sopenharmony_ci 5481cb0ef41Sopenharmony_ci 5491cb0ef41Sopenharmony_ci/* Enables/disables lenient handling of `Connection: close` and HTTP/1.0 5501cb0ef41Sopenharmony_ci * requests responses. 5511cb0ef41Sopenharmony_ci * 5521cb0ef41Sopenharmony_ci * Normally `llhttp` would error on (in strict mode) or discard (in loose mode) 5531cb0ef41Sopenharmony_ci * the HTTP request/response after the request/response with `Connection: close` 5541cb0ef41Sopenharmony_ci * and `Content-Length`. This is important to prevent cache poisoning attacks, 5551cb0ef41Sopenharmony_ci * but might interact badly with outdated and insecure clients. With this flag 5561cb0ef41Sopenharmony_ci * the extra request/response will be parsed normally. 5571cb0ef41Sopenharmony_ci * 5581cb0ef41Sopenharmony_ci * **(USE AT YOUR OWN RISK)** 5591cb0ef41Sopenharmony_ci */ 5601cb0ef41Sopenharmony_civoid llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled); 5611cb0ef41Sopenharmony_ci 5621cb0ef41Sopenharmony_ci/* Enables/disables lenient handling of `Transfer-Encoding` header. 5631cb0ef41Sopenharmony_ci * 5641cb0ef41Sopenharmony_ci * Normally `llhttp` would error when a `Transfer-Encoding` has `chunked` value 5651cb0ef41Sopenharmony_ci * and another value after it (either in a single header or in multiple 5661cb0ef41Sopenharmony_ci * headers whose value are internally joined using `, `). 5671cb0ef41Sopenharmony_ci * This is mandated by the spec to reliably determine request body size and thus 5681cb0ef41Sopenharmony_ci * avoid request smuggling. 5691cb0ef41Sopenharmony_ci * With this flag the extra value will be parsed normally. 5701cb0ef41Sopenharmony_ci * 5711cb0ef41Sopenharmony_ci * **(USE AT YOUR OWN RISK)** 5721cb0ef41Sopenharmony_ci */ 5731cb0ef41Sopenharmony_civoid llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled); 5741cb0ef41Sopenharmony_ci 5751cb0ef41Sopenharmony_ci#ifdef __cplusplus 5761cb0ef41Sopenharmony_ci} /* extern "C" */ 5771cb0ef41Sopenharmony_ci#endif 5781cb0ef41Sopenharmony_ci#endif /* INCLUDE_LLHTTP_API_H_ */ 5791cb0ef41Sopenharmony_ci 5801cb0ef41Sopenharmony_ci#endif /* INCLUDE_LLHTTP_H_ */ 581