Kea 2.7.0
config_base.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>
8
10#include <log/logger_name.h>
12#include <process/config_base.h>
13
14#include <list>
15
16using namespace isc::log;
17using namespace isc::data;
18
19namespace isc {
20namespace process {
21
22void
24 std::list<LoggerSpecification> specs;
25 for (LoggingInfo const& logging_info : logging_info_) {
26 if (logging_info.name_ == getRootLoggerName()) {
27 // Root logger has to be processed first if we expect child loggers
28 // to inherit configuration from it.
29 specs.push_front(logging_info.toSpec());
30 } else {
31 specs.push_back(logging_info.toSpec());
32 }
33 }
34 LoggerManager manager;
35 manager.process(specs.begin(), specs.end());
36}
37
38bool
39ConfigBase::equals(const ConfigBase& other) const {
40 // If number of loggers is different, then configurations aren't equal.
41 if (logging_info_.size() != other.logging_info_.size()) {
42 return (false);
43 }
44 // Pass through all loggers and try to find the match for each of them
45 // with the loggers from the other configuration. The order doesn't
46 // matter so we can't simply compare the vectors.
47 for (LoggingInfoStorage::const_iterator this_it =
48 logging_info_.begin(); this_it != logging_info_.end();
49 ++this_it) {
50 bool match = false;
51 for (LoggingInfoStorage::const_iterator other_it =
52 other.logging_info_.begin();
53 other_it != other.logging_info_.end(); ++other_it) {
54 if (this_it->equals(*other_it)) {
55 match = true;
56 break;
57 }
58 }
59 // No match found for the particular logger so return false.
60 if (!match) {
61 return (false);
62 }
63 }
64
65 // Check config control info for equality.
66 if ((config_ctl_info_ && !other.config_ctl_info_) ||
67 (!config_ctl_info_ && other.config_ctl_info_) ||
68 ((config_ctl_info_ && other.config_ctl_info_) &&
69 (!config_ctl_info_->equals(*(other.config_ctl_info_))))) {
70 return (false);
71 }
72
73 return (true);
74}
75
76void
78 // We will entirely replace loggers in the new configuration.
79 other.logging_info_.clear();
80 for (auto const& it : logging_info_) {
81 other.addLoggingInfo(it);
82 }
83
84 // Clone the config control info
85 if (config_ctl_info_) {
86 other.config_ctl_info_.reset(new ConfigControlInfo(*config_ctl_info_));
87 } else {
88 other.config_ctl_info_.reset();
89 }
90
91 // Clone server tag.
92 other.server_tag_ = server_tag_;
93}
94
95void
97 // Merge logging info.
98 if (!other.logging_info_.empty()) {
99 logging_info_ = other.logging_info_;
100 }
101
102 // Merge the config control info
103 if (other.config_ctl_info_) {
104 if (config_ctl_info_) {
105 config_ctl_info_->merge(*other.config_ctl_info_);
106 } else {
107 config_ctl_info_ = other.config_ctl_info_;
108 }
109 }
110
111 // Merge server tag.
112 if (!other.server_tag_.unspecified()) {
113 server_tag_ = other.server_tag_.get();
114 }
115}
116
120
121 // Was in the Logging global map.
122 if (!logging_info_.empty()) {
123 // Set loggers list
125 for (LoggingInfoStorage::const_iterator logger =
126 logging_info_.cbegin();
127 logger != logging_info_.cend(); ++logger) {
128 loggers->add(logger->toElement());
129 }
130 result->set("loggers", loggers);
131 }
132
133 // server-tag
134 if (!server_tag_.unspecified()) {
135 result->set("server-tag", Element::create(server_tag_.get()));
136 }
137
138 return (result);
139}
140
141} // namespace process
142} // namespace isc
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
void process(T start, T finish)
Process Specifications.
Base class for all configurations.
Definition config_base.h:33
void applyLoggingCfg() const
Apply logging configuration to log4cplus.
virtual isc::data::ElementPtr toElement() const
Converts to Element representation.
void copy(ConfigBase &new_config) const
Copies the current configuration to a new configuration.
virtual void merge(ConfigBase &other)
Merges specified configuration into this configuration.
bool equals(const ConfigBase &other) const
Compares two configuration.
Embodies configuration information used during a server's configuration process.
structure that describes one logging entry
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
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
const std::string & getRootLoggerName()
Get root logger name.
Defines the logger used by the top-level component of kea-lfc.