Software /
code /
prosody
Annotate
plugins/mod_c2s.lua @ 13105:7d9e26003b05
mod_admin_shell: Allow logging HTTP events with debug:logevents("http")
Mirroring debug:events("http"), and to replace the "Firing event: GET /"
log lines in net.http.server
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 14 May 2023 19:02:26 +0200 |
parent | 13095:1693bd4de283 |
child | 13209:c8d949cf6b09 |
rev | line source |
---|---|
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
4 -- |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 module:set_global(); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
11 local add_task = require "prosody.util.timer".add_task; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
12 local new_xmpp_stream = require "prosody.util.xmppstream".new; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
13 local nameprep = require "prosody.util.encodings".stringprep.nameprep; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
14 local sessionmanager = require "prosody.core.sessionmanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
15 local statsmanager = require "prosody.core.statsmanager"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
16 local st = require "prosody.util.stanza"; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_session; |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
18 local uuid_generate = require "prosody.util.uuid".generate; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
19 local async = require "prosody.util.async"; |
12301
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
20 local runner = async.runner; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
8044
e38e3300b955
mod_c2s: Remove unused locals [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7957
diff
changeset
|
22 local tostring, type = tostring, type; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local log = module._log; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
8388
9ee56e9ad47a
mod_c2s: Set a default value for c2s_timeout (fixes #1036)
Kim Alvefur <zash@zash.se>
parents:
8234
diff
changeset
|
28 local c2s_timeout = module:get_option_number("c2s_timeout", 300); |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
29 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); |
5757
b5ba004beb0a
mod_c2s: Change default of tcp_keepalives to true, and make it individually configurable through c2s_tcp_keepalives
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
30 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); |
11540
1937b3c3efb5
mod_c2s, mod_s2s, mod_component, mod_bosh, mod_websockets: Set default stanza size limits
Matthew Wild <mwild1@gmail.com>
parents:
11511
diff
changeset
|
31 local stanza_size_limit = module:get_option_number("c2s_stanza_size_limit", 1024*256); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
11524
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
33 local measure_connections = module:metric("gauge", "connections", "", "Established c2s connections", {"host", "type", "ip_family"}); |
6630
6735e2d735d6
mod_c2s, mod_s2s: Collect statistics on number of connections
Kim Alvefur <zash@zash.se>
parents:
6382
diff
changeset
|
34 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local sessions = module:shared("sessions"); |
5013
ab693eea0869
mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents:
4996
diff
changeset
|
36 local core_process_stanza = prosody.core_process_stanza; |
5370
7838acadb0fa
mod_announce, mod_auth_anonymous, mod_c2s, mod_c2s, mod_component, mod_iq, mod_message, mod_presence, mod_tls: Access prosody.{hosts,bare_sessions,full_sessions} instead of the old globals
Kim Alvefur <zash@zash.se>
parents:
5281
diff
changeset
|
37 local hosts = prosody.hosts; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
5773
c9a712673d8a
mod_c2s: Add session:sleep() and session:wake() to pause a session (e.g. while waiting for an external event). Needs a gallon or two of testing.
Matthew Wild <mwild1@gmail.com>
parents:
5764
diff
changeset
|
39 local stream_callbacks = { default_ns = "jabber:client" }; |
4625
325965bafae1
mod_c2s, mod_s2s: Drop default_port and default_mode from listener objects (default_port is deprecated, and default_mode already defaults to *a)
Matthew Wild <mwild1@gmail.com>
parents:
4620
diff
changeset
|
40 local listener = {}; |
7286 | 41 local runner_callbacks = {}; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
11608
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
43 local m_tls_params = module:metric( |
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
44 "counter", "encrypted", "", |
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
45 "Encrypted connections", |
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
46 {"protocol"; "cipher"} |
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
47 ); |
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
48 |
7662
946871f6e3c8
mod_c2s, mod_s2s: Switch connection counting to 'amount' type and enumerate once per statistics interval
Kim Alvefur <zash@zash.se>
parents:
7540
diff
changeset
|
49 module:hook("stats-update", function () |
11524
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
50 -- for push backends, avoid sending out updates for each increment of |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
51 -- the metric below. |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
52 statsmanager.cork() |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
53 measure_connections:clear() |
8764
81d305bbe7bc
mod_c2s: Add a counter for IPv6.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8390
diff
changeset
|
54 for _, session in pairs(sessions) do |
11524
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
55 local host = session.host or "" |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
56 local type_ = session.type or "other" |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
57 |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
58 -- we want to expose both v4 and v6 counters in all cases to make |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
59 -- queries smoother |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
60 local is_ipv6 = session.ip and session.ip:match(":") and 1 or 0 |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
61 local is_ipv4 = 1 - is_ipv6 |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
62 measure_connections:with_labels(host, type_, "ipv4"):add(is_ipv4) |
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
63 measure_connections:with_labels(host, type_, "ipv6"):add(is_ipv6) |
7466
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
64 end |
11524
6de302b53a3e
mod_c2s: Port to new OpenMetrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
11517
diff
changeset
|
65 statsmanager.uncork() |
7662
946871f6e3c8
mod_c2s, mod_s2s: Switch connection counting to 'amount' type and enumerate once per statistics interval
Kim Alvefur <zash@zash.se>
parents:
7540
diff
changeset
|
66 end); |
7466
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
67 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 --- Stream events handlers |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 function stream_callbacks.streamopened(session, attr) |
10811
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
72 -- run _streamopened in async context |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
73 session.thread:run({ stream = "opened", attr = attr }); |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
74 end |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
75 |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
76 function stream_callbacks._streamopened(session, attr) |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local send = session.send; |
10379
b917602eac04
mod_c2s: Validate that a 'to' attribute exists at all
Kim Alvefur <zash@zash.se>
parents:
10226
diff
changeset
|
78 if not attr.to then |
b917602eac04
mod_c2s: Validate that a 'to' attribute exists at all
Kim Alvefur <zash@zash.se>
parents:
10226
diff
changeset
|
79 session:close{ condition = "improper-addressing", |
b917602eac04
mod_c2s: Validate that a 'to' attribute exists at all
Kim Alvefur <zash@zash.se>
parents:
10226
diff
changeset
|
80 text = "A 'to' attribute is required on stream headers" }; |
b917602eac04
mod_c2s: Validate that a 'to' attribute exists at all
Kim Alvefur <zash@zash.se>
parents:
10226
diff
changeset
|
81 return; |
b917602eac04
mod_c2s: Validate that a 'to' attribute exists at all
Kim Alvefur <zash@zash.se>
parents:
10226
diff
changeset
|
82 end |
8844
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
83 local host = nameprep(attr.to); |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
84 if not host then |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 session:close{ condition = "improper-addressing", |
4551 | 86 text = "A valid 'to' attribute is required on stream headers" }; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 return; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
8844
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
89 if not session.host then |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
90 session.host = host; |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
91 elseif session.host ~= host then |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
92 session:close{ condition = "not-authorized", |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
93 text = "The 'to' attribute must remain the same across stream restarts" }; |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
94 return; |
29c6d2681bad
mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147)
Kim Alvefur <zash@zash.se>
parents:
8232
diff
changeset
|
95 end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 session.version = tonumber(attr.version) or 0; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 session.streamid = uuid_generate(); |
9490
6e4fbd12c11c
mod_c2s: Fix fallback for missing session logger
Kim Alvefur <zash@zash.se>
parents:
8847
diff
changeset
|
98 (session.log or log)("debug", "Client sent opening <stream:stream> to %s", session.host); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 |
5668
5a9318ac92f6
mod_c2s: Become a shared module and allow being disabled on some virtualhosts
Kim Alvefur <zash@zash.se>
parents:
5638
diff
changeset
|
100 if not hosts[session.host] or not hosts[session.host].modules.c2s then |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 -- We don't serve this host... |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)}; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 return; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 |
11359
db146bf7b120
mod_c2s: Reflect stream 'from' attribute back if set (fix #1625)
Kim Alvefur <zash@zash.se>
parents:
11120
diff
changeset
|
106 session:open_stream(host, attr.from); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 |
11517
f7275c2c58fa
mod_c2s: Fix traceback if session was destroyed while opening stream (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11514
diff
changeset
|
108 -- Opening the stream can cause the stream to be closed |
f7275c2c58fa
mod_c2s: Fix traceback if session was destroyed while opening stream (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
11514
diff
changeset
|
109 if session.destroyed then return end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 (session.log or log)("debug", "Sent reply <stream:stream> to client"); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 session.notopen = nil; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 -- If session.secure is *false* (not nil) then it means we /were/ encrypting |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 -- since we now have a new stream header, session is secured |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 if session.secure == false then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 session.secure = true; |
5859
e327f2d4e09f
mod_c2s, mod_s2s: Set session.encrypted as session.secure does not allways mean encrypted (eg consider_bosh_secure)
Kim Alvefur <zash@zash.se>
parents:
5802
diff
changeset
|
118 session.encrypted = true; |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
119 |
12480
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12311
diff
changeset
|
120 local info = session.conn:ssl_info(); |
11622
a62146353528
mod_c2s: Guard against LuaSec not returning TLS info (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
11619
diff
changeset
|
121 if type(info) == "table" then |
5801
224644752bf4
mod_c2s, mod_s2s: Log cipher and encryption info in a more compact and (hopefully) less confusing way
Kim Alvefur <zash@zash.se>
parents:
5789
diff
changeset
|
122 (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); |
5764
969e0a054795
mod_c2s, mod_s2s: Log a message that stream encryption has been enabled with some details
Kim Alvefur <zash@zash.se>
parents:
5759
diff
changeset
|
123 session.compressed = info.compression; |
11608
b2610460d9ab
mod_c2s,mod_s2s: Collect stats on TLS versions and ciphers
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
124 m_tls_params:with_labels(info.protocol, info.cipher):add(1) |
5764
969e0a054795
mod_c2s, mod_s2s: Log a message that stream encryption has been enabled with some details
Kim Alvefur <zash@zash.se>
parents:
5759
diff
changeset
|
125 else |
969e0a054795
mod_c2s, mod_s2s: Log a message that stream encryption has been enabled with some details
Kim Alvefur <zash@zash.se>
parents:
5759
diff
changeset
|
126 (session.log or log)("info", "Stream encrypted"); |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
127 end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 local features = st.stanza("stream:features"); |
12773
f100c1035576
mod_c2s: Include stream attributes in stream-features event
Matthew Wild <mwild1@gmail.com>
parents:
12677
diff
changeset
|
131 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features, stream = attr }); |
6846
7eb166fa1f26
mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
Kim Alvefur <zash@zash.se>
parents:
6630
diff
changeset
|
132 if features.tags[1] or session.full_jid then |
12804
3eef052c72d8
mod_c2s: Advertise stanza size limit to clients
Kim Alvefur <zash@zash.se>
parents:
12773
diff
changeset
|
133 if stanza_size_limit then |
3eef052c72d8
mod_c2s: Advertise stanza size limit to clients
Kim Alvefur <zash@zash.se>
parents:
12773
diff
changeset
|
134 features:reset(); |
12808
12bd40b8e105
mod_c2s,mod_s2s: Adapt to XEP-xxxx: Stream Limits Advertisement
Kim Alvefur <zash@zash.se>
parents:
12804
diff
changeset
|
135 features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" }) |
13093
93c68c454cb8
mod_c2s,mod_s2s: Fix tag name for SLA (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
12977
diff
changeset
|
136 :text_tag("max-bytes", string.format("%d", stanza_size_limit)):up(); |
12804
3eef052c72d8
mod_c2s: Advertise stanza size limit to clients
Kim Alvefur <zash@zash.se>
parents:
12773
diff
changeset
|
137 end |
6846
7eb166fa1f26
mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
Kim Alvefur <zash@zash.se>
parents:
6630
diff
changeset
|
138 send(features); |
7eb166fa1f26
mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
Kim Alvefur <zash@zash.se>
parents:
6630
diff
changeset
|
139 else |
9739
a74d78f79b23
mod_c2s: Improve log message in case there are no stream features on offer (thanks hexa)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
140 if session.secure then |
10727 | 141 -- Here SASL should be offered |
9739
a74d78f79b23
mod_c2s: Improve log message in case there are no stream features on offer (thanks hexa)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
142 (session.log or log)("warn", "No stream features to offer on secure session. Check authentication settings."); |
a74d78f79b23
mod_c2s: Improve log message in case there are no stream features on offer (thanks hexa)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
143 else |
10727 | 144 -- Normally STARTTLS would be offered |
9739
a74d78f79b23
mod_c2s: Improve log message in case there are no stream features on offer (thanks hexa)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
145 (session.log or log)("warn", "No stream features to offer on insecure session. Check encryption and security settings."); |
a74d78f79b23
mod_c2s: Improve log message in case there are no stream features on offer (thanks hexa)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
146 end |
7862
f5cbbf69cac8
mod_c2s: Clarify that there were no *stream* features to offer
Kim Alvefur <zash@zash.se>
parents:
7662
diff
changeset
|
147 session:close{ condition = "undefined-condition", text = "No stream features to proceed with" }; |
6846
7eb166fa1f26
mod_c2s, mod_s2s: Close incoming connections if there are no features to offer on incomplete streams (fixes #285)
Kim Alvefur <zash@zash.se>
parents:
6630
diff
changeset
|
148 end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
10811
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
151 function stream_callbacks.streamclosed(session, attr) |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
152 -- run _streamclosed in async context |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
153 session.thread:run({ stream = "closed", attr = attr }); |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
154 end |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
155 |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
156 function stream_callbacks._streamclosed(session) |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 session.log("debug", "Received </stream:stream>"); |
4986
9da430b69f13
mod_c2s: Change 'reason' parameter of session:close() to take nil to mean 'graceful close initiated by us' and false for 'graceful close initiated by client'
Matthew Wild <mwild1@gmail.com>
parents:
4964
diff
changeset
|
158 session:close(false); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 function stream_callbacks.error(session, error, data) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 if error == "no-stream" then |
6364
4e93e8768c36
mod_c2s, mod_s2s: Log received invalid stream headers
Matthew Wild <mwild1@gmail.com>
parents:
6279
diff
changeset
|
163 session.log("debug", "Invalid opening stream header (%s)", (data:gsub("^([^\1]+)\1", "{%1}"))); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 session:close("invalid-namespace"); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 elseif error == "parse-error" then |
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
10017
diff
changeset
|
166 (session.log or log)("debug", "Client XML parse error: %s", data); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 session:close("not-well-formed"); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 elseif error == "stream-error" then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 local condition, text = "undefined-condition"; |
8232
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
170 for child in data:childtags(nil, xmlns_xmpp_streams) do |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
171 if child.name ~= "text" then |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
172 condition = child.name; |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
173 else |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
174 text = child:get_text(); |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
175 end |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
176 if condition ~= "undefined-condition" and text then |
176b7f4e4ac9
mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987)
Kim Alvefur <zash@zash.se>
parents:
7328
diff
changeset
|
177 break; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 text = condition .. (text and (" ("..text..")") or ""); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 session.log("info", "Session closed by remote with error: %s", text); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 session:close(nil, text); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 function stream_callbacks.handlestanza(session, stanza) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 stanza = session.filter("stanzas/in", stanza); |
7286 | 188 session.thread:run(stanza); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 --- Session methods |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 local function session_close(session, reason) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 local log = session.log or log; |
12071
85c8fcb4192e
mod_c2s: Fire pre-closing event regardless of connected state
Kim Alvefur <zash@zash.se>
parents:
11974
diff
changeset
|
194 local close_event_payload = { session = session, reason = reason }; |
85c8fcb4192e
mod_c2s: Fire pre-closing event regardless of connected state
Kim Alvefur <zash@zash.se>
parents:
11974
diff
changeset
|
195 module:context(session.host):fire_event("pre-session-close", close_event_payload); |
85c8fcb4192e
mod_c2s: Fire pre-closing event regardless of connected state
Kim Alvefur <zash@zash.se>
parents:
11974
diff
changeset
|
196 reason = close_event_payload.reason; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 if session.conn then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 if session.notopen then |
6005
98b768a41c9d
mod_c2s: Break out stream opening into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
5859
diff
changeset
|
199 session:open_stream(); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 end |
4986
9da430b69f13
mod_c2s: Change 'reason' parameter of session:close() to take nil to mean 'graceful close initiated by us' and false for 'graceful close initiated by client'
Matthew Wild <mwild1@gmail.com>
parents:
4964
diff
changeset
|
201 if reason then -- nil == no err, initiated by us, false == initiated by client |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
202 local stream_error = st.stanza("stream:error"); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 if type(reason) == "string" then -- assume stream error |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
204 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
11868
ae093c259da2
mod_c2s,etc: Identify stanza object with appropriate function
Kim Alvefur <zash@zash.se>
parents:
11778
diff
changeset
|
205 elseif st.is_stanza(reason) then |
ae093c259da2
mod_c2s,etc: Identify stanza object with appropriate function
Kim Alvefur <zash@zash.se>
parents:
11778
diff
changeset
|
206 stream_error = reason; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 elseif type(reason) == "table" then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 if reason.condition then |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
209 stream_error:tag(reason.condition, stream_xmlns_attr):up(); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 if reason.text then |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
211 stream_error:tag("text", stream_xmlns_attr):text(reason.text):up(); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 if reason.extra then |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
214 stream_error:add_child(reason.extra); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 end |
5518
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
218 stream_error = tostring(stream_error); |
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
219 log("debug", "Disconnecting client, <stream:error> is: %s", stream_error); |
0220093e34fa
mod_c2s: Refactor <stream:error> building to allways tostring() it and only call send once
Kim Alvefur <zash@zash.se>
parents:
5505
diff
changeset
|
220 session.send(stream_error); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
222 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 session.send("</stream:stream>"); |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
224 function session.send() return false; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
225 |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
226 local reason_text = (reason and (reason.name or reason.text or reason.condition)) or reason; |
8819
780d728f969f
mod_c2s: Avoid concatenating potential nil value (fixes #753)
Kim Alvefur <zash@zash.se>
parents:
8388
diff
changeset
|
227 session.log("debug", "c2s stream for %s closed: %s", session.full_jid or session.ip or "<unknown>", reason_text or "session closed"); |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
228 |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
229 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
230 local conn = session.conn; |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
231 if reason_text == nil and not session.notopen and session.type == "c2s" then |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
232 -- Grace time to process data from authenticated cleanly-closed stream |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
233 add_task(stream_close_timeout, function () |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
234 if not session.destroyed then |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
235 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
236 sm_destroy_session(session, reason_text); |
11509
dfdec3f9ccb1
mod_c2s: Fix traceback in session close when conn is nil
Kim Alvefur <zash@zash.se>
parents:
11507
diff
changeset
|
237 if conn then conn:close(); end |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
238 end |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
239 end); |
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
240 else |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
241 sm_destroy_session(session, reason_text); |
11509
dfdec3f9ccb1
mod_c2s: Fix traceback in session close when conn is nil
Kim Alvefur <zash@zash.se>
parents:
11507
diff
changeset
|
242 if conn then conn:close(); end |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
243 end |
7328
de76ded98b84
mod_c2s: Just destroy the session when it has no connection (see #641)
Kim Alvefur <zash@zash.se>
parents:
7221
diff
changeset
|
244 else |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
245 local reason_text = (reason and (reason.name or reason.text or reason.condition)) or reason; |
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
246 sm_destroy_session(session, reason_text); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 |
11899
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
250 -- Close all user sessions with the specified reason. If leave_resource is |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
251 -- true, the resource named by event.resource will not be closed. |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
252 local function disconnect_user_sessions(reason, leave_resource) |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
253 return function (event) |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
254 local username, host, resource = event.username, event.host, event.resource; |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
255 local user = hosts[host].sessions[username]; |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
256 if user and user.sessions then |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
257 for r, session in pairs(user.sessions) do |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
258 if not leave_resource or r ~= resource then |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
259 session:close(reason); |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
260 end |
8192
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
261 end |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
262 end |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
263 end |
11899
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
264 end |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
265 |
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
266 module:hook_global("user-password-changed", disconnect_user_sessions({ condition = "reset", text = "Password changed" }, true), 200); |
12662
07424992d7fc
mod_authz_internal, and more: New iteration of role API
Matthew Wild <mwild1@gmail.com>
parents:
12480
diff
changeset
|
267 module:hook_global("user-role-changed", disconnect_user_sessions({ condition = "reset", text = "Role changed" }), 200); |
11899
6d06068363aa
mod_c2s: Disconnect user sessions on a role change event
Matthew Wild <mwild1@gmail.com>
parents:
11868
diff
changeset
|
268 module:hook_global("user-deleted", disconnect_user_sessions({ condition = "not-authorized", text = "Account deleted" }), 200); |
12907
d2333b468d07
mod_c2s: Disconnect accounts when they are disabled
Kim Alvefur <zash@zash.se>
parents:
12808
diff
changeset
|
269 module:hook_global("user-disabled", disconnect_user_sessions({ condition = "not-authorized", text = "Account disabled" }), 200); |
8192
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
270 |
12677
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
271 module:hook_global("c2s-session-updated", function (event) |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
272 sessions[event.session.conn] = event.session; |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
273 local replaced_conn = event.replaced_conn; |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
274 if replaced_conn then |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
275 sessions[replaced_conn] = nil; |
13095
1693bd4de283
core.sessionmanager: Delay closing a replaced connection after replacement
Kim Alvefur <zash@zash.se>
parents:
13093
diff
changeset
|
276 replaced_conn:close(); |
12677
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
277 end |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
278 end); |
3b9771d496ed
mod_smacks: Long overdue cleanup of resumption code, fixes some old TODOs
Matthew Wild <mwild1@gmail.com>
parents:
12662
diff
changeset
|
279 |
7286 | 280 function runner_callbacks:ready() |
11510 | 281 if self.data.conn then |
282 self.data.conn:resume(); | |
11511
cab64a0aad49
mod_c2s: Log about missing conn on async state changes
Kim Alvefur <zash@zash.se>
parents:
11510
diff
changeset
|
283 else |
cab64a0aad49
mod_c2s: Log about missing conn on async state changes
Kim Alvefur <zash@zash.se>
parents:
11510
diff
changeset
|
284 (self.data.log or log)("debug", "Session has no connection to resume"); |
11510 | 285 end |
7286 | 286 end |
287 | |
288 function runner_callbacks:waiting() | |
11510 | 289 if self.data.conn then |
290 self.data.conn:pause(); | |
11511
cab64a0aad49
mod_c2s: Log about missing conn on async state changes
Kim Alvefur <zash@zash.se>
parents:
11510
diff
changeset
|
291 else |
cab64a0aad49
mod_c2s: Log about missing conn on async state changes
Kim Alvefur <zash@zash.se>
parents:
11510
diff
changeset
|
292 (self.data.log or log)("debug", "Session has no connection to pause while waiting"); |
11510 | 293 end |
7286 | 294 end |
295 | |
296 function runner_callbacks:error(err) | |
297 (self.data.log or log)("error", "Traceback[c2s]: %s", err); | |
298 end | |
299 | |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 --- Port listener |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 function listener.onconnect(conn) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 local session = sm_new_session(conn); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
303 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 session.log("info", "Client connected"); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
305 |
11618
8f0fe74ede94
mod_c2s: Update a comment to reflect Direct TLS
Kim Alvefur <zash@zash.se>
parents:
11614
diff
changeset
|
306 -- Client is using Direct TLS or legacy SSL (otherwise mod_tls sets this flag) |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 if conn:ssl() then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 session.secure = true; |
5859
e327f2d4e09f
mod_c2s, mod_s2s: Set session.encrypted as session.secure does not allways mean encrypted (eg consider_bosh_secure)
Kim Alvefur <zash@zash.se>
parents:
5802
diff
changeset
|
309 session.encrypted = true; |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
310 |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
311 -- Check if TLS compression is used |
12480
7e9ebdc75ce4
net: isolate LuaSec-specifics
Jonas Schäfer <jonas@wielicki.name>
parents:
12311
diff
changeset
|
312 local info = conn:ssl_info(); |
11622
a62146353528
mod_c2s: Guard against LuaSec not returning TLS info (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
11619
diff
changeset
|
313 if type(info) == "table" then |
11619
d629135450ec
mod_c2s: Log the same messages for Direct TLS as with starttls
Kim Alvefur <zash@zash.se>
parents:
11618
diff
changeset
|
314 (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); |
d629135450ec
mod_c2s: Log the same messages for Direct TLS as with starttls
Kim Alvefur <zash@zash.se>
parents:
11618
diff
changeset
|
315 session.compressed = info.compression; |
d629135450ec
mod_c2s: Log the same messages for Direct TLS as with starttls
Kim Alvefur <zash@zash.se>
parents:
11618
diff
changeset
|
316 m_tls_params:with_labels(info.protocol, info.cipher):add(1) |
d629135450ec
mod_c2s: Log the same messages for Direct TLS as with starttls
Kim Alvefur <zash@zash.se>
parents:
11618
diff
changeset
|
317 else |
d629135450ec
mod_c2s: Log the same messages for Direct TLS as with starttls
Kim Alvefur <zash@zash.se>
parents:
11618
diff
changeset
|
318 (session.log or log)("info", "Stream encrypted"); |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
319 end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
321 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 if opt_keepalives then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 conn:setoption("keepalive", opt_keepalives); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
325 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 session.close = session_close; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
327 |
11118
ece430d49809
mod_c2s,mod_s2s: Make stanza size limits configurable
Kim Alvefur <zash@zash.se>
parents:
10013
diff
changeset
|
328 local stream = new_xmpp_stream(session, stream_callbacks, stanza_size_limit); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 session.stream = stream; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 session.notopen = true; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
331 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 function session.reset_stream() |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 session.notopen = true; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 session.stream:reset(); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
336 |
7286 | 337 session.thread = runner(function (stanza) |
10811
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
338 if st.is_stanza(stanza) then |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
339 core_process_stanza(session, stanza); |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
340 elseif stanza.stream == "opened" then |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
341 stream_callbacks._streamopened(session, stanza.attr); |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
342 elseif stanza.stream == "closed" then |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
343 stream_callbacks._streamclosed(session, stanza.attr); |
16bcbd574801
mod_c2s: Run stream open and close events in async thread, fixes #1103
Kim Alvefur <zash@zash.se>
parents:
10727
diff
changeset
|
344 end |
7286 | 345 end, runner_callbacks, session); |
346 | |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 local filter = session.filter; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 function session.data(data) |
5773
c9a712673d8a
mod_c2s: Add session:sleep() and session:wake() to pause a session (e.g. while waiting for an external event). Needs a gallon or two of testing.
Matthew Wild <mwild1@gmail.com>
parents:
5764
diff
changeset
|
349 -- Parse the data, which will store stanzas in session.pending_stanzas |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 if data then |
7539
366964dbddb1
mod_c2s: Fix whitespace (why does it keep getting messed up?)
Kim Alvefur <zash@zash.se>
parents:
7466
diff
changeset
|
351 data = filter("bytes/in", data); |
366964dbddb1
mod_c2s: Fix whitespace (why does it keep getting messed up?)
Kim Alvefur <zash@zash.se>
parents:
7466
diff
changeset
|
352 if data then |
366964dbddb1
mod_c2s: Fix whitespace (why does it keep getting messed up?)
Kim Alvefur <zash@zash.se>
parents:
7466
diff
changeset
|
353 local ok, err = stream:feed(data); |
5773
c9a712673d8a
mod_c2s: Add session:sleep() and session:wake() to pause a session (e.g. while waiting for an external event). Needs a gallon or two of testing.
Matthew Wild <mwild1@gmail.com>
parents:
5764
diff
changeset
|
354 if not ok then |
10111
0f335815244f
plugins: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
10017
diff
changeset
|
355 log("debug", "Received invalid XML (%s) %d bytes: %q", err, #data, data:sub(1, 300)); |
10849
19e7092e062c
mod_c2s,mod_s2s: Use a distinct stream error for hitting stanza size limit
Kim Alvefur <zash@zash.se>
parents:
10811
diff
changeset
|
356 if err == "stanza-too-large" then |
11770
d2a9aa1c7ac8
mod_c2s,mod_s2s: Indicate stanza size violation with condition from XEP-0205 (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
11747
diff
changeset
|
357 session:close({ |
d2a9aa1c7ac8
mod_c2s,mod_s2s: Indicate stanza size violation with condition from XEP-0205 (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
11747
diff
changeset
|
358 condition = "policy-violation", |
d2a9aa1c7ac8
mod_c2s,mod_s2s: Indicate stanza size violation with condition from XEP-0205 (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
11747
diff
changeset
|
359 text = "XML stanza is too big", |
d2a9aa1c7ac8
mod_c2s,mod_s2s: Indicate stanza size violation with condition from XEP-0205 (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
11747
diff
changeset
|
360 extra = st.stanza("stanza-too-big", { xmlns = 'urn:xmpp:errors' }), |
d2a9aa1c7ac8
mod_c2s,mod_s2s: Indicate stanza size violation with condition from XEP-0205 (thanks mjk)
Kim Alvefur <zash@zash.se>
parents:
11747
diff
changeset
|
361 }); |
10849
19e7092e062c
mod_c2s,mod_s2s: Use a distinct stream error for hitting stanza size limit
Kim Alvefur <zash@zash.se>
parents:
10811
diff
changeset
|
362 else |
19e7092e062c
mod_c2s,mod_s2s: Use a distinct stream error for hitting stanza size limit
Kim Alvefur <zash@zash.se>
parents:
10811
diff
changeset
|
363 session:close("not-well-formed"); |
19e7092e062c
mod_c2s,mod_s2s: Use a distinct stream error for hitting stanza size limit
Kim Alvefur <zash@zash.se>
parents:
10811
diff
changeset
|
364 end |
5773
c9a712673d8a
mod_c2s: Add session:sleep() and session:wake() to pause a session (e.g. while waiting for an external event). Needs a gallon or two of testing.
Matthew Wild <mwild1@gmail.com>
parents:
5764
diff
changeset
|
365 end |
c9a712673d8a
mod_c2s: Add session:sleep() and session:wake() to pause a session (e.g. while waiting for an external event). Needs a gallon or two of testing.
Matthew Wild <mwild1@gmail.com>
parents:
5764
diff
changeset
|
366 end |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 |
4548
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
370 if c2s_timeout then |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
371 add_task(c2s_timeout, function () |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
372 if session.type == "c2s_unauthed" then |
11477
c90ef8745779
mod_c2s: Log a debug message before closing due to c2s_timeout
Kim Alvefur <zash@zash.se>
parents:
11359
diff
changeset
|
373 (session.log or log)("debug", "Connection still not authenticated after c2s_timeout=%gs, closing it", c2s_timeout); |
4548
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
374 session:close("connection-timeout"); |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
375 end |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
376 end); |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
377 end |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
378 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 session.dispatch_stanza = stream_callbacks.handlestanza; |
10013
62d8689beafb
mod_c2s: Associate connection with session last (fixes #1313)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
380 |
62d8689beafb
mod_c2s: Associate connection with session last (fixes #1313)
Kim Alvefur <zash@zash.se>
parents:
9490
diff
changeset
|
381 sessions[conn] = session; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 function listener.onincoming(conn, data) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 local session = sessions[conn]; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 if session then |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 session.data(data); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 function listener.ondisconnect(conn, err) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 local session = sessions[conn]; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 if session then |
4964
c9b8ec3eb1e9
mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply </stream:stream> if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data).
Matthew Wild <mwild1@gmail.com>
parents:
4852
diff
changeset
|
394 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 sm_destroy_session(session, err); |
7221
56e65b1e54e8
mod_c2s: Remove connection object from session object when connection disconnected to prevent accidental use (see #590)
Kim Alvefur <zash@zash.se>
parents:
7100
diff
changeset
|
396 session.conn = nil; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 sessions[conn] = nil; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 end |
12301
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
399 module:fire_event("c2s-closed", { session = session; conn = conn }); |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 |
5638
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
402 function listener.onreadtimeout(conn) |
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
403 local session = sessions[conn]; |
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
404 if session then |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
405 return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session }); |
5638
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
406 end |
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
407 end |
c5b7f4858014
mod_c2s, mod_c2s: Send a whitespace on read timeout, to prod TCP into detecting if the connection died
Kim Alvefur <zash@zash.se>
parents:
5571
diff
changeset
|
408 |
9910
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
409 function listener.ondrain(conn) |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
410 local session = sessions[conn]; |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
411 if session then |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
412 return (hosts[session.host] or prosody).events.fire_event("c2s-ondrain", { session = session }); |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
413 end |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
414 end |
7a703af90c9c
mod_c2s: Fire an event when outgoing buffers have been emptied
Kim Alvefur <zash@zash.se>
parents:
9784
diff
changeset
|
415 |
11742
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
416 function listener.onpredrain(conn) |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
417 local session = sessions[conn]; |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
418 if session then |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
419 return (hosts[session.host] or prosody).events.fire_event("c2s-pre-ondrain", { session = session }); |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
420 end |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
421 end |
9c450185bac1
mod_c2s,mod_s2s: Fire event just before writes
Kim Alvefur <zash@zash.se>
parents:
11622
diff
changeset
|
422 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
423 local function keepalive(event) |
7540
e69df8093387
mod_c2s: Don't try to keep alive sessions where the stream is not (yet) open
Kim Alvefur <zash@zash.se>
parents:
7539
diff
changeset
|
424 local session = event.session; |
e69df8093387
mod_c2s: Don't try to keep alive sessions where the stream is not (yet) open
Kim Alvefur <zash@zash.se>
parents:
7539
diff
changeset
|
425 if not session.notopen then |
e69df8093387
mod_c2s: Don't try to keep alive sessions where the stream is not (yet) open
Kim Alvefur <zash@zash.se>
parents:
7539
diff
changeset
|
426 return event.session.send(' '); |
e69df8093387
mod_c2s: Don't try to keep alive sessions where the stream is not (yet) open
Kim Alvefur <zash@zash.se>
parents:
7539
diff
changeset
|
427 end |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
428 end |
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
429 |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 function listener.associate_session(conn, session) |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 sessions[conn] = session; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 end |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
433 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
434 function module.add_host(module) |
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
435 module:hook("c2s-read-timeout", keepalive, -1); |
6380
4220ffb87b22
net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents:
6364
diff
changeset
|
436 end |
4220ffb87b22
net.http, net.http.server, mod_c2s, mod_s2s, mod_component, mod_admin_telnet, mod_net_multiplex: Add ondetach to release connection from 'sessions' table (or equivalent)
Matthew Wild <mwild1@gmail.com>
parents:
6364
diff
changeset
|
437 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
438 module:hook("c2s-read-timeout", keepalive, -1); |
5668
5a9318ac92f6
mod_c2s: Become a shared module and allow being disabled on some virtualhosts
Kim Alvefur <zash@zash.se>
parents:
5638
diff
changeset
|
439 |
12302
6a8c680b8677
mod_c2s: Ignore unused event payload [luacheck]
Kim Alvefur <zash@zash.se>
parents:
12301
diff
changeset
|
440 module:hook("server-stopping", function(event) -- luacheck: ignore 212/event |
12298
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
441 -- Close ports |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12907
diff
changeset
|
442 local pm = require "prosody.core.portmanager"; |
12298
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
443 for _, netservice in pairs(module.items["net-provider"]) do |
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
444 pm.unregister_service(netservice.name, netservice); |
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
445 end |
12300
fb74ff16620c
mod_c2s: Close ports in a separate, earlier event from closing sessions
Kim Alvefur <zash@zash.se>
parents:
12298
diff
changeset
|
446 end, -80); |
12298
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
447 |
12300
fb74ff16620c
mod_c2s: Close ports in a separate, earlier event from closing sessions
Kim Alvefur <zash@zash.se>
parents:
12298
diff
changeset
|
448 module:hook("server-stopping", function(event) |
12311
bc30e1b9ad89
mod_c2s,mod_s2s: Fix error on shutdown (Thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
12309
diff
changeset
|
449 local wait, done = async.waiter(1, true); |
12301
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
450 module:hook("c2s-closed", function () |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
451 if next(sessions) == nil then done(); end |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
452 end) |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
453 |
12298
cb459f8fa740
mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
Kim Alvefur <zash@zash.se>
parents:
12071
diff
changeset
|
454 -- Close sessions |
5281
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
455 local reason = event.reason; |
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
456 for _, session in pairs(sessions) do |
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
457 session:close{ condition = "system-shutdown", text = reason }; |
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
458 end |
12301
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
459 |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
460 -- Wait for them to close properly if they haven't already |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
461 if next(sessions) ~= nil then |
12309
926a6c5d13e7
mod_c2s,mod_s2s: Wrap callback to improve tracebacks
Kim Alvefur <zash@zash.se>
parents:
12302
diff
changeset
|
462 add_task(stream_close_timeout+1, function () done() end); |
12301
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
463 module:log("info", "Waiting for sessions to close"); |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
464 wait(); |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
465 end |
4f1fe6eb1ddb
mod_c2s,mod_s2s: Wait for sessions to close before proceeding with shutdown steps
Kim Alvefur <zash@zash.se>
parents:
12300
diff
changeset
|
466 |
7100
301d58705667
mod_c2s, mod_s2s: Lower priority of session shutdown to negative, so that plugins hooking at the default priority run first (fixes #601)
Kim Alvefur <zash@zash.se>
parents:
6380
diff
changeset
|
467 end, -100); |
5281
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
468 |
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
469 |
815c689f85ad
prosody, mod_c2s, mod_s2s: Move closing of c2s and s2s sessions to respective plugins
Kim Alvefur <zash@zash.se>
parents:
5228
diff
changeset
|
470 |
5120
bcabea740c00
mod_{admin_telnet,c2s,component,http,net_multiplex,s2s}: Use module:provides() instead of module:add_item().
Waqas Hussain <waqas20@gmail.com>
parents:
5097
diff
changeset
|
471 module:provides("net", { |
4610
171051f9dd00
mod_c2s: Use module:add_item() to add the net-provider for portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4551
diff
changeset
|
472 name = "c2s"; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 listener = listener; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 default_port = 5222; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 encryption = "starttls"; |
4626
9df9e87d0339
mod_c2s: Add missing multiplexed service discovery pattern.
Kim Alvefur <zash@zash.se>
parents:
4625
diff
changeset
|
476 multiplex = { |
10465
09697a673015
mod_net_multiplex: Add support for using ALPN
Kim Alvefur <zash@zash.se>
parents:
10379
diff
changeset
|
477 protocol = "xmpp-client"; |
4626
9df9e87d0339
mod_c2s: Add missing multiplexed service discovery pattern.
Kim Alvefur <zash@zash.se>
parents:
4625
diff
changeset
|
478 pattern = "^<.*:stream.*%sxmlns%s*=%s*(['\"])jabber:client%1.*>"; |
9df9e87d0339
mod_c2s: Add missing multiplexed service discovery pattern.
Kim Alvefur <zash@zash.se>
parents:
4625
diff
changeset
|
479 }; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 }); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
481 |
5120
bcabea740c00
mod_{admin_telnet,c2s,component,http,net_multiplex,s2s}: Use module:provides() instead of module:add_item().
Waqas Hussain <waqas20@gmail.com>
parents:
5097
diff
changeset
|
482 module:provides("net", { |
11778
f254fd16218a
mod_c2s: Rename Direct TLS listener 'c2s_direct_tls' for clarity
Kim Alvefur <zash@zash.se>
parents:
11770
diff
changeset
|
483 name = "c2s_direct_tls"; |
11614
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
484 listener = listener; |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
485 encryption = "ssl"; |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
486 multiplex = { |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
487 pattern = "^<.*:stream.*%sxmlns%s*=%s*(['\"])jabber:client%1.*>"; |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
488 }; |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
489 }); |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
490 |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
491 -- COMPAT |
1ac8976f09a9
mod_c2s: Add a Direct TLS listener
Kim Alvefur <zash@zash.se>
parents:
11608
diff
changeset
|
492 module:provides("net", { |
4610
171051f9dd00
mod_c2s: Use module:add_item() to add the net-provider for portmanager
Matthew Wild <mwild1@gmail.com>
parents:
4551
diff
changeset
|
493 name = "legacy_ssl"; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
494 listener = listener; |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
495 encryption = "ssl"; |
4620
e9dc6ae68c69
mod_c2s, mod_s2s: Add multiplex support
Matthew Wild <mwild1@gmail.com>
parents:
4610
diff
changeset
|
496 multiplex = { |
e9dc6ae68c69
mod_c2s, mod_s2s: Add multiplex support
Matthew Wild <mwild1@gmail.com>
parents:
4610
diff
changeset
|
497 pattern = "^<.*:stream.*%sxmlns%s*=%s*(['\"])jabber:client%1.*>"; |
e9dc6ae68c69
mod_c2s, mod_s2s: Add multiplex support
Matthew Wild <mwild1@gmail.com>
parents:
4610
diff
changeset
|
498 }; |
4543
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
499 }); |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
500 |
db27a4c18b6a
mod_c2s, sessionmanager, xmppclient_listener: Move all c2s network and stream logic into a new module, mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
501 |