comparison mod_smacks/mod_smacks.lua @ 1530:fb7cd669f41b

mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
author Kim Alvefur <zash@zash.se>
date Mon, 20 Oct 2014 13:15:14 +0200
parents 16893646a458
children 7d86fc477993
comparison
equal deleted inserted replaced
1529:16893646a458 1530:fb7cd669f41b
55 event.features:tag("sm", sm2_attr):tag("optional"):up():up(); 55 event.features:tag("sm", sm2_attr):tag("optional"):up():up();
56 event.features:tag("sm", sm3_attr):tag("optional"):up():up(); 56 event.features:tag("sm", sm3_attr):tag("optional"):up():up();
57 end 57 end
58 end); 58 end);
59 59
60 module:hook_stanza("http://etherx.jabber.org/streams", "features",
61 function (session, stanza)
62 if can_do_smacks(session) then
63 if stanza:get_child("sm", xmlns_sm3) then
64 session.sends2s(st.stanza("enable", sm3_attr));
65 elseif stanza:get_child("sm", xmlns_sm2) then
66 session.sends2s(st.stanza("enable", sm2_attr));
67 end
68 end
69 end);
70
71 local function outgoing_stanza_filter(stanza, session) 60 local function outgoing_stanza_filter(stanza, session)
72 local is_stanza = stanza.attr and not stanza.attr.xmlns; 61 local is_stanza = stanza.attr and not stanza.attr.xmlns;
73 if is_stanza and not stanza._cached then -- Stanza in default stream namespace 62 if is_stanza and not stanza._cached then -- Stanza in default stream namespace
74 local queue = session.outgoing_stanza_queue; 63 local queue = session.outgoing_stanza_queue;
75 local cached_stanza = st.clone(stanza); 64 local cached_stanza = st.clone(stanza);
163 return true; 152 return true;
164 end 153 end
165 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100); 154 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100);
166 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100); 155 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100);
167 156
157 module:hook_stanza("http://etherx.jabber.org/streams", "features",
158 function (session, stanza)
159 if can_do_smacks(session) then
160 if stanza:get_child("sm", xmlns_sm3) then
161 session.sends2s(st.stanza("enable", sm3_attr));
162 session.smacks = xmlns_sm3;
163 elseif stanza:get_child("sm", xmlns_sm2) then
164 session.sends2s(st.stanza("enable", sm2_attr));
165 session.smacks = xmlns_sm2;
166 else
167 return;
168 end
169 wrap_session_out(session, false);
170 end
171 end);
172
168 function handle_enabled(session, stanza, xmlns_sm) 173 function handle_enabled(session, stanza, xmlns_sm)
169 module:log("debug", "Enabling stream management"); 174 module:log("debug", "Enabling stream management");
170 session.smacks = xmlns_sm; 175 session.smacks = xmlns_sm;
171 176
172 wrap_session(session, false); 177 wrap_session_in(session, false);
173 178
174 -- FIXME Resume? 179 -- FIXME Resume?
175 180
176 return true; 181 return true;
177 end 182 end