summaryrefslogtreecommitdiffstats
path: root/src/lib/hooks
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2018-04-10 15:29:21 +0200
committerFrancis Dupont <fdupont@isc.org>2018-04-10 15:29:21 +0200
commitc8ddecea3971048ae4a1fb5c41b024fe4257f76e (patch)
treed864369d5bc2ce938a2f426836afb5b4555a7798 /src/lib/hooks
parent[master] Added ChangeLog entry 1383 for #5556. (diff)
parent[5525] Added getParameterNames (diff)
downloadkea-c8ddecea3971048ae4a1fb5c41b024fe4257f76e.tar.xz
kea-c8ddecea3971048ae4a1fb5c41b024fe4257f76e.zip
[master] Merged trac5525 (Radius config)
Diffstat (limited to 'src/lib/hooks')
-rw-r--r--src/lib/hooks/library_handle.cc29
-rw-r--r--src/lib/hooks/library_handle.h14
-rw-r--r--src/lib/hooks/tests/callout_params_library.cc14
3 files changed, 51 insertions, 6 deletions
diff --git a/src/lib/hooks/library_handle.cc b/src/lib/hooks/library_handle.cc
index 7aa7a052cc..4a661fcd54 100644
--- a/src/lib/hooks/library_handle.cc
+++ b/src/lib/hooks/library_handle.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,7 +80,7 @@ LibraryHandle::deregisterAllCallouts(const std::string& name) {
}
isc::data::ConstElementPtr
-LibraryHandle::getParameter(const std::string& name) {
+LibraryHandle::getParameters() {
HookLibsCollection libinfo = HooksManager::getHooksManager().getLibraryInfo();
int index = index_;
@@ -103,8 +103,13 @@ LibraryHandle::getParameter(const std::string& name) {
// * 1..numlib - indexes for actual libraries
// * INT_MAX - post-user library callout
+ return (libinfo[index - 1].second);
+}
+
+isc::data::ConstElementPtr
+LibraryHandle::getParameter(const std::string& name) {
// Try to find appropriate parameter. May return null pointer
- isc::data::ConstElementPtr params = libinfo[index - 1].second;
+ isc::data::ConstElementPtr params = getParameters();
if (!params) {
return (isc::data::ConstElementPtr());
}
@@ -113,5 +118,23 @@ LibraryHandle::getParameter(const std::string& name) {
return (params->get(name));
}
+std::vector<std::string>
+LibraryHandle::getParameterNames() {
+ std::vector<std::string> names;
+ // Find all parameter names.
+ isc::data::ConstElementPtr params = getParameters();
+ if (!params ||
+ (params->getType() != isc::data::Element::map) ||
+ (params->size() == 0)) {
+ return (names);
+ }
+ auto map = params->mapValue();
+ for (auto elem = map.begin(); elem != map.end(); ++elem) {
+ names.push_back(elem->first);
+ }
+ return (names);
+}
+
+
} // namespace util
} // namespace isc
diff --git a/src/lib/hooks/library_handle.h b/src/lib/hooks/library_handle.h
index 5dfad2a909..983c8802a0 100644
--- a/src/lib/hooks/library_handle.h
+++ b/src/lib/hooks/library_handle.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -198,6 +198,13 @@ public:
isc::data::ConstElementPtr
getParameter(const std::string& name);
+ /// @brief Returns names of configuration parameters for the library.
+ ///
+ /// This method returns a vector of strings reflecting names of
+ /// configuration parameters specified in the configuration file.
+ ///
+ std::vector<std::string> getParameterNames();
+
private:
/// @brief Copy constructor
///
@@ -218,6 +225,11 @@ private:
/// @param Unused - should be the object to copy.
LibraryHandle& operator=(const LibraryHandle&);
+ /// @brief Get configuration parameter common code.
+ ///
+ /// @return configuration parameters.
+ isc::data::ConstElementPtr getParameters();
+
/// Back pointer to the collection object for the library
CalloutManager* callout_manager_;
diff --git a/src/lib/hooks/tests/callout_params_library.cc b/src/lib/hooks/tests/callout_params_library.cc
index b5b569a206..3fb7ab309a 100644
--- a/src/lib/hooks/tests/callout_params_library.cc
+++ b/src/lib/hooks/tests/callout_params_library.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -14,6 +14,7 @@
#include <hooks/hooks.h>
#include <iostream>
+using namespace std;
using namespace isc::hooks;
using namespace isc::data;
@@ -39,6 +40,7 @@ int load(LibraryHandle& handle) {
ConstElementPtr int_elem = handle.getParameter("ivalue");
ConstElementPtr bool_elem = handle.getParameter("bvalue");
ConstElementPtr nonexistent = handle.getParameter("nonexistent");
+ vector<string> names = handle.getParameterNames();
// String handling example.
if (!string_elem) {
@@ -51,7 +53,7 @@ int load(LibraryHandle& handle) {
return (2);
}
- std::string str = string_elem->stringValue();
+ string str = string_elem->stringValue();
if (str != "string value") {
// Parameter is specified, is a string, but has unexpected value.
//
@@ -97,6 +99,14 @@ int load(LibraryHandle& handle) {
return (9);
}
+ // Check names. As a side effect of what maps using strings are
+ // implemented names are sorted in alphabetical order.
+ if ((names.size() != 3) || (names[0] != "bvalue") ||
+ (names[1] != "ivalue") || (names[2] != "svalue")) {
+ // Expect 3 names: bvalue, ivalue, svalue.
+ return (10);
+ }
+
// All validation steps were successful. The library has all the parameters
// it needs, so we should report a success.
return (0);