diff --git a/src/mongocxx/lib/CMakeLists.txt b/src/mongocxx/lib/CMakeLists.txt index 5205f9fc4a..85728241dc 100644 --- a/src/mongocxx/lib/CMakeLists.txt +++ b/src/mongocxx/lib/CMakeLists.txt @@ -206,6 +206,7 @@ set_dist_list(src_mongocxx_lib_DIST mongocxx/private/scoped_bson_value.hh mongocxx/private/search_index_model.hh mongocxx/private/search_index_view.hh + mongocxx/private/ssl.hh mongocxx/private/uri.hh mongocxx/private/write_concern.hh mongocxx/v_noabi/mongocxx/gridfs/bucket.hh diff --git a/src/mongocxx/lib/mongocxx/private/ssl.hh b/src/mongocxx/lib/mongocxx/private/ssl.hh new file mode 100644 index 0000000000..43785ede19 --- /dev/null +++ b/src/mongocxx/lib/mongocxx/private/ssl.hh @@ -0,0 +1,24 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#define MONGOCXX_SSL_IS_ENABLED() true +#else +#define MONGOCXX_SSL_IS_ENABLED() false +#endif diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp index 7bc5d43418..7ff131c2b1 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -74,7 +75,7 @@ class database_names { client::client() noexcept = default; client::client(mongocxx::v_noabi::uri const& uri, options::client const& options) { -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() if (options.tls_opts()) { if (!uri.tls()) throw exception{error_code::k_invalid_parameter, "cannot set TLS options if 'tls=true' not in URI"}; @@ -127,7 +128,7 @@ client::client(mongocxx::v_noabi::uri const& uri, options::client const& options } } -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() if (options.tls_opts()) { auto mongoc_opts = options::make_tls_opts(*options.tls_opts()); _impl->tls_options = std::move(mongoc_opts.second); diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh index 0324d0a63b..7872d8fe87 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh @@ -21,12 +21,13 @@ #include #include +#include namespace mongocxx { namespace v_noabi { namespace options { -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() inline std::pair<::mongoc_ssl_opt_t, std::list> make_tls_opts( tls const& tls_opts) { ::mongoc_ssl_opt_t out{}; diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp index 76d70b12a5..bbf699695a 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace mongocxx { @@ -57,7 +58,7 @@ pool::~pool() = default; pool::pool(uri const& uri, options::pool const& options) : _impl{bsoncxx::make_unique(construct_client_pool(uri._impl->uri_t))} { -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() if (options.client_opts().tls_opts()) { if (!uri.tls()) throw exception{error_code::k_invalid_parameter, "cannot set TLS options if 'tls=true' not in URI"}; diff --git a/src/mongocxx/test/catch_helpers.hh b/src/mongocxx/test/catch_helpers.hh index 4dca3465ee..6e442faf30 100644 --- a/src/mongocxx/test/catch_helpers.hh +++ b/src/mongocxx/test/catch_helpers.hh @@ -17,6 +17,7 @@ #include #include +#include #include @@ -73,7 +74,7 @@ class mongocxx_exception_matcher : public Catch::Matchers::MatcherBase #include +#include #include @@ -423,7 +424,7 @@ TEST_CASE("integration tests for client metadata handshake feature") { } } -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() TEST_CASE("A client can be constructed with SSL options", "[client]") { MOCK_CLIENT; diff --git a/src/mongocxx/test/pool.cpp b/src/mongocxx/test/pool.cpp index f6f05e072e..0ed079e180 100644 --- a/src/mongocxx/test/pool.cpp +++ b/src/mongocxx/test/pool.cpp @@ -22,6 +22,7 @@ #include #include +#include #include @@ -64,7 +65,7 @@ TEST_CASE("a pool is created with the correct MongoDB URI", "[pool]") { REQUIRE(destroy_called); } -#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL) +#if MONGOCXX_SSL_IS_ENABLED() TEST_CASE( "If we pass an engaged SSL options struct to the pool class, we will use it to configure the " "underlying mongoc pool",