From 114a89b6646b5cfe88cebe83422e84ef9e3d94b7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Jun 2009 16:41:09 +0100 Subject: modulemanager: Add module:hook([xmlns, ] name, handler) which uses new stanza events --- core/modulemanager.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 18b511e6..92a50abb 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -373,6 +373,17 @@ function api:hook(event, handler) (hosts[self.host] or prosody).events.add_handler(event, handler); end +function api:hook_stanza(xmlns, name, handler) + if not handler and type(name) == "function" then + -- If only 2 options then they specified no xmlns + xmlns, name, handler = nil, xmlns, name; + elseif not (handler and name and xmlns) then + module:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); + return; + end + return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end); +end + -------------------------------------------------------------------- local actions = {}; -- cgit v1.2.3 From ca4e395f0cb12ca39f9220feb2f984ad0be9d274 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Jun 2009 17:08:47 +0100 Subject: modulemanager: Allow setting priority of stanza handlers --- core/modulemanager.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 92a50abb..6d857d59 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -368,20 +368,20 @@ function api:fire_event(...) return (hosts[self.host] or prosody).events.fire_event(...); end -function api:hook(event, handler) +function api:hook(event, handler, priority) hooks:set(self.host, self.name, event, handler, true); - (hosts[self.host] or prosody).events.add_handler(event, handler); + (hosts[self.host] or prosody).events.add_handler(event, handler, priority); end -function api:hook_stanza(xmlns, name, handler) +function api:hook_stanza(xmlns, name, handler, priority) if not handler and type(name) == "function" then -- If only 2 options then they specified no xmlns - xmlns, name, handler = nil, xmlns, name; + xmlns, name, handler, priority = nil, xmlns, name, handler; elseif not (handler and name and xmlns) then module:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); return; end - return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end); + return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); end -------------------------------------------------------------------- -- cgit v1.2.3 From 650013e7ec39a3c08ba6f4a2e36076d5d91d12a1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Jun 2009 17:15:26 +0100 Subject: modulemanager: module:log() -> self:log() fix --- core/modulemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 6d857d59..9bcd64e4 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -378,7 +378,7 @@ function api:hook_stanza(xmlns, name, handler, priority) -- If only 2 options then they specified no xmlns xmlns, name, handler, priority = nil, xmlns, name, handler; elseif not (handler and name and xmlns) then - module:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); + self:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); return; end return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); -- cgit v1.2.3 From 78259b97be85a222f040dda7d3e27f719e3b467d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Jun 2009 17:17:16 +0100 Subject: modulemanager: Don't require xmlns to be non-nil --- core/modulemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 9bcd64e4..187e4d6e 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -377,7 +377,7 @@ function api:hook_stanza(xmlns, name, handler, priority) if not handler and type(name) == "function" then -- If only 2 options then they specified no xmlns xmlns, name, handler, priority = nil, xmlns, name, handler; - elseif not (handler and name and xmlns) then + elseif not (handler and name) then self:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); return; end -- cgit v1.2.3 From 2c8f13edc6e93b58c6e21fe8cb46bd3a84221a8b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Jun 2009 21:29:34 +0100 Subject: mod_console: Show total incoming/outgoing s2s connections --- plugins/mod_console.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index c676c0eb..77d76a82 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -318,10 +318,14 @@ def_env.s2s = {}; function def_env.s2s:show(match_jid) local _print = self.session.print; local print = self.session.print; + + local count_in, count_out = 0,0; + for host, host_session in pairs(hosts) do print = function (...) _print(host); _print(...); print = _print; end for remotehost, session in pairs(host_session.s2sout) do if (not match_jid) or remotehost:match(match_jid) or host:match(match_jid) then + count_out = count_out + 1; print(" "..host.." -> "..remotehost); if session.sendq then print(" There are "..#session.sendq.." queued outgoing stanzas for this connection"); @@ -354,6 +358,7 @@ function def_env.s2s:show(match_jid) for session in pairs(incoming_s2s) do if session.to_host == host and ((not match_jid) or host:match(match_jid) or (session.from_host and session.from_host:match(match_jid))) then + count_in = count_in + 1; print(" "..host.." <- "..(session.from_host or "(unknown)")); if session.type == "s2sin_unauthed" then print(" Connection not yet authenticated"); @@ -371,10 +376,13 @@ function def_env.s2s:show(match_jid) for session in pairs(incoming_s2s) do if not session.to_host and ((not match_jid) or session.from_host and session.from_host:match(match_jid)) then + count_in = count_in + 1; print("Other incoming s2s connections"); print(" (unknown) <- "..(session.from_host or "(unknown)")); end end + + return true, "Total: "..count_out.." outgoing, "..count_in.." incoming connections"; end ------------- -- cgit v1.2.3 From ca7b97cf41f352191767af2cd6d95ad0b17a4a45 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 7 Jun 2009 17:44:48 +0100 Subject: mod_message: Require stanza lib to prevent traceback on error replies --- plugins/mod_message.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_message.lua b/plugins/mod_message.lua index eb6982f4..048a578d 100644 --- a/plugins/mod_message.lua +++ b/plugins/mod_message.lua @@ -2,6 +2,7 @@ local full_sessions = full_sessions; local bare_sessions = bare_sessions; +local st = require "util.stanza"; local jid_bare = require "util.jid".bare; local jid_split = require "util.jid".split; local user_exists = require "core.usermanager".user_exists; -- cgit v1.2.3 From aa79672dbdd1bef94119e520daacb47ac06d3935 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 8 Jun 2009 13:25:10 +0100 Subject: modulemanager: Use module_name in log entry to fix 'error initialising module "nil"' error --- core/modulemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 187e4d6e..004b7dfb 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -128,7 +128,7 @@ function load(host, module_name, config) local success, ret = pcall(mod); if not success then - log("error", "Error initialising module '%s': %s", name or "nil", ret or "nil"); + log("error", "Error initialising module '%s': %s", module_name or "nil", ret or "nil"); return nil, ret; end -- cgit v1.2.3