Comparison

mod_register_json/mod_register_json.lua @ 598:36b3ecebdc7e

mod_register_json: de-reverting change to use configmanager again (trace happened), also changed cleanup function name to avoid mismatches (??)
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 Feb 2012 00:44:46 +0000
parent 597:1004d7176be2
child 599:7df0d5c8abfd
comparison
equal deleted inserted replaced
597:1004d7176be2 598:36b3ecebdc7e
111 end 111 end
112 end 112 end
113 end 113 end
114 114
115 -- Set it up! 115 -- Set it up!
116 function cleanup() -- it could be better if module:hook("module-unloaded", ...) actually worked. 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.") 117 module:log("debug", "Cleaning up handlers and stuff as module is being unloaded.")
118 for _, options in ipairs(ports) do 118 for _, options in ipairs(ports) do
119 if options.port then 119 if options.port then
120 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil 120 httpserver.new.http_servers[options.port].handlers[options.path or "register_account"] = nil
121 end 121 end
122 end 122 end
123 123
124 -- if there are no handlers left clean and close the socket, doesn't work with server_event 124 -- if there are no handlers left clean and close the socket, doesn't work with server_event
125 local event = module:get_option_boolen("use_libevent", false) 125 local event = require "core.configmanager".get("*", "core", "use_libevent");
126 126
127 if not event then 127 if not event then
128 for _, options in ipairs(ports) do 128 for _, options in ipairs(ports) do
129 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then 129 if options.port and not next(httpserver.new.http_servers[options.port].handlers) then
130 httpserver.new.http_servers[options.port] = nil 130 httpserver.new.http_servers[options.port] = nil
135 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end 135 else if server.getserver("*", options.port) then server.removeserver("*", options.port) end end
136 end 136 end
137 end 137 end
138 end 138 end
139 139
140 prosody.events.remove_handler("module-unloaded", cleanup) 140 prosody.events.remove_handler("module-unloaded", regj_cleanup)
141 end 141 end
142 142
143 function setup() 143 function setup()
144 for id, options in ipairs(ports) do 144 for id, options in ipairs(ports) do
145 if not options.port then 145 if not options.port then
146 if not options.ssl then ports[id].port = 9280 146 if not options.ssl then ports[id].port = 9280
147 else ports[id].port = 9443 end 147 else ports[id].port = 9443 end
148 elseif options.port == 9280 and options.ssl then ports[id].port = 9443 end end 148 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" }) 149 httpserver.new_from_config(ports, handle_req, { base = "register_account" })
150 prosody.events.add_handler("module-unloaded", cleanup) 150 prosody.events.add_handler("module-unloaded", regj_cleanup)
151 end 151 end
152 152
153 if prosody.start_time then -- already started 153 if prosody.start_time then -- already started
154 setup() 154 setup()
155 else 155 else