Audio plugin host https://kx.studio/carla
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.

engine.hpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // ssl/detail/engine.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_SSL_DETAIL_ENGINE_HPP
  11. #define ASIO_SSL_DETAIL_ENGINE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/buffer.hpp"
  17. #include "asio/detail/static_mutex.hpp"
  18. #include "asio/ssl/detail/openssl_types.hpp"
  19. #include "asio/ssl/detail/verify_callback.hpp"
  20. #include "asio/ssl/stream_base.hpp"
  21. #include "asio/ssl/verify_mode.hpp"
  22. #include "asio/detail/push_options.hpp"
  23. namespace asio {
  24. namespace ssl {
  25. namespace detail {
  26. class engine
  27. {
  28. public:
  29. enum want
  30. {
  31. // Returned by functions to indicate that the engine wants input. The input
  32. // buffer should be updated to point to the data. The engine then needs to
  33. // be called again to retry the operation.
  34. want_input_and_retry = -2,
  35. // Returned by functions to indicate that the engine wants to write output.
  36. // The output buffer points to the data to be written. The engine then
  37. // needs to be called again to retry the operation.
  38. want_output_and_retry = -1,
  39. // Returned by functions to indicate that the engine doesn't need input or
  40. // output.
  41. want_nothing = 0,
  42. // Returned by functions to indicate that the engine wants to write output.
  43. // The output buffer points to the data to be written. After that the
  44. // operation is complete, and the engine does not need to be called again.
  45. want_output = 1
  46. };
  47. // Construct a new engine for the specified context.
  48. ASIO_DECL explicit engine(SSL_CTX* context);
  49. // Destructor.
  50. ASIO_DECL ~engine();
  51. // Get the underlying implementation in the native type.
  52. ASIO_DECL SSL* native_handle();
  53. // Set the peer verification mode.
  54. ASIO_DECL asio::error_code set_verify_mode(
  55. verify_mode v, asio::error_code& ec);
  56. // Set the peer verification depth.
  57. ASIO_DECL asio::error_code set_verify_depth(
  58. int depth, asio::error_code& ec);
  59. // Set a peer certificate verification callback.
  60. ASIO_DECL asio::error_code set_verify_callback(
  61. verify_callback_base* callback, asio::error_code& ec);
  62. // Perform an SSL handshake using either SSL_connect (client-side) or
  63. // SSL_accept (server-side).
  64. ASIO_DECL want handshake(
  65. stream_base::handshake_type type, asio::error_code& ec);
  66. // Perform a graceful shutdown of the SSL session.
  67. ASIO_DECL want shutdown(asio::error_code& ec);
  68. // Write bytes to the SSL session.
  69. ASIO_DECL want write(const asio::const_buffer& data,
  70. asio::error_code& ec, std::size_t& bytes_transferred);
  71. // Read bytes from the SSL session.
  72. ASIO_DECL want read(const asio::mutable_buffer& data,
  73. asio::error_code& ec, std::size_t& bytes_transferred);
  74. // Get output data to be written to the transport.
  75. ASIO_DECL asio::mutable_buffers_1 get_output(
  76. const asio::mutable_buffer& data);
  77. // Put input data that was read from the transport.
  78. ASIO_DECL asio::const_buffer put_input(
  79. const asio::const_buffer& data);
  80. // Map an error::eof code returned by the underlying transport according to
  81. // the type and state of the SSL session. Returns a const reference to the
  82. // error code object, suitable for passing to a completion handler.
  83. ASIO_DECL const asio::error_code& map_error_code(
  84. asio::error_code& ec) const;
  85. private:
  86. // Disallow copying and assignment.
  87. engine(const engine&);
  88. engine& operator=(const engine&);
  89. // Callback used when the SSL implementation wants to verify a certificate.
  90. ASIO_DECL static int verify_callback_function(
  91. int preverified, X509_STORE_CTX* ctx);
  92. // The SSL_accept function may not be thread safe. This mutex is used to
  93. // protect all calls to the SSL_accept function.
  94. ASIO_DECL static asio::detail::static_mutex& accept_mutex();
  95. // Perform one operation. Returns >= 0 on success or error, want_read if the
  96. // operation needs more input, or want_write if it needs to write some output
  97. // before the operation can complete.
  98. ASIO_DECL want perform(int (engine::* op)(void*, std::size_t),
  99. void* data, std::size_t length, asio::error_code& ec,
  100. std::size_t* bytes_transferred);
  101. // Adapt the SSL_accept function to the signature needed for perform().
  102. ASIO_DECL int do_accept(void*, std::size_t);
  103. // Adapt the SSL_connect function to the signature needed for perform().
  104. ASIO_DECL int do_connect(void*, std::size_t);
  105. // Adapt the SSL_shutdown function to the signature needed for perform().
  106. ASIO_DECL int do_shutdown(void*, std::size_t);
  107. // Adapt the SSL_read function to the signature needed for perform().
  108. ASIO_DECL int do_read(void* data, std::size_t length);
  109. // Adapt the SSL_write function to the signature needed for perform().
  110. ASIO_DECL int do_write(void* data, std::size_t length);
  111. SSL* ssl_;
  112. BIO* ext_bio_;
  113. };
  114. } // namespace detail
  115. } // namespace ssl
  116. } // namespace asio
  117. #include "asio/detail/pop_options.hpp"
  118. #if defined(ASIO_HEADER_ONLY)
  119. # include "asio/ssl/detail/impl/engine.ipp"
  120. #endif // defined(ASIO_HEADER_ONLY)
  121. #endif // ASIO_SSL_DETAIL_ENGINE_HPP