From: Lukáš Ježek Date: Thu, 19 Dec 2019 13:15:56 +0000 (+0100) Subject: daemon/lua/kluautil.lua: remove from global namespace X-Git-Tag: v5.0.0~17^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=85888f24f26686cba1ae3178f437eb1cc1951bb2;p=thirdparty%2Fknot-resolver.git daemon/lua/kluautil.lua: remove from global namespace --- diff --git a/daemon/lua/kluautil.lua b/daemon/lua/kluautil.lua index 158927914..825cbf4e8 100644 --- a/daemon/lua/kluautil.lua +++ b/daemon/lua/kluautil.lua @@ -1,6 +1,7 @@ +local kluautil = {} -- Get length of table -function kr_table_len (t) +function kluautil.kr_table_len(t) local len = 0 for _ in pairs(t) do len = len + 1 @@ -9,7 +10,7 @@ function kr_table_len (t) end -- Fetch over HTTPS -function kr_https_fetch (url, ca_file, file) +function kluautil.kr_https_fetch(url, ca_file, file) local http_ok, http_request = pcall(require, 'http.request') local openssl_ok, openssl_ctx = pcall(require, 'openssl.ssl.context') @@ -44,3 +45,4 @@ function kr_https_fetch (url, ca_file, file) return true end +return kluautil diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in index 68f77d12e..2a97fa9cf 100644 --- a/daemon/lua/sandbox.lua.in +++ b/daemon/lua/sandbox.lua.in @@ -32,9 +32,6 @@ if rawget(kres, 'str2dname') ~= nil then todname = kres.str2dname end --- Binding lua helper -kluautil = require('kluautil') - worker.resolve_pkt = function (pkt, options, finish, init) options = kres.mk_qflags(options) local task = ffi.C.worker_resolve_start(pkt, options) diff --git a/daemon/lua/trust_anchors.lua.in b/daemon/lua/trust_anchors.lua.in index 2676a6a33..1d4cc1639 100644 --- a/daemon/lua/trust_anchors.lua.in +++ b/daemon/lua/trust_anchors.lua.in @@ -118,7 +118,7 @@ end -- Fetch root anchors in XML over HTTPS, returning a zone-file-style string -- or false in case of error, and a message. local function bootstrap(url, ca) - local kluautil = pcall(require, 'kluautil') + local kluautil = require('kluautil') local file = io.tmpfile() -- RFC 7958, sec. 2, but we don't do precise XML parsing. -- @todo ICANN certificate is verified against current CA diff --git a/modules/policy/policy.test.lua b/modules/policy/policy.test.lua index e006bbf6f..912620ab3 100644 --- a/modules/policy/policy.test.lua +++ b/modules/policy/policy.test.lua @@ -104,8 +104,9 @@ local function mirror_parser(srv, cv, nqueries) end local function test_mirror() - local socket = require("cqueues.socket") - local cond = require("cqueues.condition") + local kluautil = require('kluautil') + local socket = require('cqueues.socket') + local cond = require('cqueues.condition') local cv = cond.new() local queries = {} local srv = socket.listen({ @@ -121,7 +122,7 @@ local function test_mirror() -- UDP server for test worker.bg_worker.cq:wrap(function() - local err, msg = mirror_parser(srv, cv, kr_table_len(queries)) + local err, msg = mirror_parser(srv, cv, kluautil.kr_table_len(queries)) ok(err, msg) end) diff --git a/modules/prefill/prefill.lua b/modules/prefill/prefill.lua index aa2246eea..9ad19ec35 100644 --- a/modules/prefill/prefill.lua +++ b/modules/prefill/prefill.lua @@ -49,7 +49,7 @@ local function get_file_ttl(fname) end local function download(url, fname) - local kluautil = pcall(require, 'kluautil') + local kluautil = require('kluautil') local file, rcode, errmsg file, errmsg = io.open(fname, 'w') if not file then