Mercurial > prosody-modules
comparison mod_seclabels/mod_seclabels.lua @ 452:48b615229509
mod_seclabels: Support orderd items
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 10 Oct 2011 20:14:30 +0200 |
parents | f43d2d26c1c4 |
children | 5276e1fc26b6 |
comparison
equal
deleted
inserted
replaced
451:f43d2d26c1c4 | 452:48b615229509 |
---|---|
13 stanza:tag('feature', {var=xmlns_label}):up(); | 13 stanza:tag('feature', {var=xmlns_label}):up(); |
14 stanza:tag('feature', {var=xmlns_label_catalog}):up(); | 14 stanza:tag('feature', {var=xmlns_label_catalog}):up(); |
15 end); | 15 end); |
16 | 16 |
17 local default_labels = { | 17 local default_labels = { |
18 { | |
19 name = "Unclassified", | |
20 label = true, | |
21 default = true, | |
22 }, | |
18 Classified = { | 23 Classified = { |
19 SECRET = { color = "black", bgcolor = "aqua", label = "THISISSECRET" }; | 24 SECRET = { color = "black", bgcolor = "aqua", label = "THISISSECRET" }; |
20 PUBLIC = { label = "THISISPUBLIC" }; | 25 PUBLIC = { label = "THISISPUBLIC" }; |
21 }; | 26 }; |
22 }; | 27 }; |
38 name = catalog_name, | 43 name = catalog_name, |
39 desc = catalog_desc | 44 desc = catalog_desc |
40 }); | 45 }); |
41 | 46 |
42 local function add_labels(catalog, labels, selector) | 47 local function add_labels(catalog, labels, selector) |
43 for name, value in pairs(labels) do | 48 local function add_item(item, name) |
44 if value.label then | 49 local name = name or item.name; |
50 if item.label then | |
45 if catalog_request.attr.xmlns == xmlns_label_catalog then | 51 if catalog_request.attr.xmlns == xmlns_label_catalog then |
46 catalog:tag("item", { | 52 catalog:tag("item", { |
47 selector = selector..name, | 53 selector = selector..name, |
48 default = value.default and "true" or nil, | 54 default = item.default and "true" or nil, |
49 }):tag("securitylabel", { xmlns = xmlns_label }) | 55 }):tag("securitylabel", { xmlns = xmlns_label }) |
50 else -- COMPAT | 56 else -- COMPAT |
51 catalog:tag("securitylabel", { | 57 catalog:tag("securitylabel", { |
52 xmlns = xmlns_label, | 58 xmlns = xmlns_label, |
53 selector = selector..name, | 59 selector = selector..name, |
54 default = value.default and "true" or nil, | 60 default = item.default and "true" or nil, |
55 }) | 61 }) |
56 end | 62 end |
57 if value.name or value.color or value.bgcolor then | 63 if item.display or item.color or item.bgcolor then |
58 catalog:tag("displaymarking", { | 64 catalog:tag("displaymarking", { |
59 fgcolor = value.color, | 65 fgcolor = item.color, |
60 bgcolor = value.bgcolor, | 66 bgcolor = item.bgcolor, |
61 }):text(value.name or name):up(); | 67 }):text(item.display or name):up(); |
62 end | 68 end |
63 if type(value.label) == "string" then | 69 if type(item.label) == "string" then |
64 catalog:tag("label"):text(value.label):up(); | 70 catalog:tag("label"):text(item.label):up(); |
65 elseif type(value.label) == "table" then | 71 elseif type(item.label) == "table" then |
66 catalog:tag("label"):add_child(value.label):up(); | 72 catalog:tag("label"):add_child(item.label):up(); |
67 end | 73 end |
68 catalog:up(); | 74 catalog:up(); |
69 if catalog_request.attr.xmlns == xmlns_label_catalog then | 75 if catalog_request.attr.xmlns == xmlns_label_catalog then |
70 catalog:up(); | 76 catalog:up(); |
71 end | 77 end |
72 else | 78 else |
73 add_labels(catalog, value, (selector or "")..name.."|"); | 79 add_labels(catalog, item, (selector or "")..name.."|"); |
80 end | |
81 end | |
82 for i = 1,#labels do | |
83 add_item(labels[i]) | |
84 end | |
85 for name, child in pairs(labels) do | |
86 if type(name) == "string" then | |
87 add_item(child, name) | |
74 end | 88 end |
75 end | 89 end |
76 end | 90 end |
77 -- TODO query remote servers | 91 -- TODO query remote servers |
78 --[[ FIXME later | 92 --[[ FIXME later |