-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,018 additions
and
934 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// Copyright (c) 2021 Vinnie Falco ([email protected]) | ||
// 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 <boost/system/is_error_code_enum.hpp> | ||
|
||
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_HTTP_PROTO_DECL | ||
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<std::underlying_type< | ||
error>::type>(ev), | ||
detail::error_cat}; | ||
} | ||
|
||
} // zip | ||
} // http_proto | ||
} // boost | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// | ||
// Copyright (c) 2021 Vinnie Falco ([email protected]) | ||
// 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) | ||
|
@@ -16,9 +17,6 @@ | |
#include <boost/http_proto/detail/workspace.hpp> | ||
#include <boost/http_proto/service/service.hpp> | ||
|
||
#include <boost/buffers/const_buffer.hpp> | ||
#include <boost/buffers/mutable_buffer.hpp> | ||
|
||
namespace boost { | ||
namespace http_proto { | ||
namespace zlib { | ||
|
@@ -29,8 +27,6 @@ struct decoder_config | |
unsigned mem_level = 8; | ||
}; | ||
|
||
//------------------------------------------------ | ||
|
||
constexpr | ||
inline | ||
std::size_t | ||
|
@@ -54,60 +50,142 @@ encoding_size_hint(decoder_config cfg = {}) noexcept | |
(6 * 1024); | ||
} | ||
|
||
struct BOOST_HTTP_PROTO_ZLIB_DECL | ||
/** 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 class flush | ||
{ | ||
none, | ||
partial, | ||
sync, | ||
full, | ||
finish, | ||
block, | ||
trees | ||
}; | ||
|
||
/** Input and output buffers. | ||
The application must update `next_in` and `avail_in` when `avail_in` | ||
has dropped to zero. It must update `next_out` and `avail_out` when | ||
`avail_out` has dropped to zero. | ||
*/ | ||
struct params | ||
{ | ||
/// Next input byte | ||
void const* next_in; | ||
|
||
/// Number of bytes available at `next_in` | ||
std::size_t avail_in; | ||
|
||
/// Next output byte | ||
void* next_out; | ||
|
||
/// Number of bytes remaining free at `next_out` | ||
std::size_t avail_out; | ||
}; | ||
|
||
/// Abstract interface for deflator/inflator streams. | ||
struct stream | ||
{ | ||
/** Call the underling compression/decompression algorithm. | ||
@param p The input and output buffers. | ||
@param f The flush method. | ||
@return The result of operation that contains a value | ||
of @ref error. | ||
*/ | ||
virtual system::error_code | ||
write(params& p, flush f) noexcept = 0; | ||
}; | ||
|
||
/** Provides in-memory compression and decompression functions | ||
using zlib underneath. | ||
*/ | ||
struct BOOST_HTTP_PROTO_DECL | ||
service | ||
: http_proto::service | ||
{ | ||
struct stream | ||
{ | ||
enum class flush | ||
{ | ||
none, | ||
partial, | ||
sync, | ||
full, | ||
finish, | ||
block, | ||
trees | ||
}; | ||
|
||
struct results | ||
{ | ||
std::size_t out_bytes; | ||
std::size_t in_bytes; | ||
system::error_code ec; | ||
bool finished; | ||
}; | ||
|
||
virtual results | ||
write( | ||
buffers::mutable_buffer out, | ||
buffers::const_buffer in, | ||
flush) noexcept = 0; | ||
}; | ||
|
||
virtual | ||
std::size_t | ||
space_needed() const noexcept = 0; | ||
|
||
/** Create a deflator stream by calling zlib `deflateInit2()`. | ||
@param ws A reference to the workspace used for constructing the | ||
deflator stream object and for storage used by zlib. | ||
@param level The compression level. | ||
@param window_bits The window size. | ||
@param mem_level Specifies how much memory should be allocated | ||
for the internal compression state. | ||
@return A reference to the created deflator stream. | ||
@throws std::length_error If there is insufficient free space in | ||
@ref `http_proto::detail::workspace`. | ||
*/ | ||
virtual stream& | ||
make_deflator( | ||
http_proto::detail::workspace& ws, | ||
int level, | ||
int window_bits, | ||
int mem_level) const = 0; | ||
|
||
/** Create an inflator stream by calling zlib `inflateInit2()`. | ||
@param ws A reference to the workspace used for constructing the | ||
inflator stream object and for storage used by zlib. | ||
@param window_bits The window size. | ||
@return A reference to the created inflator stream. | ||
@throws std::length_error If there is insufficient free space in | ||
@ref `http_proto::detail::workspace`. | ||
*/ | ||
virtual stream& | ||
make_inflator( | ||
http_proto::detail::workspace& ws, | ||
int window_bits) const = 0; | ||
}; | ||
|
||
void BOOST_HTTP_PROTO_ZLIB_DECL | ||
/** Installs a zlib service on the provided context. | ||
@param ctx A reference to the @ref context where the service | ||
will be installed. | ||
@throw std::invalid_argument If the zlib service already | ||
exist on the context. | ||
*/ | ||
BOOST_HTTP_PROTO_ZLIB_DECL | ||
void | ||
install_service(context& ctx); | ||
|
||
} // zlib | ||
} // http_proto | ||
} // boost | ||
|
||
#include <boost/http_proto/service/impl/zlib_service.hpp> | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.