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 | #include "manager-base.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 8 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 9 | namespace nfd { |
| 10 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 11 | NFD_LOG_INIT("ManagerBase"); |
| 12 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 13 | ManagerBase::ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 14 | : m_face(face) |
| 15 | { |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 16 | face->getValidator().addSupportedPrivilege(privilege); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | ManagerBase::~ManagerBase() |
| 20 | { |
| 21 | |
| 22 | } |
| 23 | |
| 24 | void |
| 25 | ManagerBase::sendResponse(const Name& name, |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 26 | uint32_t code, |
| 27 | const std::string& text) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 28 | { |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 29 | ControlResponse response(code, text); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 30 | sendResponse(name, response); |
| 31 | } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 32 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 33 | void |
| 34 | ManagerBase::sendResponse(const Name& name, |
Alexander Afanasyev | d482fd3 | 2014-02-09 23:40:20 -0800 | [diff] [blame] | 35 | const ControlResponse& response) |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 36 | { |
| 37 | NFD_LOG_DEBUG("responding" |
| 38 | << " name: " << name |
| 39 | << " code: " << response.getCode() |
| 40 | << " text: " << response.getText()); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 41 | |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 42 | const Block& encodedControl = response.wireEncode(); |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame] | 43 | |
Steve DiBenedetto | 86fce8e | 2014-03-06 12:16:20 -0700 | [diff] [blame] | 44 | shared_ptr<Data> responseData(make_shared<Data>(name)); |
| 45 | responseData->setContent(encodedControl); |
Steve DiBenedetto | 0b73f44 | 2014-02-05 22:02:03 -0700 | [diff] [blame] | 46 | |
Steve DiBenedetto | 86fce8e | 2014-03-06 12:16:20 -0700 | [diff] [blame] | 47 | m_face->sign(*responseData); |
| 48 | m_face->put(*responseData); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 51 | void |
| 52 | ManagerBase::onCommandValidationFailed(const shared_ptr<const Interest>& command, |
| 53 | const std::string& error) |
| 54 | { |
Steve DiBenedetto | 9dcc633 | 2014-03-12 16:50:59 -0600 | [diff] [blame] | 55 | NFD_LOG_INFO("command result: unauthorized command: " << *command); |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 56 | sendResponse(command->getName(), 403, "Unauthorized command"); |
| 57 | } |
| 58 | |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 59 | |
| 60 | } // namespace nfd |