Mercurial > prosody-modules
comparison mod_addressing/mod_addressing.lua @ 935:f66a08f208ad
mod_addressing: Optimization
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 25 Mar 2013 00:43:30 +0100 |
| parents | 442f88b49d9b |
| children |
comparison
equal
deleted
inserted
replaced
| 934:15e2c4fd26a0 | 935:f66a08f208ad |
|---|---|
| 2 -- server disco features | 2 -- server disco features |
| 3 | 3 |
| 4 local xmlns_address = 'http://jabber.org/protocol/address'; | 4 local xmlns_address = 'http://jabber.org/protocol/address'; |
| 5 | 5 |
| 6 local function handle_extended_addressing(data) | 6 local function handle_extended_addressing(data) |
| 7 local origin, stanza = data.origin, data.stanza; | 7 local stanza = data.stanza; |
| 8 if stanza.attr.type == "error" then | 8 if stanza.attr.type == "error" then |
| 9 return -- so we don't process bounces | 9 return -- so we don't process bounces |
| 10 end | 10 end |
| 11 local orig_to = stanza.attr.to; | 11 local orig_to = stanza.attr.to; |
| 12 local addresses = stanza:get_child("addresses", xmlns_address); | 12 local addresses = stanza:get_child("addresses", xmlns_address); |
| 16 addresses:maptags(function(address) | 16 addresses:maptags(function(address) |
| 17 if address.attr.xmlns == xmlns_address and address.name == "address" then | 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; | 18 local type, jid, delivered = address.attr.type, address.attr.jid, address.attr.delivered; |
| 19 if (type == "cc" or type == "bcc" or type == "to") | 19 if (type == "cc" or type == "bcc" or type == "to") |
| 20 and jid and not delivered then | 20 and jid and not delivered then |
| 21 table.insert(destinations, jid) | 21 destinations[#destinations+1] = jid; |
| 22 module:log("debug", "%s to %s", type, jid) | 22 module:log("debug", "%s to %s", type, jid) |
| 23 if type == "to" or type == "cc" then | 23 if type == "to" or type == "cc" then |
| 24 address.attr.delivered = "true"; | 24 address.attr.delivered = "true"; |
| 25 return address; | 25 return address; |
| 26 elseif type == "bcc" then | 26 elseif type == "bcc" then |
| 28 end | 28 end |
| 29 end | 29 end |
| 30 end | 30 end |
| 31 return address; -- unsupported stuff goes right back | 31 return address; -- unsupported stuff goes right back |
| 32 end); | 32 end); |
| 33 for _, destination in ipairs(destinations) do | 33 for i=1,#destinations do |
| 34 stanza.attr.to = destination; | 34 stanza.attr.to = destinations[i]; |
| 35 module:log("debug", "posting stanza to %s", destination) | 35 module:log("debug", "posting stanza to %s", destinations[i]) |
| 36 module:send(stanza); | 36 module:send(stanza); |
| 37 end | 37 end |
| 38 stanza.attr.to = orig_to; | 38 stanza.attr.to = orig_to; |
| 39 return stanza.attr.to == module.host or nil; | 39 return stanza.attr.to == module.host or nil; |
| 40 end | 40 end |
