MongoDB C++ Driver  legacy-1.0.0
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 
79 
80  //
81  // Startup and shutdown
82  //
83 
94  Options& setCallShutdownAtExit(bool value = true);
95  bool callShutdownAtExit() const;
96 
102  Options& setAutoShutdownGracePeriodMillis(unsigned int millis);
103  unsigned int autoShutdownGracePeriodMillis() const;
104 
105 
106  //
107  // Replication
108  //
109 
114  Options& setDefaultLocalThresholdMillis(int millis);
115  int defaultLocalThresholdMillis() const;
116 
117 
118  //
119  // SSL
120  //
121  // NOTE: None of the below settings have any effect unless the driver
122  // was compiled with SSL support.
123  //
124  // Glossary:
125  // - CA File: certificate authority certificate file
126  // - PEM Key File: SSL certificate file in PEM format
127  // - CRL: certificate revocation list
128  // - FIPS Mode: OpenSSL crypto library FIPS 140-2 mode processing
129  //
130 
135  Options& setSSLMode(SSLModes sslMode = kSSLRequired);
136  SSLModes SSLMode() const;
137 
139  inline bool SSLEnabled() const {
140  return SSLMode() != kSSLDisabled;
141  }
142 
147  Options& setFIPSMode(bool value = true);
148  const bool FIPSMode() const;
149 
154  Options& setSSLCAFile(const std::string& fileName);
155  const std::string& SSLCAFile() const;
156 
161  Options& setSSLPEMKeyFile(const std::string& fileName);
162  const std::string& SSLPEMKeyFile() const;
163 
168  Options& setSSLPEMKeyPassword(const std::string& password);
169  const std::string& SSLPEMKeyPassword() const;
170 
175  Options& setSSLCRLFile(const std::string& fileName);
176  const std::string& SSLCRLFile() const;
177 
182  Options& setSSLAllowInvalidCertificates(bool value = true);
183  const bool SSLAllowInvalidCertificates() const;
184 
189  Options& setSSLAllowInvalidHostnames(bool value = true);
190  const bool SSLAllowInvalidHostnames() const;
191 
192  //
193  // Logging
194  //
195 
200  Options& setLogAppenderFactory(const LogAppenderFactory& factory);
201  const LogAppenderFactory& logAppenderFactory() const;
202 
208  Options& setMinLoggedSeverity(logger::LogSeverity level);
209  logger::LogSeverity minLoggedSeverity() const;
210 
211  //
212  // Misc
213  //
214 
219  Options& setValidateObjects(bool value = true);
220  bool validateObjects() const;
221 
222  private:
223  bool _callShutdownAtExit;
224  unsigned int _autoShutdownGracePeriodMillis;
225  SSLModes _sslMode;
226  bool _useFIPSMode;
227  std::string _sslCAFile;
228  std::string _sslPEMKeyFile;
229  std::string _sslPEMKeyPassword;
230  std::string _sslCRLFile;
231  bool _sslAllowInvalidCertificates;
232  bool _sslAllowInvalidHostnames;
233  int _defaultLocalThresholdMillis;
234  LogAppenderFactory _appenderFactory;
235  logger::LogSeverity _minLoggedSeverity;
236  bool _validateObjects;
237  };
238 
239 } // namespace client
240 } // 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
bool SSLEnabled() const
A convenience: returns true if SSL is not disabled (preferred or required).
Definition: options.h:139
Don't attempt to make SSL connections, or require SSL support of the server.
Definition: options.h:66