# HG changeset patch # User Kim Alvefur # Date 1681128768 -7200 # Node ID b5a419ac0f8449fc3a59d25ee5c6f0234b6515c2 # Parent be9ac41f1619cea654ba86f628c2f835b60310b7 mod_admin_shell: Factor apart wildcard matching into function for reuse Applying this for s2s:close[all]() would also be nice. diff -r be9ac41f1619 -r b5a419ac0f84 plugins/mod_admin_shell.lua --- a/plugins/mod_admin_shell.lua Mon Apr 10 13:50:09 2023 +0200 +++ b/plugins/mod_admin_shell.lua Mon Apr 10 14:12:48 2023 +0200 @@ -1101,26 +1101,30 @@ 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;