From 9a3070c5e1f0c33c5499113e452caa193843f2ea Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 18 Jul 2021 23:16:44 +0800 Subject: [PATCH] Update llhttp to 6.0.5 [skip ci] --- thirdparty/llhttp/CMakeLists.txt | 2 +- thirdparty/llhttp/api.h | 256 ----------------------- thirdparty/llhttp/{ => include}/llhttp.h | 2 +- thirdparty/llhttp/{ => src}/api.c | 3 +- thirdparty/llhttp/{ => src}/http.c | 0 thirdparty/llhttp/{ => src}/llhttp.c | 0 6 files changed, 4 insertions(+), 259 deletions(-) delete mode 100644 thirdparty/llhttp/api.h rename thirdparty/llhttp/{ => include}/llhttp.h (99%) rename thirdparty/llhttp/{ => src}/api.c (98%) rename thirdparty/llhttp/{ => src}/http.c (100%) rename thirdparty/llhttp/{ => src}/llhttp.c (100%) diff --git a/thirdparty/llhttp/CMakeLists.txt b/thirdparty/llhttp/CMakeLists.txt index 020551ba4e..4cc29f82de 100644 --- a/thirdparty/llhttp/CMakeLists.txt +++ b/thirdparty/llhttp/CMakeLists.txt @@ -9,4 +9,4 @@ add_library(${target_name} STATIC ${${target_name}_src} ) -target_include_directories(${target_name} PUBLIC ..) +target_include_directories(${target_name} PUBLIC "include") diff --git a/thirdparty/llhttp/api.h b/thirdparty/llhttp/api.h deleted file mode 100644 index d86c022320..0000000000 --- a/thirdparty/llhttp/api.h +++ /dev/null @@ -1,256 +0,0 @@ -#ifndef INCLUDE_LLHTTP_API_H_ -#define INCLUDE_LLHTTP_API_H_ -#ifdef __cplusplus -extern "C" { -#endif -#include - -#if defined(__wasm__) -#define LLHTTP_EXPORT __attribute__((visibility("default"))) -#else -#define LLHTTP_EXPORT -#endif - -typedef llhttp__internal_t llhttp_t; -typedef struct llhttp_settings_s llhttp_settings_t; - -typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length); -typedef int (*llhttp_cb)(llhttp_t*); - -struct llhttp_settings_s { - /* Possible return values 0, -1, `HPE_PAUSED` */ - llhttp_cb on_message_begin; - - /* Possible return values 0, -1, HPE_USER */ - llhttp_data_cb on_url; - llhttp_data_cb on_status; - llhttp_data_cb on_header_field; - llhttp_data_cb on_header_value; - - /* Possible return values: - * 0 - Proceed normally - * 1 - Assume that request/response has no body, and proceed to parsing the - * next message - * 2 - Assume absence of body (as above) and make `llhttp_execute()` return - * `HPE_PAUSED_UPGRADE` - * -1 - Error - * `HPE_PAUSED` - */ - llhttp_cb on_headers_complete; - - /* Possible return values 0, -1, HPE_USER */ - llhttp_data_cb on_body; - - /* Possible return values 0, -1, `HPE_PAUSED` */ - llhttp_cb on_message_complete; - - /* When on_chunk_header is called, the current chunk length is stored - * in parser->content_length. - * Possible return values 0, -1, `HPE_PAUSED` - */ - llhttp_cb on_chunk_header; - llhttp_cb on_chunk_complete; - - /* Information-only callbacks, return value is ignored */ - llhttp_cb on_url_complete; - llhttp_cb on_status_complete; - llhttp_cb on_header_field_complete; - llhttp_cb on_header_value_complete; -}; - -/* Initialize the parser with specific type and user settings. - * - * NOTE: lifetime of `settings` has to be at least the same as the lifetime of - * the `parser` here. In practice, `settings` has to be either a static - * variable or be allocated with `malloc`, `new`, etc. - */ -LLHTTP_EXPORT -void llhttp_init(llhttp_t* parser, llhttp_type_t type, - const llhttp_settings_t* settings); - -#if defined(__wasm__) - -LLHTTP_EXPORT -llhttp_t* llhttp_alloc(llhttp_type_t type); - -LLHTTP_EXPORT -void llhttp_free(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_type(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_http_major(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_http_minor(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_method(llhttp_t* parser); - -LLHTTP_EXPORT -int llhttp_get_status_code(llhttp_t* parser); - -LLHTTP_EXPORT -uint8_t llhttp_get_upgrade(llhttp_t* parser); - -#endif // defined(__wasm__) - -/* Reset an already initialized parser back to the start state, preserving the - * existing parser type, callback settings, user data, and lenient flags. - */ -LLHTTP_EXPORT -void llhttp_reset(llhttp_t* parser); - -/* Initialize the settings object */ -LLHTTP_EXPORT -void llhttp_settings_init(llhttp_settings_t* settings); - -/* Parse full or partial request/response, invoking user callbacks along the - * way. - * - * If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing - * interrupts, and such errno is returned from `llhttp_execute()`. If - * `HPE_PAUSED` was used as a errno, the execution can be resumed with - * `llhttp_resume()` call. - * - * In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE` - * is returned after fully parsing the request/response. If the user wishes to - * continue parsing, they need to invoke `llhttp_resume_after_upgrade()`. - * - * NOTE: if this function ever returns a non-pause type error, it will continue - * to return the same error upon each successive call up until `llhttp_init()` - * is called. - */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len); - -/* This method should be called when the other side has no further bytes to - * send (e.g. shutdown of readable side of the TCP connection.) - * - * Requests without `Content-Length` and other messages might require treating - * all incoming bytes as the part of the body, up to the last byte of the - * connection. This method will invoke `on_message_complete()` callback if the - * request was terminated safely. Otherwise a error code would be returned. - */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_finish(llhttp_t* parser); - -/* Returns `1` if the incoming message is parsed until the last byte, and has - * to be completed by calling `llhttp_finish()` on EOF - */ -LLHTTP_EXPORT -int llhttp_message_needs_eof(const llhttp_t* parser); - -/* Returns `1` if there might be any other messages following the last that was - * successfully parsed. - */ -LLHTTP_EXPORT -int llhttp_should_keep_alive(const llhttp_t* parser); - -/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set - * appropriate error reason. - * - * Important: do not call this from user callbacks! User callbacks must return - * `HPE_PAUSED` if pausing is required. - */ -LLHTTP_EXPORT -void llhttp_pause(llhttp_t* parser); - -/* Might be called to resume the execution after the pause in user's callback. - * See `llhttp_execute()` above for details. - * - * Call this only if `llhttp_execute()` returns `HPE_PAUSED`. - */ -LLHTTP_EXPORT -void llhttp_resume(llhttp_t* parser); - -/* Might be called to resume the execution after the pause in user's callback. - * See `llhttp_execute()` above for details. - * - * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE` - */ -LLHTTP_EXPORT -void llhttp_resume_after_upgrade(llhttp_t* parser); - -/* Returns the latest return error */ -LLHTTP_EXPORT -llhttp_errno_t llhttp_get_errno(const llhttp_t* parser); - -/* Returns the verbal explanation of the latest returned error. - * - * Note: User callback should set error reason when returning the error. See - * `llhttp_set_error_reason()` for details. - */ -LLHTTP_EXPORT -const char* llhttp_get_error_reason(const llhttp_t* parser); - -/* Assign verbal description to the returned error. Must be called in user - * callbacks right before returning the errno. - * - * Note: `HPE_USER` error code might be useful in user callbacks. - */ -LLHTTP_EXPORT -void llhttp_set_error_reason(llhttp_t* parser, const char* reason); - -/* Returns the pointer to the last parsed byte before the returned error. The - * pointer is relative to the `data` argument of `llhttp_execute()`. - * - * Note: this method might be useful for counting the number of parsed bytes. - */ -LLHTTP_EXPORT -const char* llhttp_get_error_pos(const llhttp_t* parser); - -/* Returns textual name of error code */ -LLHTTP_EXPORT -const char* llhttp_errno_name(llhttp_errno_t err); - -/* Returns textual name of HTTP method */ -LLHTTP_EXPORT -const char* llhttp_method_name(llhttp_method_t method); - - -/* Enables/disables lenient header value parsing (disabled by default). - * - * Lenient parsing disables header value token checks, extending llhttp's - * protocol support to highly non-compliant clients/server. No - * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when - * lenient parsing is "on". - * - * **(USE AT YOUR OWN RISK)** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_headers(llhttp_t* parser, int enabled); - - -/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and - * `Content-Length` headers (disabled by default). - * - * Normally `llhttp` would error when `Transfer-Encoding` is present in - * conjunction with `Content-Length`. This error is important to prevent HTTP - * request smuggling, but may be less desirable for small number of cases - * involving legacy servers. - * - * **(USE AT YOUR OWN RISK)** - */ -LLHTTP_EXPORT -void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled); - - -/* Enables/disables lenient handling of `Connection: close` and HTTP/1.0 - * requests responses. - * - * Normally `llhttp` would error on (in strict mode) or discard (in loose mode) - * the HTTP request/response after the request/response with `Connection: close` - * and `Content-Length`. This is important to prevent cache poisoning attacks, - * but might interact badly with outdated and insecure clients. With this flag - * the extra request/response will be parsed normally. - * - * **(USE AT YOUR OWN RISK)** - */ -void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled); - -#ifdef __cplusplus -} /* extern "C" */ -#endif -#endif /* INCLUDE_LLHTTP_API_H_ */ diff --git a/thirdparty/llhttp/llhttp.h b/thirdparty/llhttp/include/llhttp.h similarity index 99% rename from thirdparty/llhttp/llhttp.h rename to thirdparty/llhttp/include/llhttp.h index b58be5d1fe..336234c6a4 100644 --- a/thirdparty/llhttp/llhttp.h +++ b/thirdparty/llhttp/include/llhttp.h @@ -3,7 +3,7 @@ #define LLHTTP_VERSION_MAJOR 6 #define LLHTTP_VERSION_MINOR 0 -#define LLHTTP_VERSION_PATCH 3 +#define LLHTTP_VERSION_PATCH 4 #ifndef LLHTTP_STRICT_MODE # define LLHTTP_STRICT_MODE 0 diff --git a/thirdparty/llhttp/api.c b/thirdparty/llhttp/src/api.c similarity index 98% rename from thirdparty/llhttp/api.c rename to thirdparty/llhttp/src/api.c index 04e57fd78c..1a3bf7b5f3 100644 --- a/thirdparty/llhttp/api.c +++ b/thirdparty/llhttp/src/api.c @@ -46,7 +46,8 @@ extern int wasm_on_url(llhttp_t* p, const char* at, size_t length); extern int wasm_on_status(llhttp_t* p, const char* at, size_t length); extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length); extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length); -extern int wasm_on_headers_complete(llhttp_t * p); +extern int wasm_on_headers_complete(llhttp_t * p, int status_code, + uint8_t upgrade, int should_keep_alive); extern int wasm_on_body(llhttp_t* p, const char* at, size_t length); extern int wasm_on_message_complete(llhttp_t * p); diff --git a/thirdparty/llhttp/http.c b/thirdparty/llhttp/src/http.c similarity index 100% rename from thirdparty/llhttp/http.c rename to thirdparty/llhttp/src/http.c diff --git a/thirdparty/llhttp/llhttp.c b/thirdparty/llhttp/src/llhttp.c similarity index 100% rename from thirdparty/llhttp/llhttp.c rename to thirdparty/llhttp/src/llhttp.c