annotate mod_cleanup_http/mod_cleanup_http.lua @ 614:40ab83736f6e

mod_admin_web: Correctly access items in NamedNodeMaps
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 14 Feb 2012 21:21:40 +0100
parents d87a9e1e6d30
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
611
d87a9e1e6d30 mod_cleanup_http: updated banner.
Marco Cirillo <maranda@lightwitch.org>
parents: 610
diff changeset
1 -- Auto-cleanup for Global BOSH modules.
d87a9e1e6d30 mod_cleanup_http: updated banner.
Marco Cirillo <maranda@lightwitch.org>
parents: 610
diff changeset
2 -- Should take care of spring cleaning without messing in either the console, or restarting
610
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4 module:set_global()
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6 local http_modules = module:get_option("cleanup_http_modules", {})
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
7 if type(http_modules) ~= "table" then module:log("error", "cleanup_http_modules needs to be a module.") ; return false end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
8
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
9 local function cleanup(data)
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
10 if data.module == "cleanup_http" then -- it's us getting unloaded destroy handler.
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
11 prosody.events.remove_handler("module-unloaded", cleanup)
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
12 elseif http_modules[data.module] then
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13 local ports = http_modules[data.module]
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
14
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
15 module:log("debug", "Cleaning up http handlers and ports as module %s is being unloaded.", data.module)
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
16 for _, options in ipairs(ports) do
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
17 if options.port then
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
18 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
20 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
21
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 -- if there are no handlers left clean and close the socket, doesn't work with server_event
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 local event = require "core.configmanager".get("*", "core", "use_libevent")
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
24
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 if not event then
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 for _, options in ipairs(ports) do
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 httpserver.new.http_servers[options.port] = nil
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
29 if options.interface then
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
30 for _, value in ipairs(options.interface) do
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
31 if server.getserver(value, options.port) then server.removeserver(value, options.port) end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
32 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
33 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
34 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
35 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
36 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
37 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
38 end
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
39
50dc20e96a78 mod_cleanup_http: "spring cleans" module, aka unload global http modules without hassle (open ports cleanup doesn't work with server_event)
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
40 prosody.events.add_handler("module-unloaded", cleanup)