Comparison

mod_carbons/mod_carbons.lua @ 888:f8d08f8ed7de

mod_carbons: Make support for v0 disabled by default, don't send v0 carbons for c2s
author Michael Holzt <kju@fqdn.org>
date Sun, 23 Dec 2012 19:30:28 +0100
parent 884:2ece37bf9cc6
child 896:d24d87ca3f5f
comparison
equal deleted inserted replaced
887:a2259870495c 888:f8d08f8ed7de
27 -- COMPAT 27 -- COMPAT
28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); 28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons);
29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); 29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons);
30 30
31 -- COMPAT :( 31 -- COMPAT :(
32 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", function(event) 32 if module:get_option_boolean("carbons_v0") then
33 local origin, stanza = event.origin, event.stanza; 33 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", function(event)
34 if stanza.attr.type == "set" then 34 local origin, stanza = event.origin, event.stanza;
35 local state = stanza.tags[1].attr.mode; 35 if stanza.attr.type == "set" then
36 origin.want_carbons = state == "enable" and xmlns_carbons_really_old; 36 local state = stanza.tags[1].attr.mode;
37 origin.send(st.reply(stanza)); 37 origin.want_carbons = state == "enable" and xmlns_carbons_really_old;
38 return true; 38 origin.send(st.reply(stanza));
39 end 39 return true;
40 end); 40 end
41 end);
42 end
41 43
42 local function message_handler(event, c2s) 44 local function message_handler(event, c2s)
43 local origin, stanza = event.origin, event.stanza; 45 local origin, stanza = event.origin, event.stanza;
44 local orig_type = stanza.attr.type; 46 local orig_type = stanza.attr.type;
45 local orig_from = stanza.attr.from; 47 local orig_from = stanza.attr.from;
107 -- Carbons are sent to resources that have enabled it 109 -- Carbons are sent to resources that have enabled it
108 if session.want_carbons 110 if session.want_carbons
109 -- but not the resource that sent the message, or the one that it's directed to 111 -- but not the resource that sent the message, or the one that it's directed to
110 and session ~= target_session 112 and session ~= target_session
111 -- and isn't among the top resources that would receive the message per standard routing rules 113 -- and isn't among the top resources that would receive the message per standard routing rules
112 and (c2s or session.priority ~= top_priority) then 114 and (c2s or session.priority ~= top_priority)
115 -- don't send v0 carbons (or copies) for c2s
116 and (not c2s or session.want_carbons ~= xmlns_carbons_really_old) then
113 carbon.attr.to = session.full_jid; 117 carbon.attr.to = session.full_jid;
114 module:log("debug", "Sending carbon to %s", session.full_jid); 118 module:log("debug", "Sending carbon to %s", session.full_jid);
115 local carbon = session.want_carbons == xmlns_carbons_old and carbon_old -- COMPAT 119 local carbon = session.want_carbons == xmlns_carbons_old and carbon_old -- COMPAT
116 or session.want_carbons == xmlns_carbons_really_old and carbon_really_old -- COMPAT 120 or session.want_carbons == xmlns_carbons_really_old and carbon_really_old -- COMPAT
117 or carbon; 121 or carbon;
131 module:hook("message/bare", message_handler, 1); 135 module:hook("message/bare", message_handler, 1);
132 module:hook("message/full", message_handler, 1); 136 module:hook("message/full", message_handler, 1);
133 137
134 module:add_feature(xmlns_carbons); 138 module:add_feature(xmlns_carbons);
135 module:add_feature(xmlns_carbons_old); 139 module:add_feature(xmlns_carbons_old);
136 module:add_feature(xmlns_carbons_really_old); 140 if module:get_option_boolean("carbons_v0") then
141 module:add_feature(xmlns_carbons_really_old);
142 end