Comparison

net/xmppserver_listener.lua @ 330:d9d4c1de16ce

s2s sessions can now be disconnected, with or without a stream error. Fixes #8
author Matthew Wild <mwild1@gmail.com>
date Tue, 18 Nov 2008 14:42:45 +0000
parent 232:20745f8f4cf1
child 331:830fd67f9378
comparison
equal deleted inserted replaced
329:3be63719428e 330:d9d4c1de16ce
33 parser:parse(data); 33 parser:parse(data);
34 end 34 end
35 return true; 35 return true;
36 end 36 end
37 37
38
39 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
40 local function session_disconnect(session, reason)
41 local log = session.log or log;
42 if session.conn then
43 if reason then
44 if type(reason) == "string" then -- assume stream error
45 log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, reason);
46 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
47 elseif type(reason) == "table" then
48 if reason.condition then
49 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
50 if reason.text then
51 stanza:tag("text", stream_xmlns_attr):text(reason.text):up();
52 end
53 if reason.extra then
54 stanza:add_child(reason.extra);
55 end
56 log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, tostring(stanza));
57 session.send(stanza);
58 elseif reason.name then -- a stanza
59 log("info", "Disconnecting %s[%s], <stream:error> is: %s", session.host or "(unknown host)", session.type, tostring(reason));
60 session.send(reason);
61 end
62 end
63 end
64 session.send("</stream:stream>");
65 session.conn.close();
66 xmppserver.disconnect(session.conn, "stream error");
67 end
68 end
69
70
38 -- End of session methods -- 71 -- End of session methods --
39 72
40 function xmppserver.listener(conn, data) 73 function xmppserver.listener(conn, data)
41 local session = sessions[conn]; 74 local session = sessions[conn];
42 if not session then 75 if not session then
54 session.log = log; 87 session.log = log;
55 88
56 print("Incoming s2s connection"); 89 print("Incoming s2s connection");
57 90
58 session.reset_stream = session_reset_stream; 91 session.reset_stream = session_reset_stream;
92 session.disconnect = session_disconnect;
59 93
60 session_reset_stream(session); -- Initialise, ready for use 94 session_reset_stream(session); -- Initialise, ready for use
61 95
62 -- FIXME: Below function should be session,stanza - and xmlhandlers should use :method() notation to call, 96 -- FIXME: Below function should be session,stanza - and xmlhandlers should use :method() notation to call,
63 -- this will avoid the useless indirection we have atm 97 -- this will avoid the useless indirection we have atm