WebSocket++  0.8.3-dev
C++ websocket client/server library
minimal_server.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_MINIMAL_HPP
29 #define WEBSOCKETPP_CONFIG_MINIMAL_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/none.hpp>
38 
39 // Transport
40 #include <websocketpp/transport/stub/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/stub.hpp>
52 
53 // RNG
54 #include <websocketpp/random/none.hpp>
55 
56 // User stub base classes
57 #include <websocketpp/endpoint_base.hpp>
58 #include <websocketpp/connection_base.hpp>
59 
60 // Extensions
61 #include <websocketpp/extensions/permessage_deflate/disabled.hpp>
62 
63 namespace websocketpp {
64 namespace config {
65 
66 /// Server config with minimal dependencies
67 /**
68  * This config strips out as many dependencies as possible. It is suitable for
69  * use as a base class for custom configs that want to implement or choose their
70  * own policies for components that even the core config includes.
71  *
72  * NOTE: this config stubs out enough that it cannot be used directly. You must
73  * supply at least a transport policy for a config based on `minimal_server` to
74  * do anything useful.
75  *
76  * Present dependency list for minimal_server config:
77  *
78  * C++98 STL:
79  * <algorithm>
80  * <map>
81  * <sstream>
82  * <string>
83  * <vector>
84  *
85  * C++11 STL or Boost
86  * <memory>
87  * <functional>
88  * <system_error>
89  *
90  * Operating System:
91  * <stdint.h> or <boost/cstdint.hpp>
92  * <netinet/in.h> or <winsock2.h> (for ntohl.. could potentially bundle this)
93  *
94  * @since 0.4.0-dev
95  */
96 struct minimal_server {
97  typedef minimal_server type;
98 
99  // Concurrency policy
100  typedef websocketpp::concurrency::none concurrency_type;
101 
102  // HTTP Parser Policies
103  typedef http::parser::request request_type;
104  typedef http::parser::response response_type;
105 
106  // Message Policies
107  typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
108  message_type;
109  typedef message_buffer::alloc::con_msg_manager<message_type>
110  con_msg_manager_type;
111  typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
112  endpoint_msg_manager_type;
113 
114  /// Logging policies
116  typedef websocketpp::log::stub alog_type;
117 
118  /// RNG policies
120 
121  /// Controls compile time enabling/disabling of thread syncronization
122  /// code Disabling can provide a minor performance improvement to single
123  /// threaded applications
124  static bool const enable_multithreading = true;
125 
127  typedef type::concurrency_type concurrency_type;
128  typedef type::elog_type elog_type;
129  typedef type::alog_type alog_type;
130  typedef type::request_type request_type;
131  typedef type::response_type response_type;
132 
133  /// Controls compile time enabling/disabling of thread syncronization
134  /// code Disabling can provide a minor performance improvement to single
135  /// threaded applications
136  static bool const enable_multithreading = true;
137 
138  /// Default timer values (in ms)
139 
140  /// Length of time to wait for socket pre-initialization
141  /**
142  * Exactly what this includes depends on the socket policy in use
143  */
144  static const long timeout_socket_pre_init = 5000;
145 
146  /// Length of time to wait before a proxy handshake is aborted
147  static const long timeout_proxy = 5000;
148 
149  /// Length of time to wait for socket post-initialization
150  /**
151  * Exactly what this includes depends on the socket policy in use.
152  * Often this means the TLS handshake
153  */
154  static const long timeout_socket_post_init = 5000;
155 
156  /// Length of time to wait for dns resolution
157  static const long timeout_dns_resolve = 5000;
158 
159  /// Length of time to wait for TCP connect
160  static const long timeout_connect = 5000;
161 
162  /// Length of time to wait for socket shutdown
163  static const long timeout_socket_shutdown = 5000;
164  };
165 
166  /// Transport Endpoint Component
167  typedef websocketpp::transport::stub::endpoint<transport_config>
168  transport_type;
169 
170  /// User overridable Endpoint base class
172  /// User overridable Connection base class
174 
175  /// Default timer values (in ms)
176 
177  /// Length of time before an opening handshake is aborted
178  static const long timeout_open_handshake = 5000;
179  /// Length of time before a closing handshake is aborted
180  static const long timeout_close_handshake = 5000;
181  /// Length of time to wait for a pong after a ping
182  static const long timeout_pong = 5000;
183 
184  /// WebSocket Protocol version to use as a client
185  /**
186  * What version of the WebSocket Protocol to use for outgoing client
187  * connections. Setting this to a value other than 13 (RFC6455) is not
188  * recommended.
189  */
190  static const int client_version = 13; // RFC6455
191 
192  /// Default static error logging channels
193  /**
194  * Which error logging channels to enable at compile time. Channels not
195  * enabled here will be unable to be selected by programs using the library.
196  * This option gives an optimizing compiler the ability to remove entirely
197  * code to test whether or not to print out log messages on a certain
198  * channel
199  *
200  * Default is all except for development/debug level errors
201  */
202  static const websocketpp::log::level elog_level =
203  websocketpp::log::elevel::none;
204 
205  /// Default static access logging channels
206  /**
207  * Which access logging channels to enable at compile time. Channels not
208  * enabled here will be unable to be selected by programs using the library.
209  * This option gives an optimizing compiler the ability to remove entirely
210  * code to test whether or not to print out log messages on a certain
211  * channel
212  *
213  * Default is all except for development/debug level access messages
214  */
215  static const websocketpp::log::level alog_level =
216  websocketpp::log::alevel::none;
217 
218  ///
219  static const size_t connection_read_buffer_size = 16384;
220 
221  /// Drop connections immediately on protocol error.
222  /**
223  * Drop connections on protocol error rather than sending a close frame.
224  * Off by default. This may result in legit messages near the error being
225  * dropped as well. It may free up resources otherwise spent dealing with
226  * misbehaving clients.
227  */
228  static const bool drop_on_protocol_error = false;
229 
230  /// Suppresses the return of detailed connection close information
231  /**
232  * Silence close suppresses the return of detailed connection close
233  * information during the closing handshake. This information is useful
234  * for debugging and presenting useful errors to end users but may be
235  * undesirable for security reasons in some production environments.
236  * Close reasons could be used by an attacker to confirm that the endpoint
237  * is out of resources or be used to identify the WebSocket implementation
238  * in use.
239  *
240  * Note: this will suppress *all* close codes, including those explicitly
241  * sent by local applications.
242  */
243  static const bool silent_close = false;
244 
245  /// Default maximum message size
246  /**
247  * Default value for the processor's maximum message size. Maximum message size
248  * determines the point at which the library will fail a connection with the
249  * message_too_big protocol error.
250  *
251  * The default is 32MB
252  *
253  * @since 0.4.0-alpha1
254  */
255  static const size_t max_message_size = 32000000;
256 
257  /// Default maximum http body size
258  /**
259  * Default value for the http parser's maximum body size. Maximum body size
260  * determines the point at which the library will abort reading an HTTP
261  * connection with the 413/request entity too large error.
262  *
263  * The default is 32MB
264  *
265  * @since 0.5.0
266  */
267  static const size_t max_http_body_size = 32000000;
268 
269  /// Global flag for enabling/disabling extensions
270  static const bool enable_extensions = true;
271 
272  /// Extension specific settings:
273 
274  /// permessage_compress extension
276  typedef core::request_type request_type;
277 
278  /// If the remote endpoint requests that we reset the compression
279  /// context after each message should we honor the request?
280  static const bool allow_disabling_context_takeover = true;
281 
282  /// If the remote endpoint requests that we reduce the size of the
283  /// LZ77 sliding window size this is the lowest value that will be
284  /// allowed. Values range from 8 to 15. A value of 8 means we will
285  /// allow any possible window size. A value of 15 means do not allow
286  /// negotiation of the window size (ie require the default).
288  };
289 
290  typedef websocketpp::extensions::permessage_deflate::disabled
291  <permessage_deflate_config> permessage_deflate_type;
292 
293  /// Autonegotiate permessage-deflate
294  /**
295  * Automatically enables the permessage-deflate extension.
296  *
297  * For clients this results in a permessage-deflate extension request being
298  * sent with every request rather than requiring it to be requested manually
299  *
300  * For servers this results in accepting the first set of extension settings
301  * requested by the client that we understand being used. The alternative is
302  * requiring the extension to be manually negotiated in `validate`. With
303  * auto-negotiate on, you may still override the auto-negotiate manually if
304  * needed.
305  */
306  //static const bool autonegotiate_compression = false;
307 };
308 
309 } // namespace config
310 } // namespace websocketpp
311 
312 #endif // WEBSOCKETPP_CONFIG_MINIMAL_HPP
websocketpp::config::minimal_server::permessage_deflate_config
Extension specific settings:
Definition: minimal_server.hpp:275
websocketpp::config::minimal_server::alog_level
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition: minimal_server.hpp:215
websocketpp::config::minimal_server::enable_multithreading
static bool const enable_multithreading
Definition: minimal_server.hpp:124
websocketpp::config::minimal_server::transport_config
Definition: minimal_server.hpp:126
websocketpp::config::minimal_server::rng_type
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition: minimal_server.hpp:119
websocketpp::config::minimal_server::permessage_deflate_config::allow_disabling_context_takeover
static const bool allow_disabling_context_takeover
Definition: minimal_server.hpp:280
websocketpp::config::minimal_server::elog_level
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition: minimal_server.hpp:202
websocketpp::config::minimal_server::transport_config::timeout_dns_resolve
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition: minimal_server.hpp:157
websocketpp::config::minimal_server::silent_close
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition: minimal_server.hpp:243
websocketpp::config::minimal_server::max_message_size
static const size_t max_message_size
Default maximum message size.
Definition: minimal_server.hpp:255
websocketpp::config::minimal_server::transport_config::timeout_proxy
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition: minimal_server.hpp:147
websocketpp::versions_supported
static std::vector< int > const versions_supported(helper, helper+4)
Container that stores the list of protocol versions supported.
websocketpp::config::minimal_server::timeout_open_handshake
static const long timeout_open_handshake
Default timer values (in ms)
Definition: minimal_server.hpp:178
websocketpp::config::minimal_server::transport_config::enable_multithreading
static bool const enable_multithreading
Definition: minimal_server.hpp:136
websocketpp::config::minimal_server::endpoint_base
websocketpp::endpoint_base endpoint_base
User overridable Endpoint base class.
Definition: minimal_server.hpp:171
websocketpp::config::minimal_server::transport_config::timeout_socket_shutdown
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition: minimal_server.hpp:163
websocketpp::config::minimal_server::connection_base
websocketpp::connection_base connection_base
User overridable Connection base class.
Definition: minimal_server.hpp:173
websocketpp::config::minimal_server::enable_extensions
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition: minimal_server.hpp:270
websocketpp::config::minimal_server::transport_config::timeout_socket_pre_init
static const long timeout_socket_pre_init
Default timer values (in ms)
Definition: minimal_server.hpp:144
websocketpp::config::minimal_server::timeout_pong
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition: minimal_server.hpp:182
websocketpp::config::minimal_server::transport_config::timeout_connect
static const long timeout_connect
Length of time to wait for TCP connect.
Definition: minimal_server.hpp:160
websocketpp::config::minimal_server::transport_config::timeout_socket_post_init
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition: minimal_server.hpp:154
websocketpp::config::minimal_server::max_http_body_size
static const size_t max_http_body_size
Default maximum http body size.
Definition: minimal_server.hpp:267
websocketpp::config::minimal_server::permessage_deflate_config::minimum_outgoing_window_bits
static const uint8_t minimum_outgoing_window_bits
Definition: minimal_server.hpp:287
websocketpp::config::minimal_server::elog_type
websocketpp::log::stub elog_type
Logging policies.
Definition: minimal_server.hpp:115
websocketpp::config::minimal_server::drop_on_protocol_error
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition: minimal_server.hpp:228
websocketpp::config::minimal_server::timeout_close_handshake
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition: minimal_server.hpp:180
websocketpp::config::minimal_server::client_version
static const int client_version
WebSocket Protocol version to use as a client.
Definition: minimal_server.hpp:190