11#ifndef INCLUDE_LLHTTP_H_
22#define INCLUDE_LLHTTP_H_
33
4- #define LLHTTP_VERSION_MAJOR 6
5- #define LLHTTP_VERSION_MINOR 0
4+ #define LLHTTP_VERSION_MAJOR 4
5+ #define LLHTTP_VERSION_MINOR 1
66#define LLHTTP_VERSION_PATCH 1
77
88#ifndef LLHTTP_STRICT_MODE
@@ -99,8 +99,7 @@ typedef enum llhttp_flags llhttp_flags_t;
9999
100100enum llhttp_lenient_flags {
101101 LENIENT_HEADERS = 0x1 ,
102- LENIENT_CHUNKED_LENGTH = 0x2 ,
103- LENIENT_KEEP_ALIVE = 0x4
102+ LENIENT_CHUNKED_LENGTH = 0x2
104103};
105104typedef enum llhttp_lenient_flags llhttp_lenient_flags_t ;
106105
@@ -231,60 +230,6 @@ typedef enum llhttp_method llhttp_method_t;
231230 XX(31, LINK, LINK) \
232231 XX(32, UNLINK, UNLINK) \
233232 XX(33, SOURCE, SOURCE) \
234-
235-
236- #define RTSP_METHOD_MAP (XX ) \
237- XX(1, GET, GET) \
238- XX(3, POST, POST) \
239- XX(6, OPTIONS, OPTIONS) \
240- XX(35, DESCRIBE, DESCRIBE) \
241- XX(36, ANNOUNCE, ANNOUNCE) \
242- XX(37, SETUP, SETUP) \
243- XX(38, PLAY, PLAY) \
244- XX(39, PAUSE, PAUSE) \
245- XX(40, TEARDOWN, TEARDOWN) \
246- XX(41, GET_PARAMETER, GET_PARAMETER) \
247- XX(42, SET_PARAMETER, SET_PARAMETER) \
248- XX(43, REDIRECT, REDIRECT) \
249- XX(44, RECORD, RECORD) \
250- XX(45, FLUSH, FLUSH) \
251-
252-
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) \
288233 XX(34, PRI, PRI) \
289234 XX(35, DESCRIBE, DESCRIBE) \
290235 XX(36, ANNOUNCE, ANNOUNCE) \
@@ -299,6 +244,7 @@ typedef enum llhttp_method llhttp_method_t;
299244 XX(45, FLUSH, FLUSH) \
300245
301246
247+
302248#ifdef __cplusplus
303249} /* extern "C" */
304250#endif
@@ -311,12 +257,6 @@ extern "C" {
311257#endif
312258#include <stddef.h>
313259
314- #if defined(__wasm__ )
315- #define LLHTTP_EXPORT __attribute__((visibility("default")))
316- #else
317- #define LLHTTP_EXPORT
318- #endif
319-
320260typedef llhttp__internal_t llhttp_t ;
321261typedef struct llhttp_settings_s llhttp_settings_t ;
322262
@@ -327,7 +267,6 @@ struct llhttp_settings_s {
327267 /* Possible return values 0, -1, `HPE_PAUSED` */
328268 llhttp_cb on_message_begin ;
329269
330- /* Possible return values 0, -1, HPE_USER */
331270 llhttp_data_cb on_url ;
332271 llhttp_data_cb on_status ;
333272 llhttp_data_cb on_header_field ;
@@ -344,7 +283,6 @@ struct llhttp_settings_s {
344283 */
345284 llhttp_cb on_headers_complete ;
346285
347- /* Possible return values 0, -1, HPE_USER */
348286 llhttp_data_cb on_body ;
349287
350288 /* Possible return values 0, -1, `HPE_PAUSED` */
@@ -357,7 +295,6 @@ struct llhttp_settings_s {
357295 llhttp_cb on_chunk_header ;
358296 llhttp_cb on_chunk_complete ;
359297
360- /* Information-only callbacks, return value is ignored */
361298 llhttp_cb on_url_complete ;
362299 llhttp_cb on_status_complete ;
363300 llhttp_cb on_header_field_complete ;
@@ -370,46 +307,15 @@ struct llhttp_settings_s {
370307 * the `parser` here. In practice, `settings` has to be either a static
371308 * variable or be allocated with `malloc`, `new`, etc.
372309 */
373- LLHTTP_EXPORT
374310void llhttp_init (llhttp_t * parser , llhttp_type_t type ,
375311 const llhttp_settings_t * settings );
376312
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-
405313/* Reset an already initialized parser back to the start state, preserving the
406314 * existing parser type, callback settings, user data, and lenient flags.
407315 */
408- LLHTTP_EXPORT
409316void llhttp_reset (llhttp_t * parser );
410317
411318/* Initialize the settings object */
412- LLHTTP_EXPORT
413319void llhttp_settings_init (llhttp_settings_t * settings );
414320
415321/* Parse full or partial request/response, invoking user callbacks along the
@@ -428,7 +334,6 @@ void llhttp_settings_init(llhttp_settings_t* settings);
428334 * to return the same error upon each successive call up until `llhttp_init()`
429335 * is called.
430336 */
431- LLHTTP_EXPORT
432337llhttp_errno_t llhttp_execute (llhttp_t * parser , const char * data , size_t len );
433338
434339/* This method should be called when the other side has no further bytes to
@@ -439,19 +344,16 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
439344 * connection. This method will invoke `on_message_complete()` callback if the
440345 * request was terminated safely. Otherwise a error code would be returned.
441346 */
442- LLHTTP_EXPORT
443347llhttp_errno_t llhttp_finish (llhttp_t * parser );
444348
445349/* Returns `1` if the incoming message is parsed until the last byte, and has
446350 * to be completed by calling `llhttp_finish()` on EOF
447351 */
448- LLHTTP_EXPORT
449352int llhttp_message_needs_eof (const llhttp_t * parser );
450353
451354/* Returns `1` if there might be any other messages following the last that was
452355 * successfully parsed.
453356 */
454- LLHTTP_EXPORT
455357int llhttp_should_keep_alive (const llhttp_t * parser );
456358
457359/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -460,59 +362,50 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
460362 * Important: do not call this from user callbacks! User callbacks must return
461363 * `HPE_PAUSED` if pausing is required.
462364 */
463- LLHTTP_EXPORT
464365void llhttp_pause (llhttp_t * parser );
465366
466367/* Might be called to resume the execution after the pause in user's callback.
467368 * See `llhttp_execute()` above for details.
468369 *
469370 * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
470371 */
471- LLHTTP_EXPORT
472372void llhttp_resume (llhttp_t * parser );
473373
474374/* Might be called to resume the execution after the pause in user's callback.
475375 * See `llhttp_execute()` above for details.
476376 *
477377 * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
478378 */
479- LLHTTP_EXPORT
480379void llhttp_resume_after_upgrade (llhttp_t * parser );
481380
482381/* Returns the latest return error */
483- LLHTTP_EXPORT
484382llhttp_errno_t llhttp_get_errno (const llhttp_t * parser );
485383
486384/* Returns the verbal explanation of the latest returned error.
487385 *
488386 * Note: User callback should set error reason when returning the error. See
489387 * `llhttp_set_error_reason()` for details.
490388 */
491- LLHTTP_EXPORT
492389const char * llhttp_get_error_reason (const llhttp_t * parser );
493390
494391/* Assign verbal description to the returned error. Must be called in user
495392 * callbacks right before returning the errno.
496393 *
497394 * Note: `HPE_USER` error code might be useful in user callbacks.
498395 */
499- LLHTTP_EXPORT
500396void llhttp_set_error_reason (llhttp_t * parser , const char * reason );
501397
502398/* Returns the pointer to the last parsed byte before the returned error. The
503399 * pointer is relative to the `data` argument of `llhttp_execute()`.
504400 *
505401 * Note: this method might be useful for counting the number of parsed bytes.
506402 */
507- LLHTTP_EXPORT
508403const char * llhttp_get_error_pos (const llhttp_t * parser );
509404
510405/* Returns textual name of error code */
511- LLHTTP_EXPORT
512406const char * llhttp_errno_name (llhttp_errno_t err );
513407
514408/* Returns textual name of HTTP method */
515- LLHTTP_EXPORT
516409const char * llhttp_method_name (llhttp_method_t method );
517410
518411
@@ -525,7 +418,6 @@ const char* llhttp_method_name(llhttp_method_t method);
525418 *
526419 * **(USE AT YOUR OWN RISK)**
527420 */
528- LLHTTP_EXPORT
529421void llhttp_set_lenient_headers (llhttp_t * parser , int enabled );
530422
531423
@@ -539,23 +431,8 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
539431 *
540432 * **(USE AT YOUR OWN RISK)**
541433 */
542- LLHTTP_EXPORT
543434void llhttp_set_lenient_chunked_length (llhttp_t * parser , int enabled );
544435
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-
559436#ifdef __cplusplus
560437} /* extern "C" */
561438#endif
0 commit comments