Mercurial > prosody-hg
comparison net/dns.lua @ 3841:f5afa0dc3aff
net.dns: Removed dependency on util.ztact by moving ztact.get/set in.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Thu, 09 Dec 2010 23:22:21 +0500 |
| parents | f2aca3e0fe3b |
| children | 9719316c854e |
comparison
equal
deleted
inserted
replaced
| 3840:abcbce5e4240 | 3841:f5afa0dc3aff |
|---|---|
| 1 -- Prosody IM | 1 -- Prosody IM |
| 2 -- This file is included with Prosody IM. It has modifications, | 2 -- This file is included with Prosody IM. It has modifications, |
| 3 -- which are hereby placed in the public domain. | 3 -- which are hereby placed in the public domain. |
| 4 | 4 |
| 5 -- public domain 20080404 lua@ztact.com | |
| 6 | |
| 7 | 5 |
| 8 -- todo: quick (default) header generation | 6 -- todo: quick (default) header generation |
| 9 -- todo: nxdomain, error handling | 7 -- todo: nxdomain, error handling |
| 10 -- todo: cache results of encodeName | 8 -- todo: cache results of encodeName |
| 11 | 9 |
| 13 -- reference: http://tools.ietf.org/html/rfc1035 | 11 -- reference: http://tools.ietf.org/html/rfc1035 |
| 14 -- reference: http://tools.ietf.org/html/rfc1876 (LOC) | 12 -- reference: http://tools.ietf.org/html/rfc1876 (LOC) |
| 15 | 13 |
| 16 | 14 |
| 17 local socket = require "socket"; | 15 local socket = require "socket"; |
| 18 local ztact = require "util.ztact"; | |
| 19 local timer = require "util.timer"; | 16 local timer = require "util.timer"; |
| 20 | 17 |
| 21 local _, windows = pcall(require, "util.windows"); | 18 local _, windows = pcall(require, "util.windows"); |
| 22 local is_windows = (_ and windows) or os.getenv("WINDIR"); | 19 local is_windows = (_ and windows) or os.getenv("WINDIR"); |
| 23 | 20 |
| 24 local coroutine, io, math, string, table = | 21 local coroutine, io, math, string, table = |
| 25 coroutine, io, math, string, table; | 22 coroutine, io, math, string, table; |
| 26 | 23 |
| 27 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack = | 24 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select = |
| 28 ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack; | 25 ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack, select; |
| 29 | 26 |
| 27 local ztact = { -- public domain 20080404 lua@ztact.com | |
| 28 get = function(parent, ...) | |
| 29 local len = select('#', ...); | |
| 30 for i=1,len do | |
| 31 parent = parent[select(i, ...)]; | |
| 32 if parent == nil then break; end | |
| 33 end | |
| 34 return parent; | |
| 35 end; | |
| 36 set = function(parent, ...) | |
| 37 local len = select('#', ...); | |
| 38 local key, value = select(len-1, ...); | |
| 39 local cutpoint, cutkey; | |
| 40 | |
| 41 for i=1,len-2 do | |
| 42 local key = select (i, ...) | |
| 43 local child = parent[key] | |
| 44 | |
| 45 if value == nil then | |
| 46 if child == nil then | |
| 47 return; | |
| 48 elseif next(child, next(child)) then | |
| 49 cutpoint = nil; cutkey = nil; | |
| 50 elseif cutpoint == nil then | |
| 51 cutpoint = parent; cutkey = key; | |
| 52 end | |
| 53 elseif child == nil then | |
| 54 child = {}; | |
| 55 parent[key] = child; | |
| 56 end | |
| 57 parent = child | |
| 58 end | |
| 59 | |
| 60 if value == nil and cutpoint then | |
| 61 cutpoint[cutkey] = nil; | |
| 62 else | |
| 63 parent[key] = value; | |
| 64 return value; | |
| 65 end | |
| 66 end; | |
| 67 }; | |
| 30 local get, set = ztact.get, ztact.set; | 68 local get, set = ztact.get, ztact.set; |
| 31 | 69 |
| 32 local default_timeout = 15; | 70 local default_timeout = 15; |
| 33 | 71 |
| 34 -------------------------------------------------- module dns | 72 -------------------------------------------------- module dns |
