Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 1324:853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Feb 2014 15:36:06 +0100 |
parents | 659da45a2b4b |
children | b21236b6b8d8 |
comparison
equal
deleted
inserted
replaced
1323:c84ff82658cb | 1324:853a382c9bd6 |
---|---|
6 local os_time = os.time; | 6 local os_time = os.time; |
7 local tonumber, tostring = tonumber, tostring; | 7 local tonumber, tostring = tonumber, tostring; |
8 local add_filter = require "util.filters".add_filter; | 8 local add_filter = require "util.filters".add_filter; |
9 local timer = require "util.timer"; | 9 local timer = require "util.timer"; |
10 local datetime = require "util.datetime"; | 10 local datetime = require "util.datetime"; |
11 local tb = require"util.debug".traceback; | |
11 | 12 |
12 local xmlns_sm2 = "urn:xmpp:sm:2"; | 13 local xmlns_sm2 = "urn:xmpp:sm:2"; |
13 local xmlns_sm3 = "urn:xmpp:sm:3"; | 14 local xmlns_sm3 = "urn:xmpp:sm:3"; |
14 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; | 15 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; |
15 local xmlns_delay = "urn:xmpp:delay"; | 16 local xmlns_delay = "urn:xmpp:delay"; |
82 | 83 |
83 local _send = session.sends2s or session.send; | 84 local _send = session.sends2s or session.send; |
84 local function new_send(stanza) | 85 local function new_send(stanza) |
85 local attr = stanza.attr; | 86 local attr = stanza.attr; |
86 if attr and not attr.xmlns then -- Stanza in default stream namespace | 87 if attr and not attr.xmlns then -- Stanza in default stream namespace |
88 session.log("debug", "Sending stanza %s", stanza:top_tag()); | |
87 local cached_stanza = st.clone(stanza); | 89 local cached_stanza = st.clone(stanza); |
88 | 90 |
89 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then | 91 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then |
90 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); | 92 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); |
91 end | 93 end |
92 | 94 |
93 queue[#queue+1] = cached_stanza; | 95 queue[#queue+1] = cached_stanza; |
96 session.log("debug", "#queue = %d", #queue); | |
94 end | 97 end |
95 if session.hibernating then | 98 if session.hibernating then |
99 session.log("debug", "hibernating, stanza queued") | |
96 -- The session is hibernating, no point in sending the stanza | 100 -- The session is hibernating, no point in sending the stanza |
97 -- over a dead connection. It will be delivered upon resumption. | 101 -- over a dead connection. It will be delivered upon resumption. |
98 return true; | 102 return true; |
99 end | 103 end |
100 local ok, err = _send(stanza); | 104 local ok, err = _send(stanza); |
202 end | 206 end |
203 end | 207 end |
204 for i=1,math_min(handled_stanza_count,#queue) do | 208 for i=1,math_min(handled_stanza_count,#queue) do |
205 t_remove(origin.outgoing_stanza_queue, 1); | 209 t_remove(origin.outgoing_stanza_queue, 1); |
206 end | 210 end |
211 origin.log("debug", "#queue = %d", #queue); | |
207 origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; | 212 origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; |
208 return true; | 213 return true; |
209 end | 214 end |
210 module:hook_stanza(xmlns_sm2, "a", handle_a); | 215 module:hook_stanza(xmlns_sm2, "a", handle_a); |
211 module:hook_stanza(xmlns_sm3, "a", handle_a); | 216 module:hook_stanza(xmlns_sm3, "a", handle_a); |
331 h = stanza.attr.h })); | 336 h = stanza.attr.h })); |
332 | 337 |
333 -- Ok, we need to re-send any stanzas that the client didn't see | 338 -- Ok, we need to re-send any stanzas that the client didn't see |
334 -- ...they are what is now left in the outgoing stanza queue | 339 -- ...they are what is now left in the outgoing stanza queue |
335 local queue = original_session.outgoing_stanza_queue; | 340 local queue = original_session.outgoing_stanza_queue; |
341 session.log("debug", "#queue = %d", #queue); | |
336 for i=1,#queue do | 342 for i=1,#queue do |
337 session.send(queue[i]); | 343 session.send(queue[i]); |
338 end | 344 end |
345 session.log("debug", "#queue = %d -- after send", #queue); | |
339 else | 346 else |
340 module:log("warn", "Client %s@%s[%s] tried to resume stream for %s@%s[%s]", | 347 module:log("warn", "Client %s@%s[%s] tried to resume stream for %s@%s[%s]", |
341 session.username or "?", session.host or "?", session.type, | 348 session.username or "?", session.host or "?", session.type, |
342 original_session.username or "?", original_session.host or "?", original_session.type); | 349 original_session.username or "?", original_session.host or "?", original_session.type); |
343 session.send(st.stanza("failed", { xmlns = xmlns_sm }) | 350 session.send(st.stanza("failed", { xmlns = xmlns_sm }) |