aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/dataforms.lua9
-rw-r--r--util/indexedbheap.lua18
-rw-r--r--util/paths.lua38
-rw-r--r--util/x509.lua23
4 files changed, 78 insertions, 10 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index b38d0e27..c352858c 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -94,6 +94,15 @@ function form_t.form(layout, data, formtype)
end
end
+ local media = field.media;
+ if media then
+ form:tag("media", { xmlns = "urn:xmpp:media-element", height = media.height, width = media.width });
+ for _, val in ipairs(media) do
+ form:tag("uri", { type = val.type }):text(val.uri):up()
+ end
+ form:up();
+ end
+
if field.required then
form:tag("required"):up();
end
diff --git a/util/indexedbheap.lua b/util/indexedbheap.lua
index 3cb03037..c60861e8 100644
--- a/util/indexedbheap.lua
+++ b/util/indexedbheap.lua
@@ -113,23 +113,27 @@ function indexed_heap:reprioritize(id, priority)
k = _percolate_down(self.priorities, k, self.ids, self.index);
end
function indexed_heap:remove_index(k)
- local size = #self.priorities;
-
local result = self.priorities[k];
+ if result == nil then return; end
+
local result_sync = self.ids[k];
local item = self.items[result_sync];
- if result == nil then return; end
- self.index[result_sync] = nil;
- self.items[result_sync] = nil;
+ local size = #self.priorities;
self.priorities[k] = self.priorities[size];
self.ids[k] = self.ids[size];
self.index[self.ids[k]] = k;
+
t_remove(self.priorities);
t_remove(self.ids);
- k = _percolate_up(self.priorities, k, self.ids, self.index);
- k = _percolate_down(self.priorities, k, self.ids, self.index);
+ self.index[result_sync] = nil;
+ self.items[result_sync] = nil;
+
+ if size > k then
+ k = _percolate_up(self.priorities, k, self.ids, self.index);
+ k = _percolate_down(self.priorities, k, self.ids, self.index);
+ end
return result, item, result_sync;
end
diff --git a/util/paths.lua b/util/paths.lua
new file mode 100644
index 00000000..3e5744df
--- /dev/null
+++ b/util/paths.lua
@@ -0,0 +1,38 @@
+local path_sep = package.config:sub(1,1);
+
+local path_util = {}
+
+-- Helper function to resolve relative paths (needed by config)
+function path_util.resolve_relative_path(parent_path, path)
+ if path then
+ -- Some normalization
+ parent_path = parent_path:gsub("%"..path_sep.."+$", "");
+ path = path:gsub("^%.%"..path_sep.."+", "");
+
+ local is_relative;
+ if path_sep == "/" and path:sub(1,1) ~= "/" then
+ is_relative = true;
+ elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and (path:sub(2,3) ~= ":\\" and path:sub(2,3) ~= ":/")) then
+ is_relative = true;
+ end
+ if is_relative then
+ return parent_path..path_sep..path;
+ end
+ end
+ return path;
+end
+
+-- Helper function to convert a glob to a Lua pattern
+function path_util.glob_to_pattern(glob)
+ return "^"..glob:gsub("[%p*?]", function (c)
+ if c == "*" then
+ return ".*";
+ elseif c == "?" then
+ return ".";
+ else
+ return "%"..c;
+ end
+ end).."$";
+end
+
+return path_util;
diff --git a/util/x509.lua b/util/x509.lua
index 857f02a4..5e1b49e5 100644
--- a/util/x509.lua
+++ b/util/x509.lua
@@ -20,11 +20,9 @@
local nameprep = require "util.encodings".stringprep.nameprep;
local idna_to_ascii = require "util.encodings".idna.to_ascii;
+local base64 = require "util.encodings".base64;
local log = require "util.logger".init("x509");
-local pairs, ipairs = pairs, ipairs;
local s_format = string.format;
-local t_insert = table.insert;
-local t_concat = table.concat;
module "x509"
@@ -214,4 +212,23 @@ function verify_identity(host, service, cert)
return false
end
+local pat = "%-%-%-%-%-BEGIN ([A-Z ]+)%-%-%-%-%-\r?\n"..
+"([0-9A-Za-z+/=\r\n]*)\r?\n%-%-%-%-%-END %1%-%-%-%-%-";
+
+function pem2der(pem)
+ local typ, data = pem:match(pat);
+ if typ and data then
+ return base64.decode(data), typ;
+ end
+end
+
+local wrap = ('.'):rep(64);
+local envelope = "-----BEGIN %s-----\n%s\n-----END %s-----\n"
+
+function der2pem(data, typ)
+ typ = typ and typ:upper() or "CERTIFICATE";
+ data = base64.encode(data);
+ return s_format(envelope, typ, data:gsub(wrap, '%0\n', (#data-1)/64), typ);
+end
+
return _M;