Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_MGMT_COMMAND_VALIDATOR_HPP |
| 26 | #define NFD_MGMT_COMMAND_VALIDATOR_HPP |
| 27 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 28 | #include "common.hpp" |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 29 | #include "config-file.hpp" |
| 30 | #include <ndn-cpp-dev/util/command-interest-validator.hpp> |
| 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | class CommandValidator |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | class Error : public std::runtime_error |
| 39 | { |
| 40 | public: |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 41 | explicit |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 42 | Error(const std::string& what) |
| 43 | : std::runtime_error(what) |
| 44 | { |
| 45 | |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | CommandValidator(); |
| 50 | |
| 51 | ~CommandValidator(); |
| 52 | |
| 53 | void |
| 54 | setConfigFile(ConfigFile& configFile); |
| 55 | |
| 56 | /** |
| 57 | * \param section "authorizations" section to parse |
| 58 | * \param isDryRun true if performing a dry run of configuration, false otherwise |
Steve DiBenedetto | 6214e56 | 2014-03-15 16:27:04 -0600 | [diff] [blame] | 59 | * \param filename filename of configuration file |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 60 | * \throws ConfigFile::Error on parse error |
| 61 | */ |
| 62 | void |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame] | 63 | onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * \param privilege name of privilege to add |
| 67 | * \throws CommandValidator::Error on duplicated privilege |
| 68 | */ |
| 69 | void |
| 70 | addSupportedPrivilege(const std::string& privilege); |
| 71 | |
| 72 | void |
| 73 | addInterestRule(const std::string& regex, |
| 74 | const ndn::IdentityCertificate& certificate); |
| 75 | |
| 76 | void |
| 77 | addInterestRule(const std::string& regex, |
| 78 | const Name& keyName, |
| 79 | const ndn::PublicKey& publicKey); |
| 80 | |
| 81 | void |
| 82 | validate(const Interest& interest, |
| 83 | const ndn::OnInterestValidated& onValidated, |
| 84 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 85 | |
| 86 | private: |
| 87 | ndn::CommandInterestValidator m_validator; |
| 88 | std::set<std::string> m_supportedPrivileges; |
| 89 | }; |
| 90 | |
| 91 | inline void |
| 92 | CommandValidator::addInterestRule(const std::string& regex, |
| 93 | const ndn::IdentityCertificate& certificate) |
| 94 | { |
| 95 | m_validator.addInterestRule(regex, certificate); |
| 96 | } |
| 97 | |
| 98 | inline void |
| 99 | CommandValidator::addInterestRule(const std::string& regex, |
| 100 | const Name& keyName, |
| 101 | const ndn::PublicKey& publicKey) |
| 102 | { |
| 103 | m_validator.addInterestRule(regex, keyName, publicKey); |
| 104 | } |
| 105 | |
| 106 | inline void |
| 107 | CommandValidator::validate(const Interest& interest, |
| 108 | const ndn::OnInterestValidated& onValidated, |
| 109 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 110 | { |
| 111 | m_validator.validate(interest, onValidated, onValidationFailed); |
| 112 | } |
| 113 | |
| 114 | } // namespace nfd |
| 115 | |
| 116 | #endif // NFD_MGMT_COMMAND_VALIDATOR_HPP |