196 for _, port in ipairs(ports) do |
196 for _, port in ipairs(ports) do |
197 port = tonumber(port); |
197 port = tonumber(port); |
198 if type(port) ~= "number" then |
198 if type(port) ~= "number" then |
199 log("error", "Non-numeric "..option.."_ports: "..tostring(port)); |
199 log("error", "Non-numeric "..option.."_ports: "..tostring(port)); |
200 else |
200 else |
201 cl.start(listener, { |
201 local ok, err = cl.start(listener, { |
202 ssl = conntype ~= "tcp" and global_ssl_ctx, |
202 ssl = conntype ~= "tcp" and global_ssl_ctx, |
203 port = port, |
203 port = port, |
204 interface = (option and config.get("*", "core", option.."_interface")) |
204 interface = (option and config.get("*", "core", option.."_interface")) |
205 or cl.get(listener).default_interface |
205 or cl.get(listener).default_interface |
206 or config.get("*", "core", "interface"), |
206 or config.get("*", "core", "interface"), |
207 type = conntype |
207 type = conntype |
208 }); |
208 }); |
|
209 if not ok then |
|
210 local friendly_message = err; |
|
211 if err:match(" in use") then |
|
212 if port == 5222 or port == 5223 or port == 5269 then |
|
213 friendly_message = "check that Prosody or another XMPP server is " |
|
214 .."not already running and using this port"; |
|
215 elseif port == 80 or port == 81 then |
|
216 friendly_message = "check that a HTTP server is not already using " |
|
217 .."this port"; |
|
218 elseif port == 5280 then |
|
219 friendly_message = "check that Prosody or a BOSH connection manager " |
|
220 .."is not already running"; |
|
221 else |
|
222 friendly_message = "this port is in use by another application"; |
|
223 end |
|
224 elseif err:match("permission") then |
|
225 friendly_message = "Prosody does not have sufficient privileges to use this port"; |
|
226 elseif err == "no ssl context" then |
|
227 if not config.get("*", "core", "ssl") then |
|
228 friendly_message = "there is no 'ssl' config under Host \"*\" which is " |
|
229 .."require for legacy SSL ports"; |
|
230 else |
|
231 friendly_message = "initializing SSL support failed, see previous log entries"; |
|
232 end |
|
233 end |
|
234 log("error", "Failed to open server port %d, %s", port, friendly_message); |
|
235 end |
209 end |
236 end |
210 end |
237 end |
211 end |
238 end |
212 end |
239 end |
213 end |
240 end |
278 prosody.events.fire_event("server-starting"); |
305 prosody.events.fire_event("server-starting"); |
279 |
306 |
280 -- start listening on sockets |
307 -- start listening on sockets |
281 prosody.net_activate_ports("c2s", "xmppclient", {5222}); |
308 prosody.net_activate_ports("c2s", "xmppclient", {5222}); |
282 prosody.net_activate_ports("s2s", "xmppserver", {5269}); |
309 prosody.net_activate_ports("s2s", "xmppserver", {5269}); |
283 prosody.net_activate_ports("component", "xmppcomponent", {}, "tcp"); |
310 prosody.net_activate_ports("component", "xmppcomponent", {5347}, "tcp"); |
284 prosody.net_activate_ports("legacy_ssl", "xmppclient", {}, "ssl"); |
311 prosody.net_activate_ports("legacy_ssl", "xmppclient", {}, "ssl"); |
285 |
312 |
286 prosody.start_time = os.time(); |
313 prosody.start_time = os.time(); |
287 end |
314 end |
288 |
315 |
289 function init_global_protection() |
316 function init_global_protection() |
290 -- Catch global accesses -- |
317 -- Catch global accesses |
291 local locked_globals_mt = { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end } |
318 local locked_globals_mt = { |
|
319 __index = function (t, k) log("warn", "%s", debug.traceback("Attempt to read a non-existent global '"..tostring(k).."'", 2)); end; |
|
320 __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end; |
|
321 }; |
292 |
322 |
293 function prosody.unlock_globals() |
323 function prosody.unlock_globals() |
294 setmetatable(_G, nil); |
324 setmetatable(_G, nil); |
295 end |
325 end |
296 |
326 |