Software /
code /
prosody
Annotate
net/xmppclient_listener.lua @ 540:ec03f6968fa8
Added function add_feature to modules API (for adding disco features)
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 04 Dec 2008 20:07:22 +0500 |
parent | 519:cccd610a0ef9 |
child | 543:cf6e19ea1cbc |
rev | line source |
---|---|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
1 -- Prosody IM v0.1 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
20 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local logger = require "logger"; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local lxp = require "lxp" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local init_xmlhandlers = require "core.xmlhandlers" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local sm_new_session = require "core.sessionmanager".new_session; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local connlisteners_register = require "net.connlisteners".register; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local t_insert = table.insert; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local t_concat = table.concat; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 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
|
32 local m_random = math.random; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local format = string.format; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 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
|
35 local sm_streamopened = sessionmanager.streamopened; |
331 | 36 local sm_streamclosed = sessionmanager.streamclosed; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local st = stanza; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
331 | 39 local stream_callbacks = { streamopened = sm_streamopened, streamclosed = sm_streamclosed }; |
40 | |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local sessions = {}; |
451
e9f269e5204e
No more reading 1 byte at a time from sockets
Matthew Wild <mwild1@gmail.com>
parents:
333
diff
changeset
|
42 local xmppclient = { default_port = 5222, default_mode = "*a" }; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 -- These are session methods -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local function session_reset_stream(session) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 -- Reset stream |
331 | 48 local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 session.parser = parser; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 session.notopen = true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 function session.data(conn, data) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 parser:parse(data); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 return true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 |
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
|
59 |
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 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
333
8d15b073fdbe
session:disconnect() -> session:close() for consistency with other Lua APIs
Matthew Wild <mwild1@gmail.com>
parents:
331
diff
changeset
|
61 local function session_close(session, reason) |
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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 |
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
|
91 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 -- End of session methods -- |
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 function xmppclient.listener(conn, data) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 local session = sessions[conn]; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 if not session then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 session = sm_new_session(conn); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 sessions[conn] = session; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 -- Logging functions -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 local mainlog, log = log; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 do |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local conn_name = tostring(conn):match("[a-f0-9]+$"); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 log = logger.init(conn_name); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 local print = function (...) log("info", t_concatall({...}, "\t")); end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 session.log = log; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 print("Client connected"); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 session.reset_stream = session_reset_stream; |
333
8d15b073fdbe
session:disconnect() -> session:close() for consistency with other Lua APIs
Matthew Wild <mwild1@gmail.com>
parents:
331
diff
changeset
|
113 session.close = session_close; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 session_reset_stream(session); -- Initialise, ready for use |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 -- 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
|
118 -- this will avoid the useless indirection we have atm |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 -- (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
|
120 |
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
|
121 -- Debug version -- |
232
20745f8f4cf1
Actually show error and position when we show a traceback :)
Matthew Wild <mwild1@gmail.com>
parents:
226
diff
changeset
|
122 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
|
123 session.stanza_dispatch = function (stanza) return select(2, xpcall(function () return core_process_stanza(session, stanza); end, handleerr)); end |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 if data then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 session.data(conn, data); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
275
7af22e56d625
Fix logging of disconnect reason, and also sending of unavailable presence on disconnect
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
130 function xmppclient.disconnect(conn, err) |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
131 local session = sessions[conn]; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
132 if session then |
318
cc20ea4a8697
Fix logging in some cases for client disconnects
Matthew Wild <mwild1@gmail.com>
parents:
275
diff
changeset
|
133 (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
|
134 sm_destroy_session(session); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
135 sessions[conn] = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
136 session = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
137 collectgarbage("collect"); |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
138 end |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 connlisteners_register("xmppclient", xmppclient); |