# HG changeset patch # User Matthew Wild # Date 1244302869 -3600 # Node ID 66f76c332a750ea467c8a669adf7f99d852e9632 # Parent f6e56a555c37a67ee834c9b399d6670d94973391 modulemanager: Add module:hook([xmlns, ] name, handler) which uses new stanza events diff -r f6e56a555c37 -r 66f76c332a75 core/modulemanager.lua --- 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 = {};