Merge 0.6->0.7
[prosody.git] / prosody
diff --git a/prosody b/prosody
index 8e96eb46ac88d1cfdc42bf146a0570928686bd17..0bcfce4b3f5ca696eb2b54f7fc2574c43a9bc36c 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -22,6 +22,9 @@ if CFG_SOURCEDIR then
        package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
 end
 
+package.path = package.path..";"..(CFG_SOURCEDIR or ".").."/fallbacks/?.lua";
+package.cpath = package.cpath..";"..(CFG_SOURCEDIR or ".").."/fallbacks/?.so";
+
 -- Substitute ~ with path to home directory in data path
 if CFG_DATADIR then
        if os.getenv("HOME") then
@@ -29,10 +32,6 @@ if CFG_DATADIR then
        end
 end
 
--- Global 'prosody' object
-prosody = { events = require "util.events".new(); };
-local prosody = prosody;
-
 -- Load the config-parsing module
 config = require "core.configmanager"
 
@@ -144,6 +143,10 @@ function set_function_metatable()
                        debug.setupvalue(f, i, value);
                end
        end
+       function mt.__tostring(f)
+               local info = debug.getinfo(f);
+               return ("function(%s:%d)"):format(info.short_src:match("[^\\/]*$"), info.linedefined);
+       end
        debug.setmetatable(function() end, mt);
 end
 
@@ -152,6 +155,10 @@ function init_global_state()
        full_sessions = {};
        hosts = {};
 
+       -- Global 'prosody' object
+       prosody = {};
+       local prosody = prosody;
+       
        prosody.bare_sessions = bare_sessions;
        prosody.full_sessions = full_sessions;
        prosody.hosts = hosts;
@@ -161,6 +168,8 @@ function init_global_state()
        
        prosody.arg = _G.arg;
 
+       prosody.events = require "util.events".new();
+       
        prosody.platform = "unknown";
        if os.getenv("WINDIR") then
                prosody.platform = "windows";
@@ -191,6 +200,7 @@ function init_global_state()
        -- Function to reopen logfiles
        function prosody.reopen_logfiles()
                log("info", "Re-opening log files");
+               eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks
                prosody.events.fire_event("reopen-log-files");
        end
 
@@ -283,6 +293,7 @@ function load_secondary_libraries()
        require "util.import"
        require "core.xmlhandlers"
        require "core.rostermanager"
+       require "core.eventmanager"
        require "core.hostmanager"
        require "core.modulemanager"
        require "core.usermanager"
@@ -326,6 +337,7 @@ end
 function prepare_to_start()
        log("info", "Prosody is using the %s backend for connection handling", server.get_backend());
        -- Signal to modules that we are ready to start
+       eventmanager.fire_event("server-starting");
        prosody.events.fire_event("server-starting");
 
        -- start listening on sockets
@@ -443,12 +455,14 @@ init_data_store();
 init_global_protection();
 prepare_to_start();
 
+eventmanager.fire_event("server-started");
 prosody.events.fire_event("server-started");
 
 loop();
 
 log("info", "Shutting down...");
 cleanup();
+eventmanager.fire_event("server-stopped");
 prosody.events.fire_event("server-stopped");
 log("info", "Shutdown complete");