Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 4797:e239668aa6d2
Merge 0.9->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 29 Apr 2012 02:10:55 +0100 |
parent | 4552:414d857ee125 |
child | 4813:77da9671ac39 |
comparison
equal
deleted
inserted
replaced
4796:04a34287dc12 | 4797:e239668aa6d2 |
---|---|
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 | |
10 | |
11 local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable; | 9 local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable; |
12 local ipairs, pairs, print, next= ipairs, pairs, print, next; | 10 local ipairs, pairs, print, next= ipairs, pairs, print, next; |
13 local format = string.format; | |
14 | 11 |
15 local hosts = hosts; | 12 local hosts = hosts; |
16 local full_sessions = full_sessions; | 13 local full_sessions = full_sessions; |
17 local bare_sessions = bare_sessions; | 14 local bare_sessions = bare_sessions; |
18 | 15 |
19 local modulemanager = require "core.modulemanager"; | |
20 local logger = require "util.logger"; | 16 local logger = require "util.logger"; |
21 local log = logger.init("sessionmanager"); | 17 local log = logger.init("sessionmanager"); |
22 local error = error; | 18 local error = error; |
23 local uuid_generate = require "util.uuid".generate; | |
24 local rm_load_roster = require "core.rostermanager".load_roster; | 19 local rm_load_roster = require "core.rostermanager".load_roster; |
25 local config_get = require "core.configmanager".get; | 20 local config_get = require "core.configmanager".get; |
26 local nameprep = require "util.encodings".stringprep.nameprep; | |
27 local resourceprep = require "util.encodings".stringprep.resourceprep; | 21 local resourceprep = require "util.encodings".stringprep.resourceprep; |
28 local nodeprep = require "util.encodings".stringprep.nodeprep; | 22 local nodeprep = require "util.encodings".stringprep.nodeprep; |
23 local uuid_generate = require "util.uuid".generate; | |
29 | 24 |
30 local initialize_filters = require "util.filters".initialize; | 25 local initialize_filters = require "util.filters".initialize; |
31 local fire_event = prosody.events.fire_event; | 26 local fire_event = prosody.events.fire_event; |
32 local add_task = require "util.timer".add_task; | 27 local add_task = require "util.timer".add_task; |
33 local gettime = require "socket".gettime; | 28 local gettime = require "socket".gettime; |
34 | 29 |
35 local st = require "util.stanza"; | 30 local st = require "util.stanza"; |
36 | |
37 local c2s_timeout = config_get("*", "core", "c2s_timeout"); | |
38 | 31 |
39 local newproxy = newproxy; | 32 local newproxy = newproxy; |
40 local getmetatable = getmetatable; | 33 local getmetatable = getmetatable; |
41 | 34 |
42 module "sessionmanager" | 35 module "sessionmanager" |
66 end | 59 end |
67 end | 60 end |
68 session.ip = conn:ip(); | 61 session.ip = conn:ip(); |
69 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); | 62 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); |
70 session.log = logger.init(conn_name); | 63 session.log = logger.init(conn_name); |
71 | |
72 if c2s_timeout then | |
73 add_task(c2s_timeout, function () | |
74 if session.type == "c2s_unauthed" then | |
75 session:close("connection-timeout"); | |
76 end | |
77 end); | |
78 end | |
79 | 64 |
80 return session; | 65 return session; |
81 end | 66 end |
82 | 67 |
83 local resting_session = { -- Resting, not dead | 68 local resting_session = { -- Resting, not dead |
215 hosts[session.host].events.fire_event("resource-bind", {session=session}); | 200 hosts[session.host].events.fire_event("resource-bind", {session=session}); |
216 | 201 |
217 return true; | 202 return true; |
218 end | 203 end |
219 | 204 |
220 function streamopened(session, attr) | |
221 local send = session.send; | |
222 session.host = attr.to; | |
223 if not session.host then | |
224 session:close{ condition = "improper-addressing", | |
225 text = "A 'to' attribute is required on stream headers" }; | |
226 return; | |
227 end | |
228 session.host = nameprep(session.host); | |
229 session.version = tonumber(attr.version) or 0; | |
230 session.streamid = uuid_generate(); | |
231 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); | |
232 | |
233 if not hosts[session.host] then | |
234 -- We don't serve this host... | |
235 session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)}; | |
236 return; | |
237 end | |
238 | |
239 send("<?xml version='1.0'?>"); | |
240 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)); | |
241 | |
242 (session.log or log)("debug", "Sent reply <stream:stream> to client"); | |
243 session.notopen = nil; | |
244 | |
245 -- If session.secure is *false* (not nil) then it means we /were/ encrypting | |
246 -- since we now have a new stream header, session is secured | |
247 if session.secure == false then | |
248 session.secure = true; | |
249 end | |
250 | |
251 local features = st.stanza("stream:features"); | |
252 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); | |
253 fire_event("stream-features", session, features); | |
254 | |
255 send(features); | |
256 | |
257 end | |
258 | |
259 function streamclosed(session) | |
260 session.log("debug", "Received </stream:stream>"); | |
261 session:close(); | |
262 end | |
263 | |
264 function send_to_available_resources(user, host, stanza) | 205 function send_to_available_resources(user, host, stanza) |
265 local jid = user.."@"..host; | 206 local jid = user.."@"..host; |
266 local count = 0; | 207 local count = 0; |
267 local user = bare_sessions[jid]; | 208 local user = bare_sessions[jid]; |
268 if user then | 209 if user then |