Realistic 3D camera system
3D camera system components
engine.hpp
Go to the documentation of this file.
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 
11 #ifndef ASIO_SSL_DETAIL_ENGINE_HPP
12 #define ASIO_SSL_DETAIL_ENGINE_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if !defined(ASIO_ENABLE_OLD_SSL)
21 # include "asio/buffer.hpp"
25 # include "asio/ssl/stream_base.hpp"
26 # include "asio/ssl/verify_mode.hpp"
27 #endif // !defined(ASIO_ENABLE_OLD_SSL)
28 
30 
31 namespace asio {
32 namespace ssl {
33 namespace detail {
34 
35 #if !defined(ASIO_ENABLE_OLD_SSL)
36 
37 class engine
38 {
39 public:
40  enum want
41  {
42  // Returned by functions to indicate that the engine wants input. The input
43  // buffer should be updated to point to the data. The engine then needs to
44  // be called again to retry the operation.
46 
47  // Returned by functions to indicate that the engine wants to write output.
48  // The output buffer points to the data to be written. The engine then
49  // needs to be called again to retry the operation.
51 
52  // Returned by functions to indicate that the engine doesn't need input or
53  // output.
55 
56  // Returned by functions to indicate that the engine wants to write output.
57  // The output buffer points to the data to be written. After that the
58  // operation is complete, and the engine does not need to be called again.
60  };
61 
62  // Construct a new engine for the specified context.
63  ASIO_DECL explicit engine(SSL_CTX* context);
64 
65  // Destructor.
67 
68  // Get the underlying implementation in the native type.
69  ASIO_DECL SSL* native_handle();
70 
71  // Set the peer verification mode.
74 
75  // Set the peer verification depth.
77  int depth, asio::error_code& ec);
78 
79  // Set a peer certificate verification callback.
81  verify_callback_base* callback, asio::error_code& ec);
82 
83  // Perform an SSL handshake using either SSL_connect (client-side) or
84  // SSL_accept (server-side).
87 
88  // Perform a graceful shutdown of the SSL session.
90 
91  // Write bytes to the SSL session.
93  asio::error_code& ec, std::size_t& bytes_transferred);
94 
95  // Read bytes from the SSL session.
97  asio::error_code& ec, std::size_t& bytes_transferred);
98 
99  // Get output data to be written to the transport.
101  const asio::mutable_buffer& data);
102 
103  // Put input data that was read from the transport.
105  const asio::const_buffer& data);
106 
107  // Map an error::eof code returned by the underlying transport according to
108  // the type and state of the SSL session. Returns a const reference to the
109  // error code object, suitable for passing to a completion handler.
111  asio::error_code& ec) const;
112 
113 private:
114  // Disallow copying and assignment.
115  engine(const engine&);
116  engine& operator=(const engine&);
117 
118  // Callback used when the SSL implementation wants to verify a certificate.
119  ASIO_DECL static int verify_callback_function(
120  int preverified, X509_STORE_CTX* ctx);
121 
122  // The SSL_accept function may not be thread safe. This mutex is used to
123  // protect all calls to the SSL_accept function.
124  ASIO_DECL static asio::detail::static_mutex& accept_mutex();
125 
126  // Perform one operation. Returns >= 0 on success or error, want_read if the
127  // operation needs more input, or want_write if it needs to write some output
128  // before the operation can complete.
129  ASIO_DECL want perform(int (engine::* op)(void*, std::size_t),
130  void* data, std::size_t length, asio::error_code& ec,
131  std::size_t* bytes_transferred);
132 
133  // Adapt the SSL_accept function to the signature needed for perform().
134  ASIO_DECL int do_accept(void*, std::size_t);
135 
136  // Adapt the SSL_connect function to the signature needed for perform().
137  ASIO_DECL int do_connect(void*, std::size_t);
138 
139  // Adapt the SSL_shutdown function to the signature needed for perform().
140  ASIO_DECL int do_shutdown(void*, std::size_t);
141 
142  // Adapt the SSL_read function to the signature needed for perform().
143  ASIO_DECL int do_read(void* data, std::size_t length);
144 
145  // Adapt the SSL_write function to the signature needed for perform().
146  ASIO_DECL int do_write(void* data, std::size_t length);
147 
148  SSL* ssl_;
149  BIO* ext_bio_;
150 };
151 
152 #endif // !defined(ASIO_ENABLE_OLD_SSL)
153 
154 } // namespace detail
155 } // namespace ssl
156 } // namespace asio
157 
159 
160 #if defined(ASIO_HEADER_ONLY)
162 #endif // defined(ASIO_HEADER_ONLY)
163 
164 #endif // ASIO_SSL_DETAIL_ENGINE_HPP
ASIO_DECL want read(const asio::mutable_buffer &data, asio::error_code &ec, std::size_t &bytes_transferred)
Definition: engine.ipp:159
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
ASIO_DECL want handshake(stream_base::handshake_type type, asio::error_code &ec)
Definition: engine.ipp:133
ASIO_DECL asio::error_code set_verify_depth(int depth, asio::error_code &ec)
Definition: engine.ipp:86
ASIO_DECL SSL * native_handle()
Definition: engine.ipp:72
handshake_type
Different handshake types.
Definition: stream_base.hpp:31
ASIO_DECL asio::mutable_buffers_1 get_output(const asio::mutable_buffer &data)
Definition: engine.ipp:173
int verify_mode
Bitmask type for peer verification.
Definition: verify_mode.hpp:35
Holds a buffer that can be modified.
Definition: buffer.hpp:91
ASIO_DECL asio::error_code set_verify_mode(verify_mode v, asio::error_code &ec)
Definition: engine.ipp:77
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_DECL
Definition: config.hpp:43
ASIO_DECL asio::const_buffer put_input(const asio::const_buffer &data)
Definition: engine.ipp:184
ASIO_DECL const asio::error_code & map_error_code(asio::error_code &ec) const
Definition: engine.ipp:195
ASIO_DECL asio::error_code set_verify_callback(verify_callback_base *callback, asio::error_code &ec)
Definition: engine.ipp:95
ASIO_DECL want write(const asio::const_buffer &data, asio::error_code &ec, std::size_t &bytes_transferred)
Definition: engine.ipp:145
ASIO_DECL want shutdown(asio::error_code &ec)
Definition: engine.ipp:140
ASIO_DECL engine(SSL_CTX *context)
Definition: engine.ipp:36