Software /
code /
prosody-modules
Diff
mod_seclabels/mod_seclabels.lua @ 450:fb152d4af082
mod_seclabels: Update to latest catalog schema, while keeping compatibility with the old one.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 05 Oct 2011 21:03:51 +0200 |
parent | 449:08ffbbdafeea |
child | 451:f43d2d26c1c4 |
line wrap: on
line diff
--- a/mod_seclabels/mod_seclabels.lua Wed Oct 05 21:00:12 2011 +0200 +++ b/mod_seclabels/mod_seclabels.lua Wed Oct 05 21:03:51 2011 +0200 @@ -1,11 +1,14 @@ local st = require "util.stanza"; local xmlns_label = "urn:xmpp:sec-label:0"; -local xmlns_label_catalog = "urn:xmpp:sec-label:catalog:0"; +local xmlns_label_catalog = "urn:xmpp:sec-label:catalog:2"; +local xmlns_label_catalog_old = "urn:xmpp:sec-label:catalog:0"; -- COMPAT module:add_feature(xmlns_label); +module:add_feature(xmlns_label_catalog); +module:add_feature(xmlns_label_catalog_old); -module:hook("account-disco-info", function(event) +module:hook("account-disco-info", function(event) -- COMPAT local stanza = event.stanza; stanza:tag('feature', {var=xmlns_label}):up(); stanza:tag('feature', {var=xmlns_label_catalog}):up(); @@ -26,11 +29,11 @@ module:hook("config-reloaded",get_conf); get_conf(); -module:hook("iq/self/"..xmlns_label_catalog..":catalog", function (request) +function handle_catalog_request(request) local catalog_request = request.stanza.tags[1]; local reply = st.reply(request.stanza) :tag("catalog", { - xmlns = xmlns_label_catalog, + xmlns = catalog_request.attr.xmlns, to = catalog_request.attr.to, name = catalog_name, desc = catalog_desc @@ -39,24 +42,42 @@ 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 catalog_request.attr.xmlns == xmlns_label_catalog then + catalog:tag("item", { + selector = selector..name, + default = value.default and "true" or nil, + }):tag("securitylabel", { xmlns = xmlns_label }) + else -- COMPAT + catalog:tag("securitylabel", { + xmlns = xmlns_label, + selector = selector..name, + default = value.default and "true" or nil, + }) + end + if value.name or value.color or value.bgcolor then + catalog:tag("displaymarking", { + fgcolor = value.color, + bgcolor = value.bgcolor, + }):text(value.name or name):up(); + end if type(value.label) == "string" then - catalog:text(value.label); - else - catalog:add_child(value.label); + catalog:tag("label"):text(value.label):up(); + elseif type(value.label) == "table" then + catalog:tag("label"):add_child(value.label):up(); end - catalog:up():up(); + catalog:up(); + if catalog_request.attr.xmlns == xmlns_label_catalog then + catalog:up(); + end else add_labels(catalog, value, (selector or "")..name.."|"); end end end - add_labels(reply, labels); + add_labels(reply, labels, ""); request.origin.send(reply); return true; -end); +end +module:hook("iq/host/"..xmlns_label_catalog..":catalog", handle_catalog_request); +module:hook("iq/self/"..xmlns_label_catalog..":catalog", handle_catalog_request); -- COMPAT +module:hook("iq/self/"..xmlns_label_catalog_old..":catalog", handle_catalog_request); -- COMPAT