comparison mod_addressing/mod_addressing.lua @ 415:3ba1a5b9d657

mod_addressing: Add partial implementation of Extended Stanza Addressing, XEP-33.
author Kim Alvefur <zash@zash.se>
date Sat, 03 Sep 2011 01:36:05 +0200
parents
children 442f88b49d9b
comparison
equal deleted inserted replaced
414:074237d7820b 415:3ba1a5b9d657
1 -- TODO Querying other servers for support, needs to keep track of remote
2 -- server disco features
3
4 local xmlns_address = 'http://jabber.org/protocol/address';
5
6 local function handle_extended_addressing(data)
7 local origin, stanza = data.origin, data.stanza;
8 if stanza.attr.type == "error" then
9 return -- so we don't process bounces
10 end
11 local orig_to = stanza.attr.to;
12 local addresses = stanza:get_child("addresses", xmlns_address);
13 if addresses then
14 module:log("debug", "Extended addressing found");
15 local destinations = {};
16 addresses:maptags(function(address)
17 if address.attr.xmlns == xmlns_address and address.name == "address" then
18 local type, jid, delivered = address.attr.type, address.attr.jid, address.attr.delivered;
19 if (type == "cc" or type == "bcc" or type == "to")
20 and jid and not delivered then
21 table.insert(destinations, jid)
22 module:log("debug", "%s to %s", type, jid)
23 if type == "to" or type == "cc" then
24 address.attr.delivered = "true";
25 return address;
26 elseif type == "bcc" then
27 return nil;
28 end
29 end
30 end
31 return address; -- unsupported stuff goes right back
32 end);
33 for _, destination in ipairs(destinations) do
34 stanza.attr.to = destination;
35 module:log("debug", "posting stanza to %s", destination)
36 core_post_stanza(hosts[module.host], stanza);
37 end
38 stanza.attr.to = orig_to;
39 return stanza.attr.to == module.host or nil;
40 end
41 end
42
43 module:hook("message/host", handle_extended_addressing, 10);
44 module:hook("message/bare", handle_extended_addressing, 10);
45 module:hook("message/full", handle_extended_addressing, 10);
46
47 module:hook("presence/host", handle_extended_addressing, 10);
48 module:hook("presence/bare", handle_extended_addressing, 10);
49 module:hook("presence/full", handle_extended_addressing, 10);
50
51 -- IQ stanzas makes no sense
52
53 module:add_feature(xmlns_address);