SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / DynamicMetadataProvider.cpp
index 4bf3656..2768440 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
@@ -43,6 +47,7 @@ using namespace std;
 #  define min(a,b)            (((a) < (b)) ? (a) : (b))
 # endif
 
+static const XMLCh id[] =                   UNICODE_LITERAL_2(i,d);
 static const XMLCh maxCacheDuration[] =     UNICODE_LITERAL_16(m,a,x,C,a,c,h,e,D,u,r,a,t,i,o,n);
 static const XMLCh minCacheDuration[] =     UNICODE_LITERAL_16(m,i,n,C,a,c,h,e,D,u,r,a,t,i,o,n);
 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);
@@ -59,14 +64,15 @@ namespace opensaml {
 
 DynamicMetadataProvider::DynamicMetadataProvider(const DOMElement* e)
     : AbstractMetadataProvider(e),
-        m_maxCacheDuration(XMLHelper::getAttrInt(e, 28800, maxCacheDuration)),
+      m_validate(XMLHelper::getAttrBool(e, false, validate)),
+        m_id(XMLHelper::getAttrString(e, "Dynamic", id)),
         m_lock(RWLock::create()),
         m_refreshDelayFactor(0.75),
         m_minCacheDuration(XMLHelper::getAttrInt(e, 600, minCacheDuration)),
-        m_validate(XMLHelper::getAttrBool(e, false, validate))
+        m_maxCacheDuration(XMLHelper::getAttrInt(e, 28800, maxCacheDuration))
 {
     if (m_minCacheDuration > m_maxCacheDuration) {
-        Category::getInstance(SAML_LOGCAT".MetadataProvider.Dynamic").error(
+        Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic").error(
             "minCacheDuration setting exceeds maxCacheDuration setting, lowering to match it"
             );
         m_minCacheDuration = m_maxCacheDuration;
@@ -77,7 +83,7 @@ DynamicMetadataProvider::DynamicMetadataProvider(const DOMElement* e)
         auto_ptr_char temp(delay);
         m_refreshDelayFactor = atof(temp.get());
         if (m_refreshDelayFactor <= 0.0 || m_refreshDelayFactor >= 1.0) {
-            Category::getInstance(SAML_LOGCAT".MetadataProvider.Dynamic").error(
+            Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic").error(
                 "invalid refreshDelayFactor setting, using default"
                 );
             m_refreshDelayFactor = 0.75;
@@ -89,7 +95,6 @@ DynamicMetadataProvider::~DynamicMetadataProvider()
 {
     // Each entity in the map is unique (no multimap semantics), so this is safe.
     clearDescriptorIndex(true);
-    delete m_lock;
 }
 
 const XMLObject* DynamicMetadataProvider::getMetadata() const
@@ -112,9 +117,14 @@ void DynamicMetadataProvider::init()
 {
 }
 
+const char* DynamicMetadataProvider::getId() const
+{
+    return m_id.c_str();
+}
+
 pair<const EntityDescriptor*,const RoleDescriptor*> DynamicMetadataProvider::getEntityDescriptor(const Criteria& criteria) const
 {
-    Category& log = Category::getInstance(SAML_LOGCAT".MetadataProvider.Dynamic");
+    Category& log = Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic");
 
     // First we check the underlying cache.
     pair<const EntityDescriptor*,const RoleDescriptor*> entity = AbstractMetadataProvider::getEntityDescriptor(criteria);
@@ -193,7 +203,7 @@ pair<const EntityDescriptor*,const RoleDescriptor*> DynamicMetadataProvider::get
         }
 
         // Filter it, which may throw.
-        doFilters(*entity2.get());
+        doFilters(*entity2);
 
         time_t now = time(nullptr);
         if (entity2->getValidUntil() && entity2->getValidUntilEpoch() < now + 60)
@@ -222,14 +232,17 @@ pair<const EntityDescriptor*,const RoleDescriptor*> DynamicMetadataProvider::get
         m_lock->wrlock();
 
         // Notify observers.
-        emitChangeEvent();
+        emitChangeEvent(*entity2);
 
         // Record the proper refresh time.
         m_cacheMap[entity2->getEntityID()] = now + cacheExp;
 
         // Make sure we clear out any existing copies, including stale metadata or if somebody snuck in.
         cacheExp = SAMLTIME_MAX;
-        indexEntity(entity2.release(), cacheExp, true);
+        indexEntity(entity2.get(), cacheExp, true);
+        entity2.release();
+
+        m_lastUpdate = now;
 
         // Downgrade back to a read lock.
         m_lock->unlock();
@@ -299,7 +312,7 @@ EntityDescriptor* DynamicMetadataProvider::resolve(const Criteria& criteria) con
     }
     catch (XMLException& e) {
         auto_ptr_char msg(e.getMessage());
-        Category::getInstance(SAML_LOGCAT".MetadataProvider.Dynamic").error(
+        Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic").error(
             "Xerces error while resolving entityID (%s): %s", name.c_str(), msg.get()
             );
         throw MetadataException(msg.get());