You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
11 KiB

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