]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1182] Made getParameters public
authorFrancis Dupont <fdupont@isc.org>
Fri, 10 Jul 2020 15:19:36 +0000 (17:19 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 13 Jul 2020 13:12:38 +0000 (15:12 +0200)
src/lib/hooks/library_handle.cc
src/lib/hooks/library_handle.h
src/lib/hooks/tests/callout_params_library.cc

index da6ec25c29d5fee70473edd0f140d687120cb326..b070448e7a7f1246c95212cc5f8502dacb65460b 100644 (file)
@@ -101,7 +101,7 @@ isc::data::ConstElementPtr
 LibraryHandle::getParameter(const std::string& name) {
     // Try to find appropriate parameter. May return null pointer
     isc::data::ConstElementPtr params = getParameters();
-    if (!params) {
+    if (!params || (params->getType() != isc::data::Element::map)) {
         return (isc::data::ConstElementPtr());
     }
 
index bc1de1729a9756c1501524082a0322dd80b5629a..14af40c729b0504f9fb5e7e800cfff1f0d4e3e6e 100644 (file)
@@ -194,11 +194,18 @@ public:
     isc::data::ConstElementPtr
     getParameter(const std::string& name);
 
+    /// @brief Get configuration parameter common code.
+    ///
+    /// @return configuration parameters.
+    isc::data::ConstElementPtr getParameters();
+
     /// @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.
     ///
+    /// @note: kept for backward compatibility.
+    /// @return a vector with parameter entry names.
     std::vector<std::string> getParameterNames();
 
 private:
@@ -221,11 +228,6 @@ 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_;
 
index 3fb7ab309a92196dc227d0bdd8e940db059dd858..d35fc008f02d386c746afe1c5d2d785170b95b77 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2020 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
@@ -36,6 +36,7 @@ version() {
 /// @param handle passed by the hooks framework
 /// @return 0 if load was successful, non-zero for errors
 int load(LibraryHandle& handle) {
+    ConstElementPtr elems        = handle.getParameters();
     ConstElementPtr string_elem  = handle.getParameter("svalue");
     ConstElementPtr int_elem     = handle.getParameter("ivalue");
     ConstElementPtr bool_elem    = handle.getParameter("bvalue");
@@ -107,10 +108,22 @@ int load(LibraryHandle& handle) {
         return (10);
     }
 
+    // Check elems map.
+    if (!elems) {
+        return (11);
+    }
+    string expected_str = "{ "
+        "\"bvalue\": true, "
+        "\"ivalue\": 42, "
+        "\"svalue\": \"string value\""
+        " }";
+    if (expected_str != elems->str()) {
+        return (12);
+    }
+
     // All validation steps were successful. The library has all the parameters
     // it needs, so we should report a success.
     return (0);
 }
-    
 
-};
+}