From e632cd29ec11f717ba218f963632dbe9d2b0683b Mon Sep 17 00:00:00 2001 From: bert hubert Date: Mon, 21 Dec 2015 19:45:01 +0000 Subject: [PATCH] it turns out, we could not simply compare DNSNames in Lua. Now we can, but it is ugly. --- pdns/lua-recursor4.cc | 6 +++++- pdns/powerdns-example-script.lua | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index d4352c60f7..a4232c563b 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -158,7 +158,11 @@ RecursorLua4::RecursorLua4(const std::string& fname) { d_lw = new LuaContext; d_lw->writeFunction("newDN", [](const std::string& dom){ return DNSName(dom); }); - d_lw->registerFunction("isPartOf", &DNSName::isPartOf); + d_lw->registerFunction("isPartOf", &DNSName::isPartOf); + d_lw->registerFunction("equal", + [](const DNSName& lhs, const std::string& rhs) { return lhs==DNSName(rhs); }); + d_lw->registerFunction("__eq", &DNSName::operator==); + d_lw->registerFunction("toString", [](const ComboAddress& ca) { return ca.toString(); }); d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); }); d_lw->writeFunction("newNMG", []() { return NetmaskGroup(); }); diff --git a/pdns/powerdns-example-script.lua b/pdns/powerdns-example-script.lua index 7c4ce2e96b..cda9e81c20 100644 --- a/pdns/powerdns-example-script.lua +++ b/pdns/powerdns-example-script.lua @@ -9,11 +9,26 @@ dropset:add("123.cn") malwareset = newDS() malwareset:add("nl") +magic2 = newDN("www.magic2.com") + -- shows the various ways of blocking, dropping, changing questions -- return false to say you did not take over the question, but we'll still listen to 'variable' -- to selectively disable the cache function preresolve(dq) print("Got question for "..dq.qname:toString()) + + -- note that the comparisons below are CaSe InSensiTivE and you don't have to worry about trailing dots + if(dq.qname:equal("magic.com")) + then + print("Magic!") + else + print("not magic..") + end + + if(dq.qname:__eq(magic2)) -- we hope to improve this syntax + then + print("Faster magic") -- compares against existing DNSName + end -- sadly, dq.qname == magic2 won't work yet if blockset:check(dq.qname) then dq.variable = true -- disable packet cache in any case -- 2.47.2