diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/hashes.lua | 27 | ||||
-rw-r--r-- | util/logger.lua | 2 | ||||
-rw-r--r-- | util/stanza.lua | 7 | ||||
-rw-r--r-- | util/uuid.lua | 2 |
4 files changed, 35 insertions, 3 deletions
diff --git a/util/hashes.lua b/util/hashes.lua new file mode 100644 index 00000000..64374a8f --- /dev/null +++ b/util/hashes.lua @@ -0,0 +1,27 @@ + +local softreq = function (...) return select(2, pcall(require, ...)); end + +module "hashes" + +local md5 = softreq("md5"); +if md5 then + if md5.digest then + local md5_digest = md5.digest; + local sha1_digest = sha1.digest; + function _M.md5(input) + return md5_digest(input); + end + function _M.sha1(input) + return sha1_digest(input); + end + elseif md5.sumhexa then + local md5_sumhexa = md5.sumhexa; + function _M.md5(input) + return md5_sumhexa(input); + end + else + error("md5 library found, but unrecognised... no hash functions will be available", 0); + end +end + +return _M; diff --git a/util/logger.lua b/util/logger.lua index 623ceb67..8d983605 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -6,7 +6,7 @@ local tostring = tostring; module "logger" function init(name) - name = nil; -- While this line is not commented, will automatically fill in file/line number info + --name = nil; -- While this line is not commented, will automatically fill in file/line number info return function (level, message, ...) if not name then local inf = debug.getinfo(3, 'Snl'); diff --git a/util/stanza.lua b/util/stanza.lua index 6bc70ab9..95a19fbd 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -6,8 +6,14 @@ local setmetatable = setmetatable; local pairs = pairs; local ipairs = ipairs; local type = type; +local next = next; +local print = print; local unpack = unpack; local s_gsub = string.gsub; + +local debug = debug; +local log = require "util.logger".init("stanza"); + module "stanza" stanza_mt = {}; @@ -91,7 +97,6 @@ function stanza_mt.__tostring(t) if t.attr then for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. s_format(" %s='%s'", k, tostring(v)); end end end - return s_format("<%s%s>%s</%s>", t.name, attr_string, children_text, t.name); end diff --git a/util/uuid.lua b/util/uuid.lua index 489522aa..e1c02c91 100644 --- a/util/uuid.lua +++ b/util/uuid.lua @@ -2,7 +2,7 @@ local m_random = math.random; module "uuid" -function uuid_generate() +function generate() return m_random(0, 99999999); end |