Kea  1.5.0
bin/agent/simple_parser.cc
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <agent/simple_parser.h>
10 #include <cc/data.h>
11 #include <cc/dhcp_config_error.h>
12 #include <hooks/hooks_parser.h>
13 #include <boost/foreach.hpp>
14 
15 using namespace isc::data;
16 
17 namespace isc {
18 namespace agent {
33 
37 const SimpleDefaults AgentSimpleParser::AGENT_DEFAULTS = {
38  { "http-host", Element::string, "127.0.0.1"},
39  { "http-port", Element::integer, "8000"}
40 };
41 
44 const SimpleDefaults AgentSimpleParser::SOCKET_DEFAULTS = {
45  { "socket-type", Element::string, "unix"}
46 };
47 
49 
53 
54 size_t AgentSimpleParser::setAllDefaults(const isc::data::ElementPtr& global) {
55  size_t cnt = 0;
56 
57  // Set global defaults first.
58  cnt = setDefaults(global, AGENT_DEFAULTS);
59 
60  // Now set the defaults for control-sockets, if any.
61  ConstElementPtr sockets = global->get("control-sockets");
62  if (sockets) {
63  ElementPtr d2 = boost::const_pointer_cast<Element>(sockets->get("d2"));
64  if (d2) {
65  cnt += SimpleParser::setDefaults(d2, SOCKET_DEFAULTS);
66  }
67 
68  ElementPtr d4 = boost::const_pointer_cast<Element>(sockets->get("dhcp4"));
69  if (d4) {
70  cnt += SimpleParser::setDefaults(d4, SOCKET_DEFAULTS);
71  }
72 
73  ElementPtr d6 = boost::const_pointer_cast<Element>(sockets->get("dhcp6"));
74  if (d6) {
75  cnt += SimpleParser::setDefaults(d6, SOCKET_DEFAULTS);
76  }
77  }
78 
79  return (cnt);
80 }
81 
82 void
83 AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
84  const isc::data::ConstElementPtr& config,
85  bool check_only) {
86 
87  // Let's get the HTTP parameters first.
88  ctx->setHttpHost(SimpleParser::getString(config, "http-host"));
89  ctx->setHttpPort(SimpleParser::getIntType<uint16_t>(config, "http-port"));
90 
91  // Control sockets are second.
92  ConstElementPtr ctrl_sockets = config->get("control-sockets");
93  if (ctrl_sockets) {
94  auto sockets_map = ctrl_sockets->mapValue();
95  for (auto cs = sockets_map.cbegin(); cs != sockets_map.cend(); ++cs) {
96  ctx->setControlSocketInfo(cs->second, cs->first);
97  }
98  }
99 
100  // User context can be done at anytime.
101  ConstElementPtr user_context = config->get("user-context");
102  if (user_context) {
103  ctx->setContext(user_context);
104  }
105 
106  // Finally, let's get the hook libs!
107 
108  using namespace isc::hooks;
109  HooksConfig& libraries = ctx->getHooksConfig();
110  ConstElementPtr hooks = config->get("hooks-libraries");
111  if (hooks) {
112  HooksLibrariesParser hooks_parser;
113  hooks_parser.parse(libraries, hooks);
114  libraries.verifyLibraries(hooks->getPosition());
115  }
116 
117  if (!check_only) {
118  // This occurs last as if it succeeds, there is no easy way
119  // revert it. As a result, the failure to commit a subsequent
120  // change causes problems when trying to roll back.
121  libraries.loadLibraries();
122  }
123 }
124 
125 };
126 };
Parser for hooks library list.
Definition: hooks_parser.h:21
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet)
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
Wrapper class that holds hooks libraries configuration.
Definition: hooks_config.h:36
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
Definition: hooks_config.cc:20
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
void loadLibraries() const
Commits hooks libraries configuration.
Definition: hooks_config.cc:55
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::hooks::HookLibsCollection & get() const
Provides access to the configured hooks libraries.
Definition: hooks_config.h:54
boost::shared_ptr< CtrlAgentCfgContext > CtrlAgentCfgContextPtr
Pointer to a configuration context.
Definition: ca_cfg_mgr.h:20
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Definition: hooks_parser.cc:28