Software /
code /
prosody
Comparison
core/modulemanager.lua @ 1319:812c028a877d
modulemanager: Allow setting priority of stanza handlers
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Jun 2009 17:08:47 +0100 |
parent | 1318:66f76c332a75 |
child | 1320:9c736b993e07 |
comparison
equal
deleted
inserted
replaced
1318:66f76c332a75 | 1319:812c028a877d |
---|---|
366 | 366 |
367 function api:fire_event(...) | 367 function api:fire_event(...) |
368 return (hosts[self.host] or prosody).events.fire_event(...); | 368 return (hosts[self.host] or prosody).events.fire_event(...); |
369 end | 369 end |
370 | 370 |
371 function api:hook(event, handler) | 371 function api:hook(event, handler, priority) |
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, priority); |
374 end | 374 end |
375 | 375 |
376 function api:hook_stanza(xmlns, name, handler) | 376 function api:hook_stanza(xmlns, name, handler, priority) |
377 if not handler and type(name) == "function" then | 377 if not handler and type(name) == "function" then |
378 -- If only 2 options then they specified no xmlns | 378 -- If only 2 options then they specified no xmlns |
379 xmlns, name, handler = nil, xmlns, name; | 379 xmlns, name, handler, priority = nil, xmlns, name, handler; |
380 elseif not (handler and name and xmlns) then | 380 elseif not (handler and name and xmlns) then |
381 module:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); | 381 module:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); |
382 return; | 382 return; |
383 end | 383 end |
384 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end); | 384 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); |
385 end | 385 end |
386 | 386 |
387 -------------------------------------------------------------------- | 387 -------------------------------------------------------------------- |
388 | 388 |
389 local actions = {}; | 389 local actions = {}; |