[xmltooling] 04/14: https://issues.shibboleth.net/jira/browse/CPPXT-77
Ferenc Wágner
wferi-guest at moszumanska.debian.org
Thu Dec 10 22:10:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
wferi-guest pushed a commit to annotated tag 1.4.2
in repository xmltooling.
commit 962ea09ea8f9e2fa004478ddd7f79ad4c6fa2a6c
Author: Scott Cantor <cantor.2 at osu.edu>
Date: Mon Jun 6 19:15:54 2011 +0000
https://issues.shibboleth.net/jira/browse/CPPXT-77
---
xmltooling/XMLToolingConfig.cpp | 168 ++++++++++++++++++++++++----------------
xmltooling/internal.h | 14 ++--
xmltoolingtest/xmltoolingtest.h | 4 +
3 files changed, 110 insertions(+), 76 deletions(-)
diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp
index a8f0bdd..62a7326 100644
--- a/xmltooling/XMLToolingConfig.cpp
+++ b/xmltooling/XMLToolingConfig.cpp
@@ -218,6 +218,76 @@ XMLToolingConfig::~XMLToolingConfig()
{
}
+#ifndef XMLTOOLING_LITE
+const KeyInfoResolver* XMLToolingConfig::getKeyInfoResolver() const
+{
+ return m_keyInfoResolver;
+}
+
+ReplayCache* XMLToolingConfig::getReplayCache() const
+{
+ return m_replayCache;
+}
+
+void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver)
+{
+ delete m_keyInfoResolver;
+ m_keyInfoResolver = keyInfoResolver;
+}
+
+void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
+{
+ delete m_replayCache;
+ m_replayCache = replayCache;
+}
+#endif
+
+PathResolver* XMLToolingConfig::getPathResolver() const
+{
+ return m_pathResolver;
+}
+
+TemplateEngine* XMLToolingConfig::getTemplateEngine() const
+{
+ return m_templateEngine;
+}
+
+const URLEncoder* XMLToolingConfig::getURLEncoder() const
+{
+ return m_urlEncoder;
+}
+
+void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
+{
+ delete m_pathResolver;
+ m_pathResolver = pathResolver;
+}
+
+void XMLToolingConfig::setTemplateEngine(TemplateEngine* templateEngine)
+{
+ delete m_templateEngine;
+ m_templateEngine = templateEngine;
+}
+
+void XMLToolingConfig::setURLEncoder(URLEncoder* urlEncoder)
+{
+ delete m_urlEncoder;
+ m_urlEncoder = urlEncoder;
+}
+
+XMLToolingInternalConfig::XMLToolingInternalConfig() :
+#ifndef XMLTOOLING_NO_XMLSEC
+ m_xsecProvider(nullptr),
+#endif
+ m_initCount(0), m_lock(Mutex::create()), m_parserPool(nullptr), m_validatingPool(nullptr)
+{
+}
+
+XMLToolingInternalConfig::~XMLToolingInternalConfig()
+{
+ delete m_lock;
+}
+
bool XMLToolingInternalConfig::log_config(const char* config)
{
try {
@@ -288,69 +358,25 @@ bool XMLToolingInternalConfig::log_config(const char* config)
return true;
}
-#ifndef XMLTOOLING_LITE
-const KeyInfoResolver* XMLToolingConfig::getKeyInfoResolver() const
-{
- return m_keyInfoResolver;
-}
-
-ReplayCache* XMLToolingConfig::getReplayCache() const
-{
- return m_replayCache;
-}
-
-void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver)
-{
- delete m_keyInfoResolver;
- m_keyInfoResolver = keyInfoResolver;
-}
-
-void XMLToolingConfig::setReplayCache(ReplayCache* replayCache)
+bool XMLToolingInternalConfig::init()
{
- delete m_replayCache;
- m_replayCache = replayCache;
-}
+#ifdef _DEBUG
+ xmltooling::NDC ndc("init");
#endif
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Config");
-PathResolver* XMLToolingConfig::getPathResolver() const
-{
- return m_pathResolver;
-}
-
-TemplateEngine* XMLToolingConfig::getTemplateEngine() const
-{
- return m_templateEngine;
-}
-
-const URLEncoder* XMLToolingConfig::getURLEncoder() const
-{
- return m_urlEncoder;
-}
-
-void XMLToolingConfig::setPathResolver(PathResolver* pathResolver)
-{
- delete m_pathResolver;
- m_pathResolver = pathResolver;
-}
+ Lock initLock(m_lock);
-void XMLToolingConfig::setTemplateEngine(TemplateEngine* templateEngine)
-{
- delete m_templateEngine;
- m_templateEngine = templateEngine;
-}
+ if (m_initCount == LONG_MAX) {
+ log.crit("library initialized too many times");
+ return false;
+ }
-void XMLToolingConfig::setURLEncoder(URLEncoder* urlEncoder)
-{
- delete m_urlEncoder;
- m_urlEncoder = urlEncoder;
-}
+ if (m_initCount >= 1) {
+ ++m_initCount;
+ return true;
+ }
-bool XMLToolingInternalConfig::init()
-{
-#ifdef _DEBUG
- xmltooling::NDC ndc("init");
-#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig");
try {
log.debug("library initialization started");
@@ -385,7 +411,6 @@ bool XMLToolingInternalConfig::init()
m_parserPool=new ParserPool();
m_validatingPool=new ParserPool(true,true);
- m_lock=XMLPlatformUtils::makeMutex();
// Load catalogs from path.
if (!catalog_path.empty()) {
@@ -463,11 +488,25 @@ bool XMLToolingInternalConfig::init()
#endif
log.info("%s library initialization complete", PACKAGE_STRING);
+ ++m_initCount;
return true;
}
void XMLToolingInternalConfig::term()
{
+#ifdef _DEBUG
+ xmltooling::NDC ndc("term");
+#endif
+
+ Lock initLock(m_lock);
+ if (m_initCount == 0) {
+ Category::getInstance(XMLTOOLING_LOGCAT".Config").crit("term without corresponding init");
+ return;
+ }
+ else if (--m_initCount > 0) {
+ return;
+ }
+
#ifndef XMLTOOLING_NO_XMLSEC
CRYPTO_set_locking_callback(nullptr);
for_each(g_openssl_locks.begin(), g_openssl_locks.end(), xmltooling::cleanup<Mutex>());
@@ -532,28 +571,23 @@ void XMLToolingInternalConfig::term()
XSECPlatformUtils::Terminate();
#endif
- XMLPlatformUtils::closeMutex(m_lock);
- m_lock=nullptr;
XMLPlatformUtils::Terminate();
#ifndef XMLTOOLING_NO_XMLSEC
curl_global_cleanup();
#endif
-#ifdef _DEBUG
- xmltooling::NDC ndc("term");
-#endif
- Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("%s library shutdown complete", PACKAGE_STRING);
+ Category::getInstance(XMLTOOLING_LOGCAT".Config").info("%s library shutdown complete", PACKAGE_STRING);
}
Lockable* XMLToolingInternalConfig::lock()
{
- xercesc::XMLPlatformUtils::lockMutex(m_lock);
+ m_lock->lock();
return this;
}
void XMLToolingInternalConfig::unlock()
{
- xercesc::XMLPlatformUtils::unlockMutex(m_lock);
+ m_lock->unlock();
}
bool XMLToolingInternalConfig::load_library(const char* path, void* context)
@@ -561,7 +595,7 @@ bool XMLToolingInternalConfig::load_library(const char* path, void* context)
#ifdef _DEBUG
xmltooling::NDC ndc("LoadLibrary");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Config");
log.info("loading extension: %s", path);
Locker locker(this);
diff --git a/xmltooling/internal.h b/xmltooling/internal.h
index d4eb294..3866372 100644
--- a/xmltooling/internal.h
+++ b/xmltooling/internal.h
@@ -75,16 +75,11 @@
namespace xmltooling {
/// @cond OFF
- class XMLToolingInternalConfig : public XMLToolingConfig
+ class XMLTOOL_DLLLOCAL XMLToolingInternalConfig : public XMLToolingConfig
{
public:
- XMLToolingInternalConfig() :
-#ifndef XMLTOOLING_NO_XMLSEC
- m_xsecProvider(nullptr),
-#endif
- m_lock(nullptr), m_parserPool(nullptr), m_validatingPool(nullptr)
- {
- }
+ XMLToolingInternalConfig();
+ ~XMLToolingInternalConfig();
static XMLToolingInternalConfig& getInternalConfig();
@@ -125,8 +120,9 @@ namespace xmltooling {
#endif
private:
+ int m_initCount;
+ Mutex* m_lock;
std::vector<void*> m_libhandles;
- void* m_lock;
ParserPool* m_parserPool;
ParserPool* m_validatingPool;
};
diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h
index 49f73e3..b34b145 100644
--- a/xmltoolingtest/xmltoolingtest.h
+++ b/xmltoolingtest/xmltoolingtest.h
@@ -37,11 +37,15 @@ public:
if (!XMLToolingConfig::getConfig().init())
return false;
+ if (!XMLToolingConfig::getConfig().init()) // should be a no-op
+ return false;
return true;
}
bool tearDownWorld() {
+ XMLToolingConfig::getConfig().term(); // should be a no-op
XMLToolingConfig::getConfig().term();
+ XMLToolingConfig::getConfig().term(); // shouldn't break anything
#if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK)
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/xmltooling.git
More information about the Pkg-shibboleth-devel
mailing list