Software /
code /
prosody
Annotate
plugins/mod_c2s.lua @ 8846:7ec098b68042 0.10.2
Merge 0.9->0.10
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 30 May 2018 21:55:09 +0100 |
parent | 8819:780d728f969f |
parent | 8844:29c6d2681bad |
child | 8847:74526c425dec |
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 |
4548
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
11 local add_task = require "util.timer".add_task; |
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
|
12 local new_xmpp_stream = require "util.xmppstream".new; |
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
|
13 local nameprep = require "util.encodings".stringprep.nameprep; |
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
|
14 local sessionmanager = require "core.sessionmanager"; |
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
|
15 local st = require "util.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
|
16 local sm_new_session, sm_destroy_session = sessionmanager.new_session, sessionmanager.destroy_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
|
17 local uuid_generate = require "util.uuid".generate; |
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
|
18 |
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
|
19 local xpcall, tostring, type = xpcall, tostring, type; |
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
|
20 local traceback = debug.traceback; |
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 |
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
|
22 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
|
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 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
|
25 |
8388
9ee56e9ad47a
mod_c2s: Set a default value for c2s_timeout (fixes #1036)
Kim Alvefur <zash@zash.se>
parents:
8234
diff
changeset
|
26 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
|
27 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
|
28 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); |
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
|
29 |
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
|
30 local measure_connections = module:measure("connections", "amount"); |
6630
6735e2d735d6
mod_c2s, mod_s2s: Collect statistics on number of connections
Kim Alvefur <zash@zash.se>
parents:
6382
diff
changeset
|
31 |
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 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
|
33 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
|
34 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
|
35 |
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
|
36 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
|
37 local listener = {}; |
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 |
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
|
39 module:hook("stats-update", function () |
7466
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
40 local count = 0; |
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
41 for _ in pairs(sessions) do |
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
42 count = count + 1; |
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
43 end |
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
44 measure_connections(count); |
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
|
45 end); |
7466
f28fa742def3
mod_c2s, mod_s2s: Bootstrap connection count statistic on module load
Kim Alvefur <zash@zash.se>
parents:
7329
diff
changeset
|
46 |
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
|
47 --- 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
|
48 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
|
49 |
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
|
50 function stream_callbacks.streamopened(session, attr) |
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
|
51 local send = session.send; |
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
|
52 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
|
53 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
|
54 session:close{ condition = "improper-addressing", |
4551 | 55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 session.streamid = uuid_generate(); |
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
|
67 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", 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
|
68 |
5668
5a9318ac92f6
mod_c2s: Become a shared module and allow being disabled on some virtualhosts
Kim Alvefur <zash@zash.se>
parents:
5638
diff
changeset
|
69 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
|
70 -- 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
|
71 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
|
72 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
|
73 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
|
74 |
6005
98b768a41c9d
mod_c2s: Break out stream opening into a separate function
Florian Zeitz <florob@babelmonkeys.de>
parents:
5859
diff
changeset
|
75 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
|
76 |
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 (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
|
78 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
|
79 |
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
|
80 -- 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
|
81 -- 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
|
82 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
|
83 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
|
84 session.encrypted = true; |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
85 |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
86 local sock = session.conn:socket(); |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
87 if sock.info then |
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
|
88 local info = sock:info(); |
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
|
89 (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
|
90 session.compressed = info.compression; |
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
|
91 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
|
92 (session.log or log)("info", "Stream encrypted"); |
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
|
93 session.compressed = sock.compression and sock:compression(); --COMPAT mw/luasec-hg |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
94 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
|
95 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
|
96 |
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 local features = st.stanza("stream:features"); |
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
|
98 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); |
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
|
99 if features.tags[1] or session.full_jid then |
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
|
100 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
|
101 else |
7862
f5cbbf69cac8
mod_c2s: Clarify that there were no *stream* features to offer
Kim Alvefur <zash@zash.se>
parents:
7662
diff
changeset
|
102 (session.log or log)("warn", "No stream features to offer"); |
f5cbbf69cac8
mod_c2s: Clarify that there were no *stream* features to offer
Kim Alvefur <zash@zash.se>
parents:
7662
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 |
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 function stream_callbacks.streamclosed(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
|
108 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
|
109 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
|
110 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
|
111 |
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 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
|
113 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
|
114 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
|
115 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
|
116 elseif error == "parse-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
|
117 (session.log or log)("debug", "Client XML parse error: %s", tostring(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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 |
5505
0b6a99e6c1b1
mod_c2s, mod_s2s, net.http, net.http.server: Improve tracebacks (omit traceback function), to make it clearer where an error occured
Matthew Wild <mwild1@gmail.com>
parents:
5370
diff
changeset
|
137 local function handleerr(err) log("error", "Traceback[c2s]: %s", traceback(tostring(err), 2)); 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
|
138 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
|
139 stanza = session.filter("stanzas/in", 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
|
140 if stanza 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
|
141 return xpcall(function () return core_process_stanza(session, stanza) end, handleerr); |
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
|
142 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
|
143 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
|
144 |
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
|
145 --- 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
|
146 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
|
147 local log = session.log or 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); |
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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 elseif reason.name then -- a stanza |
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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
173 |
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
|
174 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
|
175 function session.send() return false; end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
176 |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
177 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
|
178 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
|
179 |
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
|
180 -- 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
|
181 local conn = session.conn; |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
182 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
|
183 -- 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
|
184 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
|
185 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
|
186 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
|
187 sm_destroy_session(session, reason_text); |
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
|
188 conn:close(); |
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
|
189 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
|
190 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
|
191 else |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
192 sm_destroy_session(session, reason_text); |
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
|
193 conn:close(); |
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
|
194 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
|
195 else |
7954
60b83f83f317
mod_c2s: Rename variable no avoid name clash [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7866
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 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
|
200 |
5097
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
201 module:hook_global("user-deleted", function(event) |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
202 local username, host = event.username, event.host; |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
203 local user = hosts[host].sessions[username]; |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
204 if user and user.sessions then |
7955
bba71bfe2154
mod_c2s: Rename unused loop variable to _ [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7954
diff
changeset
|
205 for _, session in pairs(user.sessions) do |
5097
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
206 session:close{ condition = "not-authorized", text = "Account deleted" }; |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
207 end |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
208 end |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
209 end, 200); |
6c52a7a881cc
mod_c2s: When a user gets deleted, drop all their sessions
Kim Alvefur <zash@zash.se>
parents:
5013
diff
changeset
|
210 |
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
|
211 module:hook_global("user-password-changed", function(event) |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
212 local username, host, resource = event.username, event.host, event.resource; |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
213 local user = hosts[host].sessions[username]; |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
214 if user and user.sessions then |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
215 for r, session in pairs(user.sessions) do |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
216 if r ~= resource then |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
217 session:close{ condition = "reset", text = "Password changed" }; |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 end, 200); |
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
7955
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 --- 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
|
224 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
|
225 local session = sm_new_session(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
|
226 sessions[conn] = session; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
227 |
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
|
228 session.log("info", "Client connected"); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
229 |
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
|
230 -- Client is using legacy SSL (otherwise mod_tls sets this flag) |
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
|
231 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
|
232 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
|
233 session.encrypted = true; |
5228
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
234 |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
235 -- Check if TLS compression is used |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
236 local sock = conn:socket(); |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
237 if sock.info then |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
238 session.compressed = sock:info"compression"; |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
239 elseif sock.compression then |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
240 session.compressed = sock:compression(); --COMPAT mw/luasec-hg |
edabb34417b7
mod_c2s: Check if TLS compression is used
Kim Alvefur <zash@zash.se>
parents:
5120
diff
changeset
|
241 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
|
242 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
243 |
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
|
244 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
|
245 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
|
246 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
247 |
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
|
248 session.close = session_close; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
249 |
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
|
250 local stream = new_xmpp_stream(session, stream_callbacks); |
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
|
251 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
|
252 session.notopen = true; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
253 |
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
|
254 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
|
255 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
|
256 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
|
257 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5773
diff
changeset
|
258 |
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
|
259 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
|
260 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
|
261 -- 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
|
262 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
|
263 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
|
264 if data then |
366964dbddb1
mod_c2s: Fix whitespace (why does it keep getting messed up?)
Kim Alvefur <zash@zash.se>
parents:
7466
diff
changeset
|
265 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
|
266 if not ok then |
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
|
267 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); |
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
|
268 session:close("not-well-formed"); |
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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 |
4548
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
274 if c2s_timeout then |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
275 add_task(c2s_timeout, function () |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
276 if session.type == "c2s_unauthed" then |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
277 session:close("connection-timeout"); |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
278 end |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
279 end); |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
280 end |
e6e5c76ff009
sessionmanager, mod_c2s: Move timeout logic to mod_c2s
Matthew Wild <mwild1@gmail.com>
parents:
4543
diff
changeset
|
281 |
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
|
282 session.dispatch_stanza = stream_callbacks.handlestanza; |
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
|
283 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
|
284 |
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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 |
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
|
292 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
|
293 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
|
294 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
|
295 (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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 |
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
|
302 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
|
303 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
|
304 if session then |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 end |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
314 end |
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
315 |
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
|
316 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
|
317 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
|
318 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
|
319 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 |
5669
9345c161481f
mod_c2s, mod_s2s: Fire an event on read timeouts
Kim Alvefur <zash@zash.se>
parents:
5668
diff
changeset
|
324 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
|
325 |
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
|
326 module:hook("server-stopping", function(event) |
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
|
327 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
|
328 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
|
329 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
|
330 end |
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
|
331 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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 encryption = "starttls"; |
4626
9df9e87d0339
mod_c2s: Add missing multiplexed service discovery pattern.
Kim Alvefur <zash@zash.se>
parents:
4625
diff
changeset
|
340 multiplex = { |
9df9e87d0339
mod_c2s: Add missing multiplexed service discovery pattern.
Kim Alvefur <zash@zash.se>
parents:
4625
diff
changeset
|
341 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
|
342 }; |
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
|
343 }); |
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
|
344 |
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
|
345 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
|
346 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
|
347 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
|
348 encryption = "ssl"; |
4620
e9dc6ae68c69
mod_c2s, mod_s2s: Add multiplex support
Matthew Wild <mwild1@gmail.com>
parents:
4610
diff
changeset
|
349 multiplex = { |
e9dc6ae68c69
mod_c2s, mod_s2s: Add multiplex support
Matthew Wild <mwild1@gmail.com>
parents:
4610
diff
changeset
|
350 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
|
351 }; |
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
|
352 }); |
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
|
353 |
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
|
354 |