diff options
author | Waqas Hussain <waqas20@gmail.com> | 2010-12-09 23:22:21 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2010-12-09 23:22:21 +0500 |
commit | d359b28db2c74882919e9ab00899c43d5a4e87b0 (patch) | |
tree | 47250775a10fc47ca6d74de66ffe4452d1ccd59d /net/dns.lua | |
parent | 8a68aeb9bfc79c05fb6140194c90562eb0a067d0 (diff) | |
download | prosody-d359b28db2c74882919e9ab00899c43d5a4e87b0.tar.gz prosody-d359b28db2c74882919e9ab00899c43d5a4e87b0.zip |
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
Diffstat (limited to 'net/dns.lua')
-rw-r--r-- | net/dns.lua | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/net/dns.lua b/net/dns.lua index c5f219a8..c0875b5a 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -2,8 +2,6 @@ -- This file is included with Prosody IM. It has modifications, -- which are hereby placed in the public domain. --- public domain 20080404 lua@ztact.com - -- todo: quick (default) header generation -- todo: nxdomain, error handling @@ -15,7 +13,6 @@ local socket = require "socket"; -local ztact = require "util.ztact"; local timer = require "util.timer"; local _, windows = pcall(require, "util.windows"); @@ -24,9 +21,50 @@ 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 = - ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack; +local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select = + ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select; + +local ztact = { -- public domain 20080404 lua@ztact.com + get = function(parent, ...) + local len = select('#', ...); + for i=1,len do + parent = parent[select(i, ...)]; + if parent == nil then break; end + end + return parent; + end; + set = function(parent, ...) + local len = select('#', ...); + local key, value = select(len-1, ...); + local cutpoint, cutkey; + + for i=1,len-2 do + local key = select (i, ...) + local child = parent[key] + + if value == nil then + if child == nil then + return; + elseif next(child, next(child)) then + cutpoint = nil; cutkey = nil; + elseif cutpoint == nil then + cutpoint = parent; cutkey = key; + end + elseif child == nil then + child = {}; + parent[key] = child; + end + parent = child + end + if value == nil and cutpoint then + cutpoint[cutkey] = nil; + else + parent[key] = value; + return value; + end + end; +}; local get, set = ztact.get, ztact.set; local default_timeout = 15; |