]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // |
b32b8144 | 2 | // Copyright (c) 2016-2017 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 | // | |
7c673cae | 9 | |
b32b8144 FG |
10 | #ifndef BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP |
11 | #define BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP | |
7c673cae FG |
12 | |
13 | namespace boost { | |
7c673cae FG |
14 | namespace beast { |
15 | namespace websocket { | |
16 | namespace detail { | |
17 | ||
11fdf7f2 TL |
18 | inline |
19 | const char* | |
20 | error_codes:: | |
21 | name() const noexcept | |
7c673cae | 22 | { |
11fdf7f2 TL |
23 | return "boost.beast.websocket"; |
24 | } | |
7c673cae | 25 | |
11fdf7f2 TL |
26 | inline |
27 | std::string | |
28 | error_codes:: | |
29 | message(int ev) const | |
30 | { | |
31 | switch(static_cast<error>(ev)) | |
7c673cae | 32 | { |
11fdf7f2 TL |
33 | default: |
34 | case error::closed: return "The WebSocket stream was gracefully closed at both endpoints"; | |
35 | case error::buffer_overflow: return "The WebSocket operation caused a dynamic buffer overflow"; | |
36 | case error::partial_deflate_block: return "The WebSocket stream produced an incomplete deflate block"; | |
37 | case error::message_too_big: return "The WebSocket message exceeded the locally configured limit"; | |
7c673cae | 38 | |
11fdf7f2 TL |
39 | case error::bad_http_version: return "The WebSocket handshake was not HTTP/1.1"; |
40 | case error::bad_method: return "The WebSocket handshake method was not GET"; | |
41 | case error::no_host: return "The WebSocket handshake Host field is missing"; | |
42 | case error::no_connection: return "The WebSocket handshake Connection field is missing"; | |
43 | case error::no_connection_upgrade: return "The WebSocket handshake Connection field is missing the upgrade token"; | |
44 | case error::no_upgrade: return "The WebSocket handshake Upgrade field is missing"; | |
45 | case error::no_upgrade_websocket: return "The WebSocket handshake Upgrade field is missing the websocket token"; | |
46 | case error::no_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is missing"; | |
47 | case error::bad_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is invalid"; | |
48 | case error::no_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is missing"; | |
49 | case error::bad_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is invalid"; | |
50 | case error::no_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is missing"; | |
51 | case error::bad_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is invalid"; | |
52 | case error::upgrade_declined: return "The WebSocket handshake was declined by the remote peer"; | |
7c673cae | 53 | |
11fdf7f2 TL |
54 | case error::bad_opcode: return "The WebSocket frame contained an illegal opcode"; |
55 | case error::bad_data_frame: return "The WebSocket data frame was unexpected"; | |
56 | case error::bad_continuation: return "The WebSocket continuation frame was unexpected"; | |
57 | case error::bad_reserved_bits: return "The WebSocket frame contained illegal reserved bits"; | |
58 | case error::bad_control_fragment: return "The WebSocket control frame was fragmented"; | |
59 | case error::bad_control_size: return "The WebSocket control frame size was invalid"; | |
60 | case error::bad_unmasked_frame: return "The WebSocket frame was unmasked"; | |
61 | case error::bad_masked_frame: return "The WebSocket frame was masked"; | |
62 | case error::bad_size: return "The WebSocket frame size was not canonical"; | |
63 | case error::bad_frame_payload: return "The WebSocket frame payload was not valid utf8"; | |
64 | case error::bad_close_code: return "The WebSocket close frame reason code was invalid"; | |
65 | case error::bad_close_size: return "The WebSocket close frame payload size was invalid"; | |
66 | case error::bad_close_payload: return "The WebSocket close frame payload was not valid utf8"; | |
7c673cae | 67 | } |
11fdf7f2 | 68 | } |
7c673cae | 69 | |
11fdf7f2 TL |
70 | inline |
71 | error_condition | |
72 | error_codes:: | |
73 | default_error_condition(int ev) const noexcept | |
74 | { | |
75 | switch(static_cast<error>(ev)) | |
7c673cae | 76 | { |
11fdf7f2 TL |
77 | default: |
78 | case error::closed: | |
79 | case error::buffer_overflow: | |
80 | case error::partial_deflate_block: | |
81 | case error::message_too_big: | |
82 | return {ev, *this}; | |
83 | ||
84 | case error::bad_http_version: | |
85 | case error::bad_method: | |
86 | case error::no_host: | |
87 | case error::no_connection: | |
88 | case error::no_connection_upgrade: | |
89 | case error::no_upgrade: | |
90 | case error::no_upgrade_websocket: | |
91 | case error::no_sec_key: | |
92 | case error::bad_sec_key: | |
93 | case error::no_sec_version: | |
94 | case error::bad_sec_version: | |
95 | case error::no_sec_accept: | |
96 | case error::bad_sec_accept: | |
97 | case error::upgrade_declined: | |
98 | return condition::handshake_failed; | |
99 | ||
100 | case error::bad_opcode: | |
101 | case error::bad_data_frame: | |
102 | case error::bad_continuation: | |
103 | case error::bad_reserved_bits: | |
104 | case error::bad_control_fragment: | |
105 | case error::bad_control_size: | |
106 | case error::bad_unmasked_frame: | |
107 | case error::bad_masked_frame: | |
108 | case error::bad_size: | |
109 | case error::bad_frame_payload: | |
110 | case error::bad_close_code: | |
111 | case error::bad_close_size: | |
112 | case error::bad_close_payload: | |
113 | return condition::protocol_violation; | |
7c673cae | 114 | } |
11fdf7f2 TL |
115 | } |
116 | ||
117 | inline | |
118 | const char* | |
119 | error_conditions:: | |
120 | name() const noexcept | |
121 | { | |
122 | return "boost.beast.websocket"; | |
123 | } | |
7c673cae FG |
124 | |
125 | inline | |
11fdf7f2 TL |
126 | std::string |
127 | error_conditions:: | |
128 | message(int cv) const | |
7c673cae | 129 | { |
11fdf7f2 TL |
130 | switch(static_cast<condition>(cv)) |
131 | { | |
132 | default: | |
133 | case condition::handshake_failed: return "The WebSocket handshake failed"; | |
134 | case condition::protocol_violation: return "A WebSocket protocol violation occurred"; | |
135 | } | |
7c673cae FG |
136 | } |
137 | ||
138 | } // detail | |
139 | ||
140 | inline | |
141 | error_code | |
142 | make_error_code(error e) | |
143 | { | |
11fdf7f2 TL |
144 | static detail::error_codes const cat{}; |
145 | return error_code{static_cast< | |
146 | std::underlying_type<error>::type>(e), cat}; | |
147 | } | |
148 | ||
149 | inline | |
150 | error_condition | |
151 | make_error_condition(condition c) | |
152 | { | |
153 | static detail::error_conditions const cat{}; | |
154 | return error_condition{static_cast< | |
155 | std::underlying_type<condition>::type>(c), cat}; | |
7c673cae FG |
156 | } |
157 | ||
158 | } // websocket | |
159 | } // beast | |
b32b8144 | 160 | } // boost |
7c673cae FG |
161 | |
162 | #endif |