Comparison

core/sessionmanager.lua @ 329:3be63719428e

Allow us to close client connections, with or without a stream error. Partially fixes #8, we still need the same for s2s (though it should be almost a straight copy of the code, I'm too tired atm)
author Matthew Wild <mwild1@gmail.com>
date Tue, 18 Nov 2008 05:13:29 +0000
parent 317:dcb5bce69a0f
child 331:830fd67f9378
comparison
equal deleted inserted replaced
328:a1d25769970f 329:3be63719428e
94 function streamopened(session, attr) 94 function streamopened(session, attr)
95 local send = session.send; 95 local send = session.send;
96 session.host = attr.to or error("Client failed to specify destination hostname"); 96 session.host = attr.to or error("Client failed to specify destination hostname");
97 session.version = tonumber(attr.version) or 0; 97 session.version = tonumber(attr.version) or 0;
98 session.streamid = m_random(1000000, 99999999); 98 session.streamid = m_random(1000000, 99999999);
99 print(session, session.host, "Client opened stream"); 99 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host);
100 send("<?xml version='1.0'?>"); 100
101
102 send("<?xml version='1.0'?>");
101 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)); 103 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));
104
105 if not hosts[session.host] then
106 -- We don't serve this host...
107 session:disconnect{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
108 return;
109 end
110
102 111
103 local features = {}; 112 local features = {};
104 modulemanager.fire_event("stream-features", session, features); 113 modulemanager.fire_event("stream-features", session, features);
105 114
115 -- FIXME: Need to send() this all at once
106 send("<stream:features>"); 116 send("<stream:features>");
107 117
108 for _, feature in ipairs(features) do 118 for _, feature in ipairs(features) do
109 send(tostring(feature)); 119 send(tostring(feature));
110 end 120 end