src_zlib/inflate.cpp
13.6% Lines (8/59)
15.0% Functions (3/20)
| 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/inflate.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 inflate_service_impl | ||
| 31 | : public inflate_service | ||
| 32 | { | ||
| 33 | public: | ||
| 34 | using key_type = inflate_service; | ||
| 35 | |||
| 36 | explicit | ||
| 37 | 1 | inflate_service_impl( | |
| 38 | capy::execution_context&) noexcept | ||
| 39 | 1 | { | |
| 40 | 1 | } | |
| 41 | |||
| 42 | 2 | ~inflate_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) const override | ||
| 55 | { | ||
| 56 | ✗ | stream_cast sc(st); | |
| 57 | ✗ | return inflateInit(sc.get()); | |
| 58 | } | ||
| 59 | |||
| 60 | int | ||
| 61 | ✗ | init2( | |
| 62 | stream& st, | ||
| 63 | int windowBits) const override | ||
| 64 | { | ||
| 65 | ✗ | stream_cast sc(st); | |
| 66 | ✗ | return inflateInit2(sc.get(), windowBits); | |
| 67 | } | ||
| 68 | |||
| 69 | int | ||
| 70 | ✗ | inflate( | |
| 71 | stream& st, | ||
| 72 | int flush) const override | ||
| 73 | { | ||
| 74 | ✗ | stream_cast sc(st); | |
| 75 | ✗ | return ::inflate(sc.get(), flush); | |
| 76 | } | ||
| 77 | |||
| 78 | int | ||
| 79 | ✗ | inflate_end( | |
| 80 | stream& st) const override | ||
| 81 | { | ||
| 82 | ✗ | stream_cast sc(st); | |
| 83 | ✗ | return inflateEnd(sc.get()); | |
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | ✗ | set_dict( | |
| 88 | stream& st, | ||
| 89 | unsigned char const* dict, | ||
| 90 | unsigned len) const override | ||
| 91 | { | ||
| 92 | ✗ | stream_cast sc(st); | |
| 93 | ✗ | return inflateSetDictionary(sc.get(), dict, len); | |
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | ✗ | get_dict( | |
| 98 | stream& st, | ||
| 99 | unsigned char* dest, | ||
| 100 | unsigned* len) const override | ||
| 101 | { | ||
| 102 | ✗ | stream_cast sc(st); | |
| 103 | ✗ | return inflateGetDictionary(sc.get(), dest, len); | |
| 104 | } | ||
| 105 | |||
| 106 | int | ||
| 107 | ✗ | sync( | |
| 108 | stream& st) const override | ||
| 109 | { | ||
| 110 | ✗ | stream_cast sc(st); | |
| 111 | ✗ | return inflateSync(sc.get()); | |
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | ✗ | dup( | |
| 116 | stream& dest, | ||
| 117 | stream& src) const override | ||
| 118 | { | ||
| 119 | ✗ | stream_cast sc0(dest); | |
| 120 | ✗ | stream_cast sc1(src); | |
| 121 | ✗ | return inflateCopy(sc0.get(), sc1.get()); | |
| 122 | } | ||
| 123 | |||
| 124 | int | ||
| 125 | ✗ | reset( | |
| 126 | stream& st) const override | ||
| 127 | { | ||
| 128 | ✗ | stream_cast sc(st); | |
| 129 | ✗ | return inflateReset(sc.get()); | |
| 130 | } | ||
| 131 | |||
| 132 | int | ||
| 133 | ✗ | reset2( | |
| 134 | stream& st, | ||
| 135 | int windowBits) const override | ||
| 136 | { | ||
| 137 | ✗ | stream_cast sc(st); | |
| 138 | ✗ | return inflateReset2(sc.get(), windowBits); | |
| 139 | } | ||
| 140 | |||
| 141 | int | ||
| 142 | ✗ | prime( | |
| 143 | stream& st, | ||
| 144 | int bits, | ||
| 145 | int value) const override | ||
| 146 | { | ||
| 147 | ✗ | stream_cast sc(st); | |
| 148 | ✗ | return inflatePrime(sc.get(), bits, value); | |
| 149 | } | ||
| 150 | |||
| 151 | long | ||
| 152 | ✗ | mark( | |
| 153 | stream& st) const override | ||
| 154 | { | ||
| 155 | ✗ | stream_cast sc(st); | |
| 156 | ✗ | return inflateMark(sc.get()); | |
| 157 | } | ||
| 158 | |||
| 159 | int | ||
| 160 | ✗ | get_header( | |
| 161 | stream& st, | ||
| 162 | void* header) const override | ||
| 163 | { | ||
| 164 | ✗ | stream_cast sc(st); | |
| 165 | ✗ | return inflateGetHeader(sc.get(), | |
| 166 | ✗ | reinterpret_cast<gz_headerp>(header)); | |
| 167 | } | ||
| 168 | |||
| 169 | int | ||
| 170 | ✗ | back_init( | |
| 171 | stream& st, | ||
| 172 | int windowBits, | ||
| 173 | unsigned char* window) const override | ||
| 174 | { | ||
| 175 | ✗ | stream_cast sc(st); | |
| 176 | ✗ | return inflateBackInit(sc.get(), windowBits, window); | |
| 177 | } | ||
| 178 | |||
| 179 | int | ||
| 180 | ✗ | back_end( | |
| 181 | stream& st) const override | ||
| 182 | { | ||
| 183 | ✗ | stream_cast sc(st); | |
| 184 | ✗ | return inflateBackEnd(sc.get()); | |
| 185 | } | ||
| 186 | |||
| 187 | unsigned long | ||
| 188 | ✗ | compile_flags() const override | |
| 189 | { | ||
| 190 | ✗ | return zlibCompileFlags(); | |
| 191 | } | ||
| 192 | }; | ||
| 193 | |||
| 194 | inflate_service& | ||
| 195 | 1 | install_inflate_service(capy::execution_context& ctx) | |
| 196 | { | ||
| 197 | 1 | return ctx.make_service<inflate_service_impl>(); | |
| 198 | } | ||
| 199 | |||
| 200 | } // zlib | ||
| 201 | } // http | ||
| 202 | } // boost | ||
| 203 |