debug.hpp 11 KB

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