mod_auth_anonymous: add disallow_s2s to the host object if s2s communication is disal...
[prosody.git] / net / dns.lua
index 08cb0f7cacbe40b476f344be65a284a50b3e6dc7..5b32a56ccf2743cba0b6b9245a91fc764fe28e27 100644 (file)
@@ -358,6 +358,7 @@ function resolver:name()    -- - - - - - - - - - - - - - - - - - - - - -  name
        local remember, pointers = nil, 0;
        local len = self:byte();
        local n = {};
+       if len == 0 then return "." end -- Root label
        while len > 0 do
                if len >= 0xc0 then    -- name is "compressed"
                        pointers = pointers + 1;
@@ -389,6 +390,25 @@ function resolver:A(rr)    -- - - - - - - - - - - - - - - - - - - - - - - -  A
        rr.a = string.format('%i.%i.%i.%i', b1, b2, b3, b4);
 end
 
+function resolver:AAAA(rr)
+       local addr = {};
+       for i = 1, rr.rdlength, 2 do
+               local b1, b2 = self:byte(2);
+               table.insert(addr, ("%02x%02x"):format(b1, b2));
+       end
+       addr = table.concat(addr, ":"):gsub("%f[%x]0+(%x)","%1");
+       local zeros = {};
+       for item in addr:gmatch(":[0:]+:") do
+               table.insert(zeros, item)
+       end
+       if #zeros == 0 then
+               rr.aaaa = addr;
+               return
+       elseif #zeros > 1 then
+               table.sort(zeros, function(a, b) return #a > #b end);
+       end
+       rr.aaaa = addr:gsub(zeros[1], "::", 1):gsub("^0::", "::"):gsub("::0$", "::");
+end
 
 function resolver:CNAME(rr)    -- - - - - - - - - - - - - - - - - - - -  CNAME
        rr.cname = self:name();
@@ -686,7 +706,7 @@ function resolver:purge(soft)    -- - - - - - - - - - - - - - - - - - -  purge
                                end
                        end
                end
-       else self.cache = {}; end
+       else self.cache = setmetatable({}, cache_metatable); end
 end