MongoDB C++ Driver  mongocxx-3.10.0
uri.hpp
1 // Copyright 2014 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 <memory>
18 #include <string>
19 #include <vector>
20 
21 #include <mongocxx/client-fwd.hpp>
22 #include <mongocxx/pool-fwd.hpp>
23 #include <mongocxx/uri-fwd.hpp>
24 
25 #include <bsoncxx/document/view.hpp>
26 #include <bsoncxx/string/view_or_value.hpp>
27 #include <mongocxx/read_concern.hpp>
28 #include <mongocxx/read_preference.hpp>
29 #include <mongocxx/write_concern.hpp>
30 
31 #include <mongocxx/config/prelude.hpp>
32 
33 namespace mongocxx {
34 namespace v_noabi {
35 
47 class uri {
48  public:
50  struct host {
51  std::string name;
52  std::uint16_t port;
53  std::int32_t family;
54  };
55 
56  static const std::string k_default_uri;
57 
69  uri(bsoncxx::v_noabi::string::view_or_value uri_string = k_default_uri);
70 
74  uri(uri&&) noexcept;
75 
79  uri& operator=(uri&&) noexcept;
80 
84  ~uri();
85 
91  std::string auth_mechanism() const;
92 
98  std::string auth_source() const;
99 
105  std::vector<host> hosts() const;
106 
112  std::string database() const;
113 
123  bsoncxx::v_noabi::document::view options() const;
124 
130  std::string password() const;
131 
137  mongocxx::v_noabi::read_concern read_concern() const;
138 
145 
151  std::string replica_set() const;
152 
160  MONGOCXX_DEPRECATED bool ssl() const;
161 
167  bool tls() const;
168 
174  std::string to_string() const;
175 
181  std::string username() const;
182 
189 
195  stdx::optional<stdx::string_view> appname() const;
196 
202  stdx::optional<bsoncxx::v_noabi::document::view> auth_mechanism_properties() const;
203 
209  stdx::optional<bsoncxx::v_noabi::document::view> credentials();
210 
216  stdx::optional<std::int32_t> srv_max_hosts() const;
217 
224  std::vector<stdx::string_view> compressors() const;
225 
231  stdx::optional<std::int32_t> connect_timeout_ms() const;
232 
238  stdx::optional<bool> direct_connection() const;
239 
245  stdx::optional<std::int32_t> heartbeat_frequency_ms() const;
246 
252  stdx::optional<std::int32_t> local_threshold_ms() const;
253 
259  stdx::optional<std::int32_t> max_pool_size() const;
260 
266  stdx::optional<bool> retry_reads() const;
267 
273  stdx::optional<bool> retry_writes() const;
274 
280  stdx::optional<std::int32_t> server_selection_timeout_ms() const;
281 
287  stdx::optional<bool> server_selection_try_once() const;
288 
294  stdx::optional<std::int32_t> socket_timeout_ms() const;
295 
301  stdx::optional<bool> tls_allow_invalid_certificates() const;
302 
308  stdx::optional<bool> tls_allow_invalid_hostnames() const;
309 
315  stdx::optional<stdx::string_view> tls_ca_file() const;
316 
322  stdx::optional<stdx::string_view> tls_certificate_key_file() const;
323 
329  stdx::optional<stdx::string_view> tls_certificate_key_file_password() const;
330 
337  stdx::optional<bool> tls_disable_certificate_revocation_check() const;
338 
344  stdx::optional<bool> tls_disable_ocsp_endpoint_check() const;
345 
351  stdx::optional<bool> tls_insecure() const;
352 
358  stdx::optional<std::int32_t> wait_queue_timeout_ms() const;
359 
365  stdx::optional<std::int32_t> zlib_compression_level() const;
366 
367  private:
368  friend ::mongocxx::v_noabi::client;
369  friend ::mongocxx::v_noabi::pool;
370 
371  class MONGOCXX_PRIVATE impl;
372 
373  MONGOCXX_PRIVATE uri(std::unique_ptr<impl>&& implementation);
374 
375  std::unique_ptr<impl> _impl;
376 };
377 
378 } // namespace v_noabi
379 } // namespace mongocxx
380 
381 #include <mongocxx/config/postlude.hpp>
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:38
Class representing a client connection to MongoDB.
Definition: client.hpp:61
Class representing a MongoDB database.
Definition: database.hpp:46
A pool of client objects associated with a MongoDB deployment.
Definition: pool.hpp:49
A class to represent the read concern.
Definition: read_concern.hpp:56
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
Class representing a MongoDB connection string URI.
Definition: uri.hpp:47
uri(bsoncxx::v_noabi::string::view_or_value uri_string=k_default_uri)
Constructs a uri from an optional MongoDB URI string.
stdx::optional< bool > retry_reads() const
Returns the value of the option "retryReads" if present in the uri.
stdx::optional< std::int32_t > max_pool_size() const
Returns the value of the option "maxPoolSize" if present in the uri.
stdx::optional< std::int32_t > server_selection_timeout_ms() const
Returns the value of the option "serverSelectionTimeoutMS" if present in the uri.
bool ssl() const
Returns the ssl parameter from the uri.
std::string auth_mechanism() const
Returns the authentication mechanism from the uri.
stdx::optional< bool > tls_insecure() const
Returns the value of the option "tlsInsecure" if present in the uri.
stdx::optional< std::int32_t > socket_timeout_ms() const
Returns the value of the option "socketTimeoutMS" if present in the uri.
stdx::optional< bool > tls_allow_invalid_certificates() const
Returns the value of the option "tlsAllowInvalidCertificates" if present in the uri.
stdx::optional< stdx::string_view > tls_certificate_key_file_password() const
Returns the value of the option "tlsCertificateKeyFilePassword" if present in the uri.
stdx::optional< bool > retry_writes() const
Returns the value of the option "retryWrites" if present in the uri.
stdx::optional< std::int32_t > connect_timeout_ms() const
Returns the value of the option "connectTimeoutMS" if present in the uri.
bool tls() const
Returns the tls parameter from the uri.
stdx::optional< std::int32_t > local_threshold_ms() const
Returns the value of the option "localThresholdMS" if present in the uri.
stdx::optional< bool > direct_connection() const
Returns the value of the option "directConnection" if present in the uri.
std::string auth_source() const
Returns the authentication source from the uri.
std::string to_string() const
Returns the uri in a string format.
std::vector< stdx::string_view > compressors() const
Returns the list of compressors present in the uri or an empty list if "compressors" was not present ...
stdx::optional< std::int32_t > zlib_compression_level() const
Returns the value of the option "zlibCompressionLevel" if present in the uri.
stdx::optional< stdx::string_view > tls_certificate_key_file() const
Returns the value of the option "tlsCertificateKeyFile" if present in the uri.
bsoncxx::v_noabi::document::view options() const
Returns other uri options.
stdx::optional< bsoncxx::v_noabi::document::view > credentials()
Returns the value of the option credentials if present in the uri.
std::string username() const
Returns the supplied username from the uri.
stdx::optional< stdx::string_view > tls_ca_file() const
Returns the value of the option "tlsCAFile" if present in the uri.
stdx::optional< bool > tls_disable_ocsp_endpoint_check() const
Returns the value of the option "tlsDisableOCSPEndpointCheck" if present in the uri.
stdx::optional< bsoncxx::v_noabi::document::view > auth_mechanism_properties() const
Returns the value of the option "authMechanismProperties" if present in the uri.
stdx::optional< stdx::string_view > appname() const
Returns the value of the option "appname" if present in the uri.
stdx::optional< bool > server_selection_try_once() const
Returns the value of the option "serverSelectionTryOnce" if present in the uri.
stdx::optional< bool > tls_disable_certificate_revocation_check() const
Returns the value of the option "tlsDisableCertificateRevocationCheck" if present in the uri.
stdx::optional< std::int32_t > srv_max_hosts() const
Returns the value of the option "srvMaxHosts" if present in the uri.
std::string password() const
Returns the password from the uri.
uri(uri &&) noexcept
Move constructs a uri.
std::vector< host > hosts() const
Returns the hosts from the uri.
stdx::optional< bool > tls_allow_invalid_hostnames() const
Returns the value of the option "tlsAllowInvalidHostnames" if present in the uri.
std::string replica_set() const
Returns the replica set specified in the uri.
stdx::optional< std::int32_t > wait_queue_timeout_ms() const
Returns the value of the option "waitQueueTimeoutMS" if present in the uri.
stdx::optional< std::int32_t > heartbeat_frequency_ms() const
Returns the value of the option "heartbeatFrequencyMS" if present in the uri.
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:58
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19
A host.
Definition: uri.hpp:50