comparison mod_stanza_counter/mod_stanza_counter_http.lua @ 608:fb9a2ab8458a

mod_stanza_counter_http: remove cleanup function move it to a separate plugin.
author Marco Cirillo <maranda@lightwitch.org>
date Sun, 12 Feb 2012 18:01:12 +0000
parents 03be4622454f
children 34e7093cf419
comparison
equal deleted inserted replaced
607:121762432eb1 608:fb9a2ab8458a
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 sc_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", sc_cleanup)
72 end
73
74 local function setup() 47 local function setup()
75 httpserver.new_from_config(ports, req, { base = "stanza-counter" }) 48 httpserver.new_from_config(ports, req, { base = "stanza-counter" })
76 prosody.events.add_handler("module-unloaded", sc_cleanup)
77 end 49 end
78 50
79 -- set it 51 -- set it
80 if prosody.start_time then setup() else module:hook("server-started", setup) end 52 if prosody.start_time then setup() else module:hook("server-started", setup) end