Changeset

850:0900ba54991e

mod_carbons: Update to latest version of XEP-0280, while supporting the old version.
author Kim Alvefur <zash@zash.se>
date Wed, 17 Oct 2012 03:47:15 +0200
parents 849:6e2ec1825182
children 851:836e4e110c71
files mod_carbons/mod_carbons.lua
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_carbons/mod_carbons.lua	Mon Oct 15 21:02:43 2012 +0200
+++ b/mod_carbons/mod_carbons.lua	Wed Oct 17 03:47:15 2012 +0200
@@ -5,7 +5,8 @@
 
 local st = require "util.stanza";
 local jid_bare = require "util.jid".bare;
-local xmlns_carbons = "urn:xmpp:carbons:1";
+local xmlns_carbons = "urn:xmpp:carbons:2";
+local xmlns_carbons_old = "urn:xmpp:carbons:1";
 local xmlns_forward = "urn:xmpp:forward:0";
 local full_sessions, bare_sessions = full_sessions, bare_sessions;
 
@@ -14,7 +15,7 @@
 	if stanza.attr.type == "set" then
 		local state = stanza.tags[1].name;
 		module:log("debug", "%s %sd carbons", origin.full_jid, state);
-		origin.want_carbons = state == "enable";
+		origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns;
 		origin.send(st.reply(stanza));
 		return true
 	end
@@ -22,6 +23,10 @@
 module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons);
 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons);
 
+-- COMPAT
+module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons);
+module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons);
+
 local function message_handler(event, c2s)
 	local origin, stanza = event.origin, event.stanza;
 	local orig_type = stanza.attr.type;
@@ -75,6 +80,12 @@
 			:tag("forwarded", { xmlns = xmlns_forward })
 				:add_child(copy):reset();
 
+	-- COMPAT
+	local carbon_old = st.message{ from = bare_jid, type = orig_type, }
+		:tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_old }):up()
+		:tag("forwarded", { xmlns = xmlns_forward })
+			:add_child(copy):reset();
+
 	user_sessions = user_sessions and user_sessions.sessions;
 	for _, session in pairs(user_sessions) do
 		-- Carbons are sent to resources that have enabled it
@@ -85,6 +96,7 @@
 		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
 			session.send(carbon);
 		end
 	end