Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -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 | * |
| 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 25 | #ifndef NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
| 26 | #define NFD_DAEMON_MGMT_MANAGER_BASE_HPP |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 27 | |
| 28 | #include "common.hpp" |
| 29 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 30 | #include "mgmt/command-validator.hpp" |
| 31 | #include "mgmt/internal-face.hpp" |
| 32 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 33 | #include <ndn-cpp-dev/management/nfd-control-command.hpp> |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 34 | #include <ndn-cpp-dev/management/nfd-control-response.hpp> |
| 35 | #include <ndn-cpp-dev/management/nfd-control-parameters.hpp> |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 36 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 37 | namespace nfd { |
| 38 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 39 | using ndn::nfd::ControlCommand; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 40 | using ndn::nfd::ControlResponse; |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 41 | using ndn::nfd::ControlParameters; |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 42 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 43 | class InternalFace; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 44 | |
| 45 | class ManagerBase |
| 46 | { |
| 47 | public: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 49 | struct Error : public std::runtime_error |
| 50 | { |
| 51 | Error(const std::string& what) : std::runtime_error(what) {} |
| 52 | }; |
| 53 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 54 | ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 55 | |
| 56 | virtual |
| 57 | ~ManagerBase(); |
| 58 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 59 | void |
| 60 | onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 61 | const std::string& error); |
| 62 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 63 | protected: |
| 64 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 65 | static bool |
| 66 | extractParameters(const Name::Component& parameterComponent, |
| 67 | ControlParameters& extractedParameters); |
| 68 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 69 | void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 70 | setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 71 | uint32_t code, |
| 72 | const std::string& text); |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 73 | void |
| 74 | setResponse(ControlResponse& response, |
| 75 | uint32_t code, |
| 76 | const std::string& text, |
| 77 | const Block& body); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 78 | |
| 79 | void |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 80 | sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 81 | const ControlResponse& response); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 82 | |
| 83 | void |
| 84 | sendResponse(const Name& name, |
| 85 | uint32_t code, |
| 86 | const std::string& text); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 87 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 88 | void |
| 89 | sendResponse(const Name& name, |
| 90 | uint32_t code, |
| 91 | const std::string& text, |
| 92 | const Block& body); |
| 93 | |
Steve DiBenedetto | 51d242a | 2014-03-31 13:46:43 -0600 | [diff] [blame] | 94 | virtual bool |
| 95 | validateParameters(const ControlCommand& command, |
| 96 | ControlParameters& parameters); |
| 97 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 98 | PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
| 99 | void |
| 100 | addInterestRule(const std::string& regex, |
| 101 | const ndn::IdentityCertificate& certificate); |
| 102 | |
| 103 | void |
| 104 | addInterestRule(const std::string& regex, |
| 105 | const Name& keyName, |
| 106 | const ndn::PublicKey& publicKey); |
| 107 | |
| 108 | void |
| 109 | validate(const Interest& interest, |
| 110 | const ndn::OnInterestValidated& onValidated, |
| 111 | const ndn::OnInterestValidationFailed& onValidationFailed); |
| 112 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 113 | protected: |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 114 | shared_ptr<InternalFace> m_face; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 117 | inline void |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 118 | ManagerBase::setResponse(ControlResponse& response, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 119 | uint32_t code, |
| 120 | const std::string& text) |
| 121 | { |
| 122 | response.setCode(code); |
| 123 | response.setText(text); |
| 124 | } |
| 125 | |
Steve DiBenedetto | 2693db9 | 2014-02-10 15:58:36 -0700 | [diff] [blame] | 126 | inline void |
| 127 | ManagerBase::setResponse(ControlResponse& response, |
| 128 | uint32_t code, |
| 129 | const std::string& text, |
| 130 | const Block& body) |
| 131 | { |
| 132 | setResponse(response, code, text); |
| 133 | response.setBody(body); |
| 134 | } |
| 135 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 136 | inline void |
| 137 | ManagerBase::addInterestRule(const std::string& regex, |
| 138 | const ndn::IdentityCertificate& certificate) |
| 139 | { |
| 140 | m_face->getValidator().addInterestRule(regex, certificate); |
| 141 | } |
| 142 | |
| 143 | inline void |
| 144 | ManagerBase::addInterestRule(const std::string& regex, |
| 145 | const Name& keyName, |
| 146 | const ndn::PublicKey& publicKey) |
| 147 | { |
| 148 | m_face->getValidator().addInterestRule(regex, keyName, publicKey); |
| 149 | } |
| 150 | |
| 151 | inline void |
| 152 | ManagerBase::validate(const Interest& interest, |
| 153 | const ndn::OnInterestValidated& onValidated, |
| 154 | const ndn::OnInterestValidationFailed& onValidationFailed) |
| 155 | { |
| 156 | m_face->getValidator().validate(interest, onValidated, onValidationFailed); |
| 157 | } |
| 158 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 159 | |
Steve DiBenedetto | 80ddc21 | 2014-02-01 22:23:56 -0700 | [diff] [blame] | 160 | } // namespace nfd |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 161 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 162 | #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP |