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