Software /
code /
prosody
Diff
net/dns.lua @ 8908:144666d0ad2f
net.dns: Lazily generate unknown RR type names
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 10 Jun 2018 17:45:49 +0200 |
parent | 8907:b7b960d30eef |
child | 8909:dbb5ec6885fe |
line wrap: on
line diff
--- a/net/dns.lua Sun Jun 10 17:37:06 2018 +0200 +++ b/net/dns.lua Sun Jun 10 17:45:49 2018 +0200 @@ -86,13 +86,22 @@ end -local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment +local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment local a = {}; for i,s in pairs(t) do a[i] = s; a[s] = s; a[string.lower(s)] = s; end + setmetatable(a, { + __index = function (_, i) + if type(i) == "number" then + return ("%s%d"):format(prefix, i); + elseif type(i) == "string" then + return i:upper(); + end + end; + }) return a; end @@ -119,8 +128,8 @@ dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; -dns.type = augment (dns.types); -dns.class = augment (dns.classes); +dns.type = augment (dns.types, "TYPE"); +dns.class = augment (dns.classes, "CLASS"); dns.typecode = encode (dns.types); dns.classcode = encode (dns.classes);