1// 2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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/boostorg/beast 8// 9 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 38#ifndef BOOST_BEAST_ZLIB_IMPL_ERROR_IPP 39#define BOOST_BEAST_ZLIB_IMPL_ERROR_IPP 40 41#include <boost/beast/zlib/error.hpp> 42#include <type_traits> 43 44namespace boost { 45namespace beast { 46namespace zlib { 47namespace detail { 48 49class error_codes : public error_category 50{ 51public: 52 const char* 53 name() const noexcept override 54 { 55 return "boost.beast.zlib"; 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"; 64 case error::end_of_stream: return "unexpected end of deflate stream"; 65 case error::need_dict: return "need dict"; 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"; 71 case error::invalid_code_lengths: return "invalid code lengths"; 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: 83 return "beast.zlib error"; 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 110} // detail 111 112error_code 113make_error_code(error ev) 114{ 115 static detail::error_codes const cat{}; 116 return error_code{static_cast< 117 std::underlying_type<error>::type>(ev), cat}; 118} 119 120} // zlib 121} // beast 122} // boost 123 124#endif 125