Moved ReplayCache into xmltooling
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReplayCache.h
diff --git a/xmltooling/util/ReplayCache.h b/xmltooling/util/ReplayCache.h
new file mode 100644 (file)
index 0000000..94fd22d
--- /dev/null
@@ -0,0 +1,66 @@
+/*\r
+ *  Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/**\r
+ * @file xmltooling/util/ReplayCache.h\r
+ * \r
+ * Helper class on top of StorageService for detecting message replay.\r
+ */\r
+\r
+#ifndef __xmltooling_replay_h__\r
+#define __xmltooling_replay_h__\r
+\r
+#include <xmltooling/util/StorageService.h>\r
+\r
+namespace xmltooling {\r
+\r
+    /**\r
+     * Helper class on top of StorageService for detecting message replay.\r
+     */\r
+    class XMLTOOL_API ReplayCache\r
+    {\r
+        MAKE_NONCOPYABLE(ReplayCache);\r
+    public:\r
+        \r
+        /**\r
+         * Creates a replay cache on top of a particular StorageService.\r
+         * \r
+         * @param storage       pointer to a StorageService, or NULL to keep cache in memory\r
+         */\r
+        ReplayCache(StorageService* storage=NULL);\r
+\r
+        virtual ~ReplayCache();\r
+        \r
+        /**\r
+         * Returns true iff the check value is not found in the cache, and stores it.\r
+         * \r
+         * @param context   a context label to subdivide the cache\r
+         * @param s         value to check\r
+         * @param expires   time for disposal of value from cache\r
+         */\r
+        virtual bool check(const char* context, const char* s, time_t expires);\r
+    \r
+        bool check(const char* context, const XMLCh* str, time_t expires) {\r
+            auto_ptr_char temp(str);\r
+            return check(context, temp.get(), expires);\r
+        }\r
+        \r
+    private:\r
+        StorageService* m_storage;\r
+    };\r
+};\r
+\r
+#endif /* __xmltooling_replay_h__ */\r