Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 28 | namespace ndncert { |
| 29 | |
| 30 | class RedirectionPolicy : boost::noncopyable |
| 31 | { |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 32 | public: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 33 | virtual |
| 34 | ~RedirectionPolicy() = default; |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 35 | |
| 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 Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 46 | public: // factory |
| 47 | template<class PolicyType> |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 48 | static void |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 49 | registerRedirectionPolicy(const std::string& type) |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 50 | { |
| 51 | PolicyFactory& factory = getFactory(); |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 52 | BOOST_ASSERT(factory.count(type) == 0); |
| 53 | factory[type] = [] (const std::string& format) { return std::make_unique<PolicyType>(format); }; |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static std::unique_ptr<RedirectionPolicy> |
| 57 | createPolicyFunc(const std::string& policyType, const std::string& format = ""); |
| 58 | |
| 59 | private: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 60 | using CreateFunc = std::function<std::unique_ptr<RedirectionPolicy>(const std::string &)>; |
| 61 | using PolicyFactory = std::map<std::string, CreateFunc>; |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 62 | |
| 63 | static PolicyFactory& |
| 64 | getFactory(); |
| 65 | }; |
| 66 | |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 67 | } // namespace ndncert |
| 68 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 69 | #define NDNCERT_REGISTER_REDIRECTION_POLICY(C, T) \ |
| 70 | static class NdnCert##C##RedirectionPolicyRegistrationClass \ |
| 71 | { \ |
| 72 | public: \ |
| 73 | NdnCert##C##RedirectionPolicyRegistrationClass() \ |
| 74 | { \ |
| 75 | ::ndncert::RedirectionPolicy::registerRedirectionPolicy<C>(T); \ |
| 76 | } \ |
| 77 | } g_NdnCert##C##RedirectionPolicyRegistrationVariable |
| 78 | |
Tianyuan Yu | 13aac73 | 2022-03-03 20:59:54 -0800 | [diff] [blame] | 79 | #endif // NDNCERT_REDIRECTION_POLICY_HPP |