blob: 01627963a03d8a92423975e23a1b54e6df556e90 [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
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060010#include "common.hpp"
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070011#include "config-file.hpp"
12#include <ndn-cpp-dev/util/command-interest-validator.hpp>
13
14namespace nfd {
15
16class CommandValidator
17{
18public:
19
20 class Error : public std::runtime_error
21 {
22 public:
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060023 explicit
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070024 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 DiBenedetto6214e562014-03-15 16:27:04 -060041 * \param filename filename of configuration file
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070042 * \throws ConfigFile::Error on parse error
43 */
44 void
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -060045 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070046
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
68private:
69 ndn::CommandInterestValidator m_validator;
70 std::set<std::string> m_supportedPrivileges;
71};
72
73inline void
74CommandValidator::addInterestRule(const std::string& regex,
75 const ndn::IdentityCertificate& certificate)
76{
77 m_validator.addInterestRule(regex, certificate);
78}
79
80inline void
81CommandValidator::addInterestRule(const std::string& regex,
82 const Name& keyName,
83 const ndn::PublicKey& publicKey)
84{
85 m_validator.addInterestRule(regex, keyName, publicKey);
86}
87
88inline void
89CommandValidator::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