Software /
code /
prosody
Annotate
net/xmppclient_listener.lua @ 2520:f28fbc93eb54
Backed out changeset a4f9ed3f912e (you didn't see this)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 29 Jan 2010 03:06:37 +0000 |
parent | 2466:0e44b6035210 |
child | 2753:305428b14f76 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1490
diff
changeset
|
1 -- Prosody IM |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
451
diff
changeset
|
9 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local logger = require "logger"; |
1040
4c79b28bce64
xmpp{server,client}_listener: Fix global accesses
Matthew Wild <mwild1@gmail.com>
parents:
901
diff
changeset
|
12 local log = logger.init("xmppclient_listener"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local lxp = require "lxp" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local init_xmlhandlers = require "core.xmlhandlers" |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local sm_new_session = require "core.sessionmanager".new_session; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local connlisteners_register = require "net.connlisteners".register; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local t_insert = table.insert; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local t_concat = table.concat; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 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
|
22 local m_random = math.random; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local format = string.format; |
1040
4c79b28bce64
xmpp{server,client}_listener: Fix global accesses
Matthew Wild <mwild1@gmail.com>
parents:
901
diff
changeset
|
24 local sessionmanager = require "core.sessionmanager"; |
4c79b28bce64
xmpp{server,client}_listener: Fix global accesses
Matthew Wild <mwild1@gmail.com>
parents:
901
diff
changeset
|
25 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local sm_streamopened = sessionmanager.streamopened; |
331 | 27 local sm_streamclosed = sessionmanager.streamclosed; |
1040
4c79b28bce64
xmpp{server,client}_listener: Fix global accesses
Matthew Wild <mwild1@gmail.com>
parents:
901
diff
changeset
|
28 local st = require "util.stanza"; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
2454
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
30 local config = require "core.configmanager"; |
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
31 local opt_keepalives = config.get("*", "core", "tcp_keepalives"); |
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
32 |
2466
0e44b6035210
net.xmpp{client,server,component}: Update for new xmlhandlers syntax
Matthew Wild <mwild1@gmail.com>
parents:
2454
diff
changeset
|
33 local stream_callbacks = { default_ns = "jabber:client", |
901
0e8934d3c4cb
net.xmppclient_listener: Set default namespace to jabber:client
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
34 streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
35 |
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
36 function stream_callbacks.error(session, error, data) |
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
37 if error == "no-stream" then |
837
86d14e7ef60c
net/xmppclient_listener: Add some logging and handle unestablished sessions error'ing
Matthew Wild <mwild1@gmail.com>
parents:
760
diff
changeset
|
38 session.log("debug", "Invalid opening stream header"); |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
39 session:close("invalid-namespace"); |
837
86d14e7ef60c
net/xmppclient_listener: Add some logging and handle unestablished sessions error'ing
Matthew Wild <mwild1@gmail.com>
parents:
760
diff
changeset
|
40 elseif session.close then |
86d14e7ef60c
net/xmppclient_listener: Add some logging and handle unestablished sessions error'ing
Matthew Wild <mwild1@gmail.com>
parents:
760
diff
changeset
|
41 (session.log or log)("debug", "Client XML parse error: %s", tostring(error)); |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
42 session:close("xml-not-well-formed"); |
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
43 end |
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
44 end |
331 | 45 |
611
7bb91fcddaf8
Fix blank tracebacks for c2s/s2s connections
Matthew Wild <mwild1@gmail.com>
parents:
604
diff
changeset
|
46 local function handleerr(err) log("error", "Traceback[c2s]: %s: %s", tostring(err), debug.traceback()); end |
559
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
557
diff
changeset
|
47 function stream_callbacks.handlestanza(a, b) |
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
557
diff
changeset
|
48 xpcall(function () core_process_stanza(a, b) end, handleerr); |
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
557
diff
changeset
|
49 end |
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
557
diff
changeset
|
50 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 local sessions = {}; |
451
e9f269e5204e
No more reading 1 byte at a time from sockets
Matthew Wild <mwild1@gmail.com>
parents:
333
diff
changeset
|
52 local xmppclient = { default_port = 5222, default_mode = "*a" }; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 -- These are session methods -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 local function session_reset_stream(session) |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 -- Reset stream |
2077
e33658f6052c
Changed separator between attribute names and prefixes from '|' to '\1' (optimization and cleanup).
Waqas Hussain <waqas20@gmail.com>
parents:
1685
diff
changeset
|
58 local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 session.parser = parser; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 session.notopen = true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 function session.data(conn, data) |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
64 local ok, err = parser:parse(data); |
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
65 if ok then return; end |
2167
e41a6ea7fc0f
xmppclient_listener: Escape control characters when logging invalid XML.
Waqas Hussain <waqas20@gmail.com>
parents:
2077
diff
changeset
|
66 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
67 session:close("xml-not-well-formed"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
557
c9b3ffb08fe3
Disconnect with stream errors on bad XML, or invalid stream namespace
Matthew Wild <mwild1@gmail.com>
parents:
545
diff
changeset
|
69 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 return true; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
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
|
73 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
2466
0e44b6035210
net.xmpp{client,server,component}: Update for new xmlhandlers syntax
Matthew Wild <mwild1@gmail.com>
parents:
2454
diff
changeset
|
74 local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; |
333
8d15b073fdbe
session:disconnect() -> session:close() for consistency with other Lua APIs
Matthew Wild <mwild1@gmail.com>
parents:
331
diff
changeset
|
75 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
|
76 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
|
77 if session.conn then |
1617
c6e175a0d83b
xmpp{client,server,component]_listener: Open stream if sending an error and it isn't already open. Fixes #120
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
78 if session.notopen then |
c6e175a0d83b
xmpp{client,server,component]_listener: Open stream if sending an error and it isn't already open. Fixes #120
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
79 session.send("<?xml version='1.0'?>"); |
c6e175a0d83b
xmpp{client,server,component]_listener: Open stream if sending an error and it isn't already open. Fixes #120
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
80 session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); |
c6e175a0d83b
xmpp{client,server,component]_listener: Open stream if sending an error and it isn't already open. Fixes #120
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
81 end |
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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 session.send("</stream:stream>"); |
2107
90751c0ca690
xmppclient_listener: Use : syntax for connection methods, to be compatible with new server.lua
Matthew Wild <mwild1@gmail.com>
parents:
2106
diff
changeset
|
104 session.conn:close(); |
2129
fcdcdf00787c
*_listener: Update for new net.server API, specifically .listener -> .onincoming, .disconnect -> .ondisconnect
Matthew Wild <mwild1@gmail.com>
parents:
2107
diff
changeset
|
105 xmppclient.ondisconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed"); |
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
|
106 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
|
107 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
|
108 |
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
|
109 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 -- End of session methods -- |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 |
2106
0737b167a997
xmppclient_listener: Switch to .onincoming listener method, to be compatible with new server_event.lua
Matthew Wild <mwild1@gmail.com>
parents:
2077
diff
changeset
|
112 function xmppclient.onincoming(conn, data) |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 local session = sessions[conn]; |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 if not session then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 session = sm_new_session(conn); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 sessions[conn] = session; |
565
3a49d85cafbc
Backed out changeset 099d8a102deb (committed too much)
Matthew Wild <mwild1@gmail.com>
parents:
563
diff
changeset
|
117 |
585
033817e12ddb
Code tidying for xmpp{client,server}_listeners
Matthew Wild <mwild1@gmail.com>
parents:
565
diff
changeset
|
118 session.log("info", "Client connected"); |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
1255
a25b12c105bb
net.xmppclient_listener: Add small comment
Matthew Wild <mwild1@gmail.com>
parents:
1215
diff
changeset
|
120 -- Client is using legacy SSL (otherwise mod_tls sets this flag) |
2107
90751c0ca690
xmppclient_listener: Use : syntax for connection methods, to be compatible with new server.lua
Matthew Wild <mwild1@gmail.com>
parents:
2106
diff
changeset
|
121 if conn:ssl() then |
1215
d3534badd748
xmppclient_listener: A connection is also secure when it uses legacy SSL
Matthew Wild <mwild1@gmail.com>
parents:
1040
diff
changeset
|
122 session.secure = true; |
d3534badd748
xmppclient_listener: A connection is also secure when it uses legacy SSL
Matthew Wild <mwild1@gmail.com>
parents:
1040
diff
changeset
|
123 end |
d3534badd748
xmppclient_listener: A connection is also secure when it uses legacy SSL
Matthew Wild <mwild1@gmail.com>
parents:
1040
diff
changeset
|
124 |
2454
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
125 if opt_keepalives ~= nil then |
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
126 conn:setoption("keepalive", opt_keepalives); |
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
127 end |
e4818c49192d
xmppclient_listener: Allow the tcp_keepalives option in the config to control whether keepalives are used
Matthew Wild <mwild1@gmail.com>
parents:
2170
diff
changeset
|
128 |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 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
|
130 session.close = session_close; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 session_reset_stream(session); -- Initialise, ready for use |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 |
604
b6a31e97d018
stanza_dispatch != dispatch_stanza
Matthew Wild <mwild1@gmail.com>
parents:
598
diff
changeset
|
134 session.dispatch_stanza = stream_callbacks.handlestanza; |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 if data then |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 session.data(conn, data); |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 end |
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 |
2129
fcdcdf00787c
*_listener: Update for new net.server API, specifically .listener -> .onincoming, .disconnect -> .ondisconnect
Matthew Wild <mwild1@gmail.com>
parents:
2107
diff
changeset
|
141 function xmppclient.ondisconnect(conn, err) |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
142 local session = sessions[conn]; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
143 if session then |
318
cc20ea4a8697
Fix logging in some cases for client disconnects
Matthew Wild <mwild1@gmail.com>
parents:
275
diff
changeset
|
144 (session.log or log)("info", "Client disconnected: %s", err); |
1422
db9cb1f24f38
xmppclient_listener: Pass session close reason to destroy_session (to be used in unavailable presence)
Matthew Wild <mwild1@gmail.com>
parents:
1255
diff
changeset
|
145 sm_destroy_session(session, err); |
123
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
146 sessions[conn] = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
147 session = nil; |
ebd65feb188c
Fix for not destroying sessions when connection closed.
Matthew Wild <mwild1@gmail.com>
parents:
99
diff
changeset
|
148 end |
99
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
ba08b8a4eeef
Abstract connections with "connection listeners"
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 connlisteners_register("xmppclient", xmppclient); |