Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_MGMT_COMMAND_VALIDATOR_HPP |
| 8 | #define NFD_MGMT_COMMAND_VALIDATOR_HPP |
| 9 | |
| 10 | #include "config-file.hpp" |
| 11 | #include <ndn-cpp-dev/util/command-interest-validator.hpp> |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | class CommandValidator |
| 16 | { |
| 17 | public: |
| 18 | |
| 19 | class Error : public std::runtime_error |
| 20 | { |
| 21 | public: |
| 22 | Error(const std::string& what) |
| 23 | : std::runtime_error(what) |
| 24 | { |
| 25 | |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | CommandValidator(); |
| 30 | |
| 31 | ~CommandValidator(); |
| 32 | |
| 33 | void |
| 34 | setConfigFile(ConfigFile& configFile); |
| 35 | |
| 36 | /** |
| 37 | * \param section "authorizations" section to parse |
| 38 | * \param isDryRun true if performing a dry run of configuration, false otherwise |
Steve DiBenedetto | 6214e56 | 2014-03-15 16:27:04 -0600 | [diff] [blame] | 39 | * \param filename filename of configuration file |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 40 | * \throws ConfigFile::Error on parse error |
| 41 | */ |
| 42 | void |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame] | 43 | onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * \param privilege name of privilege to add |
| 47 | * \throws CommandValidator::Error on duplicated privilege |
| 48 | */ |
| 49 | void |
| 50 | addSupportedPrivilege(const std::string& privilege); |
| 51 | |
| 52 | void |
| 53 | addInterestRule(const std::string& regex, |
| 54 | const ndn::IdentityCertificate& certificate); |
| 55 | |
| 56 | void |
| 57 | addInterestRule(const std::string& regex, |
| 58 | const Name& keyName, |
| 59 | const ndn::PublicKey& publicKey); |
| 60 | |
| 61 | void |
| 62 | validate(const Interest& interest, |
| 63 | const ndn::OnInterestValidated& onValidated, |
| 64 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 65 | |
| 66 | private: |
| 67 | ndn::CommandInterestValidator m_validator; |
| 68 | std::set<std::string> m_supportedPrivileges; |
| 69 | }; |
| 70 | |
| 71 | inline void |
| 72 | CommandValidator::addInterestRule(const std::string& regex, |
| 73 | const ndn::IdentityCertificate& certificate) |
| 74 | { |
| 75 | m_validator.addInterestRule(regex, certificate); |
| 76 | } |
| 77 | |
| 78 | inline void |
| 79 | CommandValidator::addInterestRule(const std::string& regex, |
| 80 | const Name& keyName, |
| 81 | const ndn::PublicKey& publicKey) |
| 82 | { |
| 83 | m_validator.addInterestRule(regex, keyName, publicKey); |
| 84 | } |
| 85 | |
| 86 | inline void |
| 87 | CommandValidator::validate(const Interest& interest, |
| 88 | const ndn::OnInterestValidated& onValidated, |
| 89 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 90 | { |
| 91 | m_validator.validate(interest, onValidated, onValidationFailed); |
| 92 | } |
| 93 | |
| 94 | } // namespace nfd |
| 95 | |
| 96 | #endif // NFD_MGMT_COMMAND_VALIDATOR_HPP |