26 if CFG_DATADIR then |
26 if CFG_DATADIR then |
27 if os.getenv("HOME") then |
27 if os.getenv("HOME") then |
28 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
28 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
29 end |
29 end |
30 end |
30 end |
|
31 |
|
32 -- Global 'prosody' object |
|
33 prosody = { events = require "util.events".new(); }; |
|
34 local prosody = prosody; |
31 |
35 |
32 -- Load the config-parsing module |
36 -- Load the config-parsing module |
33 config = require "core.configmanager" |
37 config = require "core.configmanager" |
34 |
38 |
35 -- -- -- -- |
39 -- -- -- -- |
146 function init_global_state() |
150 function init_global_state() |
147 bare_sessions = {}; |
151 bare_sessions = {}; |
148 full_sessions = {}; |
152 full_sessions = {}; |
149 hosts = {}; |
153 hosts = {}; |
150 |
154 |
151 -- Global 'prosody' object |
|
152 prosody = {}; |
|
153 local prosody = prosody; |
|
154 |
|
155 prosody.bare_sessions = bare_sessions; |
155 prosody.bare_sessions = bare_sessions; |
156 prosody.full_sessions = full_sessions; |
156 prosody.full_sessions = full_sessions; |
157 prosody.hosts = hosts; |
157 prosody.hosts = hosts; |
158 |
158 |
159 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, |
159 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, |
160 plugins = CFG_PLUGINDIR, data = CFG_DATADIR }; |
160 plugins = CFG_PLUGINDIR, data = CFG_DATADIR }; |
161 |
161 |
162 prosody.arg = _G.arg; |
162 prosody.arg = _G.arg; |
163 |
163 |
164 prosody.events = require "util.events".new(); |
|
165 |
|
166 prosody.platform = "unknown"; |
164 prosody.platform = "unknown"; |
167 if os.getenv("WINDIR") then |
165 if os.getenv("WINDIR") then |
168 prosody.platform = "windows"; |
166 prosody.platform = "windows"; |
169 elseif package.config:sub(1,1) == "/" then |
167 elseif package.config:sub(1,1) == "/" then |
170 prosody.platform = "posix"; |
168 prosody.platform = "posix"; |
191 end |
189 end |
192 |
190 |
193 -- Function to reopen logfiles |
191 -- Function to reopen logfiles |
194 function prosody.reopen_logfiles() |
192 function prosody.reopen_logfiles() |
195 log("info", "Re-opening log files"); |
193 log("info", "Re-opening log files"); |
196 eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks |
|
197 prosody.events.fire_event("reopen-log-files"); |
194 prosody.events.fire_event("reopen-log-files"); |
198 end |
195 end |
199 |
196 |
200 -- Function to initiate prosody shutdown |
197 -- Function to initiate prosody shutdown |
201 function prosody.shutdown(reason) |
198 function prosody.shutdown(reason) |
284 function load_secondary_libraries() |
281 function load_secondary_libraries() |
285 --- Load and initialise core modules |
282 --- Load and initialise core modules |
286 require "util.import" |
283 require "util.import" |
287 require "core.xmlhandlers" |
284 require "core.xmlhandlers" |
288 require "core.rostermanager" |
285 require "core.rostermanager" |
289 require "core.eventmanager" |
|
290 require "core.hostmanager" |
286 require "core.hostmanager" |
291 require "core.modulemanager" |
287 require "core.modulemanager" |
292 require "core.usermanager" |
288 require "core.usermanager" |
293 require "core.sessionmanager" |
289 require "core.sessionmanager" |
294 require "core.stanza_router" |
290 require "core.stanza_router" |
328 end |
324 end |
329 |
325 |
330 function prepare_to_start() |
326 function prepare_to_start() |
331 log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); |
327 log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); |
332 -- Signal to modules that we are ready to start |
328 -- Signal to modules that we are ready to start |
333 eventmanager.fire_event("server-starting"); |
|
334 prosody.events.fire_event("server-starting"); |
329 prosody.events.fire_event("server-starting"); |
335 |
330 |
336 -- start listening on sockets |
331 -- start listening on sockets |
337 if config.get("*", "core", "ports") then |
332 if config.get("*", "core", "ports") then |
338 prosody.net_activate_ports(nil, "multiplex", {5222, 5269}); |
333 prosody.net_activate_ports(nil, "multiplex", {5222, 5269}); |
446 load_secondary_libraries(); |
441 load_secondary_libraries(); |
447 init_data_store(); |
442 init_data_store(); |
448 init_global_protection(); |
443 init_global_protection(); |
449 prepare_to_start(); |
444 prepare_to_start(); |
450 |
445 |
451 eventmanager.fire_event("server-started"); |
|
452 prosody.events.fire_event("server-started"); |
446 prosody.events.fire_event("server-started"); |
453 |
447 |
454 loop(); |
448 loop(); |
455 |
449 |
456 log("info", "Shutting down..."); |
450 log("info", "Shutting down..."); |
457 cleanup(); |
451 cleanup(); |
458 eventmanager.fire_event("server-stopped"); |
|
459 prosody.events.fire_event("server-stopped"); |
452 prosody.events.fire_event("server-stopped"); |
460 log("info", "Shutdown complete"); |
453 log("info", "Shutdown complete"); |
461 |
454 |