Diff

mod_seclabels/mod_seclabels.lua @ 252:8eae74a31acb

mod_seclabels: Prototype security labels plugin
author Matthew Wild <mwild1@gmail.com>
date Mon, 20 Sep 2010 21:10:49 +0100
child 266:e7296274f48c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_seclabels/mod_seclabels.lua	Mon Sep 20 21:10:49 2010 +0100
@@ -0,0 +1,48 @@
+local st = require "util.stanza";
+
+local xmlns_label = "urn:xmpp:sec-label:0";
+local xmlns_label_catalog = "urn:xmpp:sec-label:catalog:0";
+
+module:add_feature(xmlns_label);
+
+local labels = {
+	Classified = {
+		SECRET = { color = "black", bgcolor = "aqua", label = "THISISSECRET" };
+		PUBLIC = { label = "THISISPUBLIC" };
+	};
+};
+
+module:hook("iq/self/"..xmlns_label_catalog..":catalog", function (request)
+	local catalog_request = request.stanza.tags[1];
+	local reply = st.reply(request.stanza)
+		:tag("catalog", {
+			xmlns = xmlns_label_catalog,
+			to = catalog_request.attr.to,
+			name = "Default",
+			desc = "My labels"
+		});
+	
+	local function add_labels(catalog, labels, selector)
+		for name, value in pairs(labels) do
+			if value.label then
+				catalog:tag("securitylabel", { xmlns = xmlns_label, selector = selector..name })
+						:tag("displaymarking", {
+							fgcolor = value.color or "black",
+							bgcolor = value.bgcolor or "white",
+							}):text(value.name or name):up()
+						:tag("label");
+				if type(value.label) == "string" then
+					catalog:text(value.label);
+				else
+					catalog:add_child(value.label);
+				end
+				catalog:up():up();
+			else
+				add_labels(catalog, value, (selector or "")..name.."|");
+			end
+		end
+	end
+	add_labels(reply, labels);
+	request.origin.send(reply);
+	return true;
+end);