src_zlib/deflate.cpp
14.5% Lines (8/55)
16.7% Functions (3/18)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | ||
| 3 | // Copyright (c) 2025 Mohammad Nejati | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/http | ||
| 9 | // | ||
| 10 | |||
| 11 | #include <boost/capy/ex/system_context.hpp> | ||
| 12 | #include <boost/http/detail/config.hpp> | ||
| 13 | #include <boost/http/zlib/deflate.hpp> | ||
| 14 | |||
| 15 | #include "stream_cast.hpp" | ||
| 16 | |||
| 17 | #include <boost/core/detail/static_assert.hpp> | ||
| 18 | |||
| 19 | #include <zlib.h> | ||
| 20 | |||
| 21 | namespace boost { | ||
| 22 | namespace http { | ||
| 23 | namespace zlib { | ||
| 24 | |||
| 25 | BOOST_CORE_STATIC_ASSERT(sizeof(stream) == sizeof(z_stream_s)); | ||
| 26 | BOOST_CORE_STATIC_ASSERT(is_layout_identical<stream, z_stream_s>()); | ||
| 27 | |||
| 28 | //------------------------------------------------ | ||
| 29 | |||
| 30 | class deflate_service_impl | ||
| 31 | : public deflate_service | ||
| 32 | { | ||
| 33 | public: | ||
| 34 | using key_type = deflate_service; | ||
| 35 | |||
| 36 | explicit | ||
| 37 | 1 | deflate_service_impl( | |
| 38 | capy::execution_context&) noexcept | ||
| 39 | 1 | { | |
| 40 | 1 | } | |
| 41 | |||
| 42 | 2 | ~deflate_service_impl() | |
| 43 | 1 | { | |
| 44 | 2 | } | |
| 45 | |||
| 46 | char const* | ||
| 47 | ✗ | version() const noexcept override | |
| 48 | { | ||
| 49 | ✗ | return zlibVersion(); | |
| 50 | } | ||
| 51 | |||
| 52 | int | ||
| 53 | ✗ | init( | |
| 54 | stream& st, | ||
| 55 | int level) const override | ||
| 56 | { | ||
| 57 | ✗ | stream_cast sc(st); | |
| 58 | ✗ | return deflateInit(sc.get(), level); | |
| 59 | } | ||
| 60 | |||
| 61 | int | ||
| 62 | ✗ | init2( | |
| 63 | stream& st, | ||
| 64 | int level, | ||
| 65 | int method, | ||
| 66 | int windowBits, | ||
| 67 | int memLevel, | ||
| 68 | int strategy) const override | ||
| 69 | { | ||
| 70 | ✗ | stream_cast sc(st); | |
| 71 | ✗ | return deflateInit2(sc.get(), | |
| 72 | level, method, windowBits, | ||
| 73 | memLevel, strategy); | ||
| 74 | } | ||
| 75 | |||
| 76 | int | ||
| 77 | ✗ | set_dict( | |
| 78 | stream& st, | ||
| 79 | unsigned char const* dict, | ||
| 80 | unsigned len) const override | ||
| 81 | { | ||
| 82 | ✗ | stream_cast sc(st); | |
| 83 | ✗ | return deflateSetDictionary(sc.get(), dict, len); | |
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | ✗ | get_dict( | |
| 88 | stream& st, | ||
| 89 | unsigned char* dest, | ||
| 90 | unsigned* len) const override | ||
| 91 | { | ||
| 92 | ✗ | stream_cast sc(st); | |
| 93 | ✗ | return deflateGetDictionary(sc.get(), dest, len); | |
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | ✗ | dup( | |
| 98 | stream& dest, | ||
| 99 | stream& src) const override | ||
| 100 | { | ||
| 101 | ✗ | stream_cast sc0(dest); | |
| 102 | ✗ | stream_cast sc1(src); | |
| 103 | ✗ | return deflateCopy(sc0.get(), sc1.get()); | |
| 104 | } | ||
| 105 | |||
| 106 | int | ||
| 107 | ✗ | deflate( | |
| 108 | stream& st, | ||
| 109 | int flush) const override | ||
| 110 | { | ||
| 111 | ✗ | stream_cast sc(st); | |
| 112 | ✗ | return ::deflate(sc.get(), flush); | |
| 113 | } | ||
| 114 | |||
| 115 | int | ||
| 116 | ✗ | deflate_end( | |
| 117 | stream& st) const override | ||
| 118 | { | ||
| 119 | ✗ | stream_cast sc(st); | |
| 120 | ✗ | return deflateEnd(sc.get()); | |
| 121 | } | ||
| 122 | |||
| 123 | int | ||
| 124 | ✗ | reset( | |
| 125 | stream& st) const override | ||
| 126 | { | ||
| 127 | ✗ | stream_cast sc(st); | |
| 128 | ✗ | return deflateReset(sc.get()); | |
| 129 | } | ||
| 130 | |||
| 131 | int | ||
| 132 | ✗ | params( | |
| 133 | stream& st, | ||
| 134 | int level, | ||
| 135 | int strategy) const override | ||
| 136 | { | ||
| 137 | ✗ | stream_cast sc(st); | |
| 138 | ✗ | return deflateParams(sc.get(), level, strategy); | |
| 139 | } | ||
| 140 | |||
| 141 | std::size_t | ||
| 142 | ✗ | bound( | |
| 143 | stream& st, | ||
| 144 | unsigned long sourceLen) const override | ||
| 145 | { | ||
| 146 | ✗ | stream_cast sc(st); | |
| 147 | ✗ | return deflateBound(sc.get(), sourceLen); | |
| 148 | } | ||
| 149 | |||
| 150 | int | ||
| 151 | ✗ | pending( | |
| 152 | stream& st, | ||
| 153 | unsigned* pending, | ||
| 154 | int* bits) const override | ||
| 155 | { | ||
| 156 | ✗ | stream_cast sc(st); | |
| 157 | ✗ | return deflatePending(sc.get(), pending, bits); | |
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | ✗ | prime( | |
| 162 | stream& st, | ||
| 163 | int bits, | ||
| 164 | int value) const override | ||
| 165 | { | ||
| 166 | ✗ | stream_cast sc(st); | |
| 167 | ✗ | return deflatePrime(sc.get(), bits, value); | |
| 168 | } | ||
| 169 | |||
| 170 | int | ||
| 171 | ✗ | set_header( | |
| 172 | stream& st, | ||
| 173 | void* header) const override | ||
| 174 | { | ||
| 175 | ✗ | stream_cast sc(st); | |
| 176 | ✗ | return deflateSetHeader(sc.get(), | |
| 177 | ✗ | reinterpret_cast<gz_header*>(header)); | |
| 178 | } | ||
| 179 | }; | ||
| 180 | |||
| 181 | BOOST_HTTP_DECL | ||
| 182 | deflate_service& | ||
| 183 | 1 | install_deflate_service(capy::execution_context& ctx) | |
| 184 | { | ||
| 185 | 1 | return ctx.make_service<deflate_service_impl>(); | |
| 186 | } | ||
| 187 | |||
| 188 | struct inflate_service; | ||
| 189 | |||
| 190 | inflate_service& | ||
| 191 | install_inflate_service(capy::execution_context&); | ||
| 192 | |||
| 193 | void | ||
| 194 | ✗ | install_zlib_service() | |
| 195 | { | ||
| 196 | ✗ | install_deflate_service(capy::get_system_context()); | |
| 197 | ✗ | install_inflate_service(capy::get_system_context()); | |
| 198 | ✗ | } | |
| 199 | |||
| 200 | } // zlib | ||
| 201 | } // http | ||
| 202 | } // boost | ||
| 203 |