]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4297] LibraryHandle::getParameter implemented.
authorTomek Mrugalski <tomasz@isc.org>
Mon, 14 Mar 2016 23:43:32 +0000 (00:43 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Mon, 14 Mar 2016 23:43:32 +0000 (00:43 +0100)
src/lib/hooks/library_handle.cc

index e9ae1399110e4b95fbd75386cfc68120dc91c91a..c9628e415e0a9ee348a885a67d877ba90e6d55f2 100644 (file)
@@ -69,14 +69,34 @@ isc::data::ConstElementPtr
 LibraryHandle::getParameter(const std::string& name) {
     HookLibsCollection libinfo = HooksManager::getHooksManager().getLibraryInfo();
 
-    if ((index_ >= libinfo.size()) || (index_ < 0)) {
-        // Something is very wrong here. However, this is user facing
-        // interface, so we should not throw here.
+    int index = index_;
+
+    if (index == -1) {
+        // -1 means that current index is stored in CalloutManager.
+        // So let's get the index from there. See comment for
+        // LibraryHandle::index_.
+        index = callout_manager_->getLibraryIndex();
+    }
+
+    if ((index > libinfo.size()) || (index <= 0)) {
+        // Something is very wrong here. The library index is out of bounds.
+        // However, this is user facing interface, so we should not throw here.
         return (isc::data::ConstElementPtr());
     }
 
+    // Some indexes have special meaning:
+    // - 0 - pre-user library callout
+    // - 1..numlib - indexes for actual libraries
+    // INT_MAX post-user library callout
+
     // Try to find appropriate parameter. May return NULL
-    return (libinfo[index_].second->get(name));
+    ConstElementPtr params = libinfo[index - 1].second;
+    if (!params) {
+        return (isc::data::ConstElementPtr());
+    }
+
+    // May return NULL if there's no parameter.
+    return (params->get(name));
 }
 
 } // namespace util