Commit 86a29980 authored by Francis Dupont's avatar Francis Dupont
Browse files

[5530a] Finishing merge of trac5526 on master

parents cdbffcec b41502a0
[submodule "premium"]
path = premium
url = ssh://fdupont@repo.isc.org/proj/git/prod/kea-premium.git
......@@ -1689,8 +1689,9 @@ if test "$FREERADIUS_INCLUDE" != ""; then
cat >> config.report << END
FreeRADIUS client:
FREERADIUS_INCLUDE: ${FREERADIUS_INCLUDE}
FREERADIUS_LIB: ${FREERADIUS_LIB}
FREERADIUS_INCLUDE: ${FREERADIUS_INCLUDE}
FREERADIUS_LIB: ${FREERADIUS_LIB}
FREERADIUS_DICTIONARY: ${FREERADIUS_DICTIONARY}
END
fi
......
// 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
// 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_;
......
// 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment