| Kea 3.0.2-git

config_ctl_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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 <cc/dhcp_config_error.h>
10#include <process/config_ctl_parser.h>
11#include <database/dbaccess_parser.h>
12#include <cstdint>
13#include <string>
14
15 using namespace isc;
16 using namespace isc::data;
17
18 namespace isc {
19 namespace process {
20
21 ConfigControlInfoPtr
22 ConfigControlParser::parse(const data::ConstElementPtr& config_control) {
23 ConfigControlInfoPtr ctl_info(new ConfigControlInfo());
24
25 try {
26 if (config_control->contains("config-databases")) {
27
28 auto elem = config_control->get("config-databases");
29 if (elem->getType() != Element::list) {
30 isc_throw (ConfigError, "config-databases must be a list ("
31 << elem->getPosition() << ")");
32 }
33
34 const std::vector<data::ElementPtr>& db_list = elem->listValue();
35 for (auto const& db : db_list) {
36 db::DbAccessParser parser;
37 std::string access_string;
38 parser.parse(access_string, db);
42 ctl_info->addConfigDatabase(access_string);
43 }
44 }
45
46 if (config_control->contains("config-fetch-wait-time")) {
47 auto config_fetch_wait_time = getInteger(config_control,
48 "config-fetch-wait-time",
49 0, 65535);
50 ctl_info->setConfigFetchWaitTime(static_cast<uint16_t>(config_fetch_wait_time));
51 }
52
53 } catch (const isc::ConfigError&) {
54 // Position was already added
55 throw;
56 } catch (const std::exception& ex) {
57 isc_throw(ConfigError, ex.what() << " ("
58 << config_control->getPosition() << ")");
59 }
60
61 return (ctl_info);
62}
63
64} // end of namespace isc::process
65} // end of namespace isc
66
Element::list
@ list
Definition data.h:146
isc::ConfigError
An exception that is thrown if an error occurs while configuring any server.
Definition dhcp_config_error.h:43
isc::data::SimpleParser::getInteger
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
Definition lib/cc/simple_parser.cc:77
isc::db::DbAccessParser
Parse Database Parameters.
Definition dbaccess_parser.h:25
isc::db::DbAccessParser::parse
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.
Definition dbaccess_parser.cc:33
isc::process::ConfigControlInfo
Embodies configuration information used during a server's configuration process.
Definition config_ctl_info.h:141
isc::process::ConfigControlParser::parse
ConfigControlInfoPtr parse(const data::ConstElementPtr &config_control)
Parses a configuration control Element.
Definition config_ctl_parser.cc:22
config_ctl_parser.h
dbaccess_parser.h
dhcp_config_error.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data
Definition base_stamped_element.cc:12
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::db
Definition audit_entry.cc:14
isc::process
Definition cb_ctl_base.h:22
isc::process::ConfigControlInfoPtr
boost::shared_ptr< ConfigControlInfo > ConfigControlInfoPtr
Defines a pointer to a ConfigControlInfo.
Definition config_ctl_info.h:239
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148