});
#endif /* HAVE_CDB */
- g_lua.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const std::string&)>("lookup", [](std::shared_ptr<KeyValueStore>& kvs, const std::string& keyStr) {
+ g_lua.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const boost::variant<ComboAddress, DNSName, std::string>)>("lookup", [](std::shared_ptr<KeyValueStore>& kvs, const boost::variant<ComboAddress, DNSName, std::string> keyVar) {
std::string result;
if (!kvs) {
return result;
}
- try {
- ComboAddress ca(keyStr);
+ if (keyVar.type() == typeid(ComboAddress)) {
+ const auto ca = *boost::get<ComboAddress>(&keyVar);
KeyValueLookupKeySourceIP lookup;
for (const auto& key : lookup.getKeys(ca)) {
if (kvs->getValue(key, result)) {
}
}
}
- catch(const std::exception& e) {
- /* not a valid address, treating it as a DNSName */
- try {
- DNSName dn(keyStr);
- KeyValueLookupKeyQName lookup;
- for (const auto& key : lookup.getKeys(dn)) {
- if (kvs->getValue(key, result)) {
- return result;
- }
+ else if (keyVar.type() == typeid(DNSName)) {
+ DNSName dn = *boost::get<DNSName>(&keyVar);
+ KeyValueLookupKeyQName lookup;
+ for (const auto& key : lookup.getKeys(dn)) {
+ if (kvs->getValue(key, result)) {
+ return result;
}
}
- catch (const std::exception& e) {
- /* not a valid name, trying to pass it as it is */
- kvs->getValue(keyStr, result);
- }
+ }
+ else if (keyVar.type() == typeid(std::string)) {
+ std::string keyStr = *boost::get<std::string>(&keyVar);
+ kvs->getValue(keyStr, result);
}
return result;
});
- g_lua.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const std::string&)>("lookupSuffix", [](std::shared_ptr<KeyValueStore>& kvs, const std::string& keyStr) {
+ g_lua.registerFunction<std::string(std::shared_ptr<KeyValueStore>::*)(const DNSName&)>("lookupSuffix", [](std::shared_ptr<KeyValueStore>& kvs, const DNSName& dn) {
std::string result;
if (!kvs) {
return result;
}
- DNSName dn(keyStr);
KeyValueLookupKeySuffix lookup;
for (const auto& key : lookup.getKeys(dn)) {
if (kvs->getValue(key, result)) {
.. method:: KeyValueStore:lookup(key)
Does a lookup into the corresponding key value store, and return the result as a string.
- The key is first parsed as a network address, and if that fails into a DNS name. If that also fails the raw string is used for the lookup.
+ The key can be a :class:`ComboAddress` obtained via the :func:`newCA`, a :class:`DNSName` obtained via the :func:`newDNSName` function, or a raw string.
- :param string key: The key to look up
+ :param ComboAddress, DNSName or string key: The key to look up
.. method:: KeyValueStore:lookupSuffix(key)
Does a suffix-based lookup into the corresponding key value store, and return the result as a string.
- The key is parsed as a DNS name, and several lookups will be done, removing one label from the name at a time until a match has been found or there is no label left.
+ The key should be a :class:`DNSName` object obtained via the :func:`newDNSName` function, and several lookups will be done, removing one label from the name at a time until a match has been found or there is no label left.
- :param string key: The name to look up
+ :param DNSName key: The name to look up
.. method:: KeyValueStore:reload()