blob: 9e554674b3e2ffb7a7b33b85dd528124a8dd10b0 [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{
Tianyuan Yu13aac732022-03-03 20:59:54 -080032public:
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040033 virtual
34 ~RedirectionPolicy() = default;
Tianyuan Yu13aac732022-03-03 20:59:54 -080035
36 /**
37 * @brief The Redirection Policy provided by the CA operator to decide if redirection is suitable.
38 *
39 *
40 * @param vector A list of parameter key-value pair from probe.
41 * @return a boolean that is true if the provided params conform to the configured redirection policy.
42 */
43 virtual bool
44 isRedirecting(const std::multimap<std::string, std::string>& params) = 0;
45
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040046public: // factory
47 template<class PolicyType>
Tianyuan Yu13aac732022-03-03 20:59:54 -080048 static void
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040049 registerRedirectionPolicy(const std::string& type)
Tianyuan Yu13aac732022-03-03 20:59:54 -080050 {
51 PolicyFactory& factory = getFactory();
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040052 BOOST_ASSERT(factory.count(type) == 0);
53 factory[type] = [] (const std::string& format) { return std::make_unique<PolicyType>(format); };
Tianyuan Yu13aac732022-03-03 20:59:54 -080054 }
55
56 static std::unique_ptr<RedirectionPolicy>
57 createPolicyFunc(const std::string& policyType, const std::string& format = "");
58
59private:
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040060 using CreateFunc = std::function<std::unique_ptr<RedirectionPolicy>(const std::string &)>;
61 using PolicyFactory = std::map<std::string, CreateFunc>;
Tianyuan Yu13aac732022-03-03 20:59:54 -080062
63 static PolicyFactory&
64 getFactory();
65};
66
Tianyuan Yu13aac732022-03-03 20:59:54 -080067} // namespace ndncert
68
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040069#define NDNCERT_REGISTER_REDIRECTION_POLICY(C, T) \
70static class NdnCert##C##RedirectionPolicyRegistrationClass \
71{ \
72public: \
73 NdnCert##C##RedirectionPolicyRegistrationClass() \
74 { \
75 ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \
76 } \
77} g_NdnCert##C##RedirectionPolicyRegistrationVariable
78
Tianyuan Yu13aac732022-03-03 20:59:54 -080079#endif // NDNCERT_REDIRECTION_POLICY_HPP