diff options
author | Kim Alvefur <zash@zash.se> | 2018-06-10 17:45:49 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-06-10 17:45:49 +0200 |
commit | 054cdafd57234e9b22cf6178552df1d1929b86ad (patch) | |
tree | df38c9c89512c9037ff809bc98df7608f7a3816e | |
parent | 28e486f3df0f239d65a6ae771b43c92869a8f275 (diff) | |
download | prosody-054cdafd57234e9b22cf6178552df1d1929b86ad.tar.gz prosody-054cdafd57234e9b22cf6178552df1d1929b86ad.zip |
net.dns: Lazily generate unknown RR type names
-rw-r--r-- | net/dns.lua | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/net/dns.lua b/net/dns.lua index 8a7d4e7a..563c81a6 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -86,13 +86,22 @@ local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte 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.types = { 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); |