Changeset

1646:95b8b1f9a882

mod_admin_web: Cleanup
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 03 Apr 2015 23:54:03 +0200
parents 1645:9a862059bd97
children 1647:8860405e2af6
files mod_admin_web/admin_web/mod_admin_web.lua
diffstat 1 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mod_admin_web/admin_web/mod_admin_web.lua	Thu Apr 02 18:51:13 2015 -0700
+++ b/mod_admin_web/admin_web/mod_admin_web.lua	Fri Apr 03 23:54:03 2015 +0200
@@ -23,6 +23,9 @@
 local pubsub = require "util.pubsub";
 local jid_bare = require "util.jid".bare;
 
+local hosts = prosody.hosts;
+local incoming_s2s = prosody.incoming_s2s;
+
 module:set_global();
 
 local service = {};
@@ -33,7 +36,7 @@
 
 local idmap = {};
 
-function add_client(session, host)
+local function add_client(session, host)
 	local name = session.full_jid;
 	local id = idmap[name];
 	if not id then
@@ -56,7 +59,7 @@
 	module:log("debug", "Added client " .. name);
 end
 
-function del_client(session, host)
+local function del_client(session, host)
 	local name = session.full_jid;
 	local id = idmap[name];
 	if id then
@@ -65,7 +68,7 @@
 	end
 end
 
-function add_host(session, type, host)
+local function add_host(session, type, host)
 	local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
 	local id = idmap[name.."_"..type];
 	if not id then
@@ -96,7 +99,7 @@
 	module:log("debug", "Added host " .. name .. " s2s" .. type);
 end
 
-function del_host(session, type, host)
+local function del_host(session, type, host)
 	local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
 	local id = idmap[name.."_"..type];
 	if id then
@@ -105,6 +108,15 @@
 	end
 end
 
+local function get_affiliation(jid, host)
+	local bare_jid = jid_bare(jid);
+	if is_admin(bare_jid, host) then
+		return "member";
+	else
+		return "none";
+	end
+end
+
 function module.add_host(module)
 	-- Dependencies
 	module:depends("bosh");
@@ -143,7 +155,6 @@
 		end
 	end
 
-	local ok, err;
 	service[module.host] = pubsub.new({
 		broadcaster = simple_broadcast;
 		normalize_jid = jid_bare;
@@ -198,7 +209,7 @@
 	});
 
 	-- Create node for s2s sessions
-	ok, err = service[module.host]:create(xmlns_s2s_session, true);
+	local ok, err = service[module.host]:create(xmlns_s2s_session, true);
 	if not ok then
 		module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(err));
 	else
@@ -206,7 +217,7 @@
 	end
 
 	-- Add outgoing s2s sessions
-	for remotehost, session in pairs(hosts[module.host].s2sout) do
+	for _, session in pairs(hosts[module.host].s2sout) do
 		if session.type ~= "s2sout_unauthed" then
 			add_host(session, "out", module.host);
 		end
@@ -228,8 +239,8 @@
 	end
 
 	-- Add c2s sessions
-	for username, user in pairs(hosts[module.host].sessions or {}) do
-		for resource, session in pairs(user.sessions or {}) do
+	for _, user in pairs(hosts[module.host].sessions or {}) do
+		for _, session in pairs(user.sessions or {}) do
 			add_client(session, module.host);
 		end
 	end
@@ -318,12 +329,3 @@
 		del_host(event.session, "in", module.host);
 	end);
 end
-
-function get_affiliation(jid, host)
-	local bare_jid = jid_bare(jid);
-	if is_admin(bare_jid, host) then
-		return "member";
-	else
-		return "none";
-	end
-end