Changeset

416:10ff12fa82e2

merge.
author Marco Cirillo <maranda@lightwitch.org>
date Fri, 02 Sep 2011 23:36:22 +0000
parents 413:e4d33cdfed21 (current diff) 415:3ba1a5b9d657 (diff)
children 417:8fe1b47c9bde
files
diffstat 2 files changed, 111 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_addressing/mod_addressing.lua	Fri Sep 02 23:36:22 2011 +0000
@@ -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);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_server_contact_info/mod_server_contact_info.lua	Fri Sep 02 23:36:22 2011 +0000
@@ -0,0 +1,58 @@
+-- This plugin implements http://xmpp.org/extensions/xep-0157.html
+local t_insert = table.insert;
+local df_new = require "util.dataforms".new;
+
+local x_contact_info;
+-- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
+local valid_types = {
+	abuse = true;
+	admin = true;
+	feedback = true;
+	sales = true;
+	security = true;
+	support = true;
+}
+
+local function update_form_data()
+	if x_contact_info then
+		module:remove_item("extension", x_contact_info);
+	end
+	x_contact_info = nil;
+
+	local contact_config = module:get_option("contact_info");
+	if not contact_config then -- we'll use admins from the config as default
+		contact_config = { admin = {}; };
+		local admins = module:get_option("admins");
+		if not admins or #admins == 0 then
+			module:log("debug", "No contact_info or admins in config");
+			return -- Nothing to attach, so we'll just skip it.
+		end
+		module:log("debug", "No contact_info in config, using admins as fallback");
+		--TODO fetch global admins too?
+		for i = 1,#admins do
+			t_insert(contact_config.admin, "xmpp:" .. admins[i])
+			module:log("debug", "Added %s to admin-addresses", admins[i]);
+		end
+	end
+	if not next(contact_config) then
+		module:log("debug", "No contacts, skipping");
+		return -- No use in serving an empty form.
+	end
+	local form_layout = {
+		{ value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; };
+	};
+	local form_values = {};
+
+	for t,a in pairs(contact_config) do
+		if valid_types[t] and a then
+			t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
+			form_values[t .. "-addresses"] = type(a) == "table" and a or {a};
+		end
+	end
+
+	x_contact_info = df_new(form_layout):form(form_values, "result");
+	module:add_extension(x_contact_info);
+end
+
+module:hook_global("config-reloaded", update_form_data);
+update_form_data();