Kea 1.5.0
config_ctl_info.cc
Go to the documentation of this file.
1// Copyright (C) 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>
9
10using namespace isc::data;
11
12namespace isc {
13namespace process {
14
15void
16ConfigDbInfo::setAccessString(const std::string& access_str) {
17 access_str_ = access_str;
18 access_params_.clear();
19 access_params_ = db::DatabaseConnection::parse(access_str_);
20}
21
22bool
24 return (access_params_ == other.access_params_);
25}
26
30}
31
32bool
33ConfigDbInfo::getParameterValue(const std::string& name, std::string& value) const {
34 auto param = access_params_.find(name);
35 if (param == access_params_.end()) {
36 return(false);
37 }
38
39 value = param->second;
40 return(true);
41}
42
43//********* ConfiControlInfo ************//
44
46 for (auto db : other.db_infos_) {
47 addConfigDatabase(db.getAccessString());
48 }
49}
50
51void
52ConfigControlInfo::addConfigDatabase(const std::string& access_str) {
53 ConfigDbInfo new_db;
54 new_db.setAccessString(access_str);
55
56 for (auto db : db_infos_) {
57 if (new_db == db) {
58 // we have a duplicate!
59 isc_throw(BadValue, "database with access parameters: "
60 << access_str << " already exists");
61 }
62 }
63
64 db_infos_.push_back(new_db);
65}
66
67const ConfigDbInfo&
68ConfigControlInfo::findConfigDb(const std::string& param_name,
69 const std::string& param_value) {
70 for (ConfigDbInfoList::iterator db = db_infos_.begin();
71 db != db_infos_.end(); ++db) {
72 std::string db_value;
73 if (db->getParameterValue(param_name, db_value) &&
74 (param_value == db_value)) {
75 return (*db);
76 }
77 }
78
79 return (EMPTY_DB());
80}
81
82const ConfigDbInfo&
84 static ConfigDbInfo empty;
85 return (empty);
86}
87
88void
90 db_infos_.clear();
91}
92
97 for (auto db_info : db_infos_) {
98 db_list->add(db_info.toElement());
99 }
100
101 result->set("config-databases", db_list);
102 return(result);
103}
104
105bool
107 return (db_infos_ == other.db_infos_);
108}
109
110} // end of namespace isc::process
111} // 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 createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition: data.cc:263
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.
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 datbase 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.
void setAccessString(const std::string &access_str)
Set the access string.
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 parmeter.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
Defines the logger used by the top-level component of kea-dhcp-ddns.