/src/libtorrent/include/libtorrent/gzip.hpp
Line | Count | Source |
1 | | /* |
2 | | |
3 | | Copyright (c) 2008-2009, 2014-2019, Arvid Norberg |
4 | | All rights reserved. |
5 | | |
6 | | Redistribution and use in source and binary forms, with or without |
7 | | modification, are permitted provided that the following conditions |
8 | | are met: |
9 | | |
10 | | * Redistributions of source code must retain the above copyright |
11 | | notice, this list of conditions and the following disclaimer. |
12 | | * Redistributions in binary form must reproduce the above copyright |
13 | | notice, this list of conditions and the following disclaimer in |
14 | | the documentation and/or other materials provided with the distribution. |
15 | | * Neither the name of the author nor the names of its |
16 | | contributors may be used to endorse or promote products derived |
17 | | from this software without specific prior written permission. |
18 | | |
19 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
23 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | | POSSIBILITY OF SUCH DAMAGE. |
30 | | |
31 | | */ |
32 | | |
33 | | #ifndef TORRENT_GZIP_HPP_INCLUDED |
34 | | #define TORRENT_GZIP_HPP_INCLUDED |
35 | | |
36 | | #include "libtorrent/config.hpp" |
37 | | #include "libtorrent/error_code.hpp" |
38 | | #include "libtorrent/span.hpp" |
39 | | |
40 | | #include <vector> |
41 | | |
42 | | namespace libtorrent { |
43 | | |
44 | | TORRENT_EXTRA_EXPORT void inflate_gzip( |
45 | | span<char const> in |
46 | | , std::vector<char>& buffer |
47 | | , int maximum_size |
48 | | , error_code& ec); |
49 | | |
50 | | // get the ``error_category`` for zip errors |
51 | | TORRENT_EXPORT boost::system::error_category& gzip_category(); |
52 | | |
53 | | #if TORRENT_ABI_VERSION == 1 |
54 | | TORRENT_DEPRECATED |
55 | | inline boost::system::error_category& get_gzip_category() |
56 | 0 | { return gzip_category(); } |
57 | | #endif |
58 | | |
59 | | namespace gzip_errors { |
60 | | // libtorrent uses boost.system's ``error_code`` class to represent errors. libtorrent has |
61 | | // its own error category get_gzip_category() with the error codes defined by error_code_enum. |
62 | | enum error_code_enum |
63 | | { |
64 | | // Not an error |
65 | | no_error = 0, |
66 | | |
67 | | // the supplied gzip buffer has invalid header |
68 | | invalid_gzip_header, |
69 | | |
70 | | // the gzip buffer would inflate to more bytes than the specified |
71 | | // maximum size, and was rejected. |
72 | | inflated_data_too_large, |
73 | | |
74 | | // available inflate data did not terminate |
75 | | data_did_not_terminate, |
76 | | |
77 | | // output space exhausted before completing inflate |
78 | | space_exhausted, |
79 | | |
80 | | // invalid block type (type == 3) |
81 | | invalid_block_type, |
82 | | |
83 | | // stored block length did not match one's complement |
84 | | invalid_stored_block_length, |
85 | | |
86 | | // dynamic block code description: too many length or distance codes |
87 | | too_many_length_or_distance_codes, |
88 | | |
89 | | // dynamic block code description: code lengths codes incomplete |
90 | | code_lengths_codes_incomplete, |
91 | | |
92 | | // dynamic block code description: repeat lengths with no first length |
93 | | repeat_lengths_with_no_first_length, |
94 | | |
95 | | // dynamic block code description: repeat more than specified lengths |
96 | | repeat_more_than_specified_lengths, |
97 | | |
98 | | // dynamic block code description: invalid literal/length code lengths |
99 | | invalid_literal_length_code_lengths, |
100 | | |
101 | | // dynamic block code description: invalid distance code lengths |
102 | | invalid_distance_code_lengths, |
103 | | |
104 | | // invalid literal/length or distance code in fixed or dynamic block |
105 | | invalid_literal_code_in_block, |
106 | | |
107 | | // distance is too far back in fixed or dynamic block |
108 | | distance_too_far_back_in_block, |
109 | | |
110 | | // an unknown error occurred during gzip inflation |
111 | | unknown_gzip_error, |
112 | | |
113 | | // the number of error codes |
114 | | error_code_max |
115 | | }; |
116 | | |
117 | | // hidden |
118 | | TORRENT_EXPORT boost::system::error_code make_error_code(error_code_enum e); |
119 | | } // namespace gzip_errors |
120 | | |
121 | | } // namespace libtorrent |
122 | | |
123 | | namespace boost { |
124 | | namespace system { |
125 | | |
126 | | template<> |
127 | | struct is_error_code_enum<libtorrent::gzip_errors::error_code_enum> |
128 | | { static const bool value = true; }; |
129 | | |
130 | | template<> |
131 | | struct is_error_condition_enum<libtorrent::gzip_errors::error_code_enum> |
132 | | { static const bool value = true; }; |
133 | | |
134 | | } |
135 | | } |
136 | | |
137 | | #endif |