From 8978fb9a78822cebbcd501ca27abd047d36fba09 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Mon, 30 Jun 2025 18:15:11 +0000 Subject: [PATCH] Use boost.rts --- .github/workflows/ci.yml | 20 ++ CMakeLists.txt | 29 +-- build/Jamfile | 23 +-- include/boost/http_proto.hpp | 5 - include/boost/http_proto/context.hpp | 148 -------------- .../boost/http_proto/detail/type_index.hpp | 147 ------------- include/boost/http_proto/impl/context.hpp | 95 --------- include/boost/http_proto/parser.hpp | 7 +- include/boost/http_proto/request_parser.hpp | 2 +- include/boost/http_proto/response_parser.hpp | 2 +- include/boost/http_proto/serializer.hpp | 8 +- .../http_proto/service/deflate_service.hpp | 54 ----- .../http_proto/service/impl/zlib_service.hpp | 72 ------- .../http_proto/service/inflate_service.hpp | 54 ----- include/boost/http_proto/service/service.hpp | 47 ----- .../boost/http_proto/service/zlib_service.hpp | 120 ----------- src/context.cpp | 74 ------- src/detail/zlib_filter.cpp | 10 +- src/detail/zlib_filter.hpp | 10 +- src/parser.cpp | 27 ++- src/request_parser.cpp | 2 +- src/response_parser.cpp | 2 +- src/serializer.cpp | 32 +-- src/service/service.cpp | 19 -- src/service/zlib_service.cpp | 82 -------- src_brotli/src_brotli.cpp | 10 - src_zlib/service/deflate_service.cpp | 185 ----------------- src_zlib/service/inflate_service.cpp | 193 ------------------ src_zlib/service/stream_cast.hpp | 144 ------------- test/cmake_test/CMakeLists.txt | 11 +- test/limits/CMakeLists.txt | 5 +- test/limits/Jamfile | 3 +- test/unit/CMakeLists.txt | 12 +- test/unit/Jamfile | 6 +- test/unit/context.cpp | 41 ---- test/unit/parser.cpp | 46 ++--- test/unit/request_parser.cpp | 18 +- test/unit/response_parser.cpp | 6 +- test/unit/serializer.cpp | 24 ++- test/unit/service/service.cpp | 11 - test/unit/service/virtual_service.cpp | 47 ----- test/unit/service/zlib_service.cpp | 42 ---- test/unit/zlib.cpp | 105 +++++----- 43 files changed, 192 insertions(+), 1808 deletions(-) delete mode 100644 include/boost/http_proto/context.hpp delete mode 100644 include/boost/http_proto/detail/type_index.hpp delete mode 100644 include/boost/http_proto/impl/context.hpp delete mode 100644 include/boost/http_proto/service/deflate_service.hpp delete mode 100644 include/boost/http_proto/service/impl/zlib_service.hpp delete mode 100644 include/boost/http_proto/service/inflate_service.hpp delete mode 100644 include/boost/http_proto/service/service.hpp delete mode 100644 include/boost/http_proto/service/zlib_service.hpp delete mode 100644 src/context.cpp delete mode 100644 src/service/service.cpp delete mode 100644 src/service/zlib_service.cpp delete mode 100644 src_brotli/src_brotli.cpp delete mode 100644 src_zlib/service/deflate_service.cpp delete mode 100644 src_zlib/service/inflate_service.cpp delete mode 100644 src_zlib/service/stream_cast.hpp delete mode 100644 test/unit/context.cpp delete mode 100644 test/unit/service/service.cpp delete mode 100644 test/unit/service/virtual_service.cpp delete mode 100644 test/unit/service/zlib_service.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ab54572..19084390 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -828,6 +828,13 @@ jobs: repository: cppalliance/buffers ref: develop + - name: Clone Boost.RunTimeServices + uses: actions/checkout@v3 + with: + path: rts-root + repository: cppalliance/rts + ref: develop + - name: Setup C++ uses: alandefreitas/cpp-actions/setup-cpp@v1.8.10 id: setup-cpp @@ -857,9 +864,11 @@ jobs: scan-modules-dir: | http-proto-root buffers-root + rts-root scan-modules-ignore: | http_proto buffers + rts - name: Install zlib (Windows) uses: alandefreitas/cpp-actions/package-install@v1.8.10 @@ -925,6 +934,7 @@ jobs: # Patch boost-root with workspace module cp -r "$workspace_root"/http-proto-root "libs/$module" cp -r "$workspace_root"/buffers-root libs/buffers + cp -r "$workspace_root"/rts-root libs/rts - name: Boost B2 Workflow uses: alandefreitas/cpp-actions/b2-workflow@v1.8.10 @@ -1147,6 +1157,13 @@ jobs: repository: cppalliance/buffers ref: develop + - name: Clone Boost.RunTimeServices + uses: actions/checkout@v3 + with: + path: rts-root + repository: cppalliance/rts + ref: develop + - name: Clone Boost uses: alandefreitas/cpp-actions/boost-clone@v1.8.10 id: boost-clone @@ -1158,9 +1175,11 @@ jobs: scan-modules-dir: | http-proto-root buffers-root + rts-root scan-modules-ignore: | http_proto buffers + rts - name: Patch Boost id: patch @@ -1194,6 +1213,7 @@ jobs: # Patch boost-root with workspace module cp -r "$workspace_root"/http-proto-root "libs/$module" cp -r "$workspace_root"/buffers-root libs/buffers + cp -r "$workspace_root"/rts-root libs/rts - uses: actions/setup-node@v4 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index dfdf783f..50c717af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,16 +54,18 @@ set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use #------------------------------------------------- # The boost super-project requires one explicit dependency per-line. set(BOOST_HTTP_PROTO_DEPENDENCIES - Boost::align Boost::assert Boost::buffers Boost::config - Boost::container_hash + Boost::core + Boost::rts + Boost::static_assert Boost::system Boost::throw_exception + Boost::type_traits Boost::url - Boost::utility - Boost::winapi) + Boost::winapi + ) foreach (BOOST_HTTP_PROTO_DEPENDENCY ${BOOST_HTTP_PROTO_DEPENDENCIES}) if (BOOST_HTTP_PROTO_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$") @@ -136,16 +138,10 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) file(GLOB_RECURSE BOOST_HTTP_PROTO_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp include/boost/*.natvis) file(GLOB_RECURSE BOOST_HTTP_PROTO_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp) -file(GLOB_RECURSE BOOST_HTTP_PROTO_ZLIB_SOURCES CONFIGURE_DEPENDS src_zlib/*.cpp src_zlib/*.hpp) -set(BOOST_HTTP_PROTO_ZLIB_HEADERS - "include/boost/http_proto/service/zlib_service.hpp" - "include/boost/http_proto/service/deflate_service.hpp" - "include/boost/http_proto/service/inflate_service.hpp" -) + source_group("" FILES "include/boost/http_proto.hpp" "build/Jamfile") source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/http_proto PREFIX "include" FILES ${BOOST_HTTP_PROTO_HEADERS}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_HTTP_PROTO_SOURCES}) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_zlib PREFIX "src" FILES ${BOOST_HTTP_PROTO_ZLIB_SOURCES}) add_library(boost_http_proto include/boost/http_proto.hpp build/Jamfile ${BOOST_HTTP_PROTO_HEADERS} ${BOOST_HTTP_PROTO_SOURCES}) add_library(Boost::http_proto ALIAS boost_http_proto) @@ -161,17 +157,6 @@ else () target_compile_definitions(boost_http_proto PUBLIC BOOST_HTTP_PROTO_STATIC_LINK) endif () -find_package(ZLIB) -if (ZLIB_FOUND) - add_library(boost_http_proto_zlib build/Jamfile ${BOOST_HTTP_PROTO_ZLIB_HEADERS} ${BOOST_HTTP_PROTO_ZLIB_SOURCES}) - add_library(Boost::http_proto_zlib ALIAS boost_http_proto_zlib) - target_include_directories(boost_http_proto_zlib PRIVATE "${PROJECT_SOURCE_DIR}") - target_link_libraries(boost_http_proto_zlib PUBLIC boost_http_proto) - target_link_libraries(boost_http_proto_zlib PRIVATE ZLIB::ZLIB) - target_compile_definitions(boost_http_proto_zlib PUBLIC BOOST_HTTP_PROTO_HAS_ZLIB) - target_compile_definitions(boost_http_proto_zlib PRIVATE BOOST_HTTP_PROTO_ZLIB_SOURCE) -endif () - #------------------------------------------------- # # Tests diff --git a/build/Jamfile b/build/Jamfile index 794707be..d4a113ff 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -7,11 +7,8 @@ # Official repository: https://github.com/vinniefalco/http_proto # -import ac ; import ../../config/checks/config : requires ; -using zlib ; - constant c11-requires : [ requires cxx11_constexpr @@ -43,28 +40,14 @@ lib boost_http_proto : http_proto_sources : requirements /boost//buffers + /boost//rts /boost//url ../ BOOST_HTTP_PROTO_SOURCE : usage-requirements /boost//buffers + /boost//rts /boost//url ; -alias http_proto_zlib_sources : [ glob-tree-ex ./src_zlib : *.cpp ] ; - -explicit http_proto_zlib_sources ; - -lib boost_http_proto_zlib - : http_proto_zlib_sources - : requirements - /boost/http_proto//boost_http_proto - [ ac.check-library /zlib//zlib : /zlib//zlib : no ] - ../ - BOOST_HTTP_PROTO_ZLIB_SOURCE - : usage-requirements - /zlib//zlib - BOOST_HTTP_PROTO_HAS_ZLIB - ; - -boost-install boost_http_proto boost_http_proto_zlib ; +boost-install boost_http_proto ; diff --git a/include/boost/http_proto.hpp b/include/boost/http_proto.hpp index 3cd4677d..1b24bc02 100644 --- a/include/boost/http_proto.hpp +++ b/include/boost/http_proto.hpp @@ -10,7 +10,6 @@ #ifndef BOOST_HTTP_PROTO_HPP #define BOOST_HTTP_PROTO_HPP -#include #include #include #include @@ -53,8 +52,4 @@ #include #include -#include -#include -#include - #endif diff --git a/include/boost/http_proto/context.hpp b/include/boost/http_proto/context.hpp deleted file mode 100644 index 27d0cba2..00000000 --- a/include/boost/http_proto/context.hpp +++ /dev/null @@ -1,148 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_CONTEXT_HPP -#define BOOST_HTTP_PROTO_CONTEXT_HPP - -#include -#include -#include -#include - -namespace boost { -namespace http_proto { - -class context -{ - struct data; - -public: - context(context const&) = delete; - context& operator=( - context const&) = delete; - - /** Destructor. - */ - BOOST_HTTP_PROTO_DECL - ~context(); - - /** Constructor. - */ - BOOST_HTTP_PROTO_DECL - context(); - - //-------------------------------------------- - - /** Create a service. - - The service must not already exist. - - @par Exception Safety - Strong guarantee. - Calls to allocate may throw. - - @throw std::invalid_argument `find_service != nullptr` - - @return A reference to the new service. - - @tparam T The service type. - - @param args Arguments forwarded to the - service constructor. - */ - template< - class T, - class... Args> - T& - make_service( - Args&&... args); - - /** Return an existing service - - The function returns `nullptr` if the - service does not exist. - - @par Complexity - Constant. - - @par Exception Safety - Throws nothing. - - @return A pointer to the service, - or `nullptr`. - - @tparam T The service type. - */ - template - T* - find_service() const noexcept; - - /** Return true if a service exists - - @par Effects - @code - return this->find_service() != nullptr; - @endcode - - @par Complexity - Constant. - - @par Exception Safety - Throws nothing. - - @return `true` if the service exists. - - @tparam T The service type. - */ - template - bool - has_service() const noexcept; - - /** Return a reference to an existing service - - The service must exist, or else an - exception is thrown. - - @par Complexity - Constant. - - @par Exception Safety - Strong guarantee. - - @throw std::invalid_argument `find_service == nullptr`. - - @return A reference to the service. - - @tparam T The service type. - */ - template - T& - get_service() const; - -private: - BOOST_HTTP_PROTO_DECL - service* - find_service_impl( - detail::type_index ti) const noexcept; - - BOOST_HTTP_PROTO_DECL - service& - make_service_impl( - detail::type_index ti, - std::unique_ptr sp); - - std::unique_ptr p_; -}; - -} // http_proto -} // boost - -#include - -#endif diff --git a/include/boost/http_proto/detail/type_index.hpp b/include/boost/http_proto/detail/type_index.hpp deleted file mode 100644 index 4f316630..00000000 --- a/include/boost/http_proto/detail/type_index.hpp +++ /dev/null @@ -1,147 +0,0 @@ -// -// Copyright (c) 2023 Christian Mazakas -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_DETAIL_TYPE_INDEX_HPP -#define BOOST_HTTP_PROTO_DETAIL_TYPE_INDEX_HPP - -#include -#include -#include -#include -#include - -namespace boost { -namespace http_proto { -namespace detail { - -struct type_index_impl -{ -private: - boost::core::typeinfo const *pdata_ = nullptr; - - std::size_t - get_raw_name_length() const noexcept - { - // Boost.TypeIndex has a dramatically more sophisticated implementation here - // see if this eventually turns out to matter and if it does, essentially - // just do more copy-paste - return std::strlen(raw_name()); - } - - bool - equal(type_index_impl const &rhs) const noexcept - { - return raw_name() == rhs.raw_name() || - !std::strcmp(raw_name(), rhs.raw_name()); - } - -public: - type_index_impl( - boost::core::typeinfo const &type_info) noexcept - : pdata_(&type_info) {} - - type_index_impl(type_index_impl const &) = default; - type_index_impl& operator=( - type_index_impl const &) = default; - - ~type_index_impl() = default; - - template - static - type_index_impl - type_id() noexcept - { - return type_index_impl(BOOST_CORE_TYPEID(T)); - } - - char const* - raw_name() const noexcept - { - return pdata_->name(); - } - - std::size_t - hash_code() const noexcept - { - return boost::hash_range( - raw_name(), raw_name() + get_raw_name_length()); - } - - bool - operator==(type_index_impl const &rhs) const noexcept - { - return equal(rhs); - } - - bool - operator!=(type_index_impl const &rhs) const noexcept - { - return !equal(rhs); - } -}; - -// like std::type_index, -// but without requiring RTTI -using type_index = type_index_impl; - -template -type_index -get_type_index() noexcept -{ - return type_index_impl::type_id(); -} - -struct type_index_hasher -{ - std::size_t - operator()(type_index const &tid) const noexcept - { - return tid.hash_code(); - } -}; - -BOOST_NOINLINE BOOST_NORETURN -inline -void -throw_bad_cast(boost::source_location const& loc = {}) -{ - boost::throw_exception(std::bad_cast(), loc); -} - -template -U -downcast(T *p) -{ -#ifdef BOOST_NO_RTTI - return static_cast(p); -#else - auto q = dynamic_cast(p); - if(! q ) - throw_bad_cast(); - return q; -#endif -} - -template -U -downcast(T &p) -{ -#ifdef BOOST_NO_RTTI - return static_cast(p); -#else - return dynamic_cast(p); -#endif -} - -} // namespace detail -} // namespace http_proto -} // namespace boost - -#endif diff --git a/include/boost/http_proto/impl/context.hpp b/include/boost/http_proto/impl/context.hpp deleted file mode 100644 index e52f6473..00000000 --- a/include/boost/http_proto/impl/context.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_IMPL_CONTEXT_HPP -#define BOOST_HTTP_PROTO_IMPL_CONTEXT_HPP - -#include -#include - -#include -#include - -namespace boost { -namespace http_proto { - -namespace detail { - -template -using get_key_impl = - typename T::key_type; - -template -using get_key_type = - mp11::mp_eval_or; - -} // detail - -//------------------------------------------------ - -template -T& -context:: -make_service( - Args&&... args) -{ - static_assert( - std::is_base_of::value, - "Type requirements not met."); - - auto const ti = detail::get_type_index< - detail::get_key_type>(); - auto const ps = find_service_impl(ti); - if(ps) - detail::throw_invalid_argument( - "service exists"); - return detail::downcast( - make_service_impl(ti, - std::unique_ptr( - new T(*this, std::forward< - Args>(args)...)))); -} - -template -T* -context:: -find_service() const noexcept -{ - auto const ti = detail::get_type_index< - detail::get_key_type>(); - auto const ps = find_service_impl(ti); - if(! ps) - return nullptr; - return detail::downcast(ps); -} - -template -bool -context:: -has_service() const noexcept -{ - return find_service() != nullptr; -} - -template -T& -context:: -get_service() const -{ - auto ps = find_service(); - if(! ps) - detail::throw_invalid_argument( - "service not found"); - return *ps; -} - -} // http_proto -} // boost - -#endif diff --git a/include/boost/http_proto/parser.hpp b/include/boost/http_proto/parser.hpp index 6ad9485f..7cb779d8 100644 --- a/include/boost/http_proto/parser.hpp +++ b/include/boost/http_proto/parser.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -550,7 +551,7 @@ class parser class filter; BOOST_HTTP_PROTO_DECL - parser(context&, detail::kind); + parser(rts::context&, detail::kind); BOOST_HTTP_PROTO_DECL void @@ -596,7 +597,7 @@ class parser elastic, }; - context& ctx_; + rts::context& ctx_; parser_service& svc_; detail::workspace ws_; @@ -636,7 +637,7 @@ class parser BOOST_HTTP_PROTO_DECL void install_parser_service( - context& ctx, + rts::context& ctx, parser::config_base const& cfg); } // http_proto diff --git a/include/boost/http_proto/request_parser.hpp b/include/boost/http_proto/request_parser.hpp index d1c08fa0..383b5111 100644 --- a/include/boost/http_proto/request_parser.hpp +++ b/include/boost/http_proto/request_parser.hpp @@ -41,7 +41,7 @@ class request_parser */ BOOST_HTTP_PROTO_DECL explicit - request_parser(context&); + request_parser(rts::context&); /** Return a read-only view to the parsed request headers. diff --git a/include/boost/http_proto/response_parser.hpp b/include/boost/http_proto/response_parser.hpp index ebd6d8dd..62e116bd 100644 --- a/include/boost/http_proto/response_parser.hpp +++ b/include/boost/http_proto/response_parser.hpp @@ -40,7 +40,7 @@ class response_parser */ BOOST_HTTP_PROTO_DECL explicit - response_parser(context& ctx); + response_parser(rts::context& ctx); /** Prepare for the next message on the stream. diff --git a/include/boost/http_proto/serializer.hpp b/include/boost/http_proto/serializer.hpp index 10dcab7d..e3afda9a 100644 --- a/include/boost/http_proto/serializer.hpp +++ b/include/boost/http_proto/serializer.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_HTTP_PROTO_SERIALIZER_HPP #define BOOST_HTTP_PROTO_SERIALIZER_HPP -#include #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include @@ -154,7 +154,7 @@ class serializer */ BOOST_HTTP_PROTO_DECL serializer( - context& ctx); + rts::context& ctx); //-------------------------------------------- @@ -343,7 +343,7 @@ class serializer stream }; - context& ctx_; + rts::context& ctx_; serializer_service& svc_; detail::workspace ws_; @@ -373,7 +373,7 @@ class serializer BOOST_HTTP_PROTO_DECL void install_serializer_service( - context& ctx, + rts::context& ctx, serializer::config const& cfg); //------------------------------------------------ diff --git a/include/boost/http_proto/service/deflate_service.hpp b/include/boost/http_proto/service/deflate_service.hpp deleted file mode 100644 index 8742db8c..00000000 --- a/include/boost/http_proto/service/deflate_service.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2024 Christian Mazakas -// Copyright (c) 2024 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_SERVICE_DEFLATE_SERVICE_HPP -#define BOOST_HTTP_PROTO_SERVICE_DEFLATE_SERVICE_HPP - -#include -#include - -namespace boost { -namespace http_proto { -namespace zlib { - -/** Provides the ZLib compression API -*/ - -struct BOOST_SYMBOL_VISIBLE -deflate_service - : public http_proto::service -{ - virtual char const* version() const noexcept = 0; - virtual int init(stream& st, int level) const = 0; - virtual int init2(stream& st, int level, int method, - int windowBits, int memLevel, int strategy) const = 0; - virtual int set_dict(stream& st, unsigned char const* dict, unsigned len) const = 0; - virtual int get_dict(stream& st, unsigned char* dest, unsigned* len) const = 0; - virtual int dup(stream& dest, stream& src) const = 0; - virtual int deflate(stream& st, int flush) const = 0; - virtual int deflate_end(stream& st) const = 0; - virtual int reset(stream& st) const = 0; - virtual int params(stream& st, int level, int strategy) const = 0; - virtual std::size_t bound(stream& st, unsigned long sourceLen) const = 0; - virtual int pending(stream& st, unsigned* pending, int* bits) const = 0; - virtual int prime(stream& st, int bits, int value) const = 0; - virtual int set_header(stream& st, void* header) const = 0; -}; - -BOOST_HTTP_PROTO_ZLIB_DECL -void -install_deflate_service(context& ctx); - -} // zlib -} // http_proto -} // boost - -#endif diff --git a/include/boost/http_proto/service/impl/zlib_service.hpp b/include/boost/http_proto/service/impl/zlib_service.hpp deleted file mode 100644 index 7e4cbbe6..00000000 --- a/include/boost/http_proto/service/impl/zlib_service.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2024 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_SERVICE_IMPL_ZLIB_SERVICE_HPP -#define BOOST_HTTP_PROTO_SERVICE_IMPL_ZLIB_SERVICE_HPP - -#include - -namespace boost { - -namespace system { -template<> -struct is_error_code_enum< - ::boost::http_proto::zlib::error> -{ - static bool const value = true; -}; -} // system - -namespace http_proto { -namespace zlib { - -namespace detail { - -struct BOOST_SYMBOL_VISIBLE - error_cat_type - : system::error_category -{ - BOOST_HTTP_PROTO_DECL const char* name( - ) const noexcept override; - BOOST_HTTP_PROTO_DECL bool failed( - int) const noexcept override; - BOOST_HTTP_PROTO_DECL std::string message( - int) const override; - BOOST_HTTP_PROTO_DECL char const* message( - int, char*, std::size_t - ) const noexcept override; - BOOST_SYSTEM_CONSTEXPR error_cat_type() - : error_category(0xe6c6d0215d1d6e22) - { - } -}; - -BOOST_HTTP_PROTO_DECL extern - error_cat_type error_cat; - -} // detail - -inline -BOOST_SYSTEM_CONSTEXPR -system::error_code -make_error_code( - error ev) noexcept -{ - return system::error_code{ - static_cast::type>(ev), - detail::error_cat}; -} - -} // zip -} // http_proto -} // boost - -#endif diff --git a/include/boost/http_proto/service/inflate_service.hpp b/include/boost/http_proto/service/inflate_service.hpp deleted file mode 100644 index 3219eaed..00000000 --- a/include/boost/http_proto/service/inflate_service.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_SERVICE_INFLATE_SERVICE_HPP -#define BOOST_HTTP_PROTO_SERVICE_INFLATE_SERVICE_HPP - -#include -#include - -namespace boost { -namespace http_proto { -namespace zlib { - -/** Provides the ZLib decompression API -*/ -struct BOOST_SYMBOL_VISIBLE -inflate_service - : public http_proto::service -{ - virtual char const* version() const noexcept = 0; - virtual int init(stream& st) const = 0; - virtual int init2(stream& st, int windowBits) const = 0; - virtual int inflate(stream& st, int flush) const = 0; - virtual int inflate_end(stream& st) const = 0; - virtual int set_dict(stream& st, unsigned char const* dict, unsigned len) const = 0; - virtual int get_dict(stream& st, unsigned char* dest, unsigned* len) const = 0; - virtual int sync(stream& st) const = 0; - virtual int dup(stream& dest, stream& src) const = 0; - virtual int reset(stream& st) const = 0; - virtual int reset2(stream& st, int windowBits) const = 0; - virtual int prime(stream& st, int bits, int value) const = 0; - virtual long mark(stream& st) const = 0; - virtual int get_header(stream& st, void* header) const = 0; - virtual int back_init(stream& st, int windowBits, unsigned char* window) const = 0; - virtual int back_end(stream& st) const = 0; - virtual unsigned long compile_flags() const = 0; -}; - -BOOST_HTTP_PROTO_ZLIB_DECL -void -install_inflate_service(context& ctx); - -} // zlib -} // http_proto -} // boost - -#endif diff --git a/include/boost/http_proto/service/service.hpp b/include/boost/http_proto/service/service.hpp deleted file mode 100644 index d1462d2e..00000000 --- a/include/boost/http_proto/service/service.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_SERVICE_SERVICE_HPP -#define BOOST_HTTP_PROTO_SERVICE_SERVICE_HPP - -#include - -namespace boost { -namespace http_proto { - -#ifndef BOOST_HTTP_PROTO_DOCS -class services; -#endif - -/** Base class for all context services -*/ -struct BOOST_SYMBOL_VISIBLE - service -{ - BOOST_HTTP_PROTO_DECL - virtual - ~service() = 0; - -#if 0 -protected: - /** Called to perform two-phase initialization - */ - virtual - void - start() = 0; -#endif - -private: - friend class services; -}; - -} // http_proto -} // boost - -#endif diff --git a/include/boost/http_proto/service/zlib_service.hpp b/include/boost/http_proto/service/zlib_service.hpp deleted file mode 100644 index 49840b14..00000000 --- a/include/boost/http_proto/service/zlib_service.hpp +++ /dev/null @@ -1,120 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2024 Christian Mazakas -// Copyright (c) 2024 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef BOOST_HTTP_PROTO_SERVICE_ZLIB_SERVICE_HPP -#define BOOST_HTTP_PROTO_SERVICE_ZLIB_SERVICE_HPP - -#include -#include -#include -#include - -namespace boost { -namespace http_proto { -namespace zlib { - -struct stream -{ - using alloc_func = void*(*)(void*, unsigned int, unsigned int); - using free_func = void(*)(void*, void*); - - unsigned char* next_in; // next input byte - unsigned int avail_in; // number of bytes available at next_in - unsigned long total_in; // total number of input bytes read so far - - unsigned char* next_out; // next output byte will go here - unsigned int avail_out; // remaining free space at next_out - unsigned long total_out; // total number of bytes output so far - - char* msg; // last error message, NULL if no error - void* state; // not visible by applications - - alloc_func zalloc; // used to allocate internal state - free_func zfree; // used to deallocate internal state - void* opaque; // private data object passed to zalloc and zfree - - int data_type; // best guess about the data type: binary or text - // for deflate, or the decoding state for inflate - unsigned long adler; // Adler-32 or CRC-32 value of the uncompressed data - unsigned long reserved; // reserved for future use -}; - -/** Error codes returned from compression/decompression functions. - - Negative values are errors, positive values are used - for special but normal events. -*/ -enum class error -{ - ok = 0, - stream_end = 1, - need_dict = 2, - errno_ = -1, - stream_err = -2, - data_err = -3, - mem_err = -4, - buf_err = -5, - version_err = -6 -}; - -/// Flush methods -enum flush -{ - no_flush = 0, - partial_flush = 1, - sync_flush = 2, - full_flush = 3, - finish = 4, - block = 5, - trees = 6 -}; - -/// Compression levels -enum compression_level -{ - default_compression = -1, - no_compression = 0, - best_speed = 1, - best_compression = 9 -}; - -/// Compression strategy -enum compression_strategy -{ - default_strategy = 0, - filtered = 1, - huffman_only = 2, - rle = 3, - fixed = 4 -}; - -/// Possible values of the data_type field for deflate -enum data_type -{ - binary = 0, - text = 1, - ascii = 1, - unknown = 2 -}; - -/// Compression method -enum compression_method -{ - deflated = 8 -}; - -} // zlib -} // http_proto -} // boost - -#include - -#endif diff --git a/src/context.cpp b/src/context.cpp deleted file mode 100644 index d32769dd..00000000 --- a/src/context.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include -#include -//#include // doesn't support heterogenous lookup yet -#include - -namespace boost { -namespace http_proto { - -struct context::data -{ - // Installed services - std::unordered_map< - detail::type_index, - std::unique_ptr, - detail::type_index_hasher - > services; -}; - -//------------------------------------------------ - -context:: -~context() -{ -} - -context:: -context() - : p_(new data) -{ -} - -//------------------------------------------------ - -auto -context:: -find_service_impl( - detail::type_index id) const noexcept -> - service* -{ - auto it = p_->services.find(id); - if(it != p_->services.end()) - return it->second.get(); - return nullptr; -} - -auto -context:: -make_service_impl( - detail::type_index id, - std::unique_ptr sp) -> - service& -{ - auto const result = - p_->services.emplace( - id, std::move(sp)); - if(! result.second) - { - // already exists - detail::throw_out_of_range(); - } - return *result.first->second; -} - -} // http_proto -} // boost diff --git a/src/detail/zlib_filter.cpp b/src/detail/zlib_filter.cpp index b3347235..ea4e9e4f 100644 --- a/src/detail/zlib_filter.cpp +++ b/src/detail/zlib_filter.cpp @@ -65,20 +65,20 @@ process( bool force_flush) -> results { results rv; - auto flush = zlib::no_flush; + auto flush = rts::zlib::no_flush; for(;;) { auto ob = buffers::front(out); auto ib = buffers::front(in); - if(!more && flush != zlib::finish && in[1].size() == 0) + if(!more && flush != rts::zlib::finish && in[1].size() == 0) { if(buffers::size(out) < min_out_buffer()) { rv.out_short = true; return rv; } - flush = zlib::finish; + flush = rts::zlib::finish; } strm_.next_in = static_cast(const_cast(ib.data())); @@ -98,7 +98,7 @@ process( if(ec.failed()) return rv; - if(ec == zlib::error::stream_end) + if(ec == rts::zlib::error::stream_end) { rv.finished = true; return rv; @@ -114,7 +114,7 @@ process( { if(force_flush && rv.out_bytes == 0) { - flush = zlib::block; + flush = rts::zlib::block; continue; } return rv; diff --git a/src/detail/zlib_filter.hpp b/src/detail/zlib_filter.hpp index b0d13344..347f5ebc 100644 --- a/src/detail/zlib_filter.hpp +++ b/src/detail/zlib_filter.hpp @@ -12,10 +12,12 @@ #define BOOST_HTTP_PROTO_DETAIL_ZLIB_FILTER_HPP #include -#include #include #include +#include +#include +#include namespace boost { namespace http_proto { @@ -72,15 +74,15 @@ class zlib_filter bool force_flush = false); protected: - zlib::stream strm_; + rts::zlib::stream strm_; virtual std::size_t min_out_buffer() const noexcept = 0; virtual - zlib::error - do_process(zlib::flush) noexcept = 0; + rts::zlib::error + do_process(rts::zlib::flush) noexcept = 0; }; } // detail diff --git a/src/parser.cpp b/src/parser.cpp index e0d586c8..53044583 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -8,12 +8,10 @@ // Official repository: https://github.com/cppalliance/http_proto // -#include #include #include #include #include -#include #include "src/detail/zlib_filter.hpp" @@ -23,6 +21,7 @@ #include #include #include +#include #include #include @@ -299,19 +298,19 @@ clamp( class parser::filter : public detail::zlib_filter { - zlib::inflate_service& svc_; + rts::zlib::inflate_service& svc_; public: filter( - context& ctx, + rts::context& ctx, http_proto::detail::workspace& ws, int window_bits) : zlib_filter(ws) - , svc_(ctx.get_service()) + , svc_(ctx.get_service()) { - system::error_code ec = static_cast( + system::error_code ec = static_cast( svc_.init2(strm_, window_bits)); - if(ec != zlib::error::ok) + if(ec != rts::zlib::error::ok) detail::throw_system_error(ec); } @@ -324,16 +323,16 @@ class parser::filter } virtual - zlib::error - do_process(zlib::flush flush) noexcept override + rts::zlib::error + do_process(rts::zlib::flush flush) noexcept override { return static_cast< - zlib::error>(svc_.inflate(strm_, flush)); + rts::zlib::error>(svc_.inflate(strm_, flush)); } }; class parser_service - : public service + : public rts::service { public: parser::config_base cfg; @@ -341,7 +340,7 @@ class parser_service std::size_t max_codec = 0; parser_service( - context&, + rts::context&, parser::config_base const& cfg_) : cfg(cfg_) { @@ -423,7 +422,7 @@ class parser_service void install_parser_service( - context& ctx, + rts::context& ctx, parser::config_base const& cfg) { ctx.make_service< @@ -437,7 +436,7 @@ install_parser_service( //------------------------------------------------ parser:: -parser(context& ctx, detail::kind k) +parser(rts::context& ctx, detail::kind k) : ctx_(ctx) , svc_(ctx.get_service()) , ws_(svc_.space_needed) diff --git a/src/request_parser.cpp b/src/request_parser.cpp index d0916ab1..6333ede9 100644 --- a/src/request_parser.cpp +++ b/src/request_parser.cpp @@ -14,7 +14,7 @@ namespace http_proto { request_parser:: request_parser( - context& ctx) + rts::context& ctx) : parser( ctx, detail::kind::request) diff --git a/src/response_parser.cpp b/src/response_parser.cpp index 701639bf..70772510 100644 --- a/src/response_parser.cpp +++ b/src/response_parser.cpp @@ -14,7 +14,7 @@ namespace http_proto { response_parser:: response_parser( - context& ctx) + rts::context& ctx) : parser( ctx, detail::kind::response) diff --git a/src/serializer.cpp b/src/serializer.cpp index da384f4e..8fa56310 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include "src/detail/zlib_filter.hpp" @@ -23,6 +22,9 @@ #include #include #include +#include +#include +#include #include @@ -188,26 +190,26 @@ class appender class serializer::filter : public detail::zlib_filter { - zlib::deflate_service& svc_; + rts::zlib::deflate_service& svc_; public: filter( - context& ctx, + rts::context& ctx, http_proto::detail::workspace& ws, int comp_level, int window_bits, int mem_level) : zlib_filter(ws) - , svc_(ctx.get_service()) + , svc_(ctx.get_service()) { - system::error_code ec = static_cast(svc_.init2( + system::error_code ec = static_cast(svc_.init2( strm_, comp_level, - zlib::deflated, + rts::zlib::deflated, window_bits, mem_level, - zlib::default_strategy)); - if(ec != zlib::error::ok) + rts::zlib::default_strategy)); + if(ec != rts::zlib::error::ok) detail::throw_system_error(ec); } @@ -222,23 +224,23 @@ class serializer::filter } virtual - zlib::error - do_process(zlib::flush flush) noexcept override + rts::zlib::error + do_process(rts::zlib::flush flush) noexcept override { return static_cast< - zlib::error>(svc_.deflate(strm_, flush)); + rts::zlib::error>(svc_.deflate(strm_, flush)); } }; class serializer_service - : public service + : public rts::service { public: serializer::config cfg; std::size_t space_needed = 0; serializer_service( - context&, + rts::context&, serializer::config const& cfg_) : cfg(cfg_) { @@ -266,7 +268,7 @@ class serializer_service void install_serializer_service( - context& ctx, + rts::context& ctx, serializer::config const& cfg) { ctx.make_service< @@ -283,7 +285,7 @@ serializer( serializer&&) noexcept = default; serializer:: -serializer(context& ctx) +serializer(rts::context& ctx) : ctx_(ctx) , svc_(ctx.get_service()) , ws_(svc_.space_needed) diff --git a/src/service/service.cpp b/src/service/service.cpp deleted file mode 100644 index e5a037c5..00000000 --- a/src/service/service.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include - -namespace boost { -namespace http_proto { - -service:: -~service() = default; - -} // http_proto -} // boost diff --git a/src/service/zlib_service.cpp b/src/service/zlib_service.cpp deleted file mode 100644 index 7422090c..00000000 --- a/src/service/zlib_service.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// -// Copyright (c) 2024 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include - -namespace boost { -namespace http_proto { -namespace zlib { -namespace detail { - -const char* -error_cat_type:: -name() const noexcept -{ - return "boost.http.proto.zlib"; -} - -bool -error_cat_type:: -failed(int ev) const noexcept -{ - return ev < 0; -} - -std::string -error_cat_type:: -message(int ev) const -{ - return message(ev, nullptr, 0); -} - -char const* -error_cat_type:: -message( - int ev, - char*, - std::size_t) const noexcept -{ - switch(static_cast(ev)) - { - case error::ok: return "Z_OK"; - case error::stream_end: return "Z_STREAM_END"; - case error::need_dict: return "Z_NEED_DICT"; - case error::errno_: return "Z_ERRNO"; - case error::stream_err: return "Z_STREAM_ERROR"; - case error::data_err: return "Z_DATA_ERROR"; - case error::mem_err: return "Z_MEM_ERROR"; - case error::buf_err: return "Z_BUF_ERROR"; - case error::version_err: return "Z_VERSION_ERROR"; - default: - return "unknown"; - } -} - -// msvc 14.0 has a bug that warns about inability -// to use constexpr construction here, even though -// there's no constexpr construction -#if defined(_MSC_VER) && _MSC_VER <= 1900 -# pragma warning( push ) -# pragma warning( disable : 4592 ) -#endif - -#if defined(__cpp_constinit) && __cpp_constinit >= 201907L -constinit error_cat_type error_cat; -#else -error_cat_type error_cat; -#endif - -#if defined(_MSC_VER) && _MSC_VER <= 1900 -# pragma warning( pop ) -#endif - -} // detail -} // zlib -} // http_proto -} // boost diff --git a/src_brotli/src_brotli.cpp b/src_brotli/src_brotli.cpp deleted file mode 100644 index d9546a37..00000000 --- a/src_brotli/src_brotli.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/CPPAlliance/http_proto -// - -#include diff --git a/src_zlib/service/deflate_service.cpp b/src_zlib/service/deflate_service.cpp deleted file mode 100644 index 37aa6670..00000000 --- a/src_zlib/service/deflate_service.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// -// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include -#include -#include "src_zlib/service/stream_cast.hpp" - -#include - -namespace boost { -namespace http_proto { -namespace zlib { - -BOOST_STATIC_ASSERT(sizeof(stream) == sizeof(z_stream_s)); -BOOST_STATIC_ASSERT(is_layout_identical()); - -//------------------------------------------------ - -class deflate_service_impl - : public deflate_service -{ -public: - using key_type = deflate_service; - - explicit - deflate_service_impl( - http_proto::context&) noexcept - { - } - - ~deflate_service_impl() - { - } - - char const* - version() const noexcept override - { - return zlibVersion(); - } - - int - init( - stream& st, - int level) const override - { - stream_cast sc(st); - return deflateInit(sc.get(), level); - } - - int - init2( - stream& st, - int level, - int method, - int windowBits, - int memLevel, - int strategy) const override - { - stream_cast sc(st); - return deflateInit2(sc.get(), - level, method, windowBits, - memLevel, strategy); - } - - int - set_dict( - stream& st, - unsigned char const* dict, - unsigned len) const override - { - stream_cast sc(st); - return deflateSetDictionary(sc.get(), dict, len); - } - - int - get_dict( - stream& st, - unsigned char* dest, - unsigned* len) const override - { - stream_cast sc(st); - return deflateGetDictionary(sc.get(), dest, len); - } - - int - dup( - stream& dest, - stream& src) const override - { - stream_cast sc0(dest); - stream_cast sc1(src); - return deflateCopy(sc0.get(), sc1.get()); - } - - int - deflate( - stream& st, - int flush) const override - { - stream_cast sc(st); - return ::deflate(sc.get(), flush); - } - - int - deflate_end( - stream& st) const override - { - stream_cast sc(st); - return deflateEnd(sc.get()); - } - - int - reset( - stream& st) const override - { - stream_cast sc(st); - return deflateReset(sc.get()); - } - - int - params( - stream& st, - int level, - int strategy) const override - { - stream_cast sc(st); - return deflateParams(sc.get(), level, strategy); - } - - std::size_t - bound( - stream& st, - unsigned long sourceLen) const override - { - stream_cast sc(st); - return deflateBound(sc.get(), sourceLen); - } - - int - pending( - stream& st, - unsigned* pending, - int* bits) const override - { - stream_cast sc(st); - return deflatePending(sc.get(), pending, bits); - } - - int - prime( - stream& st, - int bits, - int value) const override - { - stream_cast sc(st); - return deflatePrime(sc.get(), bits, value); - } - - int - set_header( - stream& st, - void* header) const override - { - stream_cast sc(st); - return deflateSetHeader(sc.get(), - reinterpret_cast(header)); - } -}; - -void -install_deflate_service(context& ctx) -{ - ctx.make_service(); -} - -} // zlib -} // http_proto -} // boost diff --git a/src_zlib/service/inflate_service.cpp b/src_zlib/service/inflate_service.cpp deleted file mode 100644 index 6651122c..00000000 --- a/src_zlib/service/inflate_service.cpp +++ /dev/null @@ -1,193 +0,0 @@ -// -// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include -#include -#include "src_zlib/service/stream_cast.hpp" - -namespace boost { -namespace http_proto { -namespace zlib { - -//------------------------------------------------ - -class inflate_service_impl - : public inflate_service -{ -public: - using key_type = inflate_service; - - explicit - inflate_service_impl( - http_proto::context&) noexcept - { - } - - ~inflate_service_impl() - { - } - - char const* - version() const noexcept override - { - return zlibVersion(); - } - - int - init( - stream& st) const override - { - stream_cast sc(st); - return inflateInit(sc.get()); - } - - int - init2( - stream& st, - int windowBits) const override - { - stream_cast sc(st); - return inflateInit2(sc.get(), windowBits); - } - - int - inflate( - stream& st, - int flush) const override - { - stream_cast sc(st); - return ::inflate(sc.get(), flush); - } - - int - inflate_end( - stream& st) const override - { - stream_cast sc(st); - return inflateEnd(sc.get()); - } - - int - set_dict( - stream& st, - unsigned char const* dict, - unsigned len) const override - { - stream_cast sc(st); - return inflateSetDictionary(sc.get(), dict, len); - } - - int - get_dict( - stream& st, - unsigned char* dest, - unsigned* len) const override - { - stream_cast sc(st); - return inflateGetDictionary(sc.get(), dest, len); - } - - int - sync( - stream& st) const override - { - stream_cast sc(st); - return inflateSync(sc.get()); - } - - int - dup( - stream& dest, - stream& src) const override - { - stream_cast sc0(dest); - stream_cast sc1(src); - return inflateCopy(sc0.get(), sc1.get()); - } - - int - reset( - stream& st) const override - { - stream_cast sc(st); - return inflateReset(sc.get()); - } - - int - reset2( - stream& st, - int windowBits) const override - { - stream_cast sc(st); - return inflateReset2(sc.get(), windowBits); - } - - int - prime( - stream& st, - int bits, - int value) const override - { - stream_cast sc(st); - return inflatePrime(sc.get(), bits, value); - } - - long - mark( - stream& st) const override - { - stream_cast sc(st); - return inflateMark(sc.get()); - } - - int - get_header( - stream& st, - void* header) const override - { - stream_cast sc(st); - return inflateGetHeader(sc.get(), - reinterpret_cast(header)); - } - - int - back_init( - stream& st, - int windowBits, - unsigned char* window) const override - { - stream_cast sc(st); - return inflateBackInit(sc.get(), windowBits, window); - } - - int - back_end( - stream& st) const override - { - stream_cast sc(st); - return inflateBackEnd(sc.get()); - } - - unsigned long - compile_flags() const override - { - return zlibCompileFlags(); - } -}; - -void -install_inflate_service(context& ctx) -{ - ctx.make_service(); -} - -} // zlib -} // http_proto -} // boost diff --git a/src_zlib/service/stream_cast.hpp b/src_zlib/service/stream_cast.hpp deleted file mode 100644 index 487af002..00000000 --- a/src_zlib/service/stream_cast.hpp +++ /dev/null @@ -1,144 +0,0 @@ -// -// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#ifndef SRC_SERVICE_STREAM_CAST_HPP -#define SRC_SERVICE_STREAM_CAST_HPP - -#include -#include -#include -#include - -namespace boost { -namespace http_proto { -namespace zlib { - -//------------------------------------------------ - -#define SAME_FIELD(T1,T2,M) \ - offsetof(T1,M)==offsetof(T2,M) && \ - sizeof(decltype(T1::M)) == sizeof(decltype(T2::M)) - -template -constexpr -bool -is_layout_identical() -{ - return - sizeof(T1) == sizeof(T2) && - SAME_FIELD(T1, T2, next_in) && - SAME_FIELD(T1, T2, avail_in) && - SAME_FIELD(T1, T2, total_in) && - SAME_FIELD(T1, T2, next_out) && - SAME_FIELD(T1, T2, avail_out) && - SAME_FIELD(T1, T2, total_out) && - SAME_FIELD(T1, T2, msg) && - SAME_FIELD(T1, T2, state) && - SAME_FIELD(T1, T2, zalloc) && - SAME_FIELD(T1, T2, zfree) && - SAME_FIELD(T1, T2, opaque) && - SAME_FIELD(T1, T2, data_type) && - SAME_FIELD(T1, T2, adler) && - SAME_FIELD(T1, T2, reserved) - ; -} - -//------------------------------------------------ - -template()> -struct stream_cast_impl -{ - explicit - stream_cast_impl( - stream& st) - : pzs_(reinterpret_cast(&st)) - , st_(st) - { - zs_.next_in = st_.next_in; - zs_.avail_in = st_.avail_in; - zs_.total_in = st_.total_in; - zs_.next_out = st_.next_out; - zs_.avail_out = st_.avail_out; - zs_.total_out = st_.total_out; - zs_.msg = nullptr; - zs_.state = reinterpret_cast< - internal_state*>(st_.state); - zs_.zalloc = st_.zalloc; - zs_.zfree = st_.zfree; - zs_.opaque = st_.opaque; - zs_.data_type = st_.data_type; - zs_.adler = st_.adler; - zs_.reserved = st_.reserved; - } - - ~stream_cast_impl() - { - st_.next_in = zs_.next_in; - st_.avail_in = zs_.avail_in; - st_.total_in = zs_.total_in; - st_.next_out = zs_.next_out; - st_.avail_out = zs_.avail_out; - st_.total_out = zs_.total_out; - st_.msg = zs_.msg; - st_.state = zs_.state; - st_.zalloc = zs_.zalloc; - st_.zfree = zs_.zfree; - st_.opaque = zs_.opaque; - st_.data_type = zs_.data_type; - st_.adler = zs_.adler; - st_.reserved = zs_.reserved; - } - - z_stream_s* - get() noexcept - { - return pzs_; - } - -private: - z_stream_s* pzs_ = nullptr; - stream& st_; - z_stream_s zs_; -}; - -//------------------------------------------------ - -template<> -struct stream_cast_impl -{ - explicit - stream_cast_impl( - stream& st) - // VFALCO A pinch of undefined behavior here - : pzs_(reinterpret_cast(&st)) - { - - } - - z_stream_s* - get() noexcept - { - return pzs_; - } - -private: - z_stream_s* pzs_; -}; - -//------------------------------------------------ - -using stream_cast = stream_cast_impl<>; - -} // zlib -} // http_proto -} // boost - -#endif diff --git a/test/cmake_test/CMakeLists.txt b/test/cmake_test/CMakeLists.txt index 114b61d8..a7ded6af 100644 --- a/test/cmake_test/CMakeLists.txt +++ b/test/cmake_test/CMakeLists.txt @@ -26,9 +26,8 @@ else() assert buffers config - container_hash core - mp11 + rts static_assert system throw_exception @@ -38,15 +37,13 @@ else() # Secondary dependencies - describe + container_hash + mp11 variant2 align optional predef - detail - utility - preprocessor - io + describe ) foreach(dep IN LISTS deps) diff --git a/test/limits/CMakeLists.txt b/test/limits/CMakeLists.txt index f1cd903f..6133e2b9 100644 --- a/test/limits/CMakeLists.txt +++ b/test/limits/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(boost_http_proto_limits PRIVATE Boost::buffers Boost::config Boost::container_hash + Boost::rts Boost::system Boost::throw_exception Boost::url @@ -34,9 +35,5 @@ target_link_libraries(boost_http_proto_limits PRIVATE target_link_libraries(boost_http_proto_limits INTERFACE Boost::http_proto) -if (ZLIB_FOUND) - target_link_libraries(boost_http_proto_limits INTERFACE ZLIB::ZLIB) -endif() - add_test(NAME boost_http_proto_limits COMMAND boost_http_proto_limits) add_dependencies(tests boost_http_proto_limits) diff --git a/test/limits/Jamfile b/test/limits/Jamfile index 0e646535..35ada0a7 100644 --- a/test/limits/Jamfile +++ b/test/limits/Jamfile @@ -18,6 +18,7 @@ project ../.. ../../../url/extra/test_suite /boost//buffers + /boost//rts /boost//url ; @@ -26,7 +27,5 @@ run limits.cpp /boost/http_proto//http_proto_sources BOOST_HTTP_PROTO_MAX_HEADER=20 BOOST_HTTP_PROTO_NO_LIB BOOST_HTTP_PROTO_STATIC_LINK - /boost//buffers - /boost//url static ; diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index b648f99e..b8ed5952 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -25,12 +25,14 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${PFILES}) source_group("_extra" FILES ${EXTRAFILES}) add_executable(boost_http_proto_tests ${PFILES} ${EXTRAFILES}) target_include_directories(boost_http_proto_tests PRIVATE . ../../../url/extra/test_suite) -target_link_libraries(boost_http_proto_tests PRIVATE Boost::filesystem) +target_link_libraries( + boost_http_proto_tests PRIVATE + boost_http_proto + boost_filesystem + ) -if (ZLIB_FOUND) - target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto_zlib ZLIB::ZLIB) -else () - target_link_libraries(boost_http_proto_tests PRIVATE boost_http_proto) +if (TARGET boost_rts_zlib) + target_link_libraries(boost_http_proto_tests PRIVATE boost_rts_zlib) endif () add_test(NAME boost_http_proto_tests COMMAND boost_http_proto_tests) diff --git a/test/unit/Jamfile b/test/unit/Jamfile index 696896e8..614e27f8 100644 --- a/test/unit/Jamfile +++ b/test/unit/Jamfile @@ -16,7 +16,7 @@ project : requirements $(c11-requires) /boost/http_proto//boost_http_proto - [ ac.check-library /boost/http_proto//boost_http_proto_zlib : /boost/http_proto//boost_http_proto_zlib : ] + [ ac.check-library /boost/rts//boost_rts_zlib : /boost/rts//boost_rts_zlib : ] ../../../url/extra/test_suite/test_main.cpp ../../../url/extra/test_suite/test_suite.cpp ./test_helpers.cpp @@ -28,7 +28,6 @@ project ; local SOURCES = - context.cpp error.cpp field.cpp fields.cpp @@ -71,9 +70,6 @@ local SOURCES = rfc/token_rule.cpp rfc/transfer_encoding_rule.cpp rfc/detail/rules.cpp - service/service.cpp - service/zlib_service.cpp - service/virtual_service.cpp ; for local f in $(SOURCES) diff --git a/test/unit/context.cpp b/test/unit/context.cpp deleted file mode 100644 index 4b9f2ebd..00000000 --- a/test/unit/context.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -// Test that header file is self-contained. -#include - -#include "test_suite.hpp" - -namespace boost { -namespace http_proto { - -struct context_test -{ - void - testContext() - { - // default construction - { - context ctx; - } - } - - void - run() - { - testContext(); - } -}; - -TEST_SUITE( - context_test, - "boost.http_proto.context"); - -} // http_proto -} // boost diff --git a/test/unit/parser.cpp b/test/unit/parser.cpp index a5e71ac5..80f0e779 100644 --- a/test/unit/parser.cpp +++ b/test/unit/parser.cpp @@ -10,18 +10,16 @@ // Test that header file is self-contained. #include - -#include #include #include -#include + #include #include #include #include #include #include -#include +#include #include "test_helpers.hpp" @@ -197,13 +195,13 @@ struct parser_test using pieces = std::vector< core::string_view>; - context ctx_; + rts::context ctx_; core::string_view sh_; core::string_view sb_; request_parser req_pr_; response_parser res_pr_; parser* pr_ = nullptr; - opt ctx_opt_; + opt ctx_opt_; opt req_pr_opt_; opt res_pr_opt_; pieces in_; @@ -211,7 +209,7 @@ struct parser_test parser_test() : ctx_() , req_pr_( - [&]() -> context& + [&]() -> rts::context& { request_parser::config cfg; cfg.body_limit = 5; @@ -354,7 +352,7 @@ struct parser_test testConfig() { #ifdef BOOST_HTTP_PROTO_HAS_ZLIB - context ctx; + rts::context ctx; zlib::install_deflate_service(ctx); request_parser::config_base cfg1; @@ -371,7 +369,7 @@ struct parser_test void testStart() { - context ctx; + rts::context ctx; request_parser::config_base cfg; install_parser_service(ctx, cfg); @@ -452,7 +450,7 @@ struct parser_test request_parser::config const& cfg, std::size_t n) { - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); request_parser pr(ctx); @@ -495,7 +493,7 @@ struct parser_test std::size_t n, core::string_view s) { - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); system::error_code ec; request_parser pr(ctx); @@ -548,7 +546,7 @@ struct parser_test core::string_view s, system::error_code ex = error::need_data) { - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); system::error_code ec; request_parser req_pr(ctx); @@ -665,7 +663,7 @@ struct parser_test { // fill capacity first - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); system::error_code ec; @@ -710,7 +708,7 @@ struct parser_test request_parser::config cfg; pieces in({ "GET / HTTP/1.1\r\n\r\n"}); - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); system::error_code ec; request_parser pr(ctx); @@ -822,7 +820,7 @@ struct parser_test // VFALCO missing chunked implementation { // buffered payload - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); request_parser pr(ctx_); @@ -844,7 +842,7 @@ struct parser_test bool is_complete, pieces&& in) { - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); system::error_code ec; response_parser pr(ctx); @@ -909,7 +907,7 @@ struct parser_test { // no-op - context ctx; + rts::context ctx; response_parser::config cfg; install_parser_service(ctx, cfg); system::error_code ec; @@ -935,7 +933,7 @@ struct parser_test { // commit too large - context ctx; + rts::context ctx; response_parser::config cfg; install_parser_service(ctx, cfg); system::error_code ec; @@ -1134,7 +1132,7 @@ struct parser_test bool is_complete, pieces&& in) { - context ctx; + rts::context ctx; install_parser_service(ctx, cfg); system::error_code ec; response_parser pr(ctx); @@ -1617,7 +1615,7 @@ struct parser_test void testChunkedInPlace() { - context ctx; + rts::context ctx; response_parser::config cfg; install_parser_service(ctx, cfg); @@ -1853,7 +1851,7 @@ struct parser_test testMultipleMessageInPlace() { request_parser::config cfg; - context ctx; + rts::context ctx; cfg.headers.max_size = 500; cfg.min_buffer = 500; @@ -1964,7 +1962,7 @@ struct parser_test }; request_parser::config cfg; - context ctx; + rts::context ctx; cfg.min_buffer = 500; cfg.headers.max_size = 500; @@ -2044,7 +2042,7 @@ struct parser_test void testSetBodyLimit() { - context ctx; + rts::context ctx; response_parser::config cfg; cfg.body_limit = 7; install_parser_service(ctx, cfg); @@ -2132,7 +2130,7 @@ struct parser_test // the parsed header must remain valid and // accessible if an error occurs during body parsing. - context ctx; + rts::context ctx; response_parser::config cfg; install_parser_service(ctx, cfg); response_parser pr(ctx); diff --git a/test/unit/request_parser.cpp b/test/unit/request_parser.cpp index a43be461..e04d8e02 100644 --- a/test/unit/request_parser.cpp +++ b/test/unit/request_parser.cpp @@ -9,15 +9,13 @@ // Test that header file is self-contained. #include - -#include #include -#include "boost/http_proto/parser.hpp" +#include + #include "test_suite.hpp" #include -#include #include namespace boost { @@ -88,7 +86,7 @@ struct request_parser_test void good( - context& ctx, + rts::context& ctx, core::string_view s, core::string_view expected = {}) { @@ -109,7 +107,7 @@ struct request_parser_test } void - bad(context& ctx, core::string_view s) + bad(rts::context& ctx, core::string_view s) { for(std::size_t nmax = 1; nmax < s.size(); ++nmax) @@ -137,7 +135,7 @@ struct request_parser_test BOOST_TEST(req.version() == v); }; - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); @@ -204,7 +202,7 @@ struct request_parser_test { // request_parser() { - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); request_parser pr(ctx); @@ -236,7 +234,7 @@ struct request_parser_test "\r\n\r\n"; }; - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); @@ -295,7 +293,7 @@ struct request_parser_test void testGet() { - context ctx; + rts::context ctx; request_parser::config cfg; install_parser_service(ctx, cfg); request_parser pr(ctx); diff --git a/test/unit/response_parser.cpp b/test/unit/response_parser.cpp index cd2ac2f7..4162bc73 100644 --- a/test/unit/response_parser.cpp +++ b/test/unit/response_parser.cpp @@ -10,7 +10,7 @@ // Test that header file is self-contained. #include -#include +#include #include "test_suite.hpp" @@ -23,9 +23,9 @@ class response_parser_test void testSpecial() { - // response_parser(context&) + // response_parser(rts::context&) { - context ctx; + rts::context ctx; response_parser::config cfg; install_parser_service(ctx, cfg); response_parser pr(ctx); diff --git a/test/unit/serializer.cpp b/test/unit/serializer.cpp index cd531c6a..096fdd68 100644 --- a/test/unit/serializer.cpp +++ b/test/unit/serializer.cpp @@ -10,9 +10,9 @@ // Test that header file is self-contained. #include - #include #include + #include #include #include @@ -20,6 +20,8 @@ #include #include #include +#include + #include "test_helpers.hpp" #include @@ -175,7 +177,7 @@ struct serializer_test void testSyntax() { - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); response res; @@ -224,7 +226,7 @@ struct serializer_test core::string_view expected) { response res(headers); - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); sr.start(res); @@ -281,7 +283,7 @@ struct serializer_test body.remove_prefix(buf_size); } - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); buffers::const_buffer_span cbs( @@ -309,7 +311,7 @@ struct serializer_test response res(headers); // we limit the buffer size of the serializer, requiring // it to make multiple calls to source::read - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); sr.start(res, std::forward< @@ -326,7 +328,7 @@ struct serializer_test F f) { response res(headers); - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); auto stream = sr.start_stream(res); @@ -506,7 +508,7 @@ struct serializer_test response res( "HTTP/1.1 200 OK\r\n" "\r\n"); - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); @@ -647,7 +649,7 @@ struct serializer_test { // request { - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); request req( @@ -693,7 +695,7 @@ struct serializer_test // empty body { - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); request req( @@ -738,7 +740,7 @@ struct serializer_test "Expect: 100-continue\r\n" "\r\n"; - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); response res(sv); @@ -762,7 +764,7 @@ struct serializer_test "Transfer-Encoding: chunked\r\n" "\r\n"; response res(sv); - context ctx; + rts::context ctx; install_serializer_service(ctx, {}); serializer sr(ctx); auto stream = sr.start_stream(res); diff --git a/test/unit/service/service.cpp b/test/unit/service/service.cpp deleted file mode 100644 index a7c7c60f..00000000 --- a/test/unit/service/service.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -// Test that header file is self-contained. -#include diff --git a/test/unit/service/virtual_service.cpp b/test/unit/service/virtual_service.cpp deleted file mode 100644 index df11266f..00000000 --- a/test/unit/service/virtual_service.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright (c) 2023 Christian Mazakas -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -#include - -#include - -#include "test_helpers.hpp" - -namespace boost { -namespace http_proto { - -struct virtual_service : -#ifdef BOOST_NO_RTTI - service -#else - virtual service -#endif -{ - int *px_ = nullptr; - - virtual_service(context &) : px_(new int{42}) {} - ~virtual_service() override { delete px_; } - int get_value() const { return *px_; } -}; - -struct virtual_service_test { - // want to ensure that our service architecture works with virtual inheritance - void run() { - context ctx; - ctx.make_service(); - - auto const psvc = ctx.find_service(); - BOOST_TEST_EQ(psvc->get_value(), 42); - } -}; - -TEST_SUITE(virtual_service_test, "boost.http_proto.virtual_service"); - -} // namespace http_proto -} // namespace boost diff --git a/test/unit/service/zlib_service.cpp b/test/unit/service/zlib_service.cpp deleted file mode 100644 index 286a7956..00000000 --- a/test/unit/service/zlib_service.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/http_proto -// - -// Test that header file is self-contained. -#include -#include - -#ifdef BOOST_HTTP_PROTO_HAS_ZLIB - -#include - -#include "test_helpers.hpp" - -namespace boost { -namespace http_proto { - -struct zlib_service_test -{ - void - run() - { - context ctx; - zlib::install_deflate_service(ctx); - zlib::install_inflate_service(ctx); - } -}; - -TEST_SUITE( - zlib_service_test, - "boost.http_proto.zlib_service"); - -} // http_proto -} // boost - -#endif diff --git a/test/unit/zlib.cpp b/test/unit/zlib.cpp index 31b3377b..0bbf2bb1 100644 --- a/test/unit/zlib.cpp +++ b/test/unit/zlib.cpp @@ -8,36 +8,11 @@ // Official repository: https://github.com/cppalliance/http_proto // -#include - -#include "test_suite.hpp" - -#ifndef BOOST_HTTP_PROTO_HAS_ZLIB - -#include - -BOOST_PRAGMA_MESSAGE("zlib not found, building dummy zlib.cpp test") - -struct zlib_test -{ - void run() - {} -}; - -TEST_SUITE( - zlib_test, - "boost.http_proto.zlib"); - -#else - -#include #include #include #include #include #include -#include -#include #include #include @@ -47,13 +22,14 @@ TEST_SUITE( #include #include #include +#include + +#include "test_helpers.hpp" #include #include #include -#include - // opt into random ascii generation as it's easier than // maintaing a large static asset that has to be loaded // at runtime @@ -79,23 +55,31 @@ struct zlib_test { std::string deflate( + rts::zlib::deflate_service& d_svc, int window_bits, int mem_level, core::string_view str) { - ::z_stream zs{}; - - if(!BOOST_TEST_EQ( - deflateInit2(&zs, -1, Z_DEFLATED, window_bits, - mem_level, Z_DEFAULT_STRATEGY), Z_OK)) + namespace zlib = rts::zlib; + zlib::stream zs{}; + + auto ret = static_cast( + d_svc.init2( + zs, + zlib::default_compression, + zlib::deflated, + window_bits, + mem_level, + zlib::default_strategy)); + + if(!BOOST_TEST_EQ(ret, zlib::error::ok)) { - ::deflateEnd(&zs); + d_svc.deflate_end(zs); return {}; } - zs.next_in = reinterpret_cast( - const_cast(str.data())); - zs.avail_in = static_cast(str.size()); + zs.next_in = reinterpret_cast(const_cast(str.data())); + zs.avail_in = static_cast(str.size()); std::string result; for(;;) @@ -103,33 +87,37 @@ struct zlib_test constexpr auto chunk_size = 2048; result.resize(result.size() + chunk_size); auto it = result.begin() + result.size() - chunk_size; - zs.next_out = reinterpret_cast(&*it); + zs.next_out = reinterpret_cast(&*it); zs.avail_out = chunk_size; - auto ret = ::deflate(&zs, Z_FINISH); + ret = static_cast( + d_svc.deflate(zs, zlib::finish)); result.erase( it + chunk_size - zs.avail_out, result.end()); - if( ret != Z_OK ) + if(ret != zlib::error::ok) break; } - ::deflateEnd(&zs); + d_svc.deflate_end(zs); return result; } void verify_compressed( + rts::zlib::inflate_service& i_svc, span compressed, core::string_view expected) { - int ret = -1; + namespace zlib = rts::zlib; - ::z_stream zs{}; + zlib::stream zs{}; int const window_bits = 15; // default int const enable_zlib_and_gzip = 32; - ret = ::inflateInit2( - &zs, window_bits + enable_zlib_and_gzip); - if(! BOOST_TEST_EQ(ret, Z_OK) ) + auto ret = static_cast( + i_svc.init2( + zs, + window_bits + enable_zlib_and_gzip)); + if(! BOOST_TEST_EQ(ret, zlib::error::ok) ) { - ::inflateEnd(&zs); + i_svc.inflate_end(zs); return; } @@ -144,10 +132,10 @@ struct zlib_test zs.avail_out = static_cast(decompressed_output.size()); - ret = ::inflate(&zs, Z_FINISH); - if(! BOOST_TEST_EQ(ret, Z_STREAM_END) ) + ret = static_cast(i_svc.inflate(zs, zlib::finish)); + if(! BOOST_TEST_EQ(ret, zlib::error::stream_end) ) { - ::inflateEnd(&zs); + i_svc.inflate_end(zs); return; } @@ -157,7 +145,7 @@ struct zlib_test decompressed_output.data()), n); BOOST_TEST(sv2 == expected); - ::inflateEnd(&zs); + i_svc.inflate_end(zs); return; } @@ -333,8 +321,10 @@ struct zlib_test std::string const& body, bool chunked_encoding) { - context ctx; + namespace zlib = rts::zlib; + rts::context ctx; zlib::install_deflate_service(ctx); + auto& i_svc = zlib::install_inflate_service(ctx); serializer::config cfg; cfg.apply_deflate_encoder = true; cfg.apply_gzip_encoder = true; @@ -428,7 +418,7 @@ struct zlib_test // BOOST_TEST_LT(compressed.size(), body.size()); - verify_compressed(compressed, body); + verify_compressed(i_svc, compressed, body); } } @@ -612,8 +602,9 @@ struct zlib_test void test_parser() { - context ctx; - zlib::install_inflate_service(ctx); + rts::context ctx; + rts::zlib::install_inflate_service(ctx); + auto& d_svc = rts::zlib::install_deflate_service(ctx); auto append_chunked = []( std::string& msg, @@ -655,6 +646,7 @@ struct zlib_test auto body = generate_book(body_size); auto deflated_body = deflate( + d_svc, 15 + (encoding == "gzip" ? 16 : 0), 8, body); @@ -692,10 +684,13 @@ struct zlib_test pr.reset(); } } + void run() { + #ifdef BOOST_RTS_HAS_ZLIB test_serializer(); test_parser(); + #endif } }; @@ -705,5 +700,3 @@ TEST_SUITE( } // namespace http_proto } // namespace boost - -#endif