blob: 40166cfcfe8b32801890b2a8a095b3de50b87a3c [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang74c61142020-10-07 21:00:49 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
Zhiyi Zhanga62bf982020-10-26 13:10:02 -070021#ifndef NDNCERT_DETAIL_CA_STORAGE_HPP
22#define NDNCERT_DETAIL_CA_STORAGE_HPP
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080023
Zhiyi Zhang34f03f02020-10-29 18:34:42 -070024#include "detail/ca-request-state.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080025
26namespace ndn {
27namespace ndncert {
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070028namespace ca {
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080029
30class CaStorage : noncopyable
31{
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070032public: // request related
Zhiyi Zhang21d52b52020-10-05 18:29:15 -070033 /**
34 * @throw if request cannot be fetched from underlying data storage
35 */
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070036 virtual RequestState
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -070037 getRequest(const RequestId& requestId) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080038
Zhiyi Zhang21d52b52020-10-05 18:29:15 -070039 /**
40 * @throw if there is an existing request with the same request ID
41 */
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080042 virtual void
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070043 addRequest(const RequestState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080044
45 virtual void
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070046 updateRequest(const RequestState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080047
48 virtual void
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -070049 deleteRequest(const RequestId& requestId) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080050
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070051 virtual std::list<RequestState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070052 listAllRequests() = 0;
53
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070054 virtual std::list<RequestState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070055 listAllRequests(const Name& caName) = 0;
56
Davide Pesavento08994782018-01-22 12:13:41 -050057public: // factory
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080058 template<class CaStorageType>
59 static void
60 registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
61 {
62 CaStorageFactory& factory = getFactory();
63 BOOST_ASSERT(factory.count(caStorageType) == 0);
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070064 factory[caStorageType] = [] (const Name& caName, const std::string& path) {
Zhiyi Zhang32437282020-10-10 16:15:37 -070065 return std::make_unique<CaStorageType>(caName, path);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080066 };
67 }
68
69 static unique_ptr<CaStorage>
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070070 createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
71
72 virtual
73 ~CaStorage() = default;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080074
75private:
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070076 using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080077 using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
78
79 static CaStorageFactory&
80 getFactory();
81};
82
83#define NDNCERT_REGISTER_CA_STORAGE(C) \
84static class NdnCert ## C ## CaStorageRegistrationClass \
85{ \
86public: \
87 NdnCert ## C ## CaStorageRegistrationClass() \
88 { \
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070089 ::ndn::ndncert::ca::CaStorage::registerCaStorage<C>(); \
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080090 } \
91} g_NdnCert ## C ## CaStorageRegistrationVariable
92
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070093} // namespace ca
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080094} // namespace ndncert
95} // namespace ndn
96
Zhiyi Zhanga62bf982020-10-26 13:10:02 -070097#endif // NDNCERT_DETAIL_CA_STORAGE_HPP