aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-04-10 14:12:48 +0200
committerKim Alvefur <zash@zash.se>2023-04-10 14:12:48 +0200
commitf9f118178a003c39bf43ab917cd0e49ac713eadb (patch)
tree271f649d2373fb44edd07d8cf3149d2eb40d9f16 /plugins
parentffeea163934079730cf7da77b82b1804864380d0 (diff)
downloadprosody-f9f118178a003c39bf43ab917cd0e49ac713eadb.tar.gz
prosody-f9f118178a003c39bf43ab917cd0e49ac713eadb.zip
mod_admin_shell: Factor apart wildcard matching into function for reuse
Applying this for s2s:close[all]() would also be nice.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_shell.lua32
1 files changed, 18 insertions, 14 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua
index 96497545..b30b4ae5 100644
--- a/plugins/mod_admin_shell.lua
+++ b/plugins/mod_admin_shell.lua
@@ -1101,26 +1101,30 @@ local function _sort_s2s(a, b)
return _sort_hosts(a_local or "", b_local or "");
end
+local function match_wildcard(match_jid, jid)
+ -- host == host or (host) == *.(host) or sub(.host) == *(.host)
+ return jid == match_jid or jid == match_jid:sub(3) or jid:sub(-#match_jid + 1) == match_jid:sub(2);
+end
+
+local function match_s2s_jid(session, match_jid)
+ local host, remote = get_s2s_hosts(session);
+ if not match_jid or match_jid == "*" then
+ return true;
+ elseif host == match_jid or remote == match_jid then
+ return true;
+ elseif match_jid:sub(1, 2) == "*." then
+ return match_wildcard(match_jid, host) or match_wildcard(match_jid, remote);
+ end
+ return false;
+end
+
function def_env.s2s:show(match_jid, colspec)
local print = self.session.print;
local columns = get_colspec(colspec, { "id"; "host"; "dir"; "remote"; "ipv"; "secure"; "s2s_sasl"; "dialback" });
local row = format_table(columns, self.session.width);
local function match(session)
- local host, remote = get_s2s_hosts(session);
- if not match_jid or match_jid == "*" then
- return true;
- elseif host == match_jid or remote == match_jid then
- return true;
- elseif match_jid:sub(1, 2) == "*." then
- -- (host) == *.(host) or sub(.host) == *(.host)
- if host == match_jid:sub(3) or host:sub(-#match_jid + 1) == match_jid:sub(2) then
- return true
- elseif remote == match_jid:sub(3) or remote:sub(-#match_jid + 1) == match_jid:sub(2) then
- return true
- end
- end
- return false;
+ return match_s2s_jid(session, match_jid);
end
local group_by_host = true;