Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / XMLMetadataProvider.cpp
index 2f410bd..f0e5963 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.
  */
 
 /**
 #include <xmltooling/util/Threads.h>
 #include <xmltooling/validation/ValidatorSuite.h>
 
+#if defined(OPENSAML_LOG4SHIB)
+# include <log4shib/NDC.hh>
+#elif defined(OPENSAML_LOG4CPP)
+# include <log4cpp/NDC.hh>
+#endif
+
 using namespace opensaml::saml2md;
 using namespace xmltooling::logging;
 using namespace xmltooling;
@@ -62,13 +72,25 @@ namespace opensaml {
 
             void init() {
                 try {
+                    if (!m_id.empty()) {
+                        string threadid("[");
+                        threadid += m_id + ']';
+                        logging::NDC::push(threadid);
+                    }
                     background_load();
                     startup();
                 }
                 catch (...) {
                     startup();
+                    if (!m_id.empty()) {
+                        logging::NDC::pop();
+                    }
                     throw;
                 }
+
+                if (!m_id.empty()) {
+                    logging::NDC::pop();
+                }
             }
 
             const XMLObject* getMetadata() const {
@@ -107,7 +129,8 @@ namespace opensaml {
 #endif
 
 XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
-    : AbstractMetadataProvider(e), DiscoverableMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML"), false),
+    : 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_refreshDelayFactor(0.75), m_backoffFactor(1),
         m_minRefreshDelay(XMLHelper::getAttrInt(e, 600, minRefreshDelay)),
@@ -125,7 +148,7 @@ XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
         }
 
         if (m_minRefreshDelay > m_maxRefreshDelay) {
-            m_log.error("minRefreshDelay setting exceeds maxRefreshDelay/refreshInterval setting, lowering to match it");
+            m_log.warn("minRefreshDelay setting exceeds maxRefreshDelay/reloadInterval setting, lowering to match it");
             m_minRefreshDelay = m_maxRefreshDelay;
         }
     }
@@ -133,8 +156,10 @@ XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
 
 pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
 {
-    // Lower the refresh rate in case of an error.
-    m_reloadInterval = m_minRefreshDelay;
+    if (!backup) {
+        // Lower the refresh rate in case of an error.
+        m_reloadInterval = m_minRefreshDelay;
+    }
 
     // Call the base class to load/parse the appropriate XML resource.
     pair<bool,DOMElement*> raw = ReloadableXMLFile::load(backup);
@@ -215,8 +240,8 @@ pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
     // Tracking cacheUntil through the tree is TBD, but
     // validUntil is the tightest interval amongst the children.
 
-    // If a remote resource, adjust the reload interval.
-    if (!backup && !m_local) {
+    // If a remote resource that's monitored, adjust the reload interval.
+    if (!backup && !m_local && m_lock) {
         m_backoffFactor = 1;
         m_reloadInterval = computeNextRefresh();
         m_log.info("adjusted reload interval to %d seconds", m_reloadInterval);