Software /
code /
prosody-modules
Changeset
452:48b615229509
mod_seclabels: Support orderd items
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 10 Oct 2011 20:14:30 +0200 |
parents | 451:f43d2d26c1c4 |
children | 453:1969310ea06a |
files | mod_seclabels/mod_seclabels.lua |
diffstat | 1 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_seclabels/mod_seclabels.lua Wed Oct 05 23:54:33 2011 +0200 +++ b/mod_seclabels/mod_seclabels.lua Mon Oct 10 20:14:30 2011 +0200 @@ -15,6 +15,11 @@ end); local default_labels = { + { + name = "Unclassified", + label = true, + default = true, + }, Classified = { SECRET = { color = "black", bgcolor = "aqua", label = "THISISSECRET" }; PUBLIC = { label = "THISISPUBLIC" }; @@ -40,37 +45,46 @@ }); local function add_labels(catalog, labels, selector) - for name, value in pairs(labels) do - if value.label then + local function add_item(item, name) + local name = name or item.name; + if item.label then if catalog_request.attr.xmlns == xmlns_label_catalog then catalog:tag("item", { selector = selector..name, - default = value.default and "true" or nil, + default = item.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, + default = item.default and "true" or nil, }) end - if value.name or value.color or value.bgcolor then + if item.display or item.color or item.bgcolor then catalog:tag("displaymarking", { - fgcolor = value.color, - bgcolor = value.bgcolor, - }):text(value.name or name):up(); + fgcolor = item.color, + bgcolor = item.bgcolor, + }):text(item.display or name):up(); end - if type(value.label) == "string" then - catalog:tag("label"):text(value.label):up(); - elseif type(value.label) == "table" then - catalog:tag("label"):add_child(value.label):up(); + if type(item.label) == "string" then + catalog:tag("label"):text(item.label):up(); + elseif type(item.label) == "table" then + catalog:tag("label"):add_child(item.label):up(); end catalog:up(); if catalog_request.attr.xmlns == xmlns_label_catalog then catalog:up(); end else - add_labels(catalog, value, (selector or "")..name.."|"); + add_labels(catalog, item, (selector or "")..name.."|"); + end + end + for i = 1,#labels do + add_item(labels[i]) + end + for name, child in pairs(labels) do + if type(name) == "string" then + add_item(child, name) end end end