Software /
code /
prosody-modules
Comparison
mod_stanza_counter/mod_stanza_counter_http.lua @ 562:b3f8435e661c
mod_stanza_counter_http: added cleanup function (from mod_register_json)
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Tue, 17 Jan 2012 01:27:38 +0000 |
parent | 535:39c7115be370 |
child | 568:3d66b0af9a15 |
comparison
equal
deleted
inserted
replaced
561:f2ec7149b005 | 562:b3f8435e661c |
---|---|
40 return res(405, err405, {["Allow"] = "GET"}) | 40 return res(405, err405, {["Allow"] = "GET"}) |
41 end | 41 end |
42 end | 42 end |
43 | 43 |
44 -- initialization. | 44 -- initialization. |
45 -- init http interface | 45 -- init http and cleanup interface |
46 | |
47 function cleanup() -- recycled from mod_register_json, it's handy | |
48 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") | |
49 for _, options in ipairs(ports) do | |
50 if options.port then | |
51 httpserver.new.http_servers[options.port].handlers[options.path or "stanza-counter"] = nil | |
52 end | |
53 end | |
54 | |
55 -- if there are no handlers left clean and close the socket, doesn't work with server_event | |
56 local event = require "core.configmanager".get("*", "core", "use_libevent") | |
57 | |
58 if not event then | |
59 for _, options in ipairs(ports) do | |
60 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then | |
61 httpserver.new.http_servers[options.port] = nil | |
62 if options.interface then | |
63 for _, value in ipairs(options.interface) do | |
64 if server.getserver(value, options.port) then server.removeserver(value, options.port) end | |
65 end | |
66 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end | |
67 end | |
68 end | |
69 end | |
70 | |
71 prosody.events.remove_handler("module-unloaded", cleanup) | |
72 end | |
73 | |
46 local function setup() | 74 local function setup() |
47 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) | |
48 end | 77 end |
49 | 78 |
50 -- set it | 79 -- set it |
51 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 |