GPL->MIT!
[prosody.git] / core / sessionmanager.lua
index bc48d2287bbf30ebfb560a4b1f756cb9e4607d2d..64f6df9732aef0b437614f9f3bc1eabdfca2bbc2 100644 (file)
@@ -1,20 +1,9 @@
--- Prosody IM v0.1
+-- Prosody IM v0.2
 -- Copyright (C) 2008 Matthew Wild
 -- Copyright (C) 2008 Waqas Hussain
 -- 
--- This program is free software; you can redistribute it and/or
--- modify it under the terms of the GNU General Public License
--- as published by the Free Software Foundation; either version 2
--- of the License, or (at your option) any later version.
--- 
--- This program is distributed in the hope that it will be useful,
--- but WITHOUT ANY WARRANTY; without even the implied warranty of
--- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--- GNU General Public License for more details.
--- 
--- You should have received a copy of the GNU General Public License
--- along with this program; if not, write to the Free Software
--- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
 --
 
 
@@ -35,6 +24,8 @@ local uuid_generate = require "util.uuid".generate;
 local rm_load_roster = require "core.rostermanager".load_roster;
 local config_get = require "core.configmanager".get;
 
+local fire_event = require "core.eventmanager".fire_event;
+
 local gettime = require "socket".gettime;
 
 local st = require "util.stanza";
@@ -50,12 +41,13 @@ function new_session(conn)
        local session = { conn = conn,  priority = 0, type = "c2s_unauthed", conntime = gettime() };
        if true then
                session.trace = newproxy(true);
-               getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end;
+               getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end;
        end
        open_sessions = open_sessions + 1;
        log("info", "open sessions now: ".. open_sessions);
        local w = conn.write;
        session.send = function (t) w(tostring(t)); end
+       session.ip = conn.ip();
        return session;
 end
 
@@ -67,7 +59,7 @@ function destroy_session(session, err)
                local pres = st.presence{ type = "unavailable" };
                if (not err) or err == "closed" then err = "connection closed"; end
                pres:tag("status"):text("Disconnected: "..err);
-               session.stanza_dispatch(pres);
+               session:dispatch_stanza(pres);
        end
        
        -- Remove session/resource from user's session list
@@ -111,8 +103,6 @@ function bind_resource(session, resource)
        if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end
        -- We don't support binding multiple resources
 
-       session.conntimetotal = gettime()-session.conntime;
-       
        resource = resource or uuid_generate();
        --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
        
@@ -179,7 +169,7 @@ function streamopened(session, attr)
                                                
                                                
                                                local features = st.stanza("stream:features");
-                                               modulemanager.fire_event("stream-features", session, features);
+                                               fire_event("stream-features", session, features);
                                                
                                                send(features);
                                                
@@ -207,4 +197,4 @@ function send_to_available_resources(user, host, stanza)
        return count;
 end
 
-return _M;
\ No newline at end of file
+return _M;