Skip to content

Commit 86096f8

Browse files
authored
CXX-2745 fix missing include directives for SSL-related config macros (#1333)
* Define and use MONGOCXX_SSL_IS_ENABLED() function macro
1 parent 9a9a014 commit 86096f8

File tree

8 files changed

+39
-8
lines changed

8 files changed

+39
-8
lines changed

src/mongocxx/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ set_dist_list(src_mongocxx_lib_DIST
206206
mongocxx/private/scoped_bson_value.hh
207207
mongocxx/private/search_index_model.hh
208208
mongocxx/private/search_index_view.hh
209+
mongocxx/private/ssl.hh
209210
mongocxx/private/uri.hh
210211
mongocxx/private/write_concern.hh
211212
mongocxx/v_noabi/mongocxx/gridfs/bucket.hh
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <mongocxx/private/config/config.hh>
18+
#include <mongocxx/private/mongoc.hh>
19+
20+
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
21+
#define MONGOCXX_SSL_IS_ENABLED() true
22+
#else
23+
#define MONGOCXX_SSL_IS_ENABLED() false
24+
#endif

src/mongocxx/lib/mongocxx/v_noabi/mongocxx/client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <mongocxx/private/pipeline.hh>
3434
#include <mongocxx/private/read_concern.hh>
3535
#include <mongocxx/private/read_preference.hh>
36+
#include <mongocxx/private/ssl.hh>
3637
#include <mongocxx/private/uri.hh>
3738
#include <mongocxx/private/write_concern.hh>
3839

@@ -74,7 +75,7 @@ class database_names {
7475
client::client() noexcept = default;
7576

7677
client::client(mongocxx::v_noabi::uri const& uri, options::client const& options) {
77-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
78+
#if MONGOCXX_SSL_IS_ENABLED()
7879
if (options.tls_opts()) {
7980
if (!uri.tls())
8081
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
127128
}
128129
}
129130

130-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
131+
#if MONGOCXX_SSL_IS_ENABLED()
131132
if (options.tls_opts()) {
132133
auto mongoc_opts = options::make_tls_opts(*options.tls_opts());
133134
_impl->tls_options = std::move(mongoc_opts.second);

src/mongocxx/lib/mongocxx/v_noabi/mongocxx/options/tls.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
#include <list>
2222

2323
#include <mongocxx/private/mongoc.hh>
24+
#include <mongocxx/private/ssl.hh>
2425

2526
namespace mongocxx {
2627
namespace v_noabi {
2728
namespace options {
2829

29-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
30+
#if MONGOCXX_SSL_IS_ENABLED()
3031
inline std::pair<::mongoc_ssl_opt_t, std::list<bsoncxx::v_noabi::string::view_or_value>> make_tls_opts(
3132
tls const& tls_opts) {
3233
::mongoc_ssl_opt_t out{};

src/mongocxx/lib/mongocxx/v_noabi/mongocxx/pool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <mongocxx/private/client.hh>
3030
#include <mongocxx/private/mongoc_error.hh>
3131
#include <mongocxx/private/pool.hh>
32+
#include <mongocxx/private/ssl.hh>
3233
#include <mongocxx/private/uri.hh>
3334

3435
namespace mongocxx {
@@ -57,7 +58,7 @@ pool::~pool() = default;
5758

5859
pool::pool(uri const& uri, options::pool const& options)
5960
: _impl{bsoncxx::make_unique<impl>(construct_client_pool(uri._impl->uri_t))} {
60-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
61+
#if MONGOCXX_SSL_IS_ENABLED()
6162
if (options.client_opts().tls_opts()) {
6263
if (!uri.tls())
6364
throw exception{error_code::k_invalid_parameter, "cannot set TLS options if 'tls=true' not in URI"};

src/mongocxx/test/catch_helpers.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <mongocxx/exception/exception.hpp>
1818

1919
#include <mongocxx/private/mongoc.hh>
20+
#include <mongocxx/private/ssl.hh>
2021

2122
#include <bsoncxx/test/catch.hh>
2223

@@ -73,7 +74,7 @@ class mongocxx_exception_matcher : public Catch::Matchers::MatcherBase<mongocxx:
7374
auto client_pool_try_pop = libmongoc::client_pool_try_pop.create_instance(); \
7475
((void)0)
7576

76-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
77+
#if MONGOCXX_SSL_IS_ENABLED()
7778
#define MOCK_POOL \
7879
MOCK_POOL_NOSSL; \
7980
auto client_pool_set_ssl_opts = libmongoc::client_pool_set_ssl_opts.create_instance(); \
@@ -101,7 +102,7 @@ class mongocxx_exception_matcher : public Catch::Matchers::MatcherBase<mongocxx:
101102
auto client_find_databases_with_opts = mongocxx::libmongoc::client_find_databases_with_opts.create_instance(); \
102103
((void)0)
103104

104-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
105+
#if MONGOCXX_SSL_IS_ENABLED()
105106
#define MOCK_CLIENT \
106107
MOCK_CLIENT_NOSSL; \
107108
auto client_set_ssl_opts = libmongoc::client_set_ssl_opts.create_instance(); \

src/mongocxx/test/client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <mongocxx/private/conversions.hh>
2929
#include <mongocxx/private/mongoc.hh>
30+
#include <mongocxx/private/ssl.hh>
3031

3132
#include <bsoncxx/test/catch.hh>
3233

@@ -423,7 +424,7 @@ TEST_CASE("integration tests for client metadata handshake feature") {
423424
}
424425
}
425426

426-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
427+
#if MONGOCXX_SSL_IS_ENABLED()
427428
TEST_CASE("A client can be constructed with SSL options", "[client]") {
428429
MOCK_CLIENT;
429430

src/mongocxx/test/pool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <mongocxx/pool.hpp>
2323

2424
#include <mongocxx/private/mongoc.hh>
25+
#include <mongocxx/private/ssl.hh>
2526

2627
#include <bsoncxx/test/catch.hh>
2728

@@ -64,7 +65,7 @@ TEST_CASE("a pool is created with the correct MongoDB URI", "[pool]") {
6465
REQUIRE(destroy_called);
6566
}
6667

67-
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
68+
#if MONGOCXX_SSL_IS_ENABLED()
6869
TEST_CASE(
6970
"If we pass an engaged SSL options struct to the pool class, we will use it to configure the "
7071
"underlying mongoc pool",

0 commit comments

Comments
 (0)