Mercurial > prosody-modules
comparison mod_carbons/mod_carbons.lua @ 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 | 1c64ab8ae374 |
| children | f8d08f8ed7de |
comparison
equal
deleted
inserted
replaced
| 883:bec0a995f5df | 884:2ece37bf9cc6 |
|---|---|
| 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:2"; | 8 local xmlns_carbons = "urn:xmpp:carbons:2"; |
| 9 local xmlns_carbons_old = "urn:xmpp:carbons:1"; | 9 local xmlns_carbons_old = "urn:xmpp:carbons:1"; |
| 10 local xmlns_carbons_really_old = "urn:xmpp:carbons:0"; | |
| 10 local xmlns_forward = "urn:xmpp:forward:0"; | 11 local xmlns_forward = "urn:xmpp:forward:0"; |
| 11 local full_sessions, bare_sessions = full_sessions, bare_sessions; | 12 local full_sessions, bare_sessions = full_sessions, bare_sessions; |
| 12 | 13 |
| 13 local function toggle_carbons(event) | 14 local function toggle_carbons(event) |
| 14 local origin, stanza = event.origin, event.stanza; | 15 local origin, stanza = event.origin, event.stanza; |
| 24 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); | 25 module:hook("iq/self/"..xmlns_carbons..":enable", toggle_carbons); |
| 25 | 26 |
| 26 -- COMPAT | 27 -- COMPAT |
| 27 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); | 28 module:hook("iq/self/"..xmlns_carbons_old..":disable", toggle_carbons); |
| 28 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); | 29 module:hook("iq/self/"..xmlns_carbons_old..":enable", toggle_carbons); |
| 30 | |
| 31 -- COMPAT :( | |
| 32 module:hook("iq/self/"..xmlns_carbons_really_old..":carbons", function(event) | |
| 33 local origin, stanza = event.origin, event.stanza; | |
| 34 if stanza.attr.type == "set" then | |
| 35 local state = stanza.tags[1].attr.mode; | |
| 36 origin.want_carbons = state == "enable" and xmlns_carbons_really_old; | |
| 37 origin.send(st.reply(stanza)); | |
| 38 return true; | |
| 39 end | |
| 40 end); | |
| 29 | 41 |
| 30 local function message_handler(event, c2s) | 42 local function message_handler(event, c2s) |
| 31 local origin, stanza = event.origin, event.stanza; | 43 local origin, stanza = event.origin, event.stanza; |
| 32 local orig_type = stanza.attr.type; | 44 local orig_type = stanza.attr.type; |
| 33 local orig_from = stanza.attr.from; | 45 local orig_from = stanza.attr.from; |
| 84 local carbon_old = st.message{ from = bare_jid, type = orig_type, } | 96 local carbon_old = st.message{ from = bare_jid, type = orig_type, } |
| 85 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_old }):up() | 97 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_old }):up() |
| 86 :tag("forwarded", { xmlns = xmlns_forward }) | 98 :tag("forwarded", { xmlns = xmlns_forward }) |
| 87 :add_child(copy):reset(); | 99 :add_child(copy):reset(); |
| 88 | 100 |
| 101 -- COMPAT | |
| 102 local carbon_really_old = st.clone(stanza) | |
| 103 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons_really_old }):up() | |
| 104 | |
| 89 user_sessions = user_sessions and user_sessions.sessions; | 105 user_sessions = user_sessions and user_sessions.sessions; |
| 90 for _, session in pairs(user_sessions) do | 106 for _, session in pairs(user_sessions) do |
| 91 -- Carbons are sent to resources that have enabled it | 107 -- Carbons are sent to resources that have enabled it |
| 92 if session.want_carbons | 108 if session.want_carbons |
| 93 -- but not the resource that sent the message, or the one that it's directed to | 109 -- but not the resource that sent the message, or the one that it's directed to |
| 94 and session ~= target_session | 110 and session ~= target_session |
| 95 -- and isn't among the top resources that would receive the message per standard routing rules | 111 -- and isn't among the top resources that would receive the message per standard routing rules |
| 96 and (c2s or session.priority ~= top_priority) then | 112 and (c2s or session.priority ~= top_priority) then |
| 97 carbon.attr.to = session.full_jid; | 113 carbon.attr.to = session.full_jid; |
| 98 module:log("debug", "Sending carbon to %s", session.full_jid); | 114 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 | 115 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 | |
| 117 or carbon; | |
| 100 session.send(carbon); | 118 session.send(carbon); |
| 101 end | 119 end |
| 102 end | 120 end |
| 103 end | 121 end |
| 104 | 122 |
| 113 module:hook("message/bare", message_handler, 1); | 131 module:hook("message/bare", message_handler, 1); |
| 114 module:hook("message/full", message_handler, 1); | 132 module:hook("message/full", message_handler, 1); |
| 115 | 133 |
| 116 module:add_feature(xmlns_carbons); | 134 module:add_feature(xmlns_carbons); |
| 117 module:add_feature(xmlns_carbons_old); | 135 module:add_feature(xmlns_carbons_old); |
| 136 module:add_feature(xmlns_carbons_really_old); |
