WebSocket++  0.8.3-dev
C++ websocket client/server library
core.hpp
1 /*
2  * Copyright (c) 2014, Peter Thorson. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the WebSocket++ Project nor the
12  * names of its contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef WEBSOCKETPP_CONFIG_CORE_HPP
29 #define WEBSOCKETPP_CONFIG_CORE_HPP
30 
31 // Non-Policy common stuff
32 #include <websocketpp/common/platforms.hpp>
33 #include <websocketpp/common/cpp11.hpp>
34 #include <websocketpp/common/stdint.hpp>
35 
36 // Concurrency
37 #include <websocketpp/concurrency/basic.hpp>
38 
39 // Transport
40 #include <websocketpp/transport/iostream/endpoint.hpp>
41 
42 // HTTP
43 #include <websocketpp/http/request.hpp>
44 #include <websocketpp/http/response.hpp>
45 
46 // Messages
47 #include <websocketpp/message_buffer/message.hpp>
48 #include <websocketpp/message_buffer/alloc.hpp>
49 
50 // Loggers
51 #include <websocketpp/logger/basic.hpp>
52 #include <websocketpp/logger/levels.hpp>
53 
54 // RNG
55 #include <websocketpp/random/none.hpp>
56 
57 // User stub base classes
58 #include <websocketpp/endpoint_base.hpp>
59 #include <websocketpp/connection_base.hpp>
60 
61 // Extensions
62 #include <websocketpp/extensions/permessage_deflate/disabled.hpp>
63 
64 namespace websocketpp {
65 namespace config {
66 
67 /// Server config with iostream transport
68 struct core {
69  typedef core type;
70 
71  // Concurrency policy
72  typedef websocketpp::concurrency::basic concurrency_type;
73 
74  // HTTP Parser Policies
75  typedef http::parser::request request_type;
76  typedef http::parser::response response_type;
77 
78  // Message Policies
79  typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
80  message_type;
81  typedef message_buffer::alloc::con_msg_manager<message_type>
82  con_msg_manager_type;
83  typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
84  endpoint_msg_manager_type;
85 
86  /// Logging policies
89  typedef websocketpp::log::basic<concurrency_type,
90  websocketpp::log::alevel> alog_type;
91 
92  /// RNG policies
94 
95  /// Controls compile time enabling/disabling of thread syncronization
96  /// code Disabling can provide a minor performance improvement to single
97  /// threaded applications
98  static bool const enable_multithreading = true;
99 
101  typedef type::concurrency_type concurrency_type;
102  typedef type::elog_type elog_type;
103  typedef type::alog_type alog_type;
104  typedef type::request_type request_type;
105  typedef type::response_type response_type;
106 
107  /// Controls compile time enabling/disabling of thread syncronization
108  /// code Disabling can provide a minor performance improvement to single
109  /// threaded applications
110  static bool const enable_multithreading = true;
111 
112  /// Default timer values (in ms)
113 
114  /// Length of time to wait for socket pre-initialization
115  /**
116  * Exactly what this includes depends on the socket policy in use
117  */
118  static const long timeout_socket_pre_init = 5000;
119 
120  /// Length of time to wait before a proxy handshake is aborted
121  static const long timeout_proxy = 5000;
122 
123  /// Length of time to wait for socket post-initialization
124  /**
125  * Exactly what this includes depends on the socket policy in use.
126  * Often this means the TLS handshake
127  */
128  static const long timeout_socket_post_init = 5000;
129 
130  /// Length of time to wait for dns resolution
131  static const long timeout_dns_resolve = 5000;
132 
133  /// Length of time to wait for TCP connect
134  static const long timeout_connect = 5000;
135 
136  /// Length of time to wait for socket shutdown
137  static const long timeout_socket_shutdown = 5000;
138  };
139 
140  /// Transport Endpoint Component
141  typedef websocketpp::transport::iostream::endpoint<transport_config>
142  transport_type;
143 
144  /// User overridable Endpoint base class
146  /// User overridable Connection base class
148 
149  /// Default timer values (in ms)
150 
151  /// Length of time before an opening handshake is aborted
152  static const long timeout_open_handshake = 5000;
153  /// Length of time before a closing handshake is aborted
154  static const long timeout_close_handshake = 5000;
155  /// Length of time to wait for a pong after a ping
156  static const long timeout_pong = 5000;
157 
158  /// WebSocket Protocol version to use as a client
159  /**
160  * What version of the WebSocket Protocol to use for outgoing client
161  * connections. Setting this to a value other than 13 (RFC6455) is not
162  * recommended.
163  */
164  static const int client_version = 13; // RFC6455
165 
166  /// Default static error logging channels
167  /**
168  * Which error logging channels to enable at compile time. Channels not
169  * enabled here will be unable to be selected by programs using the library.
170  * This option gives an optimizing compiler the ability to remove entirely
171  * code to test whether or not to print out log messages on a certain
172  * channel
173  *
174  * Default is all except for development/debug level errors
175  */
176  static const websocketpp::log::level elog_level =
177  websocketpp::log::elevel::all ^ websocketpp::log::elevel::devel;
178 
179  /// Default static access logging channels
180  /**
181  * Which access logging channels to enable at compile time. Channels not
182  * enabled here will be unable to be selected by programs using the library.
183  * This option gives an optimizing compiler the ability to remove entirely
184  * code to test whether or not to print out log messages on a certain
185  * channel
186  *
187  * Default is all except for development/debug level access messages
188  */
189  static const websocketpp::log::level alog_level =
190  websocketpp::log::alevel::all ^ websocketpp::log::alevel::devel;
191 
192  /// Size of the per-connection read buffer
193  /**
194  * Each connection has an internal buffer of this size. A larger value will
195  * result in fewer trips through the library and less CPU overhead at the
196  * expense of increased memory usage per connection.
197  *
198  * If your application primarily deals in very large messages you may want
199  * to try setting this value higher.
200  *
201  * If your application has a lot of connections or primarily deals in small
202  * messages you may want to try setting this smaller.
203  */
204  static const size_t connection_read_buffer_size = 16384;
205 
206  /// Drop connections immediately on protocol error.
207  /**
208  * Drop connections on protocol error rather than sending a close frame.
209  * Off by default. This may result in legit messages near the error being
210  * dropped as well. It may free up resources otherwise spent dealing with
211  * misbehaving clients.
212  */
213  static const bool drop_on_protocol_error = false;
214 
215  /// Suppresses the return of detailed connection close information
216  /**
217  * Silence close suppresses the return of detailed connection close
218  * information during the closing handshake. This information is useful
219  * for debugging and presenting useful errors to end users but may be
220  * undesirable for security reasons in some production environments.
221  * Close reasons could be used by an attacker to confirm that the endpoint
222  * is out of resources or be used to identify the WebSocket implementation
223  * in use.
224  *
225  * Note: this will suppress *all* close codes, including those explicitly
226  * sent by local applications.
227  */
228  static const bool silent_close = false;
229 
230  /// Default maximum message size
231  /**
232  * Default value for the processor's maximum message size. Maximum message size
233  * determines the point at which the library will fail a connection with the
234  * message_too_big protocol error.
235  *
236  * The default is 32MB
237  *
238  * @since 0.3.0
239  */
240  static const size_t max_message_size = 32000000;
241 
242  /// Default maximum http body size
243  /**
244  * Default value for the http parser's maximum body size. Maximum body size
245  * determines the point at which the library will abort reading an HTTP
246  * connection with the 413/request entity too large error.
247  *
248  * The default is 32MB
249  *
250  * @since 0.5.0
251  */
252  static const size_t max_http_body_size = 32000000;
253 
254  /// Global flag for enabling/disabling extensions
255  static const bool enable_extensions = true;
256 
257  /// Extension specific settings:
258 
259  /// permessage_compress extension
261  typedef core::request_type request_type;
262 
263  /// If the remote endpoint requests that we reset the compression
264  /// context after each message should we honor the request?
265  static const bool allow_disabling_context_takeover = true;
266 
267  /// If the remote endpoint requests that we reduce the size of the
268  /// LZ77 sliding window size this is the lowest value that will be
269  /// allowed. Values range from 8 to 15. A value of 8 means we will
270  /// allow any possible window size. A value of 15 means do not allow
271  /// negotiation of the window size (ie require the default).
273  };
274 
275  typedef websocketpp::extensions::permessage_deflate::disabled
276  <permessage_deflate_config> permessage_deflate_type;
277 
278  /// Autonegotiate permessage-deflate
279  /**
280  * Automatically enables the permessage-deflate extension.
281  *
282  * For clients this results in a permessage-deflate extension request being
283  * sent with every request rather than requiring it to be requested manually
284  *
285  * For servers this results in accepting the first set of extension settings
286  * requested by the client that we understand being used. The alternative is
287  * requiring the extension to be manually negotiated in `validate`. With
288  * auto-negotiate on, you may still override the auto-negotiate manually if
289  * needed.
290  */
291  //static const bool autonegotiate_compression = false;
292 };
293 
294 } // namespace config
295 } // namespace websocketpp
296 
297 #endif // WEBSOCKETPP_CONFIG_CORE_HPP
websocketpp::config::core::elog_type
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
Definition: core.hpp:88
websocketpp::config::core::max_http_body_size
static const size_t max_http_body_size
Default maximum http body size.
Definition: core.hpp:252
websocketpp::config::core::transport_config::timeout_socket_post_init
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition: core.hpp:128
websocketpp::config::core::timeout_open_handshake
static const long timeout_open_handshake
Default timer values (in ms)
Definition: core.hpp:152
websocketpp::config::core::endpoint_base
websocketpp::endpoint_base endpoint_base
User overridable Endpoint base class.
Definition: core.hpp:145
websocketpp::config::core::enable_multithreading
static bool const enable_multithreading
Definition: core.hpp:98
websocketpp::config::core::transport_config::enable_multithreading
static bool const enable_multithreading
Definition: core.hpp:110
websocketpp::config::core::client_version
static const int client_version
WebSocket Protocol version to use as a client.
Definition: core.hpp:164
websocketpp::config::core::transport_config
Definition: core.hpp:100
websocketpp::config::core::transport_config::timeout_socket_shutdown
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition: core.hpp:137
websocketpp::config::core::transport_config::timeout_proxy
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition: core.hpp:121
websocketpp::config::core::timeout_close_handshake
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition: core.hpp:154
websocketpp::config::core::transport_config::timeout_connect
static const long timeout_connect
Length of time to wait for TCP connect.
Definition: core.hpp:134
websocketpp::config::core::connection_read_buffer_size
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
Definition: core.hpp:204
websocketpp::config::core::transport_config::timeout_socket_pre_init
static const long timeout_socket_pre_init
Default timer values (in ms)
Definition: core.hpp:118
websocketpp::config::core::rng_type
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition: core.hpp:93
websocketpp::versions_supported
static std::vector< int > const versions_supported(helper, helper+4)
Container that stores the list of protocol versions supported.
websocketpp::config::core::permessage_deflate_config
Extension specific settings:
Definition: core.hpp:260
websocketpp::config::core::alog_level
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition: core.hpp:189
websocketpp::config::core::permessage_deflate_config::allow_disabling_context_takeover
static const bool allow_disabling_context_takeover
Definition: core.hpp:265
websocketpp::config::core::silent_close
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition: core.hpp:228
websocketpp::config::core::elog_level
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition: core.hpp:176
websocketpp::config::core::drop_on_protocol_error
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition: core.hpp:213
websocketpp::config::core::permessage_deflate_config::minimum_outgoing_window_bits
static const uint8_t minimum_outgoing_window_bits
Definition: core.hpp:272
websocketpp::config::core::connection_base
websocketpp::connection_base connection_base
User overridable Connection base class.
Definition: core.hpp:147
websocketpp::config::core::max_message_size
static const size_t max_message_size
Default maximum message size.
Definition: core.hpp:240
websocketpp::config::core::enable_extensions
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition: core.hpp:255
websocketpp::config::core::timeout_pong
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition: core.hpp:156
websocketpp::config::core::transport_config::timeout_dns_resolve
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition: core.hpp:131