CPPXT-104 - Add exception handling to integer conversions
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReloadableXMLFile.h
index 795bd69..d7cf55e 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  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.
- * You may obtain a copy of the License at
+/**
+ * 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.
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * 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
  *
- * 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.
+ * 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.
  */
 
 /**
@@ -66,7 +70,7 @@ namespace xmltooling {
          *  <dd>use a validating parser</dd>
          *  <dt>reloadChanges</dt>
          *  <dd>enables monitoring of local file for changes</dd>
-         *  <dt>reloadInterval</dt>
+         *  <dt>reloadInterval or maxRefreshDelay</dt>
          *  <dd>enables periodic refresh of remote file</dd>
          *  <dt>backingFilePath</dt>
          *  <dd>location for backup of remote resource</dd>
@@ -83,10 +87,11 @@ namespace xmltooling {
          *  <dd>requires XML be signed with an enveloped signature verifiable with specified TrustEngine</dd>
          * </dl>
          * 
-         * @param e     DOM to supply configuration
-         * @param log   logging object to use
+         * @param e                 DOM to supply configuration
+         * @param log               logging object to use
+         * @param startReloadThread true iff refresh thread for resources should be started by constructor
          */
-        ReloadableXMLFile(const xercesc::DOMElement* e, logging::Category& log);
+        ReloadableXMLFile(const xercesc::DOMElement* e, logging::Category& log, bool startReloadThread=true);
     
         virtual ~ReloadableXMLFile();
 
@@ -107,6 +112,7 @@ namespace xmltooling {
         virtual std::pair<bool,xercesc::DOMElement*> background_load();
 
         /**
+         * @deprecated
          * Basic load/parse of configuration material.
          * 
          * <p>The base version performs basic parsing duties and returns the result.
@@ -122,6 +128,23 @@ namespace xmltooling {
         virtual std::pair<bool,xercesc::DOMElement*> load();
 
         /**
+         * Basic load/parse of configuration material.
+         *
+         * <p>The base version performs basic parsing duties and returns the result.
+         * Subclasses should override the new background_load() method and perform
+         * their own locking in conjunction with use of this method.
+         *
+         * <p>This version allows subclasses to explicitly control the use of a
+         * backup for remote resources, which allows additional validation to be
+         * performed besides just successful XML parsing.
+         *
+         * @param backup    true iff the backup source should be loaded
+         * @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(bool backup);
+
+        /**
          * Accesses a lock interface protecting use of backup file associated with the
          * object.
          *
@@ -132,6 +155,18 @@ namespace xmltooling {
         virtual Lockable* getBackupLock();
 
         /**
+         * Preserves the last remote resource caching identifier in a backup file
+         * for use on the next restart.
+         */
+        void preserveCacheTag();
+
+        /**
+         * Starts up reload thread, can be automatically called by constructor, or
+         * manually invoked by subclass.
+         */
+        void startup();
+
+        /**
          * Shuts down reload thread, should be called from subclass destructor.
          */
         void shutdown();
@@ -151,12 +186,6 @@ namespace xmltooling {
         /** Path to backup copy for remote resource. */
         std::string m_backing;
 
-        /**
-         * Before load, indicates whether the backup is handled by the base class,
-         * after load, will be true iff it started false and a backup needs to be done.
-         */
-        bool m_backupIndicator;
-
         /** Last modification of local resource. */
         time_t m_filestamp;
 
@@ -175,6 +204,9 @@ namespace xmltooling {
         /** Plugin identifier. */
         std::string m_id;
 
+        /** Indicates whether a usable version of the resource is in place. */
+        bool m_loaded;
+
 #ifndef XMLTOOLING_LITE
         /** CredentialResolver for signature verification. */
         CredentialResolver* m_credResolver;
@@ -191,7 +223,6 @@ namespace xmltooling {
         void unlock();
 
     private:
-        std::pair<bool,xercesc::DOMElement*> load(bool backup);
 #ifndef XMLTOOLING_LITE
         void validateSignature(xmlsignature::Signature& sigObj) const;
 #endif