]> granicus.if.org Git - pdns/commitdiff
it turns out, we could not simply compare DNSNames in Lua. Now we can, but it is...
authorbert hubert <bert.hubert@netherlabs.nl>
Mon, 21 Dec 2015 19:45:01 +0000 (19:45 +0000)
committerbert hubert <bert.hubert@netherlabs.nl>
Mon, 21 Dec 2015 19:45:01 +0000 (19:45 +0000)
pdns/lua-recursor4.cc
pdns/powerdns-example-script.lua

index d4352c60f7ea331319b402a0f13fac9dd6447d68..a4232c563bbd50ce54524bc2a00b5ac43ad7f3ef 100644 (file)
@@ -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<bool(DNSName::*)(const std::string&)>("equal",
+                                                             [](const DNSName& lhs, const std::string& rhs) { return lhs==DNSName(rhs); });
+  d_lw->registerFunction("__eq", &DNSName::operator==);
+
   d_lw->registerFunction<string(ComboAddress::*)()>("toString", [](const ComboAddress& ca) { return ca.toString(); });
   d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); });
   d_lw->writeFunction("newNMG", []() { return NetmaskGroup(); });
index 7c4ce2e96baab86e6ddb94d99c937f46ad3a5948..cda9e81c20052c0cadb32cf3621105f4254bb6f8 100644 (file)
@@ -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