]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // |
92f5a8d4 | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
7c673cae FG |
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 | // | |
b32b8144 FG |
7 | // Official repository: https://github.com/boostorg/beast |
8 | // | |
92f5a8d4 | 9 | |
7c673cae FG |
10 | // This is a derivative work based on Zlib, copyright below: |
11 | /* | |
12 | Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler | |
13 | ||
14 | This software is provided 'as-is', without any express or implied | |
15 | warranty. In no event will the authors be held liable for any damages | |
16 | arising from the use of this software. | |
17 | ||
18 | Permission is granted to anyone to use this software for any purpose, | |
19 | including commercial applications, and to alter it and redistribute it | |
20 | freely, subject to the following restrictions: | |
21 | ||
22 | 1. The origin of this software must not be misrepresented; you must not | |
23 | claim that you wrote the original software. If you use this software | |
24 | in a product, an acknowledgment in the product documentation would be | |
25 | appreciated but is not required. | |
26 | 2. Altered source versions must be plainly marked as such, and must not be | |
27 | misrepresented as being the original software. | |
28 | 3. This notice may not be removed or altered from any source distribution. | |
29 | ||
30 | Jean-loup Gailly Mark Adler | |
31 | jloup@gzip.org madler@alumni.caltech.edu | |
32 | ||
33 | The data format used by the zlib library is described by RFCs (Request for | |
34 | Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 | |
35 | (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). | |
36 | */ | |
37 | ||
b32b8144 FG |
38 | #ifndef BOOST_BEAST_ZLIB_IMPL_ERROR_IPP |
39 | #define BOOST_BEAST_ZLIB_IMPL_ERROR_IPP | |
7c673cae | 40 | |
92f5a8d4 | 41 | #include <boost/beast/zlib/error.hpp> |
7c673cae FG |
42 | #include <type_traits> |
43 | ||
44 | namespace boost { | |
7c673cae FG |
45 | namespace beast { |
46 | namespace zlib { | |
47 | namespace detail { | |
48 | ||
92f5a8d4 | 49 | class error_codes : public error_category |
7c673cae FG |
50 | { |
51 | public: | |
52 | const char* | |
53 | name() const noexcept override | |
54 | { | |
92f5a8d4 | 55 | return "boost.beast.zlib"; |
7c673cae FG |
56 | } |
57 | ||
58 | std::string | |
59 | message(int ev) const override | |
60 | { | |
61 | switch(static_cast<error>(ev)) | |
62 | { | |
63 | case error::need_buffers: return "need buffers"; | |
b32b8144 | 64 | case error::end_of_stream: return "unexpected end of deflate stream"; |
92f5a8d4 | 65 | case error::need_dict: return "need dict"; |
7c673cae FG |
66 | case error::stream_error: return "stream error"; |
67 | ||
68 | case error::invalid_block_type: return "invalid block type"; | |
69 | case error::invalid_stored_length: return "invalid stored block length"; | |
70 | case error::too_many_symbols: return "too many symbols"; | |
92f5a8d4 | 71 | case error::invalid_code_lengths: return "invalid code lengths"; |
7c673cae FG |
72 | case error::invalid_bit_length_repeat: return "invalid bit length repeat"; |
73 | case error::missing_eob: return "missing end of block code"; | |
74 | case error::invalid_literal_length: return "invalid literal/length code"; | |
75 | case error::invalid_distance_code: return "invalid distance code"; | |
76 | case error::invalid_distance: return "invalid distance"; | |
77 | ||
78 | case error::over_subscribed_length: return "over-subscribed length"; | |
79 | case error::incomplete_length_set: return "incomplete length set"; | |
80 | ||
81 | case error::general: | |
82 | default: | |
b32b8144 | 83 | return "beast.zlib error"; |
7c673cae FG |
84 | } |
85 | } | |
86 | ||
87 | error_condition | |
88 | default_error_condition(int ev) const noexcept override | |
89 | { | |
90 | return error_condition{ev, *this}; | |
91 | } | |
92 | ||
93 | bool | |
94 | equivalent(int ev, | |
95 | error_condition const& condition | |
96 | ) const noexcept override | |
97 | { | |
98 | return condition.value() == ev && | |
99 | &condition.category() == this; | |
100 | } | |
101 | ||
102 | bool | |
103 | equivalent(error_code const& error, int ev) const noexcept override | |
104 | { | |
105 | return error.value() == ev && | |
106 | &error.category() == this; | |
107 | } | |
108 | }; | |
109 | ||
7c673cae FG |
110 | } // detail |
111 | ||
7c673cae FG |
112 | error_code |
113 | make_error_code(error ev) | |
114 | { | |
92f5a8d4 TL |
115 | static detail::error_codes const cat{}; |
116 | return error_code{static_cast< | |
117 | std::underlying_type<error>::type>(ev), cat}; | |
7c673cae FG |
118 | } |
119 | ||
120 | } // zlib | |
121 | } // beast | |
b32b8144 | 122 | } // boost |
7c673cae FG |
123 | |
124 | #endif |