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
10#include <cc/data.h>
12#include <hooks/hooks_parser.h>
13#include <boost/foreach.hpp>
14
15using namespace isc::data;
16
17namespace isc {
18namespace agent {
33
38 { "http-host", Element::string, "127.0.0.1"},
39 { "http-port", Element::integer, "8000"}
40};
41
45 { "socket-type", Element::string, "unix"}
46};
47
49
53
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) {
66 }
67
68 ElementPtr d4 = boost::const_pointer_cast<Element>(sockets->get("dhcp4"));
69 if (d4) {
71 }
72
73 ElementPtr d6 = boost::const_pointer_cast<Element>(sockets->get("dhcp6"));
74 if (d6) {
76 }
77 }
78
79 return (cnt);
80}
81
82void
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};
static const isc::data::SimpleDefaults SOCKET_DEFAULTS
This table defines default values for control sockets.
static const isc::data::SimpleDefaults AGENT_DEFAULTS
This table defines default values for global options.
void parse(const CtrlAgentCfgContextPtr &ctx, const isc::data::ConstElementPtr &config, bool check_only)
Parses the control agent configuration.
static size_t setAllDefaults(const isc::data::ElementPtr &global)
Sets all defaults for Control Agent configuration.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
Wrapper class that holds hooks libraries configuration.
Definition: hooks_config.h:36
const isc::hooks::HookLibsCollection & get() const
Provides access to the configured hooks libraries.
Definition: hooks_config.h:54
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
Definition: hooks_config.cc:20
void loadLibraries() const
Commits hooks libraries configuration.
Definition: hooks_config.cc:55
Parser for hooks library list.
Definition: hooks_parser.h:21
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Definition: hooks_parser.cc:28
boost::shared_ptr< CtrlAgentCfgContext > CtrlAgentCfgContextPtr
Pointer to a configuration context.
Definition: ca_cfg_mgr.h:22
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
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:22
Defines the logger used by the top-level component of kea-dhcp-ddns.