Changeset

1318:66f76c332a75

modulemanager: Add module:hook([xmlns, ] name, handler) which uses new stanza events
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Jun 2009 16:41:09 +0100
parents 1317:f6e56a555c37
children 1319:812c028a877d
files core/modulemanager.lua
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = {};