Mercurial > prosody-hg
comparison plugins/mod_c2s.lua @ 10411:db2a06b9ff98
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 16 Nov 2019 16:52:31 +0100 |
| parents | b917602eac04 |
| children | 09697a673015 |
comparison
equal
deleted
inserted
replaced
| 10410:659b577f280c | 10411:db2a06b9ff98 |
|---|---|
| 54 --- Stream events handlers | 54 --- Stream events handlers |
| 55 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; | 55 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
| 56 | 56 |
| 57 function stream_callbacks.streamopened(session, attr) | 57 function stream_callbacks.streamopened(session, attr) |
| 58 local send = session.send; | 58 local send = session.send; |
| 59 if not attr.to then | |
| 60 session:close{ condition = "improper-addressing", | |
| 61 text = "A 'to' attribute is required on stream headers" }; | |
| 62 return; | |
| 63 end | |
| 59 local host = nameprep(attr.to); | 64 local host = nameprep(attr.to); |
| 60 if not host then | 65 if not host then |
| 61 session:close{ condition = "improper-addressing", | 66 session:close{ condition = "improper-addressing", |
| 62 text = "A valid 'to' attribute is required on stream headers" }; | 67 text = "A valid 'to' attribute is required on stream headers" }; |
| 63 return; | 68 return; |
| 95 local info = sock:info(); | 100 local info = sock:info(); |
| 96 (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); | 101 (session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher); |
| 97 session.compressed = info.compression; | 102 session.compressed = info.compression; |
| 98 else | 103 else |
| 99 (session.log or log)("info", "Stream encrypted"); | 104 (session.log or log)("info", "Stream encrypted"); |
| 100 session.compressed = sock.compression and sock:compression(); --COMPAT mw/luasec-hg | |
| 101 end | 105 end |
| 102 end | 106 end |
| 103 | 107 |
| 104 local features = st.stanza("stream:features"); | 108 local features = st.stanza("stream:features"); |
| 105 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); | 109 hosts[session.host].events.fire_event("stream-features", { origin = session, features = features }); |
| 106 if features.tags[1] or session.full_jid then | 110 if features.tags[1] or session.full_jid then |
| 107 send(features); | 111 send(features); |
| 108 else | 112 else |
| 109 (session.log or log)("warn", "No stream features to offer"); | 113 if session.secure then |
| 114 -- Normally STARTTLS would be offered | |
| 115 (session.log or log)("warn", "No stream features to offer on secure session. Check authentication settings."); | |
| 116 else | |
| 117 -- Here SASL should be offered | |
| 118 (session.log or log)("warn", "No stream features to offer on insecure session. Check encryption and security settings."); | |
| 119 end | |
| 110 session:close{ condition = "undefined-condition", text = "No stream features to proceed with" }; | 120 session:close{ condition = "undefined-condition", text = "No stream features to proceed with" }; |
| 111 end | 121 end |
| 112 end | 122 end |
| 113 | 123 |
| 114 function stream_callbacks.streamclosed(session) | 124 function stream_callbacks.streamclosed(session) |
| 119 function stream_callbacks.error(session, error, data) | 129 function stream_callbacks.error(session, error, data) |
| 120 if error == "no-stream" then | 130 if error == "no-stream" then |
| 121 session.log("debug", "Invalid opening stream header (%s)", (data:gsub("^([^\1]+)\1", "{%1}"))); | 131 session.log("debug", "Invalid opening stream header (%s)", (data:gsub("^([^\1]+)\1", "{%1}"))); |
| 122 session:close("invalid-namespace"); | 132 session:close("invalid-namespace"); |
| 123 elseif error == "parse-error" then | 133 elseif error == "parse-error" then |
| 124 (session.log or log)("debug", "Client XML parse error: %s", tostring(data)); | 134 (session.log or log)("debug", "Client XML parse error: %s", data); |
| 125 session:close("not-well-formed"); | 135 session:close("not-well-formed"); |
| 126 elseif error == "stream-error" then | 136 elseif error == "stream-error" then |
| 127 local condition, text = "undefined-condition"; | 137 local condition, text = "undefined-condition"; |
| 128 for child in data:childtags(nil, xmlns_xmpp_streams) do | 138 for child in data:childtags(nil, xmlns_xmpp_streams) do |
| 129 if child.name ~= "text" then | 139 if child.name ~= "text" then |
| 249 | 259 |
| 250 -- Check if TLS compression is used | 260 -- Check if TLS compression is used |
| 251 local sock = conn:socket(); | 261 local sock = conn:socket(); |
| 252 if sock.info then | 262 if sock.info then |
| 253 session.compressed = sock:info"compression"; | 263 session.compressed = sock:info"compression"; |
| 254 elseif sock.compression then | |
| 255 session.compressed = sock:compression(); --COMPAT mw/luasec-hg | |
| 256 end | 264 end |
| 257 end | 265 end |
| 258 | 266 |
| 259 if opt_keepalives then | 267 if opt_keepalives then |
| 260 conn:setoption("keepalive", opt_keepalives); | 268 conn:setoption("keepalive", opt_keepalives); |
| 281 if data then | 289 if data then |
| 282 data = filter("bytes/in", data); | 290 data = filter("bytes/in", data); |
| 283 if data then | 291 if data then |
| 284 local ok, err = stream:feed(data); | 292 local ok, err = stream:feed(data); |
| 285 if not ok then | 293 if not ok then |
| 286 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); | 294 log("debug", "Received invalid XML (%s) %d bytes: %q", err, #data, data:sub(1, 300)); |
| 287 session:close("not-well-formed"); | 295 session:close("not-well-formed"); |
| 288 end | 296 end |
| 289 end | 297 end |
| 290 end | 298 end |
| 291 end | 299 end |
| 322 | 330 |
| 323 function listener.onreadtimeout(conn) | 331 function listener.onreadtimeout(conn) |
| 324 local session = sessions[conn]; | 332 local session = sessions[conn]; |
| 325 if session then | 333 if session then |
| 326 return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session }); | 334 return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session }); |
| 335 end | |
| 336 end | |
| 337 | |
| 338 function listener.ondrain(conn) | |
| 339 local session = sessions[conn]; | |
| 340 if session then | |
| 341 return (hosts[session.host] or prosody).events.fire_event("c2s-ondrain", { session = session }); | |
| 327 end | 342 end |
| 328 end | 343 end |
| 329 | 344 |
| 330 local function keepalive(event) | 345 local function keepalive(event) |
| 331 local session = event.session; | 346 local session = event.session; |
