Kea 2.7.5
config_ctl_info.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>
9
10using namespace isc::data;
11using namespace isc::util;
12
13namespace isc {
14namespace process {
15
16void
17ConfigDbInfo::setAccessString(const std::string& access_str, bool test_mode) {
18 access_str_ = access_str;
19 access_params_.clear();
20 if (!test_mode) {
21 access_params_ = db::DatabaseConnection::parse(access_str_);
22 }
23}
24
25bool
27 return (access_params_ == other.access_params_);
28}
29
34
35bool
36ConfigDbInfo::getParameterValue(const std::string& name, std::string& value) const {
37 auto param = access_params_.find(name);
38 if (param == access_params_.end()) {
39 return (false);
40 }
41
42 value = param->second;
43 return (true);
44}
45
46//******** ConfigControlInfo ********//
47
49 : config_fetch_wait_time_(other.config_fetch_wait_time_) {
50 for (auto const& db : other.db_infos_) {
51 addConfigDatabase(db.getAccessString());
52 }
53}
54
55void
56ConfigControlInfo::addConfigDatabase(const std::string& access_str) {
57 ConfigDbInfo new_db;
58 new_db.setAccessString(access_str);
59
60 for (auto const& db : db_infos_) {
61 if (new_db == db) {
62 // we have a duplicate!
63 isc_throw(BadValue, "database with access parameters: "
64 << access_str << " already exists");
65 }
66 }
67
68 db_infos_.push_back(new_db);
69}
70
71const ConfigDbInfo&
72ConfigControlInfo::findConfigDb(const std::string& param_name,
73 const std::string& param_value) {
74 for (auto const& db : db_infos_) {
75 std::string db_value;
76 if (db.getParameterValue(param_name, db_value) && (param_value == db_value)) {
77 return (db);
78 }
79 }
80
81 return (EMPTY_DB());
82}
83
84const ConfigDbInfo&
86 static ConfigDbInfo empty;
87 return (empty);
88}
89
90void
92 db_infos_.clear();
93 config_fetch_wait_time_ = Optional<uint16_t>(30, true);
94}
95
96void
98 if (!other.db_infos_.empty()) {
99 db_infos_ = other.db_infos_;
100 }
101}
102
107 for (auto const& db_info : db_infos_) {
108 db_list->add(db_info.toElement());
109 }
110
111 result->set("config-databases", db_list);
112
113 if (!config_fetch_wait_time_.unspecified()) {
114 result->set("config-fetch-wait-time",
115 Element::create(static_cast<int>(config_fetch_wait_time_)));
116 }
117
118 return (result);
119}
120
121bool
123 return ((db_infos_ == other.db_infos_) &&
124 (config_fetch_wait_time_.get() == other.config_fetch_wait_time_.get()));
125}
126
127} // end of namespace isc::process
128} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
Embodies configuration information used during a server's configuration process.
static const ConfigDbInfo & EMPTY_DB()
Fetches the not-found value returned by database list searches.
void merge(const ConfigControlInfo &other)
Merges specified configuration into this configuration.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void addConfigDatabase(const std::string &access_str)
Sets configuration database access string.
bool equals(const ConfigControlInfo &other) const
Compares two objects for equality.
const ConfigDbInfo & findConfigDb(const std::string &param_name, const std::string &param_value)
Retrieves the database with the given access parameter value.
void clear()
Empties the contents of the class, including the database list.
Provides configuration information used during a server's configuration process.
bool equals(const ConfigDbInfo &other) const
Compares two objects for equality.
bool getParameterValue(const std::string &name, std::string &value) const
Fetch the value of a given parameter.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void setAccessString(const std::string &access_str, bool test_mode=false)
Set the access string.
T get() const
Retrieves the encapsulated value.
Definition optional.h:114
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
Definition optional.h:136
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
Defines the logger used by the top-level component of kea-lfc.