Software /
code /
prosody
Comparison
main.lua @ 53:14ea0fe6ca86
Session destruction fixes, some debugging code while we fix the rest. Also change logger to be more useful.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 04 Oct 2008 15:25:54 +0100 |
parent | 49:1cd2a8db392d |
child | 65:9c471840acb9 |
comparison
equal
deleted
inserted
replaced
52:93e468eb2ffb | 53:14ea0fe6ca86 |
---|---|
31 local t_insert = table.insert; | 31 local t_insert = table.insert; |
32 local t_concat = table.concat; | 32 local t_concat = table.concat; |
33 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end | 33 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end |
34 local m_random = math.random; | 34 local m_random = math.random; |
35 local format = string.format; | 35 local format = string.format; |
36 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session"); | |
36 local st = stanza; | 37 local st = stanza; |
37 ------------------------------ | 38 ------------------------------ |
38 | 39 |
39 | 40 |
40 | 41 |
46 | 47 |
47 function handler(conn, data, err) | 48 function handler(conn, data, err) |
48 local session = sessions[conn]; | 49 local session = sessions[conn]; |
49 | 50 |
50 if not session then | 51 if not session then |
51 sessions[conn] = sessionmanager.new_session(conn); | 52 sessions[conn] = sm_new_session(conn); |
52 session = sessions[conn]; | 53 session = sessions[conn]; |
53 | 54 |
54 -- Logging functions -- | 55 -- Logging functions -- |
55 | 56 |
56 local mainlog, log = log; | 57 local mainlog, log = log; |
73 local pres = st.presence{ type = "unavailable" }; | 74 local pres = st.presence{ type = "unavailable" }; |
74 if err == "closed" then err = "connection closed"; end | 75 if err == "closed" then err = "connection closed"; end |
75 pres:tag("status"):text("Disconnected: "..err); | 76 pres:tag("status"):text("Disconnected: "..err); |
76 session.stanza_dispatch(pres); | 77 session.stanza_dispatch(pres); |
77 end | 78 end |
78 if session.username then | |
79 hosts[session.host].sessions[session.username] = nil; | |
80 end | |
81 session = nil; | 79 session = nil; |
82 print("Disconnected: "..err); | 80 print("Disconnected: "..tostring(err)); |
83 collectgarbage("collect"); | 81 collectgarbage("collect"); |
84 end | 82 end |
85 end | 83 end |
86 if data then | 84 if data then |
87 session.connhandler:data(data); | 85 session.connhandler:data(data); |
89 | 87 |
90 --log("info", "core", "Client disconnected, connection closed"); | 88 --log("info", "core", "Client disconnected, connection closed"); |
91 end | 89 end |
92 | 90 |
93 function disconnect(conn, err) | 91 function disconnect(conn, err) |
94 sessions[conn].disconnect(err); | 92 sm_destroy_session(sessions[conn]); |
95 sessions[conn] = nil; | 93 sessions[conn] = nil; |
96 end | 94 end |
97 | 95 |
98 modulemanager.loadall(); | 96 modulemanager.loadall(); |
99 | 97 |