Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 1522:d4a4ed31567e
mod_smacks: Trick session.send() into not returning nil or mod_message will act as if messages were not delivered
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 13 Oct 2014 14:19:49 +0200 |
parents | 2881d532f385 |
children | 120817435151 |
comparison
equal
deleted
inserted
replaced
1521:71af9c272d72 | 1522:d4a4ed31567e |
---|---|
70 | 70 |
71 local function outgoing_stanza_filter(stanza, session) | 71 local function outgoing_stanza_filter(stanza, session) |
72 local is_stanza = stanza.attr and not stanza.attr.xmlns; | 72 local is_stanza = stanza.attr and not stanza.attr.xmlns; |
73 if is_stanza and not stanza._cached then -- Stanza in default stream namespace | 73 if is_stanza and not stanza._cached then -- Stanza in default stream namespace |
74 local queue = session.outgoing_stanza_queue; | 74 local queue = session.outgoing_stanza_queue; |
75 module:log("debug", "st.clone( %s ) -- %s a stanza", tostring(stanza), is_stanza and "is" or "is not"); | |
76 local cached_stanza = st.clone(stanza); | 75 local cached_stanza = st.clone(stanza); |
77 cached_stanza._cached = true; | 76 cached_stanza._cached = true; |
78 | 77 |
79 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then | 78 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then |
80 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); | 79 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); |
81 end | 80 end |
82 | 81 |
83 queue[#queue+1] = cached_stanza; | 82 queue[#queue+1] = cached_stanza; |
84 session.log("debug", "#queue = %d", #queue); | 83 session.log("debug", "#queue = %d", #queue); |
84 if session.hibernating then | |
85 session.log("debug", "hibernating, stanza queued"); | |
86 return ""; -- Hack to make session.send() not return nil | |
87 end | |
85 if #queue > max_unacked_stanzas then | 88 if #queue > max_unacked_stanzas then |
86 module:add_timer(0, function () | 89 module:add_timer(0, function () |
87 if not session.awaiting_ack then | 90 if not session.awaiting_ack then |
88 session.awaiting_ack = true; | 91 session.awaiting_ack = true; |
89 session.send(st.stanza("r", { xmlns = session.smacks })); | 92 session.send(st.stanza("r", { xmlns = session.smacks })); |
90 end | 93 end |
91 end); | 94 end); |
92 end | 95 end |
93 end | 96 end |
94 if session.hibernating then | |
95 session.log("debug", "hibernating, stanza queued") | |
96 -- The session is hibernating, no point in sending the stanza | |
97 -- over a dead connection. It will be delivered upon resumption. | |
98 return nil; -- or empty string? | |
99 end | |
100 return stanza; | 97 return stanza; |
101 end | 98 end |
102 | 99 |
103 local function count_incoming_stanzas(stanza, session) | 100 local function count_incoming_stanzas(stanza, session) |
104 if not stanza.attr.xmlns then | 101 if not stanza.attr.xmlns then |
107 end | 104 end |
108 return stanza; | 105 return stanza; |
109 end | 106 end |
110 | 107 |
111 local function wrap_session(session, resume) | 108 local function wrap_session(session, resume) |
112 -- Overwrite process_stanza() and send() | |
113 local queue; | 109 local queue; |
114 if not resume then | 110 if not resume then |
115 queue = {}; | 111 queue = {}; |
116 session.outgoing_stanza_queue = queue; | 112 session.outgoing_stanza_queue = queue; |
117 session.last_acknowledged_stanza = 0; | 113 session.last_acknowledged_stanza = 0; |