aboutsummaryrefslogtreecommitdiffstats
path: root/net/dns.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-12-09 23:22:21 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-12-09 23:22:21 +0500
commitd05d634f7a04a5555612aad0efc540f77fe441f6 (patch)
treecde4931ea72437ba6831dfd54f5c432983fdf6d8 /net/dns.lua
parent34eaa793cedfdd14b61e104d2d95455c0475c0dc (diff)
downloadprosody-d05d634f7a04a5555612aad0efc540f77fe441f6.tar.gz
prosody-d05d634f7a04a5555612aad0efc540f77fe441f6.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.lua48
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;