Comparison

core/modulemanager.lua @ 1334:6846c5cc9ce2

modulemanager: Added function add_identity(category, type) to the modules API
author Waqas Hussain <waqas20@gmail.com>
date Fri, 12 Jun 2009 14:32:32 +0500
parent 1330:baad431dabc5
child 1346:e34f9455b779
comparison
equal deleted inserted replaced
1333:d74441a2f3e8 1334:6846c5cc9ce2
45 local handler_info = {}; 45 local handler_info = {};
46 46
47 local modulehelpers = setmetatable({}, { __index = _G }); 47 local modulehelpers = setmetatable({}, { __index = _G });
48 48
49 local features_table = multitable_new(); 49 local features_table = multitable_new();
50 local identities_table = multitable_new();
50 local handler_table = multitable_new(); 51 local handler_table = multitable_new();
51 local hooked = multitable_new(); 52 local hooked = multitable_new();
52 local hooks = multitable_new(); 53 local hooks = multitable_new();
53 local event_hooks = multitable_new(); 54 local event_hooks = multitable_new();
54 55
160 log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err); 161 log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err);
161 end 162 end
162 end 163 end
163 modulemap[host][name] = nil; 164 modulemap[host][name] = nil;
164 features_table:remove(host, name); 165 features_table:remove(host, name);
166 identities_table:remove(host, name);
165 local params = handler_table:get(host, name); -- , {module.host, origin_type, tag, xmlns} 167 local params = handler_table:get(host, name); -- , {module.host, origin_type, tag, xmlns}
166 for _, param in pairs(params or NULL) do 168 for _, param in pairs(params or NULL) do
167 local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]); 169 local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]);
168 if handlers then 170 if handlers then
169 handler_info[handlers[1]] = nil; 171 handler_info[handlers[1]] = nil;
324 end 326 end
325 327
326 addDiscoInfoHandler("*host", function(reply, to, from, node) 328 addDiscoInfoHandler("*host", function(reply, to, from, node)
327 if #node == 0 then 329 if #node == 0 then
328 local done = {}; 330 local done = {};
331 for module, identities in pairs(identities_table:get(to) or NULL) do -- for each module
332 for identity, attr in pairs(identities) do
333 if not done[identity] then
334 reply:tag("identity", attr):up(); -- TODO cache
335 done[identity] = true;
336 end
337 end
338 end
339 for module, identities in pairs(identities_table:get("*") or NULL) do -- for each module
340 for identity, attr in pairs(identities) do
341 if not done[identity] then
342 reply:tag("identity", attr):up(); -- TODO cache
343 done[identity] = true;
344 end
345 end
346 end
329 for module, features in pairs(features_table:get(to) or NULL) do -- for each module 347 for module, features in pairs(features_table:get(to) or NULL) do -- for each module
330 for feature in pairs(features) do 348 for feature in pairs(features) do
331 if not done[feature] then 349 if not done[feature] then
332 reply:tag("feature", {var = feature}):up(); -- TODO cache 350 reply:tag("feature", {var = feature}):up(); -- TODO cache
333 done[feature] = true; 351 done[feature] = true;
346 end 364 end
347 end); 365 end);
348 366
349 function api:add_feature(xmlns) 367 function api:add_feature(xmlns)
350 features_table:set(self.host, self.name, xmlns, true); 368 features_table:set(self.host, self.name, xmlns, true);
369 end
370 function api:add_identity(category, typ)
371 identities_table:set(self.host, self.name, category.."\0"..typ, {category = category, typ = typ});
351 end 372 end
352 373
353 local event_hook = function(host, mod_name, event_name, ...) 374 local event_hook = function(host, mod_name, event_name, ...)
354 if type((...)) == "table" and (...).host and (...).host ~= host then return; end 375 if type((...)) == "table" and (...).host and (...).host ~= host then return; end
355 for handler in pairs(event_hooks:get(host, mod_name, event_name) or NULL) do 376 for handler in pairs(event_hooks:get(host, mod_name, event_name) or NULL) do