aboutsummaryrefslogtreecommitdiffstats
path: root/net/dns.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-12-14 18:29:40 +0000
committerMatthew Wild <mwild1@gmail.com>2010-12-14 18:29:40 +0000
commit83fc3aa616588ab0f0133f07ec16ee4727db267a (patch)
treef640ee95129be60cf4fafd347b2a369b60d10a63 /net/dns.lua
parenta99ff085ab056e54e1ba40227347f6e696a2aab7 (diff)
downloadprosody-83fc3aa616588ab0f0133f07ec16ee4727db267a.tar.gz
prosody-83fc3aa616588ab0f0133f07ec16ee4727db267a.zip
net.dns: Clean up tostring() of returned records, as a result PTR records can now be tostring()'d
Diffstat (limited to 'net/dns.lua')
-rw-r--r--net/dns.lua39
1 files changed, 17 insertions, 22 deletions
diff --git a/net/dns.lua b/net/dns.lua
index f3d80291..23a453aa 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -21,8 +21,8 @@ local is_windows = (_ and windows) or os.getenv("WINDIR");
local coroutine, io, math, string, table =
coroutine, io, math, string, table;
-local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select =
- ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select;
+local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select, type=
+ ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select, type;
local ztact = { -- public domain 20080404 lua@ztact.com
get = function(parent, ...)
@@ -160,29 +160,24 @@ resolver.timeout = default_timeout;
local SRV_tostring;
+local function default_rr_tostring(rr)
+ local rr_val = rr.type and rr[rr.type:lower()];
+ if type(rr_val) ~= "string" then
+ return "<UNKNOWN RDATA TYPE>";
+ end
+ return rr_val;
+end
+
+local special_tostrings = {
+ LOC = resolver.LOC_tostring;
+ MX = function (rr) return string.format('%2i %s', rr.pref, rr.mx); end;
+ SRV = SRV_tostring;
+};
local rr_metatable = {}; -- - - - - - - - - - - - - - - - - - - rr_metatable
function rr_metatable.__tostring(rr)
- local s0 = string.format('%2s %-5s %6i %-28s', rr.class, rr.type, rr.ttl, rr.name);
- local s1 = '';
- if rr.type == 'A' then
- s1 = ' '..rr.a;
- elseif rr.type == 'MX' then
- s1 = string.format(' %2i %s', rr.pref, rr.mx);
- elseif rr.type == 'CNAME' then
- s1 = ' '..rr.cname;
- elseif rr.type == 'LOC' then
- s1 = ' '..resolver.LOC_tostring(rr);
- elseif rr.type == 'NS' then
- s1 = ' '..rr.ns;
- elseif rr.type == 'SRV' then
- s1 = ' '..SRV_tostring(rr);
- elseif rr.type == 'TXT' then
- s1 = ' '..rr.txt;
- else
- s1 = ' <UNKNOWN RDATA TYPE>';
- end
- return s0..s1;
+ local rr_string = (special_tostrings[rr.type] or default_rr_tostring)(rr);
+ return string.format('%2s %-5s %6i %-28s %s', rr.class, rr.type, rr.ttl, rr.name, rr_string);
end