Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
251:d36160f4961f | 252:8eae74a31acb |
---|---|
1 local st = require "util.stanza"; | |
2 | |
3 local xmlns_label = "urn:xmpp:sec-label:0"; | |
4 local xmlns_label_catalog = "urn:xmpp:sec-label:catalog:0"; | |
5 | |
6 module:add_feature(xmlns_label); | |
7 | |
8 local labels = { | |
9 Classified = { | |
10 SECRET = { color = "black", bgcolor = "aqua", label = "THISISSECRET" }; | |
11 PUBLIC = { label = "THISISPUBLIC" }; | |
12 }; | |
13 }; | |
14 | |
15 module:hook("iq/self/"..xmlns_label_catalog..":catalog", function (request) | |
16 local catalog_request = request.stanza.tags[1]; | |
17 local reply = st.reply(request.stanza) | |
18 :tag("catalog", { | |
19 xmlns = xmlns_label_catalog, | |
20 to = catalog_request.attr.to, | |
21 name = "Default", | |
22 desc = "My labels" | |
23 }); | |
24 | |
25 local function add_labels(catalog, labels, selector) | |
26 for name, value in pairs(labels) do | |
27 if value.label then | |
28 catalog:tag("securitylabel", { xmlns = xmlns_label, selector = selector..name }) | |
29 :tag("displaymarking", { | |
30 fgcolor = value.color or "black", | |
31 bgcolor = value.bgcolor or "white", | |
32 }):text(value.name or name):up() | |
33 :tag("label"); | |
34 if type(value.label) == "string" then | |
35 catalog:text(value.label); | |
36 else | |
37 catalog:add_child(value.label); | |
38 end | |
39 catalog:up():up(); | |
40 else | |
41 add_labels(catalog, value, (selector or "")..name.."|"); | |
42 end | |
43 end | |
44 end | |
45 add_labels(reply, labels); | |
46 request.origin.send(reply); | |
47 return true; | |
48 end); |