Leosac  0.8.0
Open Source Access Control
TcpNotifier.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "TcpNotifier.hpp"
21 #include "core/auth/Auth.hpp"
23 
24 using namespace Leosac;
25 using namespace Leosac::Module;
26 using namespace Leosac::Module::TCPNotifier;
27 
28 TCPNotifierModule::TCPNotifierModule(zmqpp::context &ctx, zmqpp::socket *pipe,
29  const boost::property_tree::ptree &cfg,
30  CoreUtilsPtr utils)
31  : BaseModule(ctx, pipe, cfg, utils)
32  , xmlnne_("") // fixme maybe: we don't have access to kernel config path at this
33  // point.
34 {
36 }
37 
39 {
40 }
41 
43 {
44  for (auto &&itr : config_.get_child("module_config"))
45  {
46  xmlnne_("instance", itr.first);
47  std::vector<std::string> auth_sources;
48  std::vector<std::string> connects;
49  std::vector<std::string> binds;
50 
51  for (auto &&srcs : itr.second.get_child("sources"))
52  {
53  xmlnne_("source", srcs.first);
54  auto name = srcs.second.get<std::string>("");
55  auth_sources.push_back(name);
56  }
57 
58  if (itr.second.get_child_optional("connect"))
59  {
60  for (auto &&srcs : itr.second.get_child("connect"))
61  {
62  xmlnne_("endpoint", srcs.first);
63  auto name = srcs.second.get<std::string>("");
64  connects.push_back(name);
65  }
66  }
67 
68  if (itr.second.get_child_optional("bind"))
69  {
70  for (auto &&srcs : itr.second.get_child("bind"))
71  {
72  xmlnne_("endpoint", srcs.first);
73  auto name = srcs.second.get<std::string>("");
74  binds.push_back(name);
75  }
76  }
77 
78  if (!(connects.empty() || binds.empty()))
79  {
80  ERROR("Bind or connect. Not both !");
81  continue;
82  }
83 
84  Tools::PropertyTreeExtractor extractor(itr.second, "TCP-Notifier");
85  int protocol_id = extractor.get<int>("protocol");
86  auto protocol = ProtocolHandler::create(protocol_id);
87 
88  if (!protocol)
89  {
90  ERROR("Cannot instanciate a protocol number " << protocol_id);
91  continue;
92  }
93  auto ni = std::make_unique<NotifierInstance>(
94  ctx_, reactor_, auth_sources, connects, binds, std::move(protocol));
95  instances_.push_back(std::move(ni));
96  }
97 }
Leosac::Module::TCPNotifier::ProtocolHandler::create
static ProtocolHandlerUPtr create(int protocol_id)
Create an instance of a protocol handler depending on the requested protocol id.
Definition: ProtocolHandler.cpp:27
Leosac::Module::TCPNotifier::TCPNotifierModule::xmlnne_
Tools::XmlNodeNameEnforcer xmlnne_
Definition: TcpNotifier.hpp:52
Leosac::Module::BaseModule
Base class for module implementation.
Definition: BaseModule.hpp:110
Leosac::Tools::PropertyTreeExtractor::get
T get(const std::string &node_name)
Extract a mandatory property from the tree.
Definition: PropertyTreeExtractor.cpp:36
ERROR
@ ERROR
Definition: log.hpp:32
Auth.hpp
Leosac::Module::TCPNotifier::TCPNotifierModule::process_config
void process_config()
Process the configuration file.
Definition: TcpNotifier.cpp:42
Leosac::Module
All modules that provides features to Leosac shall be in this namespace.
PropertyTreeExtractor.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::TCPNotifier::TCPNotifierModule::~TCPNotifierModule
~TCPNotifierModule()
Definition: TcpNotifier.cpp:38
Leosac::Module::BaseModule::config_
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
Definition: BaseModule.hpp:193
Leosac::Module::BaseModule::reactor_
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
Definition: BaseModule.hpp:214
Leosac::Module::TCPNotifier
Definition: NotifierInstance.hpp:33
Leosac::Module::TCPNotifier::TCPNotifierModule::instances_
std::vector< NotifierInstanceUPtr > instances_
Definition: TcpNotifier.hpp:51
Leosac::Tools::PropertyTreeExtractor
This class is a simpler helper to extract value from a property tree.
Definition: PropertyTreeExtractor.hpp:38
Leosac::Module::TCPNotifier::TCPNotifierModule::TCPNotifierModule
TCPNotifierModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Definition: TcpNotifier.cpp:28
Leosac::Module::BaseModule::ctx_
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
Definition: BaseModule.hpp:183
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
TcpNotifier.hpp