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 | f97951c83e447753a4a856e5470ef3655c2bc432 (patch) | |
| tree | 5eecdc7fdbd8fcba30bc36843472a2b223a83acd /qpid/cpp/src | |
| parent | 61bd69531da409a8c1550bbc67b59a222175b23f (diff) | |
| download | qpid-python-f97951c83e447753a4a856e5470ef3655c2bc432.tar.gz | |
QPID-5788: delayed initiation of nss
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1600188 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
| -rw-r--r-- | qpid/cpp/src/qpid/client/SslConnector.cpp | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/qpid/cpp/src/qpid/client/SslConnector.cpp b/qpid/cpp/src/qpid/client/SslConnector.cpp index b292c0e6d6..9f8d31cfda 100644 --- a/qpid/cpp/src/qpid/client/SslConnector.cpp +++ b/qpid/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, |
