modulemanager: Add module:hook([xmlns, ] name, handler) which uses new stanza events
--- a/core/modulemanager.lua Fri Jun 05 20:18:55 2009 +0100
+++ b/core/modulemanager.lua Sat Jun 06 16:41:09 2009 +0100
@@ -373,6 +373,17 @@
(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 = {};