Kea  1.9.9-git
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 
10 using namespace isc::data;
11 using namespace isc::util;
12 
13 namespace isc {
14 namespace process {
15 
16 void
17 ConfigDbInfo::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 
25 bool
26 ConfigDbInfo::equals(const ConfigDbInfo& other) const {
27  return (access_params_ == other.access_params_);
28 }
29 
31 ConfigDbInfo::toElement() const {
33 }
34 
35 bool
36 ConfigDbInfo::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 
48 ConfigControlInfo::ConfigControlInfo(const ConfigControlInfo& other)
49  : config_fetch_wait_time_(other.config_fetch_wait_time_) {
50  for (auto db : other.db_infos_) {
51  addConfigDatabase(db.getAccessString());
52  }
53 }
54 
55 void
56 ConfigControlInfo::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 
71 const ConfigDbInfo&
72 ConfigControlInfo::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 
86 const ConfigDbInfo&
88  static ConfigDbInfo empty;
89  return (empty);
90 }
91 
92 void
94  db_infos_.clear();
95  config_fetch_wait_time_ = Optional<uint16_t>(30, true);
96 }
97 
98 void
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 
123 bool
125  return ((db_infos_ == other.db_infos_) &&
126  (config_fetch_wait_time_ == other.config_fetch_wait_time_));
127 }
128 
129 } // end of namespace isc::process
130 } // end of namespace isc
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
Definition: optional.h:121
void addConfigDatabase(const std::string &access_str)
Sets configuration database access string.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Embodies configuration information used during a server's configuration process.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
void merge(const ConfigControlInfo &other)
Merges specified configuration into this configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition: edns.h:19
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
void clear()
Empties the contents of the class, including the database list.
bool equals(const ConfigControlInfo &other) const
Compares two objects for equality.
void setAccessString(const std::string &access_str, bool test_mode=false)
Set the access string.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Provides configuration information used during a server's configuration process.
const ConfigDbInfo & findConfigDb(const std::string &param_name, const std::string &param_value)
Retrieves the database with the given access parameter value.
static const ConfigDbInfo & EMPTY_DB()
Fetches the not-found value returned by database list searches.