Software / code / prosody
Comparison
plugins/mod_admin_telnet.lua @ 6791:e813e8cf6046
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 20 Aug 2015 13:05:22 +0200 |
| parent | 6581:f2a7ad099e01 |
| parent | 6781:05cd80ec107c |
| child | 6839:298182fd2387 |
comparison
equal
deleted
inserted
replaced
| 6776:4412a2307c89 | 6791:e813e8cf6046 |
|---|---|
| 344 return hosts; | 344 return hosts; |
| 345 end | 345 end |
| 346 elseif type(hosts) == "string" then | 346 elseif type(hosts) == "string" then |
| 347 return set.new { hosts }; | 347 return set.new { hosts }; |
| 348 elseif hosts == nil then | 348 elseif hosts == nil then |
| 349 local mm = require "modulemanager"; | |
| 350 local hosts_set = set.new(array.collect(keys(prosody.hosts))) | 349 local hosts_set = set.new(array.collect(keys(prosody.hosts))) |
| 351 / function (host) return (prosody.hosts[host].type == "local" or module and mm.is_loaded(host, module)) and host or nil; end; | 350 / function (host) return (prosody.hosts[host].type == "local" or module and modulemanager.is_loaded(host, module)) and host or nil; end; |
| 352 if module and mm.get_module("*", module) then | 351 if module and modulemanager.get_module("*", module) then |
| 353 hosts_set:add("*"); | 352 hosts_set:add("*"); |
| 354 end | 353 end |
| 355 return hosts_set; | 354 return hosts_set; |
| 356 end | 355 end |
| 357 end | 356 end |
| 358 | 357 |
| 359 function def_env.module:load(name, hosts, config) | 358 function def_env.module:load(name, hosts, config) |
| 360 local mm = require "modulemanager"; | |
| 361 | |
| 362 hosts = get_hosts_set(hosts); | 359 hosts = get_hosts_set(hosts); |
| 363 | 360 |
| 364 -- Load the module for each host | 361 -- Load the module for each host |
| 365 local ok, err, count, mod = true, nil, 0, nil; | 362 local ok, err, count, mod = true, nil, 0, nil; |
| 366 for host in hosts do | 363 for host in hosts do |
| 367 if (not mm.is_loaded(host, name)) then | 364 if (not modulemanager.is_loaded(host, name)) then |
| 368 mod, err = mm.load(host, name, config); | 365 mod, err = modulemanager.load(host, name, config); |
| 369 if not mod then | 366 if not mod then |
| 370 ok = false; | 367 ok = false; |
| 371 if err == "global-module-already-loaded" then | 368 if err == "global-module-already-loaded" then |
| 372 if count > 0 then | 369 if count > 0 then |
| 373 ok, err, count = true, nil, 1; | 370 ok, err, count = true, nil, 1; |
| 384 | 381 |
| 385 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); | 382 return ok, (ok and "Module loaded onto "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
| 386 end | 383 end |
| 387 | 384 |
| 388 function def_env.module:unload(name, hosts) | 385 function def_env.module:unload(name, hosts) |
| 389 local mm = require "modulemanager"; | |
| 390 | |
| 391 hosts = get_hosts_set(hosts, name); | 386 hosts = get_hosts_set(hosts, name); |
| 392 | 387 |
| 393 -- Unload the module for each host | 388 -- Unload the module for each host |
| 394 local ok, err, count = true, nil, 0; | 389 local ok, err, count = true, nil, 0; |
| 395 for host in hosts do | 390 for host in hosts do |
| 396 if mm.is_loaded(host, name) then | 391 if modulemanager.is_loaded(host, name) then |
| 397 ok, err = mm.unload(host, name); | 392 ok, err = modulemanager.unload(host, name); |
| 398 if not ok then | 393 if not ok then |
| 399 ok = false; | 394 ok = false; |
| 400 self.session.print(err or "Unknown error unloading module"); | 395 self.session.print(err or "Unknown error unloading module"); |
| 401 else | 396 else |
| 402 count = count + 1; | 397 count = count + 1; |
| 406 end | 401 end |
| 407 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); | 402 return ok, (ok and "Module unloaded from "..count.." host"..(count ~= 1 and "s" or "")) or ("Last error: "..tostring(err)); |
| 408 end | 403 end |
| 409 | 404 |
| 410 function def_env.module:reload(name, hosts) | 405 function def_env.module:reload(name, hosts) |
| 411 local mm = require "modulemanager"; | |
| 412 | |
| 413 hosts = array.collect(get_hosts_set(hosts, name)):sort(function (a, b) | 406 hosts = array.collect(get_hosts_set(hosts, name)):sort(function (a, b) |
| 414 if a == "*" then return true | 407 if a == "*" then return true |
| 415 elseif b == "*" then return false | 408 elseif b == "*" then return false |
| 416 else return a < b; end | 409 else return a < b; end |
| 417 end); | 410 end); |
| 418 | 411 |
| 419 -- Reload the module for each host | 412 -- Reload the module for each host |
| 420 local ok, err, count = true, nil, 0; | 413 local ok, err, count = true, nil, 0; |
| 421 for _, host in ipairs(hosts) do | 414 for _, host in ipairs(hosts) do |
| 422 if mm.is_loaded(host, name) then | 415 if modulemanager.is_loaded(host, name) then |
| 423 ok, err = mm.reload(host, name); | 416 ok, err = modulemanager.reload(host, name); |
| 424 if not ok then | 417 if not ok then |
| 425 ok = false; | 418 ok = false; |
| 426 self.session.print(err or "Unknown error reloading module"); | 419 self.session.print(err or "Unknown error reloading module"); |
| 427 else | 420 else |
| 428 count = count + 1; | 421 count = count + 1; |