Kea 2.5.5
config_ctl_info.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2021 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
33}
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 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 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 (ConfigDbInfoList::iterator db = db_infos_.begin();
75 db != db_infos_.end(); ++db) {
76 std::string db_value;
77 if (db->getParameterValue(param_name, db_value) &&
78 (param_value == db_value)) {
79 return (*db);
80 }
81 }
82
83 return (EMPTY_DB());
84}
85
86const ConfigDbInfo&
88 static ConfigDbInfo empty;
89 return (empty);
90}
91
92void
94 db_infos_.clear();
95 config_fetch_wait_time_ = Optional<uint16_t>(30, true);
96}
97
98void
100 if (!other.db_infos_.empty()) {
101 db_infos_ = other.db_infos_;
102 }
103}
104
107 ElementPtr result = Element::createMap();
108 ElementPtr db_list = Element::createList();
109 for (auto db_info : db_infos_) {
110 db_list->add(db_info.toElement());
111 }
112
113 result->set("config-databases", db_list);
114
115 if (!config_fetch_wait_time_.unspecified()) {
116 result->set("config-fetch-wait-time",
117 Element::create(static_cast<int>(config_fetch_wait_time_)));
118 }
119
120 return (result);
121}
122
123bool
125 return ((db_infos_ == other.db_infos_) &&
126 (config_fetch_wait_time_.get() == other.config_fetch_wait_time_.get()));
127}
128
129} // end of namespace isc::process
130} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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
Definition: edns.h:19
Defines the logger used by the top-level component of kea-lfc.