Kea 2.5.8
library_handle.cc
Go to the documentation of this file.
1// Copyright (C) 2013-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
11#include <hooks/hooks_manager.h>
12
13#include <iostream>
14
15namespace isc {
16namespace hooks {
17
18// Callout manipulation - all deferred to the CalloutManager.
19
20void
21LibraryHandle::registerCallout(const std::string& name, CalloutPtr callout) {
22 int index = index_;
23
24 if (index_ == -1) {
25 // -1 means that current index is stored in CalloutManager.
26 // So let's get the index from there. See comment for
27 // LibraryHandle::index_.
28 index = callout_manager_.getLibraryIndex();
29 }
30
31 // Register the callout.
32 callout_manager_.registerCallout(name, callout, index);
33}
34
35void
36LibraryHandle::registerCommandCallout(const std::string& command_name,
37 CalloutPtr callout) {
38 // Register hook point for this command, if one doesn't exist.
39 callout_manager_.registerCommandHook(command_name);
40 // Register the command handler as a callout.
41 registerCallout(ServerHooks::commandToHookName(command_name), callout);
42}
43
44
45bool
46LibraryHandle::deregisterCallout(const std::string& name, CalloutPtr callout) {
47 int index = index_;
48
49 if (index_ == -1) {
50 // -1 means that current index is stored in CalloutManager.
51 // So let's get the index from there. See comment for
52 // LibraryHandle::index_.
53 index = callout_manager_.getLibraryIndex();
54 }
55
56 return (callout_manager_.deregisterCallout(name, callout, index));
57}
58
59bool
60LibraryHandle::deregisterAllCallouts(const std::string& name) {
61 int index = index_;
62
63 if (index_ == -1) {
64 // -1 means that current index is stored in CalloutManager.
65 // So let's get the index from there. See comment for
66 // LibraryHandle::index_.
67 index = callout_manager_.getLibraryIndex();
68 }
69
70 return (callout_manager_.deregisterAllCallouts(name, index));
71}
72
76
77 int index = index_;
78
79 if (index == -1) {
80 // -1 means that current index is stored in CalloutManager.
81 // So let's get the index from there. See comment for
82 // LibraryHandle::index_.
83 index = callout_manager_.getLibraryIndex();
84 }
85
86 if ((index > libinfo.size()) || (index <= 0)) {
87 // Something is very wrong here. The library index is out of bounds.
88 // However, this is user facing interface, so we should not throw here.
90 }
91
92 // Some indexes have special meaning:
93 // * 0 - pre-user library callout
94 // * 1 -> numlib - indexes for actual libraries
95 // * INT_MAX - post-user library callout
96
97 return (libinfo[index - 1].second);
98}
99
101LibraryHandle::getParameter(const std::string& name) {
102 // Try to find appropriate parameter. May return null pointer
104 if (!params || (params->getType() != isc::data::Element::map)) {
106 }
107
108 // May return null pointer if there's no parameter.
109 return (params->get(name));
110}
111
112std::vector<std::string>
114 std::vector<std::string> names;
115 // Find all parameter names.
117 if (!params ||
118 (params->getType() != isc::data::Element::map) ||
119 (params->size() == 0)) {
120 return (names);
121 }
122 auto const& map = params->mapValue();
123 for (auto const& elem : map) {
124 names.push_back(elem.first);
125 }
126 return (names);
127}
128
129} // namespace util
130} // namespace isc
bool deregisterAllCallouts(const std::string &name, int library_index)
Removes all callouts on a hook for the current library.
int getLibraryIndex() const
Get current library index.
bool deregisterCallout(const std::string &name, CalloutPtr callout, int library_index)
De-Register a callout on a hook for the current library.
void registerCommandHook(const std::string &command_name)
Registers a hook point for the specified command name.
void registerCallout(const std::string &name, CalloutPtr callout, int library_index)
Register a callout on a hook for the current library.
static HookLibsCollection getLibraryInfo()
Return list of loaded libraries with its parameters.
void registerCallout(const std::string &name, CalloutPtr callout)
Register a callout on a hook.
bool deregisterAllCallouts(const std::string &name)
Removes all callouts on a hook.
isc::data::ConstElementPtr getParameter(const std::string &name)
Returns configuration parameter for the library.
std::vector< std::string > getParameterNames()
Returns names of configuration parameters for the library.
void registerCommandCallout(const std::string &command_name, CalloutPtr callout)
Register control command handler.
isc::data::ConstElementPtr getParameters()
Get configuration parameter common code.
bool deregisterCallout(const std::string &name, CalloutPtr callout)
De-Register a callout on a hook.
static std::string commandToHookName(const std::string &command_name)
Generates hook point name for the given control command name.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
Definition: libinfo.h:31
Defines the logger used by the top-level component of kea-lfc.