Kea 2.7.6
hooks_config.cc
Go to the documentation of this file.
1// Copyright (C) 2017-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 <hooks/hooks_manager.h>
11
12using namespace std;
13using namespace isc;
14using namespace isc::data;
15
16namespace isc {
17namespace hooks {
18
19void
21 bool multi_threading_enabled) const {
22 // The code used to follow this logic:
23 //
24 // Check if the list of libraries has changed. If not, nothing is done.
25 //
26 // We no longer rely on this. Parameters can change. And even if the
27 // parameters stay the same, they could point to files that could
28 // change. We can skip loading routines only if there were and there still
29 // are no libraries specified.
30 vector<string> current_libraries = HooksManager::getLibraryNames();
31 if (current_libraries.empty() && libraries_.empty()) {
32 return;
33 }
34
35 // Library list has changed, validate each of the libraries specified.
36 vector<string> lib_names = isc::hooks::extractNames(libraries_);
37 vector<string> error_libs = HooksManager::validateLibraries(lib_names,
38 multi_threading_enabled);
39 if (!error_libs.empty()) {
40
41 // Construct the list of libraries in error for the message.
42 string error_list = error_libs[0];
43 for (size_t i = 1; i < error_libs.size(); ++i) {
44 error_list += (string(", ") + error_libs[i]);
45 }
47 "hooks libraries failed to validate - "
48 "library or libraries in error are: "
49 << error_list << " (" << position << ")");
50 }
51}
52
53void
54HooksConfig::loadLibraries(bool multi_threading_enabled) const {
59 if (!HooksManager::loadLibraries(libraries_, multi_threading_enabled)) {
61 "One or more hook libraries failed to load");
62 }
63}
64
65bool
66HooksConfig::equal(const HooksConfig& other) const {
67
76 for (auto const& this_it : libraries_) {
77 bool match = false;
78 for (auto const& other_it : other.libraries_) {
79 if (this_it.first != other_it.first) {
80 continue;
81 }
82 if (isNull(this_it.second) && isNull(other_it.second)) {
83 match = true;
84 break;
85 }
86 if (isNull(this_it.second) || isNull(other_it.second)) {
87 continue;
88 }
89 if (this_it.second->equals(*other_it.second)) {
90 match = true;
91 break;
92 }
93 }
94 // No match found for the particular hooks library so return false.
95 if (!match) {
96 return (false);
97 }
98 }
99 return (true);
100}
101
104 // hooks-libraries is a list of maps
106 // Iterate through libraries
107 for (auto const& hl : libraries_) {
108 // Entries are maps
110 // Set the library name
111 map->set("library", Element::create(hl.first));
112 // Set parameters (not set vs set empty map)
113 if (!isNull(hl.second)) {
114 map->set("parameters", hl.second);
115 }
116 // Push to the list
117 result->add(map);
118 }
119 return (result);
120}
121
122}
123}
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
Wrapper class that holds hooks libraries configuration.
bool equal(const HooksConfig &other) const
Compares two Hooks Config classes for equality.
void verifyLibraries(const isc::data::Element::Position &position, bool multi_threading_enabled) const
Verifies that libraries stored in libraries_ are valid.
isc::data::ElementPtr toElement() const
Unparse a configuration object.
void loadLibraries(bool multi_threading_enabled) const
Commits hooks libraries configuration.
static std::vector< std::string > getLibraryNames()
Return list of loaded libraries.
static std::vector< std::string > validateLibraries(const std::vector< std::string > &libraries, bool multi_threading_enabled=false)
Validate library list.
static bool loadLibraries(const HookLibsCollection &libraries, bool multi_threading_enabled=false)
Load and reload libraries.
Exception thrown when a library failed to validate.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool isNull(ConstElementPtr p)
Checks whether the given ElementPtr is a NULL pointer.
Definition data.cc:1148
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::vector< std::string > extractNames(const isc::hooks::HookLibsCollection &libraries)
Extracts names from HookLibsCollection.
Definition libinfo.cc:19
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.
Definition data.h:94