MongoDB C++ Driver  legacy-1.0.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
options.h
1 /* Copyright 2014 10gen 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 
16 #pragma once
17 
18 #include <string>
19 
20 #include "mongo/client/export_macros.h"
21 #include "mongo/logger/log_domain.h"
22 #include "mongo/logger/message_log_domain.h"
23 #include "mongo/stdx/functional.h"
24 
25 namespace mongo {
26 namespace client {
27 
32  class MONGO_CLIENT_API Options {
33  public:
34 
35  // Defaults for non-boolean or std::string parameters that are not defaulted to the
36  // empty string. These are useful in case you which to set a parameter to a scale
37  // factor or mutation of the default.
38  static const unsigned int kDefaultAutoShutdownGracePeriodMillis = 0;
39  static const int kDefaultDefaultLocalThresholdMillis = 15;
40 
41  // Helpful typedefs for logging-related options
42  typedef std::auto_ptr<logger::MessageLogDomain::EventAppender> LogAppenderPtr;
43  typedef stdx::function<LogAppenderPtr()> LogAppenderFactory;
44 
48  static const Options& current();
49 
53  Options();
54 
56  enum DefaultPorts {
57  kDbServer = 27017,
58  kShardServer = 27018,
59  kConfigServer = 27019
60  };
61 
63  enum SSLModes {
64 
67 
73  // kSSLPreferred,
74 
76  kSSLRequired
77  };
78 
80  enum TLSProtocol {
81  kTLS1_0,
82  kTLS1_1,
83  kTLS1_2
84  };
85 
86  //
87  // Startup and shutdown
88  //
89 
100  Options& setCallShutdownAtExit(bool value = true);
101  bool callShutdownAtExit() const;
102 
108  Options& setAutoShutdownGracePeriodMillis(unsigned int millis);
109  unsigned int autoShutdownGracePeriodMillis() const;
110 
111 
112  //
113  // Replication
114  //
115 
120  Options& setDefaultLocalThresholdMillis(int millis);
121  int defaultLocalThresholdMillis() const;
122 
123 
124  //
125  // SSL
126  //
127  // NOTE: None of the below settings have any effect unless the driver
128  // was compiled with SSL support.
129  //
130  // Glossary:
131  // - CA File: certificate authority certificate file
132  // - PEM Key File: SSL certificate file in PEM format
133  // - CRL: certificate revocation list
134  // - FIPS Mode: OpenSSL crypto library FIPS 140-2 mode processing
135  //
136 
141  Options& setSSLMode(SSLModes sslMode = kSSLRequired);
142  SSLModes SSLMode() const;
143 
145  inline bool SSLEnabled() const {
146  return SSLMode() != kSSLDisabled;
147  }
148 
153  Options& setFIPSMode(bool value = true);
154  const bool FIPSMode() const;
155 
161  Options& setSSLDisabledTLSProtocols(const std::vector<TLSProtocol>& protocols);
162  const std::vector<TLSProtocol>& SSLDisabledTLSProtocols() const;
163 
168  Options& setSSLCAFile(const std::string& fileName);
169  const std::string& SSLCAFile() const;
170 
175  Options& setSSLPEMKeyFile(const std::string& fileName);
176  const std::string& SSLPEMKeyFile() const;
177 
182  Options& setSSLPEMKeyPassword(const std::string& password);
183  const std::string& SSLPEMKeyPassword() const;
184 
189  Options& setSSLCRLFile(const std::string& fileName);
190  const std::string& SSLCRLFile() const;
191 
196  Options& setSSLAllowInvalidCertificates(bool value = true);
197  const bool SSLAllowInvalidCertificates() const;
198 
203  Options& setSSLAllowInvalidHostnames(bool value = true);
204  const bool SSLAllowInvalidHostnames() const;
205 
210  Options& setSSLCipherConfig(const std::string& config);
211  const std::string& SSLCipherConfig() const;
212 
213  //
214  // Logging
215  //
216 
221  Options& setLogAppenderFactory(const LogAppenderFactory& factory);
222  const LogAppenderFactory& logAppenderFactory() const;
223 
229  Options& setMinLoggedSeverity(logger::LogSeverity level);
230  logger::LogSeverity minLoggedSeverity() const;
231 
232  //
233  // Misc
234  //
235 
240  Options& setValidateObjects(bool value = true);
241  bool validateObjects() const;
242 
243  private:
244  bool _callShutdownAtExit;
245  unsigned int _autoShutdownGracePeriodMillis;
246  SSLModes _sslMode;
247  bool _useFIPSMode;
248  std::vector<TLSProtocol> _sslDisabledTLSProtocols;
249  std::string _sslCAFile;
250  std::string _sslPEMKeyFile;
251  std::string _sslPEMKeyPassword;
252  std::string _sslCRLFile;
253  bool _sslAllowInvalidCertificates;
254  bool _sslAllowInvalidHostnames;
255  std::string _sslCipherConfig;
256  int _defaultLocalThresholdMillis;
257  LogAppenderFactory _appenderFactory;
258  logger::LogSeverity _minLoggedSeverity;
259  bool _validateObjects;
260  };
261 
262 } // namespace client
263 } // namespace mongo
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
DefaultPorts
The default ports where different mongodb servers tend to run.
Definition: options.h:56
SSLModes
The possible modes for SSL support in an SSL enabled build of the driver.
Definition: options.h:63
The Options structure is passed to mongo::client::initialize to configure various properties and conf...
Definition: options.h:32
TLSProtocol
The TLS protocols.
Definition: options.h:80
bool SSLEnabled() const
A convenience: returns true if SSL is not disabled (preferred or required).
Definition: options.h:145
Don't attempt to make SSL connections, or require SSL support of the server.
Definition: options.h:66