changeset 884:2ece37bf9cc6

mod_carbons: Support the pre-forwarding version of Carbons. Please don't implement this.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Dec 2012 15:36:55 +0100
parents bec0a995f5df
children 292ea8df7267
files mod_carbons/mod_carbons.lua
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_carbons/mod_carbons.lua	Thu Dec 20 12:12:36 2012 +0100
+++ b/mod_carbons/mod_carbons.lua	Sat Dec 22 15:36:55 2012 +0100
@@ -7,6 +7,7 @@
 local jid_bare = require "util.jid".bare;
 local xmlns_carbons = "urn:xmpp:carbons:2";
 local xmlns_carbons_old = "urn:xmpp:carbons:1";
+local xmlns_carbons_really_old = "urn:xmpp:carbons:0";
 local xmlns_forward = "urn:xmpp:forward:0";
 local full_sessions, bare_sessions = full_sessions, bare_sessions;
 
@@ -27,6 +28,17 @@
 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons);
 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons);
 
+-- COMPAT :(
+module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", function(event)
+	local origin, stanza = event.origin, event.stanza;
+	if stanza.attr.type == "set" then
+		local state = stanza.tags[1].attr.mode;
+		origin.want_carbons = state == "enable" and xmlns_carbons_really_old;
+		origin.send(st.reply(stanza));
+		return true;
+	end
+end);
+
 local function message_handler(event, c2s)
 	local origin, stanza = event.origin, event.stanza;
 	local orig_type = stanza.attr.type;
@@ -86,6 +98,10 @@
 		:tag("forwarded", { xmlns = xmlns_forward })
 			:add_child(copy):reset();
 
+	-- COMPAT
+	local carbon_really_old = st.clone(stanza)
+		:tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_really_old }):up()
+
 	user_sessions = user_sessions and user_sessions.sessions;
 	for _, session in pairs(user_sessions) do
 		-- Carbons are sent to resources that have enabled it
@@ -96,7 +112,9 @@
 		and (c2s or session.priority ~= top_priority) then
 			carbon.attr.to = session.full_jid;
 			module:log("debug", "Sending carbon to %s", session.full_jid);
-			local carbon = session.want_carbons == xmlns_carbons_old and carbon_old or carbon; -- COMPAT
+			local carbon = session.want_carbons == xmlns_carbons_old and carbon_old -- COMPAT
+			or session.want_carbons == xmlns_carbons_really_old and carbon_really_old -- COMPAT
+			or carbon;
 			session.send(carbon);
 		end
 	end
@@ -115,3 +133,4 @@
 
 module:add_feature(xmlns_carbons);
 module:add_feature(xmlns_carbons_old);
+module:add_feature(xmlns_carbons_really_old);