changeset 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 074237d7820b
children 10ff12fa82e2
files mod_addressing/mod_addressing.lua
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_addressing/mod_addressing.lua	Sat Sep 03 01:36:05 2011 +0200
@@ -0,0 +1,53 @@
+-- TODO Querying other servers for support, needs to keep track of remote
+-- server disco features
+
+local xmlns_address = 'http://jabber.org/protocol/address';
+
+local function handle_extended_addressing(data)
+	local origin, stanza = data.origin, data.stanza;
+	if stanza.attr.type == "error" then
+		return -- so we don't process bounces
+	end
+	local orig_to = stanza.attr.to;
+	local addresses = stanza:get_child("addresses", xmlns_address);
+	if addresses then
+		module:log("debug", "Extended addressing found");
+		local destinations = {};
+		addresses:maptags(function(address)
+			if address.attr.xmlns == xmlns_address and address.name == "address" then
+				local type, jid, delivered = address.attr.type, address.attr.jid, address.attr.delivered;
+				if (type == "cc" or type == "bcc" or type == "to")
+					and jid and not delivered then
+					table.insert(destinations, jid)
+					module:log("debug", "%s to %s", type, jid)
+					if type == "to" or type == "cc" then
+						address.attr.delivered = "true";
+						return address;
+					elseif type == "bcc" then
+						return nil;
+					end
+				end
+			end
+			return address; -- unsupported stuff goes right back
+		end);
+		for _, destination in ipairs(destinations) do
+			stanza.attr.to = destination;
+			module:log("debug", "posting stanza to %s", destination)
+			core_post_stanza(hosts[module.host], stanza);
+		end
+		stanza.attr.to = orig_to;
+		return stanza.attr.to == module.host or nil;
+	end
+end
+
+module:hook("message/host", handle_extended_addressing, 10);
+module:hook("message/bare", handle_extended_addressing, 10);
+module:hook("message/full", handle_extended_addressing, 10);
+
+module:hook("presence/host", handle_extended_addressing, 10);
+module:hook("presence/bare", handle_extended_addressing, 10);
+module:hook("presence/full", handle_extended_addressing, 10);
+
+-- IQ stanzas makes no sense
+
+module:add_feature(xmlns_address);