Comparison

core/modulemanager.lua @ 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
parent 1309:a544e68a0989
child 1319:812c028a877d
comparison
equal deleted inserted replaced
1317:f6e56a555c37 1318:66f76c332a75
371 function api:hook(event, handler) 371 function api:hook(event, handler)
372 hooks:set(self.host, self.name, event, handler, true); 372 hooks:set(self.host, self.name, event, handler, true);
373 (hosts[self.host] or prosody).events.add_handler(event, handler); 373 (hosts[self.host] or prosody).events.add_handler(event, handler);
374 end 374 end
375 375
376 function api:hook_stanza(xmlns, name, handler)
377 if not handler and type(name) == "function" then
378 -- If only 2 options then they specified no xmlns
379 xmlns, name, handler = nil, xmlns, name;
380 elseif not (handler and name and xmlns) then
381 module:log("warn", "Error: Insufficient parameters to module:hook_stanza()");
382 return;
383 end
384 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end);
385 end
386
376 -------------------------------------------------------------------- 387 --------------------------------------------------------------------
377 388
378 local actions = {}; 389 local actions = {};
379 390
380 function actions.load(params) 391 function actions.load(params)