.. function:: dblookup(name, type)
+ .. versionadded:: 4.9.0
+
Does a database lookup for name and type, and returns a (possibly empty) array of string results.
Please keep the following in mind:
* it does not evaluate any LUA code found
- * if you needed just one string, perhaps you want ``dblookup('www.example.org', 'A')[1]`` to take the first item from the array
+ * if you needed just one string, perhaps you want ``dblookup('www.example.org', pdns.A)[1]`` to take the first item from the array
* some things, like ifurlup, don't like empty tables, so be careful not to accidentally look up a name that does not have any records of that type, if you are going to use the result in ``ifurlup``
Example usage: ::
- www IN LUA A "ifurlup('https://www.example.com/', {dblookup('www1.example.com', 'A'), dblookup('www2.example.com', 'A'), dblookup('www3.example.com', 'A')})"
+ www IN LUA A "ifurlup('https://www.example.com/', {dblookup('www1.example.com', pdns.A), dblookup('www2.example.com', pdns.A), dblookup('www3.example.com', pdns.A)})"
:param string name: Name to look up in the database
- :param string type: DNS type to look for
+ :param int type: DNS type to look for
return result;
});
- lua.writeFunction("dblookup", [](const string& record, const string& type) {
+ lua.writeFunction("dblookup", [](const string& record, uint16_t qtype) {
DNSName rec;
- QType qtype;
vector<string> ret;
try {
rec = DNSName(record);
- qtype = type;
- if (qtype.getCode() == 0) {
- throw std::invalid_argument("unknown type");
- }
}
catch (const std::exception& e) {
- g_log << Logger::Error << "DB lookup cannot be performed, the name (" << record << ") or type (" << type << ") is malformed: " << e.what() << endl;
+ g_log << Logger::Error << "DB lookup cannot be performed, the name (" << record << ") is malformed: " << e.what() << endl;
return ret;
}
try {
counter IN LUA TXT ";counter = counter or 0 counter=counter+1 return tostring(counter)"
lookmeup IN A 192.0.2.5
-dblookup IN LUA A "dblookup('lookmeup.example.org', 'A')[1]"
+dblookup IN LUA A "dblookup('lookmeup.example.org', pdns.A)[1]"
""",
'createforward6.example.org': """
createforward6.example.org. 3600 IN SOA {soa}