a95514dd540de3a113d2f99cab31ed8b3b94c755
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReplayCache.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/util/ReplayCache.h
19  * 
20  * Helper class on top of StorageService for detecting message replay.
21  */
22
23 #if !defined(__xmltooling_replay_h__) && !defined(XMLTOOLING_LITE)
24 #define __xmltooling_replay_h__
25
26 #include <xmltooling/base.h>
27
28 namespace xmltooling {
29
30     class XMLTOOL_API StorageService;
31
32     /**
33      * Helper class on top of StorageService for detecting message replay.
34      */
35     class XMLTOOL_API ReplayCache
36     {
37     MAKE_NONCOPYABLE(ReplayCache);
38     public:
39         
40         /**
41          * Creates a replay cache on top of a particular StorageService.
42          *
43          * The lifetime of the StorageService <strong>MUST</strong> be longer than
44          * the lifetime of the ReplayCache.
45          * 
46          * @param storage       pointer to a StorageService, or nullptr to keep cache in memory
47          */
48         ReplayCache(StorageService* storage=nullptr);
49
50         virtual ~ReplayCache();
51         
52         /**
53          * Returns true iff the check value is not found in the cache, and stores it.
54          * 
55          * @param context   a context label to subdivide the cache
56          * @param s         value to check
57          * @param expires   time for disposal of value from cache
58          */
59         virtual bool check(const char* context, const char* s, time_t expires);
60     
61         /**
62          * Returns true iff the check value is not found in the cache, and stores it.
63          * 
64          * @param context   a context label to subdivide the cache
65          * @param s         value to check
66          * @param expires   time for disposal of value from cache
67          */
68         bool check(const char* context, const XMLCh* s, time_t expires);
69         
70     private:
71         bool m_owned;
72         StorageService* m_storage;
73     };
74 };
75
76 #endif /* __xmltooling_replay_h__ */