blob: 290cabdfb2bca6c1cf1a60cde99776e183475ded [file] [log] [blame]
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -07001/* -*- 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
13namespace nfd {
14
15class CommandValidator
16{
17public:
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 DiBenedetto6214e562014-03-15 16:27:04 -060039 * \param filename filename of configuration file
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070040 * \throws ConfigFile::Error on parse error
41 */
42 void
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -060043 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070044
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
66private:
67 ndn::CommandInterestValidator m_validator;
68 std::set<std::string> m_supportedPrivileges;
69};
70
71inline void
72CommandValidator::addInterestRule(const std::string& regex,
73 const ndn::IdentityCertificate& certificate)
74{
75 m_validator.addInterestRule(regex, certificate);
76}
77
78inline void
79CommandValidator::addInterestRule(const std::string& regex,
80 const Name& keyName,
81 const ndn::PublicKey& publicKey)
82{
83 m_validator.addInterestRule(regex, keyName, publicKey);
84}
85
86inline void
87CommandValidator::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