weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, Regents of the University of California. |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef REPO_HANDLES_COMMAND_BASE_HANDLE_HPP |
| 21 | #define REPO_HANDLES_COMMAND_BASE_HANDLE_HPP |
| 22 | |
| 23 | #include "common.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 24 | #include "repo-command.hpp" |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 25 | #include "repo-command-parameter.hpp" |
| 26 | #include "repo-command-response.hpp" |
| 27 | #include "storage/repo-storage.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 28 | |
| 29 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 30 | #include <ndn-cxx/security/validator.hpp> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 31 | |
| 32 | namespace repo { |
| 33 | |
| 34 | class CommandBaseHandle |
| 35 | { |
| 36 | public: |
| 37 | class Error : public std::runtime_error |
| 38 | { |
| 39 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 40 | using std::runtime_error::runtime_error; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 43 | ndn::mgmt::Authorization |
| 44 | makeAuthorization(); |
| 45 | |
| 46 | template<typename T> |
| 47 | bool |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 48 | validateParameters(const ndn::mgmt::ControlParametersBase& parameters) const |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 49 | { |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 50 | const auto& castParams = dynamic_cast<const RepoCommandParameter&>(parameters); |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 51 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 52 | T command; |
| 53 | try { |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 54 | command.validateRequest(castParams); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 55 | } |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 56 | catch (const RepoCommand::ArgumentError&) { |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 57 | return false; |
| 58 | } |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | protected: |
Davide Pesavento | 7df36bd | 2023-10-28 19:32:43 -0400 | [diff] [blame] | 63 | CommandBaseHandle(Face& face, RepoStorage& storageHandle, |
| 64 | Scheduler& scheduler, ndn::security::Validator& validator); |
| 65 | |
| 66 | ~CommandBaseHandle() = default; |
| 67 | |
| 68 | protected: |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 69 | Face& face; |
| 70 | RepoStorage& storageHandle; |
| 71 | Scheduler& scheduler; |
| 72 | |
| 73 | private: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 74 | ndn::security::Validator& m_validator; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 75 | }; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 76 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 77 | } // namespace repo |
| 78 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 79 | #endif // REPO_HANDLES_COMMAND_BASE_HANDLE_HPP |