blob: 995ea487484a68e936212f872a791aec71b816a5 [file] [log] [blame]
weijia yuan82cf9142018-10-21 12:25:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventob691ba12025-01-02 23:55:16 -05003 * Copyright (c) 2014-2025, Regents of the University of California.
weijia yuan82cf9142018-10-21 12:25:02 -07004 *
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 yuan82cf9142018-10-21 12:25:02 -070024#include "repo-command.hpp"
Davide Pesaventob691ba12025-01-02 23:55:16 -050025#include "repo-command-parameter.hpp"
26#include "repo-command-response.hpp"
27#include "storage/repo-storage.hpp"
weijia yuan82cf9142018-10-21 12:25:02 -070028
29#include <ndn-cxx/mgmt/dispatcher.hpp>
Davide Pesavento11904062022-04-14 22:33:28 -040030#include <ndn-cxx/security/validator.hpp>
weijia yuan82cf9142018-10-21 12:25:02 -070031
32namespace repo {
33
34class CommandBaseHandle
35{
36public:
37 class Error : public std::runtime_error
38 {
39 public:
Davide Pesavento11904062022-04-14 22:33:28 -040040 using std::runtime_error::runtime_error;
weijia yuan82cf9142018-10-21 12:25:02 -070041 };
42
weijia yuan82cf9142018-10-21 12:25:02 -070043 ndn::mgmt::Authorization
44 makeAuthorization();
45
46 template<typename T>
47 bool
Davide Pesaventob691ba12025-01-02 23:55:16 -050048 validateParameters(const ndn::mgmt::ControlParametersBase& parameters) const
weijia yuan82cf9142018-10-21 12:25:02 -070049 {
Davide Pesaventob691ba12025-01-02 23:55:16 -050050 const auto& castParams = dynamic_cast<const RepoCommandParameter&>(parameters);
Davide Pesavento11904062022-04-14 22:33:28 -040051
weijia yuan82cf9142018-10-21 12:25:02 -070052 T command;
53 try {
Davide Pesaventob691ba12025-01-02 23:55:16 -050054 command.validateRequest(castParams);
weijia yuan82cf9142018-10-21 12:25:02 -070055 }
Davide Pesavento11904062022-04-14 22:33:28 -040056 catch (const RepoCommand::ArgumentError&) {
weijia yuan82cf9142018-10-21 12:25:02 -070057 return false;
58 }
59 return true;
60 }
61
62protected:
Davide Pesavento7df36bd2023-10-28 19:32:43 -040063 CommandBaseHandle(Face& face, RepoStorage& storageHandle,
64 Scheduler& scheduler, ndn::security::Validator& validator);
65
66 ~CommandBaseHandle() = default;
67
68protected:
weijia yuan82cf9142018-10-21 12:25:02 -070069 Face& face;
70 RepoStorage& storageHandle;
71 Scheduler& scheduler;
72
73private:
Davide Pesavento11904062022-04-14 22:33:28 -040074 ndn::security::Validator& m_validator;
weijia yuan82cf9142018-10-21 12:25:02 -070075};
Davide Pesavento11904062022-04-14 22:33:28 -040076
weijia yuan82cf9142018-10-21 12:25:02 -070077} // namespace repo
78
Davide Pesavento11904062022-04-14 22:33:28 -040079#endif // REPO_HANDLES_COMMAND_BASE_HANDLE_HPP