Software /
code /
prosody-modules
Comparison
mod_carbons/mod_carbons.lua @ 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 |
parent | 837:0ef11dee7050 |
child | 854:1c64ab8ae374 |
comparison
equal
deleted
inserted
replaced
849:6e2ec1825182 | 850:0900ba54991e |
---|---|
3 -- | 3 -- |
4 -- This file is MIT/X11 licensed. | 4 -- This file is MIT/X11 licensed. |
5 | 5 |
6 local st = require "util.stanza"; | 6 local st = require "util.stanza"; |
7 local jid_bare = require "util.jid".bare; | 7 local jid_bare = require "util.jid".bare; |
8 local xmlns_carbons = "urn:xmpp:carbons:1"; | 8 local xmlns_carbons = "urn:xmpp:carbons:2"; |
9 local xmlns_carbons_old = "urn:xmpp:carbons:1"; | |
9 local xmlns_forward = "urn:xmpp:forward:0"; | 10 local xmlns_forward = "urn:xmpp:forward:0"; |
10 local full_sessions, bare_sessions = full_sessions, bare_sessions; | 11 local full_sessions, bare_sessions = full_sessions, bare_sessions; |
11 | 12 |
12 local function toggle_carbons(event) | 13 local function toggle_carbons(event) |
13 local origin, stanza = event.origin, event.stanza; | 14 local origin, stanza = event.origin, event.stanza; |
14 if stanza.attr.type == "set" then | 15 if stanza.attr.type == "set" then |
15 local state = stanza.tags[1].name; | 16 local state = stanza.tags[1].name; |
16 module:log("debug", "%s %sd carbons", origin.full_jid, state); | 17 module:log("debug", "%s %sd carbons", origin.full_jid, state); |
17 origin.want_carbons = state == "enable"; | 18 origin.want_carbons = state == "enable" and stanza.tags[1].attr.xmlns; |
18 origin.send(st.reply(stanza)); | 19 origin.send(st.reply(stanza)); |
19 return true | 20 return true |
20 end | 21 end |
21 end | 22 end |
22 module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons); | 23 module:hook("iq/self/"..xmlns_carbons..":disable", toggle_carbons); |
23 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); | 24 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); |
25 | |
26 -- COMPAT | |
27 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); | |
28 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); | |
24 | 29 |
25 local function message_handler(event, c2s) | 30 local function message_handler(event, c2s) |
26 local origin, stanza = event.origin, event.stanza; | 31 local origin, stanza = event.origin, event.stanza; |
27 local orig_type = stanza.attr.type; | 32 local orig_type = stanza.attr.type; |
28 local orig_from = stanza.attr.from; | 33 local orig_from = stanza.attr.from; |
73 local carbon = st.message{ from = bare_jid, type = orig_type, } | 78 local carbon = st.message{ from = bare_jid, type = orig_type, } |
74 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up() | 79 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up() |
75 :tag("forwarded", { xmlns = xmlns_forward }) | 80 :tag("forwarded", { xmlns = xmlns_forward }) |
76 :add_child(copy):reset(); | 81 :add_child(copy):reset(); |
77 | 82 |
83 -- COMPAT | |
84 local carbon_old = st.message{ from = bare_jid, type = orig_type, } | |
85 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_old }):up() | |
86 :tag("forwarded", { xmlns = xmlns_forward }) | |
87 :add_child(copy):reset(); | |
88 | |
78 user_sessions = user_sessions and user_sessions.sessions; | 89 user_sessions = user_sessions and user_sessions.sessions; |
79 for _, session in pairs(user_sessions) do | 90 for _, session in pairs(user_sessions) do |
80 -- Carbons are sent to resources that have enabled it | 91 -- Carbons are sent to resources that have enabled it |
81 if session.want_carbons | 92 if session.want_carbons |
82 -- but not the resource that sent the message, or the one that it's directed to | 93 -- but not the resource that sent the message, or the one that it's directed to |
83 and session ~= target_session | 94 and session ~= target_session |
84 -- and isn't among the top resources that would receive the message per standard routing rules | 95 -- and isn't among the top resources that would receive the message per standard routing rules |
85 and (c2s or session.priority ~= top_priority) then | 96 and (c2s or session.priority ~= top_priority) then |
86 carbon.attr.to = session.full_jid; | 97 carbon.attr.to = session.full_jid; |
87 module:log("debug", "Sending carbon to %s", session.full_jid); | 98 module:log("debug", "Sending carbon to %s", session.full_jid); |
99 local carbon = session.want_carbons == xmlns_carbons_old and carbon_old or carbon; -- COMPAT | |
88 session.send(carbon); | 100 session.send(carbon); |
89 end | 101 end |
90 end | 102 end |
91 end | 103 end |
92 | 104 |