blob: b2cb184e26556d2109b325cda8ded1e19757b6d8 [file] [log] [blame]
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 DiBenedetto2c2b8892014-02-27 11:46:48 -070024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_MGMT_COMMAND_VALIDATOR_HPP
26#define NFD_DAEMON_MGMT_COMMAND_VALIDATOR_HPP
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070027
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060028#include "common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070029#include "config-file.hpp"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070030#include <ndn-cxx/util/command-interest-validator.hpp>
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070031
32namespace nfd {
33
34class CommandValidator
35{
36public:
37
38 class Error : public std::runtime_error
39 {
40 public:
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060041 explicit
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070042 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 DiBenedetto6214e562014-03-15 16:27:04 -060059 * \param filename filename of configuration file
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070060 * \throws ConfigFile::Error on parse error
61 */
62 void
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -060063 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070064
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
86private:
87 ndn::CommandInterestValidator m_validator;
88 std::set<std::string> m_supportedPrivileges;
89};
90
91inline void
92CommandValidator::addInterestRule(const std::string& regex,
93 const ndn::IdentityCertificate& certificate)
94{
95 m_validator.addInterestRule(regex, certificate);
96}
97
98inline void
99CommandValidator::addInterestRule(const std::string& regex,
100 const Name& keyName,
101 const ndn::PublicKey& publicKey)
102{
103 m_validator.addInterestRule(regex, keyName, publicKey);
104}
105
106inline void
107CommandValidator::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
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700116#endif // NFD_DAEMON_MGMT_COMMAND_VALIDATOR_HPP