Set no_ticket option where possible, to avoid openssl bug connecting to older servers.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReloadableXMLFile.h
index b702d4b..d8dda9e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
 #ifndef __xmltooling_reloadable_h__
 #define __xmltooling_reloadable_h__
 
+#include <xmltooling/logging.h>
 #include <xmltooling/Lockable.h>
 #include <xmltooling/util/Threads.h>
 
@@ -51,12 +52,17 @@ namespace xmltooling {
          *  <dt>validate</dt>
          *  <dd>use a validating parser</dd>
          *  <dt>reloadChanges</dt>
-         *  <dd>enables monitoring of resources for changes</dd>
+         *  <dd>enables monitoring of local file for changes</dd>
+         *  <dt>reloadInterval</dt>
+         *  <dd>enables periodic refresh of remote file</dd>
+         *  <dt>backingFilePath</dt>
+         *  <dd>location for backup of remote resource</dd>
          * </dl>
          * 
-         * @param e DOM to supply configuration
+         * @param e     DOM to supply configuration
+         * @param log   logging object to use
          */
-        ReloadableXMLFile(const xercesc::DOMElement* e);
+        ReloadableXMLFile(const xercesc::DOMElement* e, logging::Category& log);
     
         virtual ~ReloadableXMLFile() {
             delete m_lock;
@@ -72,17 +78,10 @@ namespace xmltooling {
          * @return a pair consisting of a flag indicating whether to take ownership of
          *      the document, and the root element of the tree to load
          */
-        virtual std::pair<bool,xercesc::DOMElement*> load();
-        
-        /**
-         * Overrideable method to determine whether a remote resource remains valid.
-         * 
-         * @return  true iff the resource remains valid and should not be reloaded
-         */
-        virtual bool isValid() const {
-            return true;
+        virtual std::pair<bool,xercesc::DOMElement*> load() {
+            return load(false);
         }
-
+        
         /** Root of the original DOM element passed into constructor. */
         const xercesc::DOMElement* m_root;
         
@@ -94,12 +93,21 @@ namespace xmltooling {
         
         /** Resource location, may be a local path or a URI. */
         std::string m_source;
+
+        /** Path to backup copy for remote resources. */
+        std::string m_backing;
         
-        /** Last modification of local resource. */
+        /** Last modification of local resource or reload of remote resource. */
         time_t m_filestamp;
-        
+
+        /** Time in seconds to wait before trying for new copy of remote resource. */
+        time_t m_reloadInterval;
+
         /** Shared lock for guarding reloads. */
         RWLock* m_lock;
+        
+        /** Logging object. */
+        logging::Category& m_log;
 
     public:
         Lockable* lock();
@@ -108,6 +116,9 @@ namespace xmltooling {
             if (m_lock)
                 m_lock->unlock();
         }
+
+    private:
+        std::pair<bool,xercesc::DOMElement*> load(bool backup);
     };
 
 };