X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsaml2%2Fmetadata%2Fimpl%2FXMLMetadataProvider.cpp;h=c97ab3d747ea3e7b9bd41a442113562357135767;hb=3d601510d00f3d81e0b591659b41de4a88aa618f;hp=c65f6939b892f2e19b2989b4f462e3717f8ef7a4;hpb=7b378c2db55dd428123ea0ed2b168aae5a5843b7;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp index c65f693..c97ab3d 100644 --- a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp +++ b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp @@ -50,6 +50,7 @@ using namespace opensaml::saml2md; using namespace xmltooling::logging; using namespace xmltooling; +using namespace boost; using namespace std; #if defined (_MSC_VER) @@ -68,7 +69,6 @@ namespace opensaml { virtual ~XMLMetadataProvider() { shutdown(); - delete m_object; } void init() { @@ -124,7 +124,7 @@ namespace opensaml { } const XMLObject* getMetadata() const { - return m_object; + return m_object.get(); } protected: @@ -136,8 +136,8 @@ namespace opensaml { void index(time_t& validUntil); time_t computeNextRefresh(); - XMLObject* m_object; - bool m_discoveryFeed; + scoped_ptr m_object; + bool m_discoveryFeed,m_dropDOM; double m_refreshDelayFactor; unsigned int m_backoffFactor; time_t m_minRefreshDelay,m_maxRefreshDelay,m_lastValidUntil; @@ -149,6 +149,7 @@ namespace opensaml { } static const XMLCh discoveryFeed[] = UNICODE_LITERAL_13(d,i,s,c,o,v,e,r,y,F,e,e,d); + static const XMLCh dropDOM[] = UNICODE_LITERAL_7(d,r,o,p,D,O,M); static const XMLCh minRefreshDelay[] = UNICODE_LITERAL_15(m,i,n,R,e,f,r,e,s,h,D,e,l,a,y); static const XMLCh refreshDelayFactor[] = UNICODE_LITERAL_18(r,e,f,r,e,s,h,D,e,l,a,y,F,a,c,t,o,r); }; @@ -161,7 +162,8 @@ namespace opensaml { XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e) : MetadataProvider(e), AbstractMetadataProvider(e), DiscoverableMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML"), false), - m_object(nullptr), m_discoveryFeed(XMLHelper::getAttrBool(e, true, discoveryFeed)), + m_discoveryFeed(XMLHelper::getAttrBool(e, true, discoveryFeed)), + m_dropDOM(XMLHelper::getAttrBool(e, true, dropDOM)), m_refreshDelayFactor(0.75), m_backoffFactor(1), m_minRefreshDelay(XMLHelper::getAttrInt(e, 600, minRefreshDelay)), m_maxRefreshDelay(m_reloadInterval), m_lastValidUntil(SAMLTIME_MAX) @@ -198,7 +200,7 @@ pair XMLMetadataProvider::load(bool backup) XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : nullptr); // Unmarshall objects, binding the document. - auto_ptr xmlObject(XMLObjectBuilder::buildOneFromElement(raw.second, true)); + scoped_ptr xmlObject(XMLObjectBuilder::buildOneFromElement(raw.second, true)); docjanitor.release(); if (!dynamic_cast(xmlObject.get()) && !dynamic_cast(xmlObject.get())) @@ -233,7 +235,7 @@ pair XMLMetadataProvider::load(bool backup) } try { - doFilters(*xmlObject.get()); + doFilters(*xmlObject); } catch (exception&) { if (!backupKey.empty()) @@ -250,16 +252,17 @@ pair XMLMetadataProvider::load(bool backup) preserveCacheTag(); } - xmlObject->releaseThisAndChildrenDOM(); - xmlObject->setDocument(nullptr); + if (m_dropDOM) { + xmlObject->releaseThisAndChildrenDOM(); + xmlObject->setDocument(nullptr); + } // Swap it in after acquiring write lock if necessary. if (m_lock) m_lock->wrlock(); SharedLock locker(m_lock, false); bool changed = m_object!=nullptr; - delete m_object; - m_object = xmlObject.release(); + m_object.swap(xmlObject); m_lastValidUntil = SAMLTIME_MAX; index(m_lastValidUntil); if (m_discoveryFeed) @@ -328,7 +331,7 @@ time_t XMLMetadataProvider::computeNextRefresh() else { // Compute the smaller of the validUntil / cacheDuration constraints. time_t ret = m_lastValidUntil - now; - const CacheableSAMLObject* cacheable = dynamic_cast(m_object); + const CacheableSAMLObject* cacheable = dynamic_cast(m_object.get()); if (cacheable && cacheable->getCacheDuration()) ret = min(ret, cacheable->getCacheDurationEpoch()); @@ -348,10 +351,10 @@ time_t XMLMetadataProvider::computeNextRefresh() void XMLMetadataProvider::index(time_t& validUntil) { clearDescriptorIndex(); - EntitiesDescriptor* group=dynamic_cast(m_object); + EntitiesDescriptor* group = dynamic_cast(m_object.get()); if (group) { indexGroup(group, validUntil); return; } - indexEntity(dynamic_cast(m_object), validUntil); + indexEntity(dynamic_cast(m_object.get()), validUntil); }