blob: 462a7218ce58a6a67e4bb56a6dd333fdf6686bfc [file] [log] [blame]
Tianyuan Yu13aac732022-03-03 20:59:54 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento6866b902024-12-22 23:11:26 -05003 * Copyright (c) 2017-2024, Regents of the University of California.
Tianyuan Yu13aac732022-03-03 20:59:54 -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
21#ifndef NDNCERT_REDIRECTION_POLICY_HPP
22#define NDNCERT_REDIRECTION_POLICY_HPP
23
Davide Pesavento6866b902024-12-22 23:11:26 -050024#include "detail/ndncert-common.hpp"
Tianyuan Yu13aac732022-03-03 20:59:54 -080025
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.
Davide Pesavento6866b902024-12-22 23:11:26 -050038 * @param params A list of parameter key-value pairs from the probe.
39 * @return true if the provided @p params conform to the configured redirection policy.
Tianyuan Yu13aac732022-03-03 20:59:54 -080040 */
41 virtual bool
42 isRedirecting(const std::multimap<std::string, std::string>& params) = 0;
43
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040044public: // factory
45 template<class PolicyType>
Tianyuan Yu13aac732022-03-03 20:59:54 -080046 static void
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040047 registerRedirectionPolicy(const std::string& type)
Tianyuan Yu13aac732022-03-03 20:59:54 -080048 {
49 PolicyFactory& factory = getFactory();
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040050 BOOST_ASSERT(factory.count(type) == 0);
51 factory[type] = [] (const std::string& format) { return std::make_unique<PolicyType>(format); };
Tianyuan Yu13aac732022-03-03 20:59:54 -080052 }
53
54 static std::unique_ptr<RedirectionPolicy>
55 createPolicyFunc(const std::string& policyType, const std::string& format = "");
56
57private:
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040058 using CreateFunc = std::function<std::unique_ptr<RedirectionPolicy>(const std::string &)>;
59 using PolicyFactory = std::map<std::string, CreateFunc>;
Tianyuan Yu13aac732022-03-03 20:59:54 -080060
61 static PolicyFactory&
62 getFactory();
63};
64
Tianyuan Yu13aac732022-03-03 20:59:54 -080065} // namespace ndncert
66
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040067#define NDNCERT_REGISTER_REDIRECTION_POLICY(C, T) \
68static class NdnCert##C##RedirectionPolicyRegistrationClass \
69{ \
70public: \
71 NdnCert##C##RedirectionPolicyRegistrationClass() \
72 { \
73 ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \
74 } \
75} g_NdnCert##C##RedirectionPolicyRegistrationVariable
76
Tianyuan Yu13aac732022-03-03 20:59:54 -080077#endif // NDNCERT_REDIRECTION_POLICY_HPP