Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 1487:66f18c18befa
Merge with main branch.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 05 Jul 2009 19:05:25 +0200 |
parent | 1479:eef17ebe3ca1 |
child | 1523:841d61be198f |
comparison
equal
deleted
inserted
replaced
1486:3e04efa8af7e | 1487:66f18c18befa |
---|---|
38 module "sessionmanager" | 38 module "sessionmanager" |
39 | 39 |
40 local open_sessions = 0; | 40 local open_sessions = 0; |
41 | 41 |
42 function new_session(conn) | 42 function new_session(conn) |
43 local session = { conn = conn, priority = 0, type = "c2s_unauthed", conntime = gettime() }; | 43 local session = { conn = conn, type = "c2s_unauthed", conntime = gettime() }; |
44 if true then | 44 if true then |
45 session.trace = newproxy(true); | 45 session.trace = newproxy(true); |
46 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; | 46 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; |
47 end | 47 end |
48 open_sessions = open_sessions + 1; | 48 open_sessions = open_sessions + 1; |
54 end | 54 end |
55 | 55 |
56 function destroy_session(session, err) | 56 function destroy_session(session, err) |
57 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); | 57 (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); |
58 | 58 |
59 -- Send unavailable presence | |
60 if session.presence then | |
61 local pres = st.presence{ type = "unavailable" }; | |
62 if (not err) or err == "closed" then err = "connection closed"; end | |
63 pres:tag("status"):text("Disconnected: "..err):up(); | |
64 session:dispatch_stanza(pres); | |
65 end | |
66 | |
67 -- Remove session/resource from user's session list | 59 -- Remove session/resource from user's session list |
68 if session.full_jid then | 60 if session.full_jid then |
69 hosts[session.host].events.fire_event("resource-unbind", session); | 61 hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); |
70 | 62 |
71 hosts[session.host].sessions[session.username].sessions[session.resource] = nil; | 63 hosts[session.host].sessions[session.username].sessions[session.resource] = nil; |
72 full_sessions[session.full_jid] = nil; | 64 full_sessions[session.full_jid] = nil; |
73 | 65 |
74 if not next(hosts[session.host].sessions[session.username].sessions) then | 66 if not next(hosts[session.host].sessions[session.username].sessions) then |
130 condition = "conflict"; | 122 condition = "conflict"; |
131 text = "Replaced by new connection"; | 123 text = "Replaced by new connection"; |
132 }; | 124 }; |
133 if not next(sessions) then | 125 if not next(sessions) then |
134 hosts[session.host].sessions[session.username] = { sessions = sessions }; | 126 hosts[session.host].sessions[session.username] = { sessions = sessions }; |
127 bare_sessions[session.username.."@"..session.host] = hosts[session.host].sessions[session.username]; | |
135 end | 128 end |
136 end | 129 end |
137 if increment and sessions[resource] then | 130 if increment and sessions[resource] then |
138 local count = 1; | 131 local count = 1; |
139 while sessions[resource.."#"..count] do | 132 while sessions[resource.."#"..count] do |
149 hosts[session.host].sessions[session.username].sessions[resource] = session; | 142 hosts[session.host].sessions[session.username].sessions[resource] = session; |
150 full_sessions[session.full_jid] = session; | 143 full_sessions[session.full_jid] = session; |
151 | 144 |
152 session.roster = rm_load_roster(session.username, session.host); | 145 session.roster = rm_load_roster(session.username, session.host); |
153 | 146 |
154 hosts[session.host].events.fire_event("resource-bind", session); | 147 hosts[session.host].events.fire_event("resource-bind", {session=session}); |
155 | 148 |
156 return true; | 149 return true; |
157 end | 150 end |
158 | 151 |
159 function streamopened(session, attr) | 152 function streamopened(session, attr) |
163 session.version = tonumber(attr.version) or 0; | 156 session.version = tonumber(attr.version) or 0; |
164 session.streamid = m_random(1000000, 99999999); | 157 session.streamid = m_random(1000000, 99999999); |
165 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); | 158 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); |
166 | 159 |
167 send("<?xml version='1.0'?>"); | 160 send("<?xml version='1.0'?>"); |
168 send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s' version='1.0'>", session.streamid, session.host)); | 161 send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s' version='1.0' xml:lang='en'>", session.streamid, session.host)); |
169 | 162 |
170 if not hosts[session.host] then | 163 if not hosts[session.host] then |
171 -- We don't serve this host... | 164 -- We don't serve this host... |
172 session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)}; | 165 session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)}; |
173 return; | 166 return; |