From: Tomek Mrugalski Date: Mon, 14 Mar 2016 23:43:32 +0000 (+0100) Subject: [4297] LibraryHandle::getParameter implemented. X-Git-Tag: trac4298_base~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ab1463695e901d3b3dca58f17f1658d1b655ecb;p=thirdparty%2Fkea.git [4297] LibraryHandle::getParameter implemented. --- diff --git a/src/lib/hooks/library_handle.cc b/src/lib/hooks/library_handle.cc index e9ae139911..c9628e415e 100644 --- a/src/lib/hooks/library_handle.cc +++ b/src/lib/hooks/library_handle.cc @@ -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