Comparison

core/modulemanager.lua @ 4344:a24ee48ec30d

modulemanager: Add module:hook_global(name, handler, priority) to hook global (server-wide) events
author Matthew Wild <mwild1@gmail.com>
date Sun, 14 Aug 2011 13:56:13 -0400
parent 4337:a2ee8ab82dd9
child 4363:35ebd8e5747a
comparison
equal deleted inserted replaced
4343:203137823046 4344:a24ee48ec30d
173 end 173 end
174 -- unhook event handlers hooked by module:hook 174 -- unhook event handlers hooked by module:hook
175 for event, handlers in pairs(hooks:get(host, name) or NULL) do 175 for event, handlers in pairs(hooks:get(host, name) or NULL) do
176 for handler in pairs(handlers or NULL) do 176 for handler in pairs(handlers or NULL) do
177 (hosts[host] or prosody).events.remove_handler(event, handler); 177 (hosts[host] or prosody).events.remove_handler(event, handler);
178 end
179 end
180 -- unhook event handlers hooked by module:hook_global
181 for event, handlers in pairs(hooks:get("*", name) or NULL) do
182 for handler in pairs(handlers or NULL) do
183 prosody.events.remove_handler(event, handler);
178 end 184 end
179 end 185 end
180 hooks:remove(host, name); 186 hooks:remove(host, name);
181 if mod.module.items then -- remove items 187 if mod.module.items then -- remove items
182 for key,t in pairs(mod.module.items) do 188 for key,t in pairs(mod.module.items) do
289 function api:hook(event, handler, priority) 295 function api:hook(event, handler, priority)
290 hooks:set(self.host, self.name, event, handler, true); 296 hooks:set(self.host, self.name, event, handler, true);
291 (hosts[self.host] or prosody).events.add_handler(event, handler, priority); 297 (hosts[self.host] or prosody).events.add_handler(event, handler, priority);
292 end 298 end
293 299
300 function api:hook_global(event, handler, priority)
301 hooks:set("*", self.name, event, handler, true);
302 prosody.events.add_handler(event, handler, priority);
303 end
304
294 function api:hook_stanza(xmlns, name, handler, priority) 305 function api:hook_stanza(xmlns, name, handler, priority)
295 if not handler and type(name) == "function" then 306 if not handler and type(name) == "function" then
296 -- If only 2 options then they specified no xmlns 307 -- If only 2 options then they specified no xmlns
297 xmlns, name, handler, priority = nil, xmlns, name, handler; 308 xmlns, name, handler, priority = nil, xmlns, name, handler;
298 elseif not (handler and name) then 309 elseif not (handler and name) then