blob: bd94b187104cb93b0422483c2df847bc668abbf3 [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07001/* -*- 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 DiBenedetto042bfe92014-01-30 15:05:08 -07008
Steve DiBenedetto042bfe92014-01-30 15:05:08 -07009namespace nfd {
10
Steve DiBenedetto3970c892014-01-31 23:31:13 -070011NFD_LOG_INIT("ManagerBase");
12
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070013ManagerBase::ManagerBase(shared_ptr<InternalFace> face, const std::string& privilege)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070014 : m_face(face)
15{
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070016 face->getValidator().addSupportedPrivilege(privilege);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070017}
18
19ManagerBase::~ManagerBase()
20{
21
22}
23
24void
25ManagerBase::sendResponse(const Name& name,
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070026 uint32_t code,
27 const std::string& text)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070028{
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080029 ControlResponse response(code, text);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070030 sendResponse(name, response);
31}
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070032
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070033void
34ManagerBase::sendResponse(const Name& name,
Alexander Afanasyevd482fd32014-02-09 23:40:20 -080035 const ControlResponse& response)
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070036{
37 NFD_LOG_DEBUG("responding"
38 << " name: " << name
39 << " code: " << response.getCode()
40 << " text: " << response.getText());
Steve DiBenedetto3970c892014-01-31 23:31:13 -070041
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070042 const Block& encodedControl = response.wireEncode();
Steve DiBenedetto3970c892014-01-31 23:31:13 -070043
Steve DiBenedetto86fce8e2014-03-06 12:16:20 -070044 shared_ptr<Data> responseData(make_shared<Data>(name));
45 responseData->setContent(encodedControl);
Steve DiBenedetto0b73f442014-02-05 22:02:03 -070046
Steve DiBenedetto86fce8e2014-03-06 12:16:20 -070047 m_face->sign(*responseData);
48 m_face->put(*responseData);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070049}
50
Steve DiBenedetto2c2b8892014-02-27 11:46:48 -070051void
52ManagerBase::onCommandValidationFailed(const shared_ptr<const Interest>& command,
53 const std::string& error)
54{
55 NFD_LOG_INFO("command result: unauthorized verb: " << command);
56 sendResponse(command->getName(), 403, "Unauthorized command");
57}
58
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070059
60} // namespace nfd