Software /
code /
prosody
Comparison
plugins/mod_c2s.lua @ 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'
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Jul 2012 12:56:47 +0100 |
parent | 4964:c9b8ec3eb1e9 |
child | 4996:164dc19519d8 |
comparison
equal
deleted
inserted
replaced
4985:0f72123ff513 | 4986:9da430b69f13 |
---|---|
74 send(features); | 74 send(features); |
75 end | 75 end |
76 | 76 |
77 function stream_callbacks.streamclosed(session) | 77 function stream_callbacks.streamclosed(session) |
78 session.log("debug", "Received </stream:stream>"); | 78 session.log("debug", "Received </stream:stream>"); |
79 session:close(); | 79 session:close(false); |
80 end | 80 end |
81 | 81 |
82 function stream_callbacks.error(session, error, data) | 82 function stream_callbacks.error(session, error, data) |
83 if error == "no-stream" then | 83 if error == "no-stream" then |
84 session.log("debug", "Invalid opening stream header"); | 84 session.log("debug", "Invalid opening stream header"); |
120 if session.conn then | 120 if session.conn then |
121 if session.notopen then | 121 if session.notopen then |
122 session.send("<?xml version='1.0'?>"); | 122 session.send("<?xml version='1.0'?>"); |
123 session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); | 123 session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); |
124 end | 124 end |
125 if reason then | 125 if reason then -- nil == no err, initiated by us, false == initiated by client |
126 if type(reason) == "string" then -- assume stream error | 126 if type(reason) == "string" then -- assume stream error |
127 log("info", "Disconnecting client, <stream:error> is: %s", reason); | 127 log("info", "Disconnecting client, <stream:error> is: %s", reason); |
128 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); | 128 session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); |
129 elseif type(reason) == "table" then | 129 elseif type(reason) == "table" then |
130 if reason.condition then | 130 if reason.condition then |
141 log("info", "Disconnecting client, <stream:error> is: %s", tostring(reason)); | 141 log("info", "Disconnecting client, <stream:error> is: %s", tostring(reason)); |
142 session.send(reason); | 142 session.send(reason); |
143 end | 143 end |
144 end | 144 end |
145 end | 145 end |
146 | |
146 session.send("</stream:stream>"); | 147 session.send("</stream:stream>"); |
147 | |
148 function session.send() return false; end | 148 function session.send() return false; end |
149 | 149 |
150 local reason = (reason and (reason.text or reason.condition)) or reason or "session closed"; | 150 local reason = (reason and (reason.text or reason.condition)) or reason; |
151 session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason); | 151 session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason or "session closed"); |
152 | 152 |
153 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote | 153 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote |
154 local conn = session.conn; | 154 local conn = session.conn; |
155 if reason == "session closed" and not session.notopen and session.type == "c2s" then | 155 if reason == nil and not session.notopen and session.type == "c2s" then |
156 -- Grace time to process data from authenticated cleanly-closed stream | 156 -- Grace time to process data from authenticated cleanly-closed stream |
157 add_task(stream_close_timeout, function () | 157 add_task(stream_close_timeout, function () |
158 if not session.destroyed then | 158 if not session.destroyed then |
159 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); | 159 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); |
160 sm_destroy_session(session, reason); | 160 sm_destroy_session(session, reason); |