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