aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/xmppclient_listener.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua
index b5028db0..1f6691da 100644
--- a/net/xmppclient_listener.lua
+++ b/net/xmppclient_listener.lua
@@ -33,6 +33,39 @@ local function session_reset_stream(session)
return true;
end
+
+local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
+local function session_disconnect(session, reason)
+ local log = session.log or log;
+ if session.conn then
+ if reason then
+ if type(reason) == "string" then -- assume stream error
+ log("info", "Disconnecting client, <stream:error> is: %s", reason);
+ session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }));
+ elseif type(reason) == "table" then
+ if reason.condition then
+ local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up();
+ if reason.text then
+ stanza:tag("text", stream_xmlns_attr):text(reason.text):up();
+ end
+ if reason.extra then
+ stanza:add_child(reason.extra);
+ end
+ log("info", "Disconnecting client, <stream:error> is: %s", tostring(stanza));
+ session.send(stanza);
+ elseif reason.name then -- a stanza
+ log("info", "Disconnecting client, <stream:error> is: %s", tostring(reason));
+ session.send(reason);
+ end
+ end
+ end
+ session.send("</stream:stream>");
+ session.conn.close();
+ xmppclient.disconnect(session.conn, "stream error");
+ end
+end
+
+
-- End of session methods --
function xmppclient.listener(conn, data)
@@ -54,6 +87,7 @@ function xmppclient.listener(conn, data)
print("Client connected");
session.reset_stream = session_reset_stream;
+ session.disconnect = session_disconnect;
session_reset_stream(session); -- Initialise, ready for use