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 |
| 39 | * \throws ConfigFile::Error on parse error |
| 40 | */ |
| 41 | void |
Steve DiBenedetto | 1a3c673 | 2014-03-13 06:44:05 -0600 | [diff] [blame^] | 42 | onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * \param privilege name of privilege to add |
| 46 | * \throws CommandValidator::Error on duplicated privilege |
| 47 | */ |
| 48 | void |
| 49 | addSupportedPrivilege(const std::string& privilege); |
| 50 | |
| 51 | void |
| 52 | addInterestRule(const std::string& regex, |
| 53 | const ndn::IdentityCertificate& certificate); |
| 54 | |
| 55 | void |
| 56 | addInterestRule(const std::string& regex, |
| 57 | const Name& keyName, |
| 58 | const ndn::PublicKey& publicKey); |
| 59 | |
| 60 | void |
| 61 | validate(const Interest& interest, |
| 62 | const ndn::OnInterestValidated& onValidated, |
| 63 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 64 | |
| 65 | private: |
| 66 | ndn::CommandInterestValidator m_validator; |
| 67 | std::set<std::string> m_supportedPrivileges; |
| 68 | }; |
| 69 | |
| 70 | inline void |
| 71 | CommandValidator::addInterestRule(const std::string& regex, |
| 72 | const ndn::IdentityCertificate& certificate) |
| 73 | { |
| 74 | m_validator.addInterestRule(regex, certificate); |
| 75 | } |
| 76 | |
| 77 | inline void |
| 78 | CommandValidator::addInterestRule(const std::string& regex, |
| 79 | const Name& keyName, |
| 80 | const ndn::PublicKey& publicKey) |
| 81 | { |
| 82 | m_validator.addInterestRule(regex, keyName, publicKey); |
| 83 | } |
| 84 | |
| 85 | inline void |
| 86 | CommandValidator::validate(const Interest& interest, |
| 87 | const ndn::OnInterestValidated& onValidated, |
| 88 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 89 | { |
| 90 | m_validator.validate(interest, onValidated, onValidationFailed); |
| 91 | } |
| 92 | |
| 93 | } // namespace nfd |
| 94 | |
| 95 | #endif // NFD_MGMT_COMMAND_VALIDATOR_HPP |