Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 3 | * 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 | * The University of Memphis |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 24 | */ |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
| 27 | #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 28 | |
| 29 | #include "common.hpp" |
| 30 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 31 | #include "mgmt/command-validator.hpp" |
| 32 | #include "mgmt/internal-face.hpp" |
| 33 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 34 | #include <ndn-cxx/management/nfd-control-command.hpp> |
| 35 | #include <ndn-cxx/management/nfd-control-response.hpp> |
| 36 | #include <ndn-cxx/management/nfd-control-parameters.hpp> |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 37 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 38 | namespace nfd { |
| 39 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 40 | using ndn::nfd::ControlCommand; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 41 | using ndn::nfd::ControlResponse; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 42 | using ndn::nfd::ControlParameters; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 43 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 44 | class InternalFace; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 45 | |
| 46 | class ManagerBase |
| 47 | { |
| 48 | public: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 50 | struct Error : public std::runtime_error |
| 51 | { |
| 52 | Error(const std::string& what) : std::runtime_error(what) {} |
| 53 | }; |
| 54 | |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 55 | ManagerBase(shared_ptr<InternalFace> face, |
| 56 | const std::string& privilege, |
| 57 | ndn::KeyChain& keyChain); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 58 | |
| 59 | virtual |
| 60 | ~ManagerBase(); |
| 61 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 62 | void |
| 63 | onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 64 | const std::string& error); |
| 65 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 66 | protected: |
| 67 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 68 | static bool |
| 69 | extractParameters(const Name::Component& parameterComponent, |
| 70 | ControlParameters& extractedParameters); |
| 71 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 72 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 73 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 74 | uint32_t code, |
| 75 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 76 | void |
| 77 | setResponse(ControlResponse& response, |
| 78 | uint32_t code, |
| 79 | const std::string& text, |
| 80 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 81 | |
| 82 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 83 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 84 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 85 | |
| 86 | void |
| 87 | sendResponse(const Name& name, |
| 88 | uint32_t code, |
| 89 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 90 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 91 | void |
| 92 | sendResponse(const Name& name, |
| 93 | uint32_t code, |
| 94 | const std::string& text, |
| 95 | const Block& body); |
| 96 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 97 | virtual bool |
| 98 | validateParameters(const ControlCommand& command, |
| 99 | ControlParameters& parameters); |
| 100 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 101 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 102 | void |
| 103 | addInterestRule(const std::string& regex, |
| 104 | const ndn::IdentityCertificate& certificate); |
| 105 | |
| 106 | void |
| 107 | addInterestRule(const std::string& regex, |
| 108 | const Name& keyName, |
| 109 | const ndn::PublicKey& publicKey); |
| 110 | |
| 111 | void |
| 112 | validate(const Interest& interest, |
| 113 | const ndn::OnInterestValidated& onValidated, |
| 114 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 115 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 116 | protected: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 117 | shared_ptr<InternalFace> m_face; |
Vince Lehman | 5144f82 | 2014-07-23 15:12:56 -0700 | [diff] [blame] | 118 | ndn::KeyChain& m_keyChain; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 121 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 122 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 123 | uint32_t code, |
| 124 | const std::string& text) |
| 125 | { |
| 126 | response.setCode(code); |
| 127 | response.setText(text); |
| 128 | } |
| 129 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 130 | inline void |
| 131 | ManagerBase::setResponse(ControlResponse& response, |
| 132 | uint32_t code, |
| 133 | const std::string& text, |
| 134 | const Block& body) |
| 135 | { |
| 136 | setResponse(response, code, text); |
| 137 | response.setBody(body); |
| 138 | } |
| 139 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 140 | inline void |
| 141 | ManagerBase::addInterestRule(const std::string& regex, |
| 142 | const ndn::IdentityCertificate& certificate) |
| 143 | { |
| 144 | m_face->getValidator().addInterestRule(regex, certificate); |
| 145 | } |
| 146 | |
| 147 | inline void |
| 148 | ManagerBase::addInterestRule(const std::string& regex, |
| 149 | const Name& keyName, |
| 150 | const ndn::PublicKey& publicKey) |
| 151 | { |
| 152 | m_face->getValidator().addInterestRule(regex, keyName, publicKey); |
| 153 | } |
| 154 | |
| 155 | inline void |
| 156 | ManagerBase::validate(const Interest& interest, |
| 157 | const ndn::OnInterestValidated& onValidated, |
| 158 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 159 | { |
| 160 | m_face->getValidator().validate(interest, onValidated, onValidationFailed); |
| 161 | } |
| 162 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 163 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 164 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 166 | #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP |