diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 210e63a56..d9f46af81 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index eded4e59b..27cd4a66c 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -20,16 +20,6 @@ #include #include -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - -#include - -#if defined(MQTT_USE_WS) -#include -#endif // defined(MQTT_USE_WS) - #include #include #include @@ -112,7 +102,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -122,7 +112,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -135,7 +125,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -146,7 +136,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -204,7 +194,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -214,7 +204,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -227,7 +217,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -238,7 +228,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -335,7 +325,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -344,7 +334,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -961,7 +951,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(as::ssl::verify_peer); + ctx_.set_verify_mode(tls::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -982,14 +972,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1076,20 +1066,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(as::ssl::stream_base::client); + socket.handshake(tls::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(as::ssl::stream_base::client, ec); + socket.handshake(tls::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1098,21 +1088,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(as::ssl::stream_base::client); + socket.next_layer().handshake(tls::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(as::ssl::stream_base::client, ec); + socket.next_layer().handshake(tls::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1163,12 +1153,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - as::ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1188,12 +1178,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - as::ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1452,13 +1442,13 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1479,7 +1469,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - as::ssl::context ctx_{as::ssl::context::tlsv12}; + tls::context ctx_{tls::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1592,9 +1582,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1607,7 +1597,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1617,9 +1607,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1632,7 +1622,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1644,9 +1634,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1657,7 +1647,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1668,9 +1658,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1681,7 +1671,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1803,9 +1793,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1818,7 +1808,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1828,9 +1818,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1843,7 +1833,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1855,9 +1845,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1868,7 +1858,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1879,9 +1869,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1892,7 +1882,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 1cd52ca4c..192cc1900 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/include/mqtt/server.hpp b/include/mqtt/server.hpp index 62cdb37c3..461cb5340 100644 --- a/include/mqtt/server.hpp +++ b/include/mqtt/server.hpp @@ -13,17 +13,8 @@ #include #include - -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - #include -#if defined(MQTT_USE_WS) -#include -#endif // defined(MQTT_USE_WS) - #include #include #include @@ -212,7 +203,7 @@ template < > class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -230,7 +221,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -246,7 +237,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -254,7 +245,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -262,7 +253,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -349,7 +340,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -357,7 +348,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -393,7 +384,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - as::ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -419,7 +410,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -701,7 +692,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -719,7 +710,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -735,7 +726,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -743,7 +734,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -751,7 +742,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -838,7 +829,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -846,7 +837,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -883,7 +874,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - as::ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -987,7 +978,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 79d71485e..2cc2c4305 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -82,7 +82,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 686d831df..076605cf7 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -10,10 +10,6 @@ #include #include -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - #include namespace MQTT_NS { diff --git a/include/mqtt/tls.hpp b/include/mqtt/tls.hpp new file mode 100644 index 000000000..c9480d98f --- /dev/null +++ b/include/mqtt/tls.hpp @@ -0,0 +1,42 @@ +// Copyright Takatoshi Kondo 2020 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(MQTT_TLS_HPP) +#define MQTT_TLS_HPP + +#if defined(MQTT_USE_TLS) + +#if !defined(MQTT_TLS_INCLUDE) +#define MQTT_TLS_INCLUDE +#endif // !defined(MQTT_TLS_INCLUDE) + +#include MQTT_TLS_INCLUDE + +#if !defined(MQTT_TLS_NS) +#define MQTT_TLS_NS boost::asio::ssl +#endif // !defined(MQTT_TLS_NS) + +#include + +namespace MQTT_NS { +namespace tls = MQTT_TLS_NS; +} // namespace MQTT_NS + + +#if defined(MQTT_USE_WS) + +#if !defined(MQTT_TLS_WS_INCLUDE) +#define MQTT_TLS_WS_INCLUDE +#endif // !defined(MQTT_TLS_WS_INCLUDE) + +#include MQTT_TLS_WS_INCLUDE + +#endif // defined(MQTT_USE_WS) + +#endif // defined(MQTT_USE_TLS) + + +#endif // MQTT_TLS_HPP diff --git a/include/mqtt/ws_endpoint.hpp b/include/mqtt/ws_endpoint.hpp index 61842ff3e..cd56456ed 100644 --- a/include/mqtt/ws_endpoint.hpp +++ b/include/mqtt/ws_endpoint.hpp @@ -7,10 +7,6 @@ #if !defined(MQTT_WS_ENDPOINT_HPP) #define MQTT_WS_ENDPOINT_HPP -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - #include #include #include diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index a953c7061..0eba22508 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,10 +112,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + MQTT_NS::tls::context ctx {MQTT_NS::tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(MQTT_NS::tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -178,10 +178,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + MQTT_NS::tls::context ctx {MQTT_NS::tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(MQTT_NS::tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - as::ssl::stream_base::client, + MQTT_NS::tls::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -261,10 +261,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + MQTT_NS::tls::context ctx {MQTT_NS::tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - as::ssl::stream socket(ioc, ctx); + ctx.set_verify_mode(MQTT_NS::tls::verify_peer); + MQTT_NS::tls::stream socket(ioc, ctx); char buf;