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