Yes, we don't put these things in here, we put them in here.
[prosody.git] / net / dns.lua
index 01ee133c7ef0d0e8e9921e1937bd5caef555877f..7364161e367e18f50848dd2477dc4276f485495e 100644 (file)
@@ -19,8 +19,8 @@ local ztact = require 'util.ztact'
 local coroutine, io, math, socket, string, table =
       coroutine, io, math, socket, string, table
 
-local ipairs, next, pairs, print, setmetatable, tostring =
-      ipairs, next, pairs, print, setmetatable, tostring
+local ipairs, next, pairs, print, setmetatable, tostring, assert, error =
+      ipairs, next, pairs, print, setmetatable, tostring, assert, error
 
 local get, set = ztact.get, ztact.set
 
@@ -130,7 +130,7 @@ function rr_metatable.__tostring (rr)
 
 local rrs_metatable = {}    -- - - - - - - - - - - - - - - - - -  rrs_metatable
 function rrs_metatable.__tostring (rrs)
-  t = {}
+  local t = {}
   for i,rr in pairs (rrs) do  append (t, tostring (rr)..'\n')  end
   return table.concat (t)
   end
@@ -502,11 +502,16 @@ function resolver:setnameserver (address)    -- - - - - - - - - - setnameserver
 
 function resolver:adddefaultnameservers ()    -- - - - -  adddefaultnameservers
   local resolv_conf = io.open("/etc/resolv.conf");
-  if not resolv_conf then return nil; end
-  for line in resolv_conf:lines() do
-    address = string.match (line, 'nameserver%s+(%d+%.%d+%.%d+%.%d+)')
-    if address then  self:addnameserver (address)  end
-    end  end
+  if resolv_conf then
+         for line in resolv_conf:lines() do
+               local address = string.match (line, 'nameserver%s+(%d+%.%d+%.%d+%.%d+)')
+               if address then  self:addnameserver (address)  end
+         end
+  else -- FIXME correct for windows, using opendns nameservers for now
+       self:addnameserver ("208.67.222.222")
+       self:addnameserver ("208.67.220.220")
+  end
+end
 
 
 function resolver:getsocket (servernum)    -- - - - - - - - - - - - - getsocket
@@ -582,7 +587,7 @@ function resolver:purge (soft)    -- - - - - - - - - - - - - - - - - - -  purge
     for class,types in pairs (self.cache or {}) do
       for type,names in pairs (types) do
         for name,rrs in pairs (names) do
-          prune (rrs, time, 'soft')
+          prune (rrs, self.time, 'soft')
           end  end  end
   else  self.cache = {}  end
   end
@@ -594,7 +599,7 @@ function resolver:query (qname, qtype, qclass)    -- - - - - - - - - - -- query
 
   if not self.server then  self:adddefaultnameservers ()  end
 
-  local question = question or encodeQuestion (qname, qtype, qclass)
+  local question = encodeQuestion (qname, qtype, qclass)
   local peek = self:peek (qname, qtype, qclass)
   if peek then  return peek  end
 
@@ -767,7 +772,7 @@ function dns.resolver ()    -- - - - - - - - - - - - - - - - - - - - - resolver
 
   -- this function seems to be redundant with resolver.new ()
 
-  r = { active = {}, cache = {}, unsorted = {}, wanted = {}, yielded = {} }
+  local r = { active = {}, cache = {}, unsorted = {}, wanted = {}, yielded = {} }
   setmetatable (r, resolver)
   setmetatable (r.cache, cache_metatable)
   setmetatable (r.unsorted, { __mode = 'kv' })