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 
10 using namespace isc::data;
11 
12 namespace isc {
13 namespace process {
14 
15 void
16 ConfigDbInfo::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 
22 bool
23 ConfigDbInfo::equals(const ConfigDbInfo& other) const {
24  return (access_params_ == other.access_params_);
25 }
26 
28 ConfigDbInfo::toElement() const {
30 }
31 
32 bool
33 ConfigDbInfo::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 
45 ConfigControlInfo::ConfigControlInfo(const ConfigControlInfo& other) {
46  for (auto db : other.db_infos_) {
47  addConfigDatabase(db.getAccessString());
48  }
49 }
50 
51 void
52 ConfigControlInfo::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 
67 const ConfigDbInfo&
68 ConfigControlInfo::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 
82 const ConfigDbInfo&
83 ConfigControlInfo::EMPTY_DB() {
84  static ConfigDbInfo empty;
85  return (empty);
86 }
87 
88 void
89 ConfigControlInfo::clear() {
90  db_infos_.clear();
91 }
92 
94 ConfigControlInfo::toElement() const {
95  ElementPtr result = Element::createMap();
96  ElementPtr db_list = Element::createList();
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 
105 bool
106 ConfigControlInfo::equals(const ConfigControlInfo& other) const {
107  return (db_infos_ == other.db_infos_);
108 }
109 
110 } // end of namespace isc::process
111 } // end of namespace isc
Embodies configuration information used during a server's configuration process.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
void setAccessString(const std::string &access_str)
Set the access string.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
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
#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...
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an 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.