Mercurial > prosody-modules
comparison mod_register_json/mod_register_json.lua @ 607:121762432eb1
mod_register_json: remove cleanup function move it to a separate plugin.
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Sun, 12 Feb 2012 17:59:45 +0000 |
| parents | 7df0d5c8abfd |
| children | 6f0e0d6790a7 |
comparison
equal
deleted
inserted
replaced
| 606:a9249614b0fe | 607:121762432eb1 |
|---|---|
| 111 end | 111 end |
| 112 end | 112 end |
| 113 end | 113 end |
| 114 | 114 |
| 115 -- Set it up! | 115 -- Set it up! |
| 116 function regj_cleanup() -- it could be better if module:hook("module-unloaded", ...) actually worked. | |
| 117 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.") | |
| 118 for _, options in ipairs(ports) do | |
| 119 if options.port then | |
| 120 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil | |
| 121 end | |
| 122 end | |
| 123 | |
| 124 -- if there are no handlers left clean and close the socket, doesn't work with server_event | |
| 125 local event = require "core.configmanager".get("*", "core", "use_libevent") | |
| 126 | |
| 127 if not event then | |
| 128 for _, options in ipairs(ports) do | |
| 129 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then | |
| 130 httpserver.new.http_servers[options.port] = nil | |
| 131 if options.interface then | |
| 132 for _, value in ipairs(options.interface) do | |
| 133 if server.getserver(value, options.port) then server.removeserver(value, options.port) end | |
| 134 end | |
| 135 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end | |
| 136 end | |
| 137 end | |
| 138 end | |
| 139 | |
| 140 prosody.events.remove_handler("module-unloaded", regj_cleanup) | |
| 141 end | |
| 142 | 116 |
| 143 function setup() | 117 function setup() |
| 144 for id, options in ipairs(ports) do | 118 for id, options in ipairs(ports) do |
| 145 if not options.port then | 119 if not options.port then |
| 146 if not options.ssl then ports[id].port = 9280 | 120 if not options.ssl then ports[id].port = 9280 |
| 147 else ports[id].port = 9443 end | 121 else ports[id].port = 9443 end |
| 148 elseif options.port == 9280 and options.ssl then ports[id].port = 9443 end end | 122 elseif options.port == 9280 and options.ssl then ports[id].port = 9443 end end |
| 149 httpserver.new_from_config(ports, handle_req, { base = "register_account" }) | 123 httpserver.new_from_config(ports, handle_req, { base = "register_account" }) |
| 150 prosody.events.add_handler("module-unloaded", regj_cleanup) | |
| 151 end | 124 end |
| 152 | 125 |
| 153 if prosody.start_time then -- already started | 126 if prosody.start_time then -- already started |
| 154 setup() | 127 setup() |
| 155 else | 128 else |
