2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Example implementation of memory cache for crl.
22 #ifndef _CRL_MEMORY_CACHE_H_
23 #define _CRL_MEMORY_CACHE_H_
32 typedef std::vector<char> BinaryBuffer;
34 typedef struct CrlRecord_t {
39 typedef std::map<std::string,CrlRecord> MemoryCache;
41 void memoryCacheWrite(
42 const char *distributionPoint,
45 time_t nextUpdateTime,
48 MemoryCache *cache = static_cast<MemoryCache*>(userParam);
51 record.buffer.resize(bodySize);
52 memcpy(&record.buffer[0], body, bodySize);
53 record.nextUpdate = nextUpdateTime;
55 cache->insert(std::make_pair(std::string(distributionPoint),record));
59 const char *distributorPoint,
62 time_t *nextUpdateTime,
65 MemoryCache *cache = static_cast<MemoryCache*>(userParam);
66 auto iter = cache->find(distributorPoint);
67 if (iter == cache->end()) {
70 CrlRecord record = iter->second;
71 *bodySize = record.buffer.size();
72 *body = new char[*bodySize];
73 memcpy(*body, &record.buffer[0], *bodySize);
74 *nextUpdateTime = record.nextUpdate;
85 #endif // _CRL_MEMORY_CACHE_H_