Mercurial > prosody-modules
comparison mod_http_user_count/mod_http_user_count.lua @ 1830:a45f2f79e99b
mod_http_user_count: Support for host and MUC session counts
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 05 Sep 2015 23:08:40 +0100 |
| parents | fe29627a5ed8 |
| children |
comparison
equal
deleted
inserted
replaced
| 1829:23b3c8e294d2 | 1830:a45f2f79e99b |
|---|---|
| 1 local it = require "util.iterators"; | 1 local it = require "util.iterators"; |
| 2 local jid_split = require "util.jid".prepped_split; | |
| 2 | 3 |
| 3 module:depends("http"); | 4 module:depends("http"); |
| 5 | |
| 6 local function check_muc(jid) | |
| 7 local room_name, host = jid_split(jid); | |
| 8 if not hosts[host] then | |
| 9 return nil, "No such host: "..host; | |
| 10 elseif not hosts[host].modules.muc then | |
| 11 return nil, "Host '"..host.."' is not a MUC service"; | |
| 12 end | |
| 13 return room_name, host; | |
| 14 end | |
| 4 | 15 |
| 5 module:provides("http", { | 16 module:provides("http", { |
| 6 route = { | 17 route = { |
| 7 ["GET /sessions"] = function () return tostring(it.count(it.keys(prosody.full_sessions))); end; | 18 ["GET /sessions"] = function () return tostring(it.count(it.keys(prosody.full_sessions))); end; |
| 8 ["GET /users"] = function () return tostring(it.count(it.keys(prosody.bare_sessions))); end; | 19 ["GET /users"] = function () return tostring(it.count(it.keys(prosody.bare_sessions))); end; |
| 20 ["GET /host"] = function () return tostring(it.count(it.keys(prosody.hosts[module.host].sessions))); end; | |
| 21 ["GET /room/*"] = function (request, room_jid) | |
| 22 local name, host = check_muc(room_jid); | |
| 23 if not name then | |
| 24 return "0"; | |
| 25 end | |
| 26 local room = prosody.hosts[host].modules.muc.rooms[name.."@"..host]; | |
| 27 if not room then | |
| 28 return "0"; | |
| 29 end | |
| 30 return tostring(it.count(it.keys(room._occupants))); | |
| 31 end; | |
| 9 }; | 32 }; |
| 10 }); | 33 }); |
