gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReplayCache.h
1 /*
2  *  Copyright 2001-2006 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 #ifndef __xmltooling_replay_h__
24 #define __xmltooling_replay_h__
25
26 #include <xmltooling/util/StorageService.h>
27
28 namespace xmltooling {
29
30     /**
31      * Helper class on top of StorageService for detecting message replay.
32      */
33     class XMLTOOL_API ReplayCache
34     {
35         MAKE_NONCOPYABLE(ReplayCache);
36     public:
37         
38         /**
39          * Creates a replay cache on top of a particular StorageService.
40          * 
41          * @param storage       pointer to a StorageService, or NULL to keep cache in memory
42          */
43         ReplayCache(StorageService* storage=NULL);
44
45         virtual ~ReplayCache();
46         
47         /**
48          * Returns true iff the check value is not found in the cache, and stores it.
49          * 
50          * @param context   a context label to subdivide the cache
51          * @param s         value to check
52          * @param expires   time for disposal of value from cache
53          */
54         virtual bool check(const char* context, const char* s, time_t expires);
55     
56         bool check(const char* context, const XMLCh* str, time_t expires) {
57             auto_ptr_char temp(str);
58             return check(context, temp.get(), expires);
59         }
60         
61     private:
62         StorageService* m_storage;
63     };
64 };
65
66 #endif /* __xmltooling_replay_h__ */