comparison mod_smacks/mod_smacks.lua @ 255:9b9b089407b1

mod_smacks: Fix to reply to stream for s2s sessions
author Matthew Wild <mwild1@gmail.com>
date Thu, 07 Oct 2010 16:14:31 +0100
parents 263858d40ceb
children 57de4a7840ef
comparison
equal deleted inserted replaced
254:9b4a114b2fe6 255:9b9b089407b1
28 28
29 -- Overwrite process_stanza() and send() 29 -- Overwrite process_stanza() and send()
30 local queue = {}; 30 local queue = {};
31 session.outgoing_stanza_queue = queue; 31 session.outgoing_stanza_queue = queue;
32 session.last_acknowledged_stanza = 0; 32 session.last_acknowledged_stanza = 0;
33 local _send = session.send; 33 local _send = session.sends2s or session.send;
34 function session.send(stanza) 34 local function new_send(stanza)
35 local attr = stanza.attr; 35 local attr = stanza.attr;
36 if attr and not attr.xmlns then -- Stanza in default stream namespace 36 if attr and not attr.xmlns then -- Stanza in default stream namespace
37 queue[#queue+1] = st.reply(stanza); 37 queue[#queue+1] = st.reply(stanza);
38 end 38 end
39 local ok, err = _send(stanza); 39 local ok, err = _send(stanza);
40 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack then 40 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack then
41 session.awaiting_ack = true; 41 session.awaiting_ack = true;
42 return _send(st.stanza("r", { xmlns = xmlns_sm })); 42 return _send(st.stanza("r", { xmlns = xmlns_sm }));
43 end 43 end
44 return ok, err; 44 return ok, err;
45 end
46
47 if session.sends2s then
48 session.sends2s = new_send;
49 else
50 session.send = new_send;
45 end 51 end
46 52
47 session.handled_stanza_count = 0; 53 session.handled_stanza_count = 0;
48 add_filter(session, "stanzas/in", function (stanza) 54 add_filter(session, "stanzas/in", function (stanza)
49 if not stanza.attr.xmlns then 55 if not stanza.attr.xmlns then
64 module:log("debug", "Received ack request from non-smack-enabled session"); 70 module:log("debug", "Received ack request from non-smack-enabled session");
65 return; 71 return;
66 end 72 end
67 module:log("debug", "Received ack request, acking for %d", origin.handled_stanza_count); 73 module:log("debug", "Received ack request, acking for %d", origin.handled_stanza_count);
68 -- Reply with <a> 74 -- Reply with <a>
69 origin.send(st.stanza("a", { xmlns = xmlns_sm, h = tostring(origin.handled_stanza_count) })); 75 (origin.sends2s or origin.send)(st.stanza("a", { xmlns = xmlns_sm, h = tostring(origin.handled_stanza_count) }));
70 return true; 76 return true;
71 end); 77 end);
72 78
73 module:hook_stanza(xmlns_sm, "a", function (origin, stanza) 79 module:hook_stanza(xmlns_sm, "a", function (origin, stanza)
74 if not origin.smacks then return; end 80 if not origin.smacks then return; end