blob: 97c7c18c72ba1df9e8e3c47cf6b945491f5377a2 [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
39 * \throws ConfigFile::Error on parse error
40 */
41 void
Steve DiBenedetto1a3c6732014-03-13 06:44:05 -060042 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070043
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
65private:
66 ndn::CommandInterestValidator m_validator;
67 std::set<std::string> m_supportedPrivileges;
68};
69
70inline void
71CommandValidator::addInterestRule(const std::string& regex,
72 const ndn::IdentityCertificate& certificate)
73{
74 m_validator.addInterestRule(regex, certificate);
75}
76
77inline void
78CommandValidator::addInterestRule(const std::string& regex,
79 const Name& keyName,
80 const ndn::PublicKey& publicKey)
81{
82 m_validator.addInterestRule(regex, keyName, publicKey);
83}
84
85inline void
86CommandValidator::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