Browse Source

[4297] LibraryHandle::getParameter implemented.

Tomek Mrugalski 9 years ago
parent
commit
5ab1463695
1 changed files with 24 additions and 4 deletions
  1. 24 4
      src/lib/hooks/library_handle.cc

+ 24 - 4
src/lib/hooks/library_handle.cc

@@ -69,14 +69,34 @@ isc::data::ConstElementPtr
 LibraryHandle::getParameter(const std::string& name) {
 LibraryHandle::getParameter(const std::string& name) {
     HookLibsCollection libinfo = HooksManager::getHooksManager().getLibraryInfo();
     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());
         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
     // 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
 } // namespace util