|
| 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 | +#include "mongo/platform/basic.h" |
| 17 | + |
| 18 | +#include "mongo/client/private/options.h" |
| 19 | +#include "mongo/client/options.h" |
| 20 | + |
| 21 | +namespace mongo { |
| 22 | +namespace client { |
| 23 | + |
| 24 | + namespace { |
| 25 | + // The unique global options instance. |
| 26 | + Options options; |
| 27 | + } // namespace |
| 28 | + |
| 29 | +#if !defined(_MSC_EXTENSIONS) |
| 30 | + const int Options::kDefaultDefaultLocalThresholdMillis; |
| 31 | + const int Options::kDefaultAutoShutdownGracePeriodMillis; |
| 32 | +#endif |
| 33 | + |
| 34 | + void setOptions(const Options& newOptions) { |
| 35 | + options = newOptions; |
| 36 | + } |
| 37 | + |
| 38 | + const Options& Options::current() { |
| 39 | + return options; |
| 40 | + } |
| 41 | + |
| 42 | + Options::Options() |
| 43 | + : _callShutdownAtExit(true) |
| 44 | + , _autoShutdownGracePeriodMillis(kDefaultAutoShutdownGracePeriodMillis) |
| 45 | + , _sslMode(kSSLDisabled) |
| 46 | + , _useFIPSMode(false) |
| 47 | + , _sslAllowInvalidCertificates(false) |
| 48 | + , _defaultLocalThresholdMillis(kDefaultDefaultLocalThresholdMillis) |
| 49 | + , _validateObjects(false) |
| 50 | + {} |
| 51 | + |
| 52 | + Options& Options::setCallShutdownAtExit(bool value) { |
| 53 | + _callShutdownAtExit = value; |
| 54 | + return *this; |
| 55 | + } |
| 56 | + |
| 57 | + bool Options::callShutdownAtExit() const { |
| 58 | + return _callShutdownAtExit; |
| 59 | + } |
| 60 | + |
| 61 | + Options& Options::setAutoShutdownGracePeriodMillis(int millis) { |
| 62 | + _autoShutdownGracePeriodMillis = millis; |
| 63 | + return *this; |
| 64 | + } |
| 65 | + |
| 66 | + int Options::autoShutdownGracePeriodMillis() const { |
| 67 | + return _autoShutdownGracePeriodMillis; |
| 68 | + } |
| 69 | + |
| 70 | + Options& Options::setDefaultLocalThresholdMillis(int millis) { |
| 71 | + _defaultLocalThresholdMillis = millis; |
| 72 | + return *this; |
| 73 | + } |
| 74 | + |
| 75 | + int Options::defaultLocalThresholdMillis() const { |
| 76 | + return _defaultLocalThresholdMillis; |
| 77 | + } |
| 78 | + |
| 79 | + Options& Options::setSSLMode(SSLModes sslMode) { |
| 80 | + _sslMode = sslMode; |
| 81 | + return *this; |
| 82 | + } |
| 83 | + |
| 84 | + Options::SSLModes Options::SSLMode() const { |
| 85 | + return _sslMode; |
| 86 | + } |
| 87 | + |
| 88 | + Options& Options::setFIPSMode(bool value) { |
| 89 | + _useFIPSMode = value; |
| 90 | + return *this; |
| 91 | + } |
| 92 | + |
| 93 | + const bool Options::FIPSMode() const { |
| 94 | + return _useFIPSMode; |
| 95 | + } |
| 96 | + |
| 97 | + Options& Options::setSSLCAFile(const std::string& fileName) { |
| 98 | + _sslCAFile = fileName; |
| 99 | + return *this; |
| 100 | + } |
| 101 | + |
| 102 | + const std::string& Options::SSLCAFile() const { |
| 103 | + return _sslCAFile; |
| 104 | + } |
| 105 | + |
| 106 | + Options& Options::setSSLPEMKeyFile(const std::string& fileName) { |
| 107 | + _sslPEMKeyFile = fileName; |
| 108 | + return *this; |
| 109 | + } |
| 110 | + |
| 111 | + const std::string& Options::SSLPEMKeyFile() const { |
| 112 | + return _sslPEMKeyFile; |
| 113 | + } |
| 114 | + |
| 115 | + Options& Options::setSSLPEMKeyPassword(const std::string& password) { |
| 116 | + _sslPEMKeyPassword = password; |
| 117 | + return *this; |
| 118 | + } |
| 119 | + |
| 120 | + const std::string& Options::SSLPEMKeyPassword() const { |
| 121 | + return _sslPEMKeyPassword; |
| 122 | + } |
| 123 | + |
| 124 | + Options& Options::setSSLCRLFile(const std::string& fileName) { |
| 125 | + _sslCRLFile = fileName; |
| 126 | + return *this; |
| 127 | + } |
| 128 | + |
| 129 | + const std::string& Options::SSLCRLFile() const { |
| 130 | + return _sslCRLFile; |
| 131 | + } |
| 132 | + |
| 133 | + Options& Options::setSSLAllowInvalidCertificates(bool value) { |
| 134 | + _sslAllowInvalidCertificates = value; |
| 135 | + return *this; |
| 136 | + } |
| 137 | + |
| 138 | + const bool Options::SSLAllowInvalidCertificates() const { |
| 139 | + return _sslAllowInvalidCertificates; |
| 140 | + } |
| 141 | + |
| 142 | + Options& Options::setValidateObjects(bool value) { |
| 143 | + _validateObjects = value; |
| 144 | + return *this; |
| 145 | + } |
| 146 | + |
| 147 | + bool Options::validateObjects() const { |
| 148 | + return _validateObjects; |
| 149 | + } |
| 150 | + |
| 151 | +} // namespace client |
| 152 | +} // namespace mongo |
0 commit comments