Software /
code /
prosody
Comparison
core/moduleapi.lua @ 6655:a99ed5f5f709
moduleapi: Minor variable renaming to avoid clashes with the 'type' function
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 06 May 2015 19:02:07 +0100 |
parent | 6654:22a7ee3379bc |
child | 6656:58c111a39d27 |
comparison
equal
deleted
inserted
replaced
6654:22a7ee3379bc | 6655:a99ed5f5f709 |
---|---|
61 end | 61 end |
62 | 62 |
63 function api:add_feature(xmlns) | 63 function api:add_feature(xmlns) |
64 self:add_item("feature", xmlns); | 64 self:add_item("feature", xmlns); |
65 end | 65 end |
66 function api:add_identity(category, type, name) | 66 function api:add_identity(category, identity_type, name) |
67 self:add_item("identity", {category = category, type = type, name = name}); | 67 self:add_item("identity", {category = category, type = identity_type, name = name}); |
68 end | 68 end |
69 function api:add_extension(data) | 69 function api:add_extension(data) |
70 self:add_item("extension", data); | 70 self:add_item("extension", data); |
71 end | 71 end |
72 function api:has_feature(xmlns) | 72 function api:has_feature(xmlns) |
73 for _, feature in ipairs(self:get_host_items("feature")) do | 73 for _, feature in ipairs(self:get_host_items("feature")) do |
74 if feature == xmlns then return true; end | 74 if feature == xmlns then return true; end |
75 end | 75 end |
76 return false; | 76 return false; |
77 end | 77 end |
78 function api:has_identity(category, type, name) | 78 function api:has_identity(category, identity_type, name) |
79 for _, id in ipairs(self:get_host_items("identity")) do | 79 for _, id in ipairs(self:get_host_items("identity")) do |
80 if id.category == category and id.type == type and id.name == name then | 80 if id.category == category and id.type == identity_type and id.name == name then |
81 return true; | 81 return true; |
82 end | 82 end |
83 end | 83 end |
84 return false; | 84 return false; |
85 end | 85 end |
327 function api:get_host_items(key) | 327 function api:get_host_items(key) |
328 local result = modulemanager.get_items(key, self.host) or {}; | 328 local result = modulemanager.get_items(key, self.host) or {}; |
329 return result; | 329 return result; |
330 end | 330 end |
331 | 331 |
332 function api:handle_items(type, added_cb, removed_cb, existing) | 332 function api:handle_items(item_type, added_cb, removed_cb, existing) |
333 self:hook("item-added/"..type, added_cb); | 333 self:hook("item-added/"..item_type, added_cb); |
334 self:hook("item-removed/"..type, removed_cb); | 334 self:hook("item-removed/"..item_type, removed_cb); |
335 if existing ~= false then | 335 if existing ~= false then |
336 for _, item in ipairs(self:get_host_items(type)) do | 336 for _, item in ipairs(self:get_host_items(item_type)) do |
337 added_cb({ item = item }); | 337 added_cb({ item = item }); |
338 end | 338 end |
339 end | 339 end |
340 end | 340 end |
341 | 341 |
387 function api:load_resource(path, mode) | 387 function api:load_resource(path, mode) |
388 path = resolve_relative_path(self:get_directory(), path); | 388 path = resolve_relative_path(self:get_directory(), path); |
389 return io.open(path, mode); | 389 return io.open(path, mode); |
390 end | 390 end |
391 | 391 |
392 function api:open_store(name, type) | 392 function api:open_store(name, store_type) |
393 return require"core.storagemanager".open(self.host, name or self.name, type); | 393 return require"core.storagemanager".open(self.host, name or self.name, store_type); |
394 end | 394 end |
395 | 395 |
396 function api:measure(name, type) | 396 function api:measure(name, stat_type) |
397 return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); | 397 return measure(stat_type, "/"..self.host.."/mod_"..self.name.."/"..name); |
398 end | 398 end |
399 | 399 |
400 function api:measure_object_event(events_object, event_name, stat_name) | 400 function api:measure_object_event(events_object, event_name, stat_name) |
401 local m = self:measure(stat_name or event_name, "duration"); | 401 local m = self:measure(stat_name or event_name, "duration"); |
402 local function handler(handlers, event_name, event_data) | 402 local function handler(handlers, _event_name, _event_data) |
403 local finished = m(); | 403 local finished = m(); |
404 local ret = handlers(event_name, event_data); | 404 local ret = handlers(_event_name, _event_data); |
405 finished(); | 405 finished(); |
406 return ret; | 406 return ret; |
407 end | 407 end |
408 return self:hook_object_event(events_object, event_name, handler); | 408 return self:hook_object_event(events_object, event_name, handler); |
409 end | 409 end |