blob: cba0cd8bc56cd665ea76015150314eb4d911a767 [file] [log] [blame]
Tianyuan Yu13aac732022-03-03 20:59:54 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2017-2022, Regents of the University of California.
4 *
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
21#ifndef NDNCERT_REDIRECTION_POLICY_HPP
22#define NDNCERT_REDIRECTION_POLICY_HPP
23
24#include "detail/ca-request-state.hpp"
25
26#include <map>
27
28namespace ndncert {
29
30class RedirectionPolicy : boost::noncopyable
31{
32protected:
33 explicit RedirectionPolicy(const std::string& format = "") {}
34
35public:
36 virtual ~RedirectionPolicy() = default;
37
38 /**
39 * @brief The Redirection Policy provided by the CA operator to decide if redirection is suitable.
40 *
41 *
42 * @param vector A list of parameter key-value pair from probe.
43 * @return a boolean that is true if the provided params conform to the configured redirection policy.
44 */
45 virtual bool
46 isRedirecting(const std::multimap<std::string, std::string>& params) = 0;
47
48public:
49 template <class PolicyType>
50 static void
51 registerRedirectionPolicy(const std::string& typeName)
52 {
53 PolicyFactory& factory = getFactory();
54 BOOST_ASSERT(factory.count(typeName) == 0);
55 factory[typeName] = [](const std::string& format) { return std::make_unique<PolicyType>(format); };
56 }
57
58 static std::unique_ptr<RedirectionPolicy>
59 createPolicyFunc(const std::string& policyType, const std::string& format = "");
60
61private:
62 typedef std::function<std::unique_ptr<RedirectionPolicy>(const std::string&)> FactoryCreateFunc;
63 typedef std::map<std::string, FactoryCreateFunc> PolicyFactory;
64
65 static PolicyFactory&
66 getFactory();
67};
68
69#define NDNCERT_REGISTER_POLICY_FACTORY(C, T) \
70 static class NdnCert##C##PolicyFactoryRegistrationClass \
71 { \
72 public: \
73 NdnCert##C##PolicyFactoryRegistrationClass() \
74 { \
75 ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \
76 } \
77 } g_NdnCert##C##RedirectionPolicyRegistrationVariable
78
79} // namespace ndncert
80
81#endif // NDNCERT_REDIRECTION_POLICY_HPP