comparison mod_register_json/mod_register_json.lua @ 370:16da8cd69715

mod_register_json: There again, finally found the right way to pass the ports table to be processed correctly.
author Marco Cirillo <maranda@lightwitch.org>
date Fri, 22 Apr 2011 01:49:53 +0000
parents 29a8828243ce
children ea6641deec12
comparison
equal deleted inserted replaced
369:29a8828243ce 370:16da8cd69715
7 local jid_prep = require "util.jid".prep; 7 local jid_prep = require "util.jid".prep;
8 local jid_split = require "util.jid".split; 8 local jid_split = require "util.jid".split;
9 local usermanager = require "core.usermanager"; 9 local usermanager = require "core.usermanager";
10 local b64_decode = require "util.encodings".base64.decode; 10 local b64_decode = require "util.encodings".base64.decode;
11 local json_decode = require "util.json".decode; 11 local json_decode = require "util.json".decode;
12 local httpserver = require "net.httpserver";
12 local os_time = os.time; 13 local os_time = os.time;
13 14
14 module.host = "*" -- HTTP/BOSH Servlets need to be global. 15 module.host = "*" -- HTTP/BOSH Servlets need to be global.
15 16
16 -- Pick up configuration. 17 -- Pick up configuration.
104 end 105 end
105 end 106 end
106 107
107 -- Set it up! 108 -- Set it up!
108 local function setup() 109 local function setup()
109 local port = module:get_option("reg_servlet_port") or 9280; 110 local ports = module:get_option("reg_servlet_ports") or { 9280 };
110 local base_name = module:get_option("reg_servlet_base") or "register_account"; 111 local port_number, base_name, ssl_table;
111 local ssl_cert = module:get_option("reg_servlet_sslcert") or false; 112 for _, opts in ipairs(ports) do
112 local ssl_key = module:get_option("reg_servlet_sslkey") or false; 113 if type(opts) == "number" then
113 if not ssl_cert or not ssl_key then 114 port_number, base_name = opts, "register_account";
114 require "net.httpserver".new_from_config({ port = port }, handle_req, { base = base_name }); 115 elseif type(opts) == "table" then
116 port_number, base_name, ssl_table = opts.port or 9280, opts.path or "register_account", opts.ssl or nil;
117 elseif type(opts) == "string" then
118 base_name, port_number = opts, 9280;
119 end
120 end
121
122 if ssl_table == nil then
123 ports = { { port = port_number } };
124 httpserver.new_from_config(ports, handle_req, { base = base_name });
115 else 125 else
116 if module:get_option("reg_servlet_port") == nil then port = 9443; end 126 if port_number == 9280 then port_number = 9443; end
117 require "net.httpserver".new_from_config({ port = port; ssl = { key = ssl_key, certificate = ssl_cert }; }, handle_req, { base = base_name }); 127 ports = { { port = port_number, ssl = ssl_table } };
128 httpserver.new_from_config(ports, handle_req, { base = base_name });
118 end 129 end
119 end 130 end
120 131
121 if prosody.start_time then -- already started 132 if prosody.start_time then -- already started
122 setup(); 133 setup();