| 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/inflate_service.hpp> | ||
| 11 | #include <zlib.h> | ||
| 12 | #include "src_zlib/service/stream_cast.hpp" | ||
| 13 | |||
| 14 | namespace boost { | ||
| 15 | namespace http_proto { | ||
| 16 | namespace zlib { | ||
| 17 | |||
| 18 | //------------------------------------------------ | ||
| 19 | |||
| 20 | class inflate_service_impl | ||
| 21 | : public inflate_service | ||
| 22 | , public http_proto::service | ||
| 23 | { | ||
| 24 | public: | ||
| 25 | using key_type = inflate_service; | ||
| 26 | |||
| 27 | explicit | ||
| 28 | ✗ | inflate_service_impl( | |
| 29 | http_proto::context&) noexcept | ||
| 30 | ✗ | { | |
| 31 | ✗ | } | |
| 32 | |||
| 33 | ✗ | ~inflate_service_impl() | |
| 34 | ✗ | { | |
| 35 | ✗ | } | |
| 36 | |||
| 37 | char const* | ||
| 38 | ✗ | version() const noexcept override | |
| 39 | { | ||
| 40 | ✗ | return zlibVersion(); | |
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | ✗ | init( | |
| 45 | stream_t& st) const override | ||
| 46 | { | ||
| 47 | ✗ | stream_cast sc(st); | |
| 48 | ✗ | return inflateInit(sc.get()); | |
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | ✗ | init2( | |
| 53 | stream_t& st, | ||
| 54 | int windowBits) const override | ||
| 55 | { | ||
| 56 | ✗ | stream_cast sc(st); | |
| 57 | ✗ | return inflateInit2(sc.get(), windowBits); | |
| 58 | } | ||
| 59 | |||
| 60 | int | ||
| 61 | ✗ | inflate( | |
| 62 | stream_t& st, | ||
| 63 | int flush) const override | ||
| 64 | { | ||
| 65 | ✗ | stream_cast sc(st); | |
| 66 | ✗ | return ::inflate(sc.get(), flush); | |
| 67 | } | ||
| 68 | |||
| 69 | int | ||
| 70 | ✗ | inflate_end( | |
| 71 | stream_t& st) const override | ||
| 72 | { | ||
| 73 | ✗ | stream_cast sc(st); | |
| 74 | ✗ | return inflateEnd(sc.get()); | |
| 75 | } | ||
| 76 | |||
| 77 | int | ||
| 78 | ✗ | set_dict( | |
| 79 | stream_t& st, | ||
| 80 | unsigned char const* dict, | ||
| 81 | unsigned len) const override | ||
| 82 | { | ||
| 83 | ✗ | stream_cast sc(st); | |
| 84 | ✗ | return inflateSetDictionary(sc.get(), dict, len); | |
| 85 | } | ||
| 86 | |||
| 87 | int | ||
| 88 | ✗ | get_dict( | |
| 89 | stream_t& st, | ||
| 90 | unsigned char* dest, | ||
| 91 | unsigned* len) const override | ||
| 92 | { | ||
| 93 | ✗ | stream_cast sc(st); | |
| 94 | ✗ | return inflateGetDictionary(sc.get(), dest, len); | |
| 95 | } | ||
| 96 | |||
| 97 | int | ||
| 98 | ✗ | sync( | |
| 99 | stream_t& st) const override | ||
| 100 | { | ||
| 101 | ✗ | stream_cast sc(st); | |
| 102 | ✗ | return inflateSync(sc.get()); | |
| 103 | } | ||
| 104 | |||
| 105 | int | ||
| 106 | ✗ | dup( | |
| 107 | stream_t& dest, | ||
| 108 | stream_t& src) const override | ||
| 109 | { | ||
| 110 | ✗ | stream_cast sc0(dest); | |
| 111 | ✗ | stream_cast sc1(src); | |
| 112 | ✗ | return inflateCopy(sc0.get(), sc1.get()); | |
| 113 | } | ||
| 114 | |||
| 115 | int | ||
| 116 | ✗ | reset( | |
| 117 | stream_t& st) const override | ||
| 118 | { | ||
| 119 | ✗ | stream_cast sc(st); | |
| 120 | ✗ | return inflateReset(sc.get()); | |
| 121 | } | ||
| 122 | |||
| 123 | int | ||
| 124 | ✗ | reset2( | |
| 125 | stream_t& st, | ||
| 126 | int windowBits) const override | ||
| 127 | { | ||
| 128 | ✗ | stream_cast sc(st); | |
| 129 | ✗ | return inflateReset2(sc.get(), windowBits); | |
| 130 | } | ||
| 131 | |||
| 132 | int | ||
| 133 | ✗ | prime( | |
| 134 | stream_t& st, | ||
| 135 | int bits, | ||
| 136 | int value) const override | ||
| 137 | { | ||
| 138 | ✗ | stream_cast sc(st); | |
| 139 | ✗ | return inflatePrime(sc.get(), bits, value); | |
| 140 | } | ||
| 141 | |||
| 142 | long | ||
| 143 | ✗ | mark( | |
| 144 | stream_t& st) const override | ||
| 145 | { | ||
| 146 | ✗ | stream_cast sc(st); | |
| 147 | ✗ | return inflateMark(sc.get()); | |
| 148 | } | ||
| 149 | |||
| 150 | int | ||
| 151 | ✗ | get_header( | |
| 152 | stream_t& st, | ||
| 153 | void* header) const override | ||
| 154 | { | ||
| 155 | ✗ | stream_cast sc(st); | |
| 156 | ✗ | return inflateGetHeader(sc.get(), | |
| 157 | ✗ | reinterpret_cast<gz_headerp>(header)); | |
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | ✗ | back_init( | |
| 162 | stream_t& st, | ||
| 163 | int windowBits, | ||
| 164 | unsigned char* window) const override | ||
| 165 | { | ||
| 166 | ✗ | stream_cast sc(st); | |
| 167 | ✗ | return inflateBackInit(sc.get(), windowBits, window); | |
| 168 | } | ||
| 169 | |||
| 170 | int | ||
| 171 | ✗ | back_end( | |
| 172 | stream_t& st) const override | ||
| 173 | { | ||
| 174 | ✗ | stream_cast sc(st); | |
| 175 | ✗ | return inflateBackEnd(sc.get()); | |
| 176 | } | ||
| 177 | |||
| 178 | unsigned long | ||
| 179 | ✗ | compile_flags() const override | |
| 180 | { | ||
| 181 | ✗ | return zlibCompileFlags(); | |
| 182 | } | ||
| 183 | }; | ||
| 184 | |||
| 185 | void | ||
| 186 | ✗ | install_inflate_service(context& ctx) | |
| 187 | { | ||
| 188 | ✗ | ctx.make_service<inflate_service_impl>(); | |
| 189 | ✗ | } | |
| 190 | |||
| 191 | } // zlib | ||
| 192 | } // http_proto | ||
| 193 | } // boost | ||
| 194 |