From 90ddf43ecbb4213a3298b7a8681fc74b8622cc21 Mon Sep 17 00:00:00 2001 From: cantor Date: Thu, 1 Apr 2010 01:15:55 +0000 Subject: [PATCH] Migrate to updated reloadable-file APIs. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/branches/REL_2@3245 cb58f699-b61c-0410-a6fe-9272a202ed29 --- shibsp/attribute/filtering/impl/XMLAttributeFilter.cpp | 13 +++++++++---- shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp | 12 ++++++++---- shibsp/impl/XMLAccessControl.cpp | 14 ++++++++++---- shibsp/impl/XMLRequestMapper.cpp | 13 +++++++++---- shibsp/impl/XMLServiceProvider.cpp | 13 +++++++++---- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/shibsp/attribute/filtering/impl/XMLAttributeFilter.cpp b/shibsp/attribute/filtering/impl/XMLAttributeFilter.cpp index 67abf9b..2e5183f 100644 --- a/shibsp/attribute/filtering/impl/XMLAttributeFilter.cpp +++ b/shibsp/attribute/filtering/impl/XMLAttributeFilter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -99,7 +100,7 @@ namespace shibsp { { public: XMLFilter(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".AttributeFilter")), m_impl(NULL) { - load(); + background_load(); } ~XMLFilter() { delete m_impl; @@ -110,7 +111,7 @@ namespace shibsp { } protected: - pair load(); + pair background_load(); private: XMLFilterImpl* m_impl; @@ -456,7 +457,7 @@ void XMLFilterImpl::filterAttributes(const FilteringContext& context, vector XMLFilter::load() +pair XMLFilter::background_load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); @@ -469,6 +470,10 @@ pair XMLFilter::load() // If we held the document, transfer it to the impl. If we didn't, it's a no-op. impl->setDocument(docjanitor.release()); + // Perform the swap inside a lock. + if (m_lock) + m_lock->wrlock(); + SharedLock locker(m_lock, false); delete m_impl; m_impl = impl; diff --git a/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp b/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp index 9b9d98d..a61e67b 100644 --- a/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp +++ b/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,7 +180,7 @@ namespace shibsp { { public: XMLExtractor(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor.XML")), m_impl(NULL) { - load(); + background_load(); } ~XMLExtractor() { delete m_impl; @@ -196,7 +196,7 @@ namespace shibsp { } protected: - pair load(); + pair background_load(); private: XMLExtractorImpl* m_impl; @@ -981,7 +981,7 @@ void XMLExtractor::extractAttributes( throw AttributeExtractionException("Unable to extract attributes, unknown object type."); } -pair XMLExtractor::load() +pair XMLExtractor::background_load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); @@ -994,6 +994,10 @@ pair XMLExtractor::load() // If we held the document, transfer it to the impl. If we didn't, it's a no-op. impl->setDocument(docjanitor.release()); + // Perform the swap inside a lock. + if (m_lock) + m_lock->wrlock(); + SharedLock locker(m_lock, false); delete m_impl; m_impl = impl; diff --git a/shibsp/impl/XMLAccessControl.cpp b/shibsp/impl/XMLAccessControl.cpp index 7e08b73..f46015c 100644 --- a/shibsp/impl/XMLAccessControl.cpp +++ b/shibsp/impl/XMLAccessControl.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2009 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ namespace shibsp { public: XMLAccessControl(const DOMElement* e) : ReloadableXMLFile(e, Category::getInstance(SHIBSP_LOGCAT".AccessControl.XML")), m_rootAuthz(NULL) { - load(); // guarantees an exception or the policy is loaded + background_load(); // guarantees an exception or the policy is loaded } ~XMLAccessControl() { @@ -115,7 +116,7 @@ namespace shibsp { aclresult_t authorized(const SPRequest& request, const Session* session) const; protected: - pair load(); + pair background_load(); private: AccessControl* m_rootAuthz; @@ -414,7 +415,7 @@ AccessControl::aclresult_t Operator::authorized(const SPRequest& request, const return shib_acl_false; } -pair XMLAccessControl::load() +pair XMLAccessControl::background_load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); @@ -434,8 +435,13 @@ pair XMLAccessControl::load() else authz=new Operator(raw.second); + // Perform the swap inside a lock. + if (m_lock) + m_lock->wrlock(); + SharedLock locker(m_lock, false); delete m_rootAuthz; m_rootAuthz = authz; + return make_pair(false,(DOMElement*)NULL); } diff --git a/shibsp/impl/XMLRequestMapper.cpp b/shibsp/impl/XMLRequestMapper.cpp index 9c3a0c4..a57ee65 100644 --- a/shibsp/impl/XMLRequestMapper.cpp +++ b/shibsp/impl/XMLRequestMapper.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -116,7 +117,7 @@ namespace shibsp { { public: XMLRequestMapper(const DOMElement* e) : ReloadableXMLFile(e,Category::getInstance(SHIBSP_LOGCAT".RequestMapper")), m_impl(NULL) { - load(); + background_load(); } ~XMLRequestMapper() { @@ -126,7 +127,7 @@ namespace shibsp { Settings getSettings(const HTTPRequest& request) const; protected: - pair load(); + pair background_load(); private: XMLRequestMapperImpl* m_impl; @@ -630,7 +631,7 @@ const Override* XMLRequestMapperImpl::findOverride(const char* vhost, const HTTP return o ? o->locate(request) : this; } -pair XMLRequestMapper::load() +pair XMLRequestMapper::background_load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); @@ -638,11 +639,15 @@ pair XMLRequestMapper::load() // If we own it, wrap it. XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL); - XMLRequestMapperImpl* impl = new XMLRequestMapperImpl(raw.second,m_log); + XMLRequestMapperImpl* impl = new XMLRequestMapperImpl(raw.second, m_log); // If we held the document, transfer it to the impl. If we didn't, it's a no-op. impl->setDocument(docjanitor.release()); + // Perform the swap inside a lock. + if (m_lock) + m_lock->wrlock(); + SharedLock locker(m_lock, false); delete m_impl; m_impl = impl; diff --git a/shibsp/impl/XMLServiceProvider.cpp b/shibsp/impl/XMLServiceProvider.cpp index 9f86df3..dfd01f5 100644 --- a/shibsp/impl/XMLServiceProvider.cpp +++ b/shibsp/impl/XMLServiceProvider.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #ifndef SHIBSP_LITE @@ -292,7 +293,7 @@ namespace { } void init() { - load(); + background_load(); } ~XMLConfig() { @@ -392,7 +393,7 @@ namespace { #endif protected: - pair load(); + pair background_load(); private: friend class XMLConfigImpl; @@ -1725,7 +1726,7 @@ void XMLConfig::receive(DDF& in, ostream& out) } #endif -pair XMLConfig::load() +pair XMLConfig::background_load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); @@ -1733,11 +1734,15 @@ pair XMLConfig::load() // If we own it, wrap it. XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL); - XMLConfigImpl* impl = new XMLConfigImpl(raw.second,(m_impl==NULL),this,m_log); + XMLConfigImpl* impl = new XMLConfigImpl(raw.second, (m_impl==NULL), this, m_log); // If we held the document, transfer it to the impl. If we didn't, it's a no-op. impl->setDocument(docjanitor.release()); + // Perform the swap inside a lock. + if (m_lock) + m_lock->wrlock(); + SharedLock locker(m_lock, false); delete m_impl; m_impl = impl; -- 2.1.4