Software /
code /
prosody
Annotate
net/xmppclient_listener.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 | 318:cc20ea4a8697 |
child | 330:d9d4c1de16ce |
rev | line source |
---|---|
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local logger = require "logger"; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local lxp = require "lxp" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local init_xmlhandlers = require "core.xmlhandlers" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local sm_new_session = require "core.sessionmanager".new_session; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local connlisteners_register = require "net.connlisteners".register; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local t_insert = table.insert; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local t_concat = table.concat; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local m_random = math.random; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local format = string.format; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; --import("core.sessionmanager", "new_session", "destroy_session"); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local sm_streamopened = sessionmanager.streamopened; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local st = stanza; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local sessions = {}; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local xmppclient = { default_port = 5222 }; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 -- These are session methods -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local function session_reset_stream(session) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 -- Reset stream |
148 | 25 local parser = lxp.new(init_xmlhandlers(session, sm_streamopened), "|"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 session.parser = parser; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 session.notopen = true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 function session.data(conn, data) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 parser:parse(data); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 return true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
36 |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
37 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
38 local function session_disconnect(session, reason) |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
39 local log = session.log or log; |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
40 if session.conn then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
41 if reason then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
42 if type(reason) == "string" then -- assume stream error |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
43 log("info", "Disconnecting client, <stream:error> is: %s", reason); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
44 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
45 elseif type(reason) == "table" then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
46 if reason.condition then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
47 local stanza = st.stanza("stream:error"):tag(reason.condition, stream_xmlns_attr):up(); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
48 if reason.text then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
49 stanza:tag("text", stream_xmlns_attr):text(reason.text):up(); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
50 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
51 if reason.extra then |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
52 stanza:add_child(reason.extra); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
53 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
54 log("info", "Disconnecting client, <stream:error> is: %s", tostring(stanza)); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
55 session.send(stanza); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
56 elseif reason.name then -- a stanza |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
57 log("info", "Disconnecting client, <stream:error> is: %s", tostring(reason)); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
58 session.send(reason); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
59 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
60 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
61 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
62 session.send("</stream:stream>"); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
63 session.conn.close(); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
64 xmppclient.disconnect(session.conn, "stream error"); |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
65 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
66 end |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
67 |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
68 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 -- End of session methods -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 function xmppclient.listener(conn, data) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 local session = sessions[conn]; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 if not session then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 session = sm_new_session(conn); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 sessions[conn] = session; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 -- Logging functions -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 local mainlog, log = log; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 do |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 local conn_name = tostring(conn):match("[a-f0-9]+$"); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 log = logger.init(conn_name); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 local print = function (...) log("info", t_concatall({...}, "\t")); end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 session.log = log; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 print("Client connected"); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 session.reset_stream = session_reset_stream; |
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)
Matthew Wild <mwild1@gmail.com>
parents:
318
diff
changeset
|
90 session.disconnect = session_disconnect; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 session_reset_stream(session); -- Initialise, ready for use |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 -- TODO: Below function should be session,stanza - and xmlhandlers should use :method() notation to call, |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 -- this will avoid the useless indirection we have atm |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 -- (I'm on a mission, no time to fix now) |
226
ba4711c4e8d2
Committing code to get nicer tracebacks for errors, also we no longer consider such errors fatal (probably a bad thing, I know...)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
97 |
ba4711c4e8d2
Committing code to get nicer tracebacks for errors, also we no longer consider such errors fatal (probably a bad thing, I know...)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
98 -- Debug version -- |
232
20745f8f4cf1
Actually show error and position when we show a traceback :)
Matthew Wild <mwild1@gmail.com>
parents:
226
diff
changeset
|
99 local function handleerr(err) print("Traceback:", err, debug.traceback()); end |
226
ba4711c4e8d2
Committing code to get nicer tracebacks for errors, also we no longer consider such errors fatal (probably a bad thing, I know...)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
100 session.stanza_dispatch = function (stanza) return select(2, xpcall(function () return core_process_stanza(session, stanza); end, handleerr)); end |
ba4711c4e8d2
Committing code to get nicer tracebacks for errors, also we no longer consider such errors fatal (probably a bad thing, I know...)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
101 |
ba4711c4e8d2
Committing code to get nicer tracebacks for errors, also we no longer consider such errors fatal (probably a bad thing, I know...)
Matthew Wild <mwild1@gmail.com>
parents:
166
diff
changeset
|
102 -- session.stanza_dispatch = function (stanza) return core_process_stanza(session, stanza); end |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if data then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 session.data(conn, data); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
275
7af22e56d625
Fix logging of disconnect reason, and also sending of unavailable presence on disconnect
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
110 function xmppclient.disconnect(conn, err) |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
111 local session = sessions[conn]; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
112 if session then |
275
7af22e56d625
Fix logging of disconnect reason, and also sending of unavailable presence on disconnect
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
113 if session.presence and session.presence.attr.type ~= "unavailable" then |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
114 local pres = st.presence{ type = "unavailable" }; |
275
7af22e56d625
Fix logging of disconnect reason, and also sending of unavailable presence on disconnect
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
115 if err == "closed" then err = "connection closed"; end |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
116 pres:tag("status"):text("Disconnected: "..err); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
117 session.stanza_dispatch(pres); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
118 end |
318
cc20ea4a8697
Fix logging in some cases for client disconnects
Matthew Wild <mwild1@gmail.com>
parents:
275
diff
changeset
|
119 (session.log or log)("info", "Client disconnected: %s", err); |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
120 sm_destroy_session(session); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
121 sessions[conn] = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
122 session = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
123 collectgarbage("collect"); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
124 end |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 connlisteners_register("xmppclient", xmppclient); |