Mercurial > prosody-modules
comparison mod_stanza_counter/mod_stanza_counter_http.lua @ 600:03be4622454f
mod_stanza_counter_http: de-revert to use configmanager instead of module mm for the cleanup function also give it an unique name (mismatch possible "??")
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Thu, 09 Feb 2012 00:52:18 +0000 |
| parents | 3d66b0af9a15 |
| children | fb9a2ab8458a |
comparison
equal
deleted
inserted
replaced
| 599:7df0d5c8abfd | 600:03be4622454f |
|---|---|
| 42 end | 42 end |
| 43 | 43 |
| 44 -- initialization. | 44 -- initialization. |
| 45 -- init http and cleanup interface | 45 -- init http and cleanup interface |
| 46 | 46 |
| 47 function cleanup() -- recycled from mod_register_json, it's handy | 47 function sc_cleanup() -- recycled from mod_register_json, it's handy |
| 48 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") | 48 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") |
| 49 for _, options in ipairs(ports) do | 49 for _, options in ipairs(ports) do |
| 50 if options.port then | 50 if options.port then |
| 51 httpserver.new.http_servers[options.port].handlers[options.path or "stanza-counter"] = nil | 51 httpserver.new.http_servers[options.port].handlers[options.path or "stanza-counter"] = nil |
| 52 end | 52 end |
| 53 end | 53 end |
| 54 | 54 |
| 55 -- if there are no handlers left clean and close the socket, doesn't work with server_event | 55 -- if there are no handlers left clean and close the socket, doesn't work with server_event |
| 56 local event = module:get_option_boolen("use_libevent", false) | 56 local event = require "core.configmanager".get("*", "core", "use_libevent") |
| 57 | 57 |
| 58 if not event then | 58 if not event then |
| 59 for _, options in ipairs(ports) do | 59 for _, options in ipairs(ports) do |
| 60 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then | 60 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then |
| 61 httpserver.new.http_servers[options.port] = nil | 61 httpserver.new.http_servers[options.port] = nil |
| 66 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end | 66 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end |
| 67 end | 67 end |
| 68 end | 68 end |
| 69 end | 69 end |
| 70 | 70 |
| 71 prosody.events.remove_handler("module-unloaded", cleanup) | 71 prosody.events.remove_handler("module-unloaded", sc_cleanup) |
| 72 end | 72 end |
| 73 | 73 |
| 74 local function setup() | 74 local function setup() |
| 75 httpserver.new_from_config(ports, req, { base = "stanza-counter" }) | 75 httpserver.new_from_config(ports, req, { base = "stanza-counter" }) |
| 76 prosody.events.add_handler("module-unloaded", cleanup) | 76 prosody.events.add_handler("module-unloaded", sc_cleanup) |
| 77 end | 77 end |
| 78 | 78 |
| 79 -- set it | 79 -- set it |
| 80 if prosody.start_time then setup() else module:hook("server-started", setup) end | 80 if prosody.start_time then setup() else module:hook("server-started", setup) end |
