Comparison

plugins/carbons.lua @ 274:a228f3c7808a

plugins.carbons: Update to XEP v0.6. Check that messages are from your bare jid.
author Kim Alvefur <zash@zash.se>
date Tue, 10 Jan 2012 21:08:19 +0100
parent 250:a5ac643a7fd6
child 277:0d34cd815a93
comparison
equal deleted inserted replaced
273:c5b7a4c717a6 274:a228f3c7808a
2 2
3 local xmlns_carbons = "urn:xmpp:carbons:1"; 3 local xmlns_carbons = "urn:xmpp:carbons:1";
4 local xmlns_forward = "urn:xmpp:forward:0"; 4 local xmlns_forward = "urn:xmpp:forward:0";
5 local os_date = os.date; 5 local os_date = os.date;
6 local datetime = function(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end 6 local datetime = function(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end
7 local bare_jid = require "util.jid".bare;
7 8
8 -- TODO Check disco for support 9 -- TODO Check disco for support
9 10
10 function verse.plugins.carbons(stream) 11 function verse.plugins.carbons(stream)
11 local carbons = {}; 12 local carbons = {};
38 callback(success); 39 callback(success);
39 end 40 end
40 end or nil); 41 end or nil);
41 end 42 end
42 43
44 local my_bare;
45 stream:hook("bind-success", function()
46 my_bare = bare_jid(stream.jid);
47 end);
48
43 stream:hook("message", function(stanza) 49 stream:hook("message", function(stanza)
44 stream:debug(stanza); 50 local carbon_dir = fwd:get_child(nil, xmlns_carbons);
45 local fwd = stanza:get_child("forwarded", xmlns_forward); 51 if stanza.attr.from == my_bare and carbon_dir then
46 if fwd then
47 local carbon_dir = fwd:get_child(nil, xmlns_carbons);
48 carbon_dir = carbon_dir and carbon_dir.name; 52 carbon_dir = carbon_dir and carbon_dir.name;
49 if carbon_dir then 53 local fwd = stanza:get_child("forwarded", xmlns_forward);
50 local fwd_stanza = fwd:get_child("message", "jabber:client"); 54 local fwd_stanza = fwd and fwd:get_child("message", "jabber:client");
51 assert(fwd_stanza, "No stanza included.\n"..tostring(stanza).."\n--\n"..tostring(fwd_stanza)); 55 if fwd_stanza then
52 return stream:event("carbon", { 56 return stream:event("carbon", {
53 dir = carbon_dir, 57 dir = carbon_dir,
54 stanza = fwd_stanza, 58 stanza = fwd_stanza,
55 timestamp = nil or datetime(), -- TODO check for delay tag 59 timestamp = nil or datetime(), -- TODO check for delay tag
56 }); 60 });