Comparison

plugins/mod_admin_telnet.lua @ 10506:af214e2739f5

mod_admin_telnet: Merge hostname comparison functions Missed that there existed one already when writing the one for host:list
author Kim Alvefur <zash@zash.se>
date Sun, 15 Dec 2019 21:42:42 +0100
parent 10505:142bdba5eea2
child 10507:4d3549e64489
comparison
equal deleted inserted replaced
10505:142bdba5eea2 10506:af214e2739f5
431 end 431 end
432 432
433 local function _sort_hosts(a, b) 433 local function _sort_hosts(a, b)
434 if a == "*" then return true 434 if a == "*" then return true
435 elseif b == "*" then return false 435 elseif b == "*" then return false
436 else return a < b; end 436 else return a:gsub("[^.]+", string.reverse):reverse() < b:gsub("[^.]+", string.reverse):reverse(); end
437 end 437 end
438 438
439 function def_env.module:reload(name, hosts) 439 function def_env.module:reload(name, hosts)
440 hosts = array.collect(get_hosts_set(hosts, name)):sort(_sort_hosts) 440 hosts = array.collect(get_hosts_set(hosts, name)):sort(_sort_hosts)
441 441
962 end 962 end
963 function def_env.host:deactivate(hostname, reason) 963 function def_env.host:deactivate(hostname, reason)
964 return hostmanager.deactivate(hostname, reason); 964 return hostmanager.deactivate(hostname, reason);
965 end 965 end
966 966
967 local function compare_hosts(a, b)
968 return a:gsub("[^.]+", string.reverse):reverse() < b:gsub("[^.]+", string.reverse):reverse();
969 end
970
971 function def_env.host:list() 967 function def_env.host:list()
972 local print = self.session.print; 968 local print = self.session.print;
973 local i = 0; 969 local i = 0;
974 local type; 970 local type;
975 for host, host_session in iterators.sorted_pairs(prosody.hosts, compare_hosts) do 971 for host, host_session in iterators.sorted_pairs(prosody.hosts, _sort_hosts) do
976 i = i + 1; 972 i = i + 1;
977 type = host_session.type; 973 type = host_session.type;
978 if type == "local" then 974 if type == "local" then
979 print(host); 975 print(host);
980 else 976 else