diff options
| author | Gordon Sim <gsim@apache.org> | 2014-06-04 13:15:02 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2014-06-04 13:15:02 +0000 |
| commit | b162278ab318bcead84b22d4fd7bf648108f1700 (patch) | |
| tree | 1f265a5d4ef2cd6c93282c109e4e8fc436bf376b /cpp/src | |
| parent | b396c3279e2dbcd1bb19059fa0ff057e22636177 (diff) | |
| download | qpid-python-b162278ab318bcead84b22d4fd7bf648108f1700.tar.gz | |
QPID-5788: delayed initiation of nss
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1600188 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
| -rw-r--r-- | cpp/src/qpid/client/SslConnector.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/cpp/src/qpid/client/SslConnector.cpp b/cpp/src/qpid/client/SslConnector.cpp index b292c0e6d6..9f8d31cfda 100644 --- a/cpp/src/qpid/client/SslConnector.cpp +++ b/cpp/src/qpid/client/SslConnector.cpp @@ -37,6 +37,7 @@ #include "qpid/sys/Poller.h" #include "qpid/sys/SecuritySettings.h" #include "qpid/Msg.h" +#include "qpid/types/Exception.h" #include <iostream> #include <boost/bind.hpp> @@ -114,30 +115,50 @@ public: // Static constructor which registers connector here namespace { - Connector* create(Poller::shared_ptr p, framing::ProtocolVersion v, const ConnectionSettings& s, ConnectionImpl* c) { - return new SslConnector(p, v, s, c); - } + Connector* create(Poller::shared_ptr p, framing::ProtocolVersion v, const ConnectionSettings& s, ConnectionImpl* c); struct StaticInit { + static bool initialised; + StaticInit() { - try { + Connector::registerFactory("ssl", &create); + }; + ~StaticInit() { + if (initialised) shutdownNSS(); + } + + void checkInitialised() { + static qpid::sys::Mutex lock; + qpid::sys::Mutex::ScopedLock l(lock); + if (!initialised) { CommonOptions common("", "", QPIDC_CONF_FILE); SslOptions options; - common.parse(0, 0, common.clientConfig, true); - options.parse (0, 0, common.clientConfig, true); + try { + common.parse(0, 0, common.clientConfig, true); + options.parse (0, 0, common.clientConfig, true); + } catch (const std::exception& e) { + throw qpid::types::Exception(QPID_MSG("Failed to parse options while initialising SSL connector: " << e.what())); + } if (options.certDbPath.empty()) { - QPID_LOG(info, "SSL connector not enabled, you must set QPID_SSL_CERT_DB to enable it."); + throw qpid::types::Exception(QPID_MSG("SSL connector not enabled, you must set QPID_SSL_CERT_DB to enable it.")); } else { - initNSS(options); - Connector::registerFactory("ssl", &create); + try { + initNSS(options); + initialised = true; + } catch (const std::exception& e) { + throw qpid::types::Exception(QPID_MSG("Failed to initialise SSL: " << e.what())); + } } - } catch (const std::exception& e) { - QPID_LOG(error, "Failed to initialise SSL connector: " << e.what()); } - }; + } - ~StaticInit() { shutdownNSS(); } } init; + bool StaticInit::initialised = false; + + Connector* create(Poller::shared_ptr p, framing::ProtocolVersion v, const ConnectionSettings& s, ConnectionImpl* c) { + init.checkInitialised(); + return new SslConnector(p, v, s, c); + } } SslConnector::SslConnector(Poller::shared_ptr p, |
