Comparison

core/sessionmanager.lua @ 4543:db27a4c18b6a

mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Jan 2012 23:57:13 +0000
parent 4456:2724bc4c9dff
child 4548:e6e5c76ff009
comparison
equal deleted inserted replaced
4542:50aca1e0bfbd 4543:db27a4c18b6a
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 logger = require "util.logger"; 16 local logger = require "util.logger";
20 local log = logger.init("sessionmanager"); 17 local log = logger.init("sessionmanager");
21 local error = error; 18 local error = error;
22 local uuid_generate = require "util.uuid".generate;
23 local rm_load_roster = require "core.rostermanager".load_roster; 19 local rm_load_roster = require "core.rostermanager".load_roster;
24 local config_get = require "core.configmanager".get; 20 local config_get = require "core.configmanager".get;
25 local nameprep = require "util.encodings".stringprep.nameprep;
26 local resourceprep = require "util.encodings".stringprep.resourceprep; 21 local resourceprep = require "util.encodings".stringprep.resourceprep;
27 local nodeprep = require "util.encodings".stringprep.nodeprep; 22 local nodeprep = require "util.encodings".stringprep.nodeprep;
28 23
29 local initialize_filters = require "util.filters".initialize; 24 local initialize_filters = require "util.filters".initialize;
30 local fire_event = prosody.events.fire_event; 25 local fire_event = prosody.events.fire_event;
214 hosts[session.host].events.fire_event("resource-bind", {session=session}); 209 hosts[session.host].events.fire_event("resource-bind", {session=session});
215 210
216 return true; 211 return true;
217 end 212 end
218 213
219 function streamopened(session, attr)
220 local send = session.send;
221 session.host = attr.to;
222 if not session.host then
223 session:close{ condition = "improper-addressing",
224 text = "A 'to' attribute is required on stream headers" };
225 return;
226 end
227 session.host = nameprep(session.host);
228 session.version = tonumber(attr.version) or 0;
229 session.streamid = uuid_generate();
230 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host);
231
232 if not hosts[session.host] then
233 -- We don't serve this host...
234 session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
235 return;
236 end
237
238 send("<?xml version='1.0'?>");
239 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));
240
241 (session.log or log)("debug", "Sent reply <stream:stream> to client");
242 session.notopen = nil;
243
244 -- If session.secure is *false* (not nil) then it means we /were/ encrypting
245 -- since we now have a new stream header, session is secured
246 if session.secure == false then
247 session.secure = true;
248 end
249
250 local features = st.stanza("stream:features");
251 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features });
252 fire_event("stream-features", session, features);
253
254 send(features);
255
256 end
257
258 function streamclosed(session)
259 session.log("debug", "Received </stream:stream>");
260 session:close();
261 end
262
263 function send_to_available_resources(user, host, stanza) 214 function send_to_available_resources(user, host, stanza)
264 local jid = user.."@"..host; 215 local jid = user.."@"..host;
265 local count = 0; 216 local count = 0;
266 local user = bare_sessions[jid]; 217 local user = bare_sessions[jid];
267 if user then 218 if user then