3 UCI Validation Layer - Main Library
4 (c) 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 (c) 2008 Steven Barth <steven@midlink.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
18 --- UVL - UCI Validation Layer
22 local fs = require "luci.fs"
23 local uci = require "luci.model.uci"
24 local util = require "luci.util"
25 local table = require "table"
26 local string = require "string"
28 local require, pcall, ipairs, pairs = require, pcall, ipairs, pairs
29 local type, error, tonumber, tostring = type, error, tonumber, tostring
30 local unpack, loadfile = unpack, loadfile
34 local ERR = require "luci.uvl.errors"
35 local datatypes = require "luci.uvl.datatypes"
36 local validation = require "luci.uvl.validation"
37 local dependencies = require "luci.uvl.dependencies"
39 local TYPE_SCHEME = 0x00
40 local TYPE_CONFIG = 0x01
41 local TYPE_SECTION = 0x02
42 local TYPE_OPTION = 0x03
43 local TYPE_ENUM = 0x04
45 --- Boolean; default true;
46 -- treat sections found in config but not in scheme as error
47 STRICT_UNKNOWN_SECTIONS = true
49 --- Boolean; default true;
50 -- treat options found in config but not in scheme as error
51 STRICT_UNKNOWN_OPTIONS = true
53 --- Boolean; default true;
54 -- treat failed external validators as error
55 STRICT_EXTERNAL_VALIDATORS = true
57 --- Boolean; default true;
58 -- treat list values stored as options like errors
59 STRICT_LIST_TYPE = true
62 local default_schemedir = "/lib/uci/schema"
63 local default_savedir = "/tmp/.uvl"
66 --- Object constructor
69 -- @param schemedir Path to the scheme directory (optional)
70 -- @return Instance object
73 function UVL.__init__( self, schemedir )
74 self.schemedir = schemedir or default_schemedir
80 self.dep = dependencies
81 self.datatypes = datatypes
85 --- Parse given scheme and return the scheme tree.
86 -- @param scheme Name of the scheme to parse
87 -- @return Table containing the parsed scheme or nil on error
88 -- @return String containing the reason for errors (if any)
89 function UVL.get_scheme( self, scheme )
90 if not self.packages[scheme] then
91 local ok, err = self:read_scheme( scheme )
96 return self.packages[scheme], nil
99 --- Validate given configuration, section or option.
100 -- @param config Name of the configuration to validate
101 -- @param section Name of the section to validate (optional)
102 -- @param option Name of the option to validate (optional)
103 -- @return Boolean indicating whether the given config validates
104 -- @return String containing the reason for errors (if any)
105 function UVL.validate( self, config, section, option )
106 if config and section and option then
107 return self:validate_option( config, section, option )
108 elseif config and section then
109 return self:validate_section( config, section )
111 return self:validate_config( config )
115 --- Validate given configuration.
116 -- @param cfg Name of the configuration to validate
117 -- @return Boolean indicating whether the given config validates
118 -- @return String containing the reason for errors (if any)
119 function UVL.validate_config( self, cfg, uci )
121 if not self.packages[cfg] then
122 local ok, err = self:read_scheme(cfg)
128 local co = config( self, uci or cfg, uci and cfg )
134 if not co:config() then
135 return false, co:errors()
138 local function _uci_foreach( type, func )
139 for k, v in pairs(co:config()) do
140 if v['.type'] == type then
141 sc[type] = sc[type] + 1
142 local ok, err = func( k, v )
143 if not ok then co:error(err) end
148 for k, v in pairs( self.packages[cfg].sections ) do
152 return self:_validate_section( co:section(s) )
157 if STRICT_UNKNOWN_SECTIONS then
158 for k, v in pairs(co:config()) do
159 local so = co:section(k)
160 if not self.beenthere[so:cid()] then
161 co:error(ERR.SECT_UNKNOWN(so))
166 for _, k in ipairs(util.keys(sc)) do
167 local so = co:section(k)
168 if so:scheme('required') and sc[k] == 0 then
169 co:error(ERR.SECT_REQUIRED(so))
170 elseif so:scheme('unique') and sc[k] > 1 then
171 co:error(ERR.SECT_UNIQUE(so))
175 return co:ok(), co:errors()
178 --- Validate given config section.
179 -- @param config Name of the configuration to validate
180 -- @param section Name of the section to validate
181 -- @return Boolean indicating whether the given config validates
182 -- @return String containing the reason for errors (if any)
183 function UVL.validate_section( self, cfg, section, uci )
185 if not self.packages[cfg] then
186 local ok, err = self:read_scheme( cfg )
192 local co = config( self, uci or cfg, uci and cfg )
193 local so = co:section( section )
198 if not co:config() then
199 return false, co:errors()
203 return self:_validate_section( so )
205 return false, ERR.SECT_NOTFOUND(so)
209 --- Validate given config option.
210 -- @param config Name of the configuration to validate
211 -- @param section Name of the section to validate
212 -- @param option Name of the option to validate
213 -- @return Boolean indicating whether the given config validates
214 -- @return String containing the reason for errors (if any)
215 function UVL.validate_option( self, cfg, section, option, uci )
217 if not self.packages[cfg] then
218 local ok, err = self:read_scheme( cfg )
224 local co = config( self, uci or cfg, uci and cfg )
225 local so = co:section( section )
226 local oo = so:option( option )
228 if not co:config() then
229 return false, co:errors()
232 if so:config() and oo:config() then
233 return self:_validate_option( oo )
235 return false, ERR.OPT_NOTFOUND(oo)
240 function UVL._validate_section( self, section )
242 self.beenthere[section:cid()] = true
244 if section:config() then
245 if section:scheme('named') == true and
246 section:config('.anonymous') == true
248 return false, ERR.SECT_NAMED(section)
251 for _, v in ipairs(section:variables()) do
252 local ok, err = self:_validate_option( v )
254 v:scheme('required') or v:scheme('type') == "enum" or (
255 not err:is(ERR.ERR_DEP_NOTEQUAL) and
256 not err:is(ERR.ERR_DEP_NOVALUE)
263 local ok, err = dependencies.check( self, section )
268 return false, ERR.SECT_NOTFOUND(section)
271 if STRICT_UNKNOWN_OPTIONS and not section:scheme('dynamic') then
272 for k, v in pairs(section:config()) do
273 local oo = section:option(k)
274 if k:sub(1,1) ~= "." and not self.beenthere[oo:cid()] then
275 section:error(ERR.OPT_UNKNOWN(oo))
280 return section:ok(), section:errors()
283 function UVL._validate_option( self, option, nodeps )
285 self.beenthere[option:cid()] = true
287 if not option:scheme() and not option:parent():scheme('dynamic') then
288 if STRICT_UNKNOWN_OPTIONS then
289 return false, option:error(ERR.OPT_UNKNOWN(option))
294 elseif option:scheme() then
295 if option:scheme('required') and not option:value() then
296 return false, option:error(ERR.OPT_REQUIRED(option))
298 elseif option:value() then
299 local val = option:value()
301 if option:scheme('type') == "reference" or
302 option:scheme('type') == "enum"
304 local scheme_values = option:scheme('values') or { }
305 local config_values = ( type(val) == "table" and val or { val } )
306 for _, v in ipairs(config_values) do
307 if not scheme_values[v] then
308 return false, option:error( ERR.OPT_BADVALUE(
309 option, { v, util.serialize_data(
310 util.keys(scheme_values)
315 elseif option:scheme('type') == "list" then
316 if type(val) ~= "table" and STRICT_LIST_TYPE then
317 return false, option:error(ERR.OPT_NOTLIST(option))
321 if option:scheme('datatype') then
322 local dt = option:scheme('datatype')
324 if self.datatypes[dt] then
325 val = ( type(val) == "table" and val or { val } )
326 for i, v in ipairs(val) do
327 if not self.datatypes[dt]( v ) then
328 return false, option:error(
329 ERR.OPT_INVVALUE(option, { v, dt })
334 return false, option:error(ERR.OPT_DATATYPE(option, dt))
339 local ok, err = dependencies.check( self, option )
346 local ok, err = validation.check( self, option )
347 if not ok and STRICT_EXTERNAL_VALIDATORS then
348 return false, option:error(err)
352 return option:ok(), option:errors()
355 --- Find all parts of given scheme and construct validation tree.
356 -- This is normally done on demand, so you don't have to call this function
358 -- @param shm Name of the scheme to parse
359 -- @param alias Create an alias for the loaded scheme
360 function UVL.read_scheme( self, shm, alias )
362 local so = scheme( self, shm )
363 local bc = "%s/bytecode/%s.lua" %{ self.schemedir, shm }
365 if not fs.access(bc) then
366 local files = fs.glob(self.schemedir .. '/*/' .. shm)
370 for i, file in ipairs( files ) do
371 if not fs.access(file) then
372 return false, so:error(ERR.SME_READ(so,file))
375 local uci = uci.cursor( fs.dirname(file), default_savedir )
377 local sname = fs.basename(file)
378 local sd, err = uci:load( sname )
381 return false, ERR.UCILOAD(so, err)
384 ok, err = pcall(function()
385 uci:foreach(sname, "package", function(s)
386 self:_parse_package(so, s[".name"], s)
388 uci:foreach(sname, "section", function(s)
389 self:_parse_section(so, s[".name"], s)
391 uci:foreach(sname, "variable", function(s)
392 self:_parse_var(so, s[".name"], s)
394 uci:foreach(sname, "enum", function(s)
395 self:_parse_enum(so, s[".name"], s)
401 if ok and alias then self.packages[alias] = self.packages[shm] end
402 return ok and self, err
404 return false, so:error(ERR.SME_FIND(so, self.schemedir))
407 local sc = loadfile(bc)
409 self.packages[shm] = sc()
412 return false, so:error(ERR.SME_READ(so,bc))
417 -- helper function to check for required fields
418 local function _req( t, n, c, r )
419 for i, v in ipairs(r) do
421 local p, o = scheme:sid(), nil
423 if t == TYPE_SECTION then
424 o = section( scheme, nil, p, n )
425 elseif t == TYPE_OPTION then
426 o = option( scheme, nil, p, '(nil)', n )
427 elseif t == TYPE_ENUM then
428 o = enum( scheme, nil, p, '(nil)', '(nil)', n )
431 return false, ERR.SME_REQFLD(o,v)
437 -- helper function to validate references
438 local function _ref( c, t )
440 if c == TYPE_SECTION then
443 elseif c == TYPE_OPTION then
446 elseif c == TYPE_ENUM then
451 for o in t[k]:gmatch("[^.]+") do
454 r[1] = ( #r[1] > 0 and r[1] or scheme:sid() )
457 return false, ERR.SME_BADREF(scheme, k)
463 -- helper function to read bools
464 local function _bool( v )
465 return ( v == "true" or v == "yes" or v == "on" or v == "1" )
468 -- Step 0: get package meta information
469 function UVL._parse_package(self, scheme, k, v)
470 local sid = scheme:sid()
471 local pkg = self.packages[sid] or {
478 pkg.description = v.description
480 self.packages[sid] = pkg
483 -- Step 1: get all sections
484 function UVL._parse_section(self, scheme, k, v)
485 local ok, err = _req( TYPE_SECTION, k, v, { "name", "package" } )
486 if err then error(scheme:error(err)) end
488 local r, err = _ref( TYPE_SECTION, v )
489 if err then error(scheme:error(err)) end
491 local p = self.packages[r[1]] or {
496 p.sections[v.name] = p.sections[v.name] or { }
497 p.variables[v.name] = p.variables[v.name] or { }
498 self.packages[r[1]] = p
500 local s = p.sections[v.name]
501 local so = scheme:section(v.name)
503 for k, v2 in pairs(v) do
504 if k ~= "name" and k ~= "package" and k:sub(1,1) ~= "." then
505 if k == "depends" then
506 s.depends = self:_read_dependency( v2, s.depends )
507 if not s.depends then
508 return false, scheme:error(
509 ERR.SME_BADDEP(so, util.serialize_data(s.depends))
512 elseif k == "dynamic" or k == "unique" or
513 k == "required" or k == "named"
522 s.dynamic = s.dynamic or false
523 s.unique = s.unique or false
524 s.required = s.required or false
525 s.named = s.named or false
529 -- Step 2: get all variables
530 function UVL._parse_var(self, scheme, k, v)
531 local ok, err = _req( TYPE_OPTION, k, v, { "name", "section" } )
532 if err then error(scheme:error(err)) end
534 local r, err = _ref( TYPE_OPTION, v )
535 if err then error(scheme:error(err)) end
537 local p = self.packages[r[1]]
540 ERR.SME_VBADPACK({scheme:sid(), '', v.name}, r[1])
544 local s = p.variables[r[2]]
547 ERR.SME_VBADSECT({scheme:sid(), '', v.name}, r[2])
551 s[v.name] = s[v.name] or { }
554 local so = scheme:section(r[2])
555 local to = so:option(v.name)
557 for k, v2 in pairs(v) do
558 if k ~= "name" and k ~= "section" and k:sub(1,1) ~= "." then
559 if k == "depends" then
560 t.depends = self:_read_dependency( v2, t.depends )
561 if not t.depends then
562 error(scheme:error(so:error(
563 ERR.SME_BADDEP(to, util.serialize_data(v2))
566 elseif k == "validator" then
567 t.validators = self:_read_validator( v2, t.validators )
568 if not t.validators then
569 error(scheme:error(so:error(
570 ERR.SME_BADVAL(to, util.serialize_data(v2))
573 elseif k == "valueof" then
574 local values, err = self:_read_reference( v2 )
576 error(scheme:error(so:error(
577 ERR.REFERENCE(to, util.serialize_data(v2)):child(err)
582 t.valueof = type(v2) == "table" and v2 or {v2}
583 elseif k == "required" then
591 t.type = t.type or "variable"
592 t.datatype = t.datatype or "string"
593 t.required = t.required or false
596 -- Step 3: get all enums
597 function UVL._parse_enum(self, scheme, k, v)
598 local ok, err = _req( TYPE_ENUM, k, v, { "value", "variable" } )
599 if err then error(scheme:error(err)) end
601 local r, err = _ref( TYPE_ENUM, v )
602 if err then error(scheme:error(err)) end
604 local p = self.packages[r[1]]
607 ERR.SME_EBADPACK({scheme:sid(), '', '', v.value}, r[1])
611 local s = p.variables[r[2]]
614 ERR.SME_EBADSECT({scheme:sid(), '', '', v.value}, r[2])
621 ERR.SME_EBADOPT({scheme:sid(), '', '', v.value}, r[3])
626 local so = scheme:section(r[2])
627 local oo = so:option(r[3])
628 local eo = oo:enum(v.value)
630 if t.type ~= "enum" and t.type ~= "reference" then
631 error(scheme:error(ERR.SME_EBADTYPE(eo)))
635 t.values = { [v.value] = v.title or v.value }
636 t.valuelist = { {value = v.value, title = v.title} }
638 t.values[v.value] = v.title or v.value
639 t.valuelist[#t.valuelist + 1] = {value = v.value, title = v.title}
642 if not t.enum_depends then
648 error(scheme:error(ERR.SME_EBADDEF(eo)))
654 t.enum_depends[v.value] = self:_read_dependency(
655 v.depends, t.enum_depends[v.value]
658 if not t.enum_depends[v.value] then
659 error(scheme:error(so:error(oo:error(
660 ERR.SME_BADDEP(eo, util.serialize_data(v.depends))
666 -- Read a dependency specification
667 function UVL._read_dependency( self, values, deps )
668 local expr = "%$?[%w_]+"
670 values = ( type(values) == "table" and values or { values } )
671 for _, value in ipairs(values) do
672 local condition = { }
673 for val in value:gmatch("[^,]+") do
674 local k, e, v = val:match("%s*([%w$_.]+)%s*(=?)%s*(.*)")
677 k:match("^"..expr.."%."..expr.."%."..expr.."$") or
678 k:match("^"..expr.."%."..expr.."$") or
679 k:match("^"..expr.."$")
681 condition[k] = (e == '=') and v or true
690 deps[#deps+1] = condition
698 -- Read a validator specification
699 function UVL._read_validator( self, values, validators )
701 values = ( type(values) == "table" and values or { values } )
702 for _, value in ipairs(values) do
705 if value:match("^exec:") then
706 validator = value:gsub("^exec:","")
707 elseif value:match("^lua:") then
708 validator = self:_resolve_function( (value:gsub("^lua:","") ) )
709 elseif value:match("^regexp:") then
710 local pattern = value:gsub("^regexp:","")
711 validator = function( type, dtype, pack, sect, optn, ... )
712 local values = { ... }
713 for _, v in ipairs(values) do
715 pcall( string.match, v, pattern )
719 elseif not match then
721 'Value "%s" does not match pattern "%s"' % {
731 if not validators then
732 validators = { validator }
734 validators[#validators+1] = validator
745 -- Read a reference specification (XXX: We should validate external configs too...)
746 function UVL._read_reference( self, values )
748 values = ( type(values) == "table" and values or { values } )
750 for _, value in ipairs(values) do
751 local ref = util.split(value, ".")
753 if #ref == 2 or #ref == 3 then
754 local co = config( self, ref[1] )
755 if not co:config() then return false, co:errors() end
757 for k, v in pairs(co:config()) do
758 if v['.type'] == ref[2] then
760 if v['.anonymous'] == true then
761 return false, ERR.SME_INVREF('', value)
763 val[k] = k -- XXX: title/description would be nice
764 elseif v[ref[3]] then
765 val[v[ref[3]]] = v[ref[3]] -- XXX: dito
770 return false, ERR.SME_BADREF('', value)
777 -- Resolve given path
778 function UVL._resolve_function( self, value )
779 local path = util.split(value, ".")
782 local stat, mod = pcall(
783 require, table.concat(path, ".", 1, i)
787 for j=i+1, #path-1 do
788 if not type(mod) == "table" then
796 mod = type(mod) == "table" and mod[path[#path]] or nil
797 if type(mod) == "function" then
805 --- Object representation of an uvl item - base class.
806 uvlitem = util.class()
808 function uvlitem.cid(self)
809 if #self.cref == 1 then
812 local r = { unpack(self.cref) }
814 if c and c[r[2]] and c[r[2]]['.anonymous'] and c[r[2]]['.index'] then
815 r[2] = '@' .. c[r[2]]['.type'] ..
816 '[' .. tostring(c[r[2]]['.index']) .. ']'
818 return table.concat( r, '.' )
822 function uvlitem.sid(self)
823 return table.concat( self.sref, '.' )
826 function uvlitem.scheme(self, opt)
827 local s = self.s and self.s.packages
828 s = s and s[self.sref[1]]
829 if #self.sref == 4 or #self.sref == 3 then
830 s = s and s.variables
831 s = s and s[self.sref[2]]
832 s = s and s[self.sref[3]]
833 elseif #self.sref == 2 then
835 s = s and s[self.sref[2]]
845 function uvlitem.config(self, opt)
848 if #self.cref >= 2 and #self.cref <= 4 then
849 c = c and self.c[self.cref[2]] or nil
850 if #self.cref >= 3 then
851 c = c and c[self.cref[3]] or nil
862 function uvlitem.title(self)
863 return self:scheme() and self:scheme('title') or
864 self.cref[3] or self.cref[2] or self.cref[1]
867 function uvlitem.type(self)
868 if self.t == TYPE_CONFIG then
870 elseif self.t == TYPE_SECTION then
872 elseif self.t == TYPE_OPTION then
874 elseif self.t == TYPE_ENUM then
879 function uvlitem.error(self, ...)
881 local errconst = { ERR.CONFIG, ERR.SECTION, ERR.OPTION, ERR.OPTION }
882 self.e = errconst[#self.cref]( self )
885 return self.e:child( ... )
888 function uvlitem.errors(self)
892 function uvlitem.ok(self)
893 return not self:errors()
896 function uvlitem.parent(self)
899 elseif #self.cref == 3 or #self.cref == 4 then
900 return section( self.s, self.c, self.cref[1], self.cref[2] )
901 elseif #self.cref == 2 then
902 return config( self.s, self.c, self.cref[1] )
908 function uvlitem._loadconf(self, co, c)
909 co = co or self._configcache
912 co, err = uci.cursor():get_all(c)
915 self:error(ERR.UCILOAD(self, err))
918 self._configcache = co
924 --- Object representation of a scheme.
927 -- @name luci.uvl.scheme
929 --- Scheme instance constructor.
932 -- @param scheme Scheme instance
933 -- @param co Configuration data
934 -- @param c Configuration name
935 -- @return Config instance
936 scheme = util.class(uvlitem)
938 function scheme.__init__(self, scheme, co, c)
945 self.c = self:_loadconf(co, c)
950 --- Add an error to scheme.
951 -- @return Scheme error context
952 function scheme.error(self, ...)
953 if not self.e then self.e = ERR.SCHEME( self ) end
954 return self.e:child( ... )
957 --- Get an associated config object.
958 -- @return Config instance
959 function scheme.config(self)
960 local co = config( self.s, self.cref[1] )
966 --- Get all section objects associated with this scheme.
967 -- @return Table containing all associated luci.uvl.section instances
968 function scheme.sections(self)
970 if self.s.packages[self.sref[1]].sections then
971 for o, _ in pairs( self.s.packages[self.sref[1]].sections ) do
973 self.s, self.c, self.cref[1], self.cref[2], o
980 --- Get an associated section object.
981 -- @param s Section to select
982 -- @return Section instance
983 function scheme.section(self, s)
984 local so = section( self.s, self.c, self.cref[1], s )
991 --- Object representation of a config.
994 -- @name luci.uvl.config
996 --- Config instance constructor.
999 -- @param scheme Scheme instance
1000 -- @param co Configuration data
1001 -- @param c Configuration name
1002 -- @return Config instance
1003 config = util.class(uvlitem)
1005 function config.__init__(self, scheme, co, c)
1012 self.c = self:_loadconf(co, c)
1014 self.t = TYPE_CONFIG
1017 --- Get all section objects associated with this config.
1018 -- @return Table containing all associated luci.uvl.section instances
1019 function config.sections(self)
1021 if self.s.packages[self.sref[1]].sections then
1022 for o, _ in pairs( self.s.packages[self.sref[1]].sections ) do
1024 self.s, self.c, self.cref[1], self.cref[2], o
1031 --- Get an associated section object.
1032 -- @param s Section to select
1033 -- @return Section instance
1034 function config.section(self, s)
1035 local so = section( self.s, self.c, self.cref[1], s )
1042 --- Object representation of a scheme/config section.
1045 -- @name luci.uvl.section
1047 --- Section instance constructor.
1050 -- @param scheme Scheme instance
1051 -- @param co Configuration data
1052 -- @param c Configuration name
1053 -- @param s Section name
1054 -- @return Section instance
1055 section = util.class(uvlitem)
1057 function section.__init__(self, scheme, co, c, s)
1058 self.cref = { c, s }
1059 self.sref = { c, co and co[s] and co[s]['.type'] or s }
1060 self.c = self:_loadconf(co, c)
1062 self.t = TYPE_SECTION
1065 --- Get all option objects associated with this section.
1066 -- @return Table containing all associated luci.uvl.option instances
1067 function section.variables(self)
1069 if self.s.packages[self.sref[1]].variables[self.sref[2]] then
1071 self.s.packages[self.sref[1]].variables[self.sref[2]]
1074 self.s, self.c, self.cref[1], self.cref[2], o
1081 --- Get an associated option object.
1082 -- @param o Option to select
1083 -- @return Option instance
1084 function section.option(self, o)
1085 local oo = option( self.s, self.c, self.cref[1], self.cref[2], o )
1092 --- Object representation of a scheme/config option.
1095 -- @name luci.uvl.option
1097 --- Section instance constructor.
1100 -- @param scheme Scheme instance
1101 -- @param co Configuration data
1102 -- @param c Configuration name
1103 -- @param s Section name
1104 -- @param o Option name
1105 -- @return Option instance
1106 option = util.class(uvlitem)
1108 function option.__init__(self, scheme, co, c, s, o)
1109 self.cref = { c, s, o }
1110 self.sref = { c, co and co[s] and co[s]['.type'] or s, o }
1111 self.c = self:_loadconf(co, c)
1113 self.t = TYPE_OPTION
1116 --- Get the value of this option.
1117 -- @return The associated configuration value
1118 function option.value(self)
1119 local v = self:config() or self:scheme('default')
1120 if v and self:scheme('multival') then
1121 v = util.split( v, "%s+", nil, true )
1126 --- Get the associated section information in scheme.
1127 -- @return Table containing the scheme properties
1128 function option.section(self)
1129 return self.s.packages[self.sref[1]].sections[self.sref[2]]
1132 --- Construct an enum object instance from given or default value.
1133 -- @param v Value to select
1134 -- @return Enum instance for selected value
1135 function option.enum(self, val)
1138 self.cref[1], self.cref[2], self.cref[3],
1144 --- Object representation of a enum value.
1147 -- @name luci.uvl.enum
1149 --- Section instance constructor.
1152 -- @param scheme Scheme instance
1153 -- @param co Configuration data
1154 -- @param c Configuration name
1155 -- @param s Section name
1156 -- @param o Enum name
1157 -- @param v Enum value
1158 -- @return Enum value instance
1159 enum = util.class(option)
1161 function enum.__init__(self, scheme, co, c, s, o, v)
1162 self.cref = { c, s, o, v }
1163 self.sref = { c, co and co[s] and co[s]['.type'] or s, o, v }
1164 self.c = self:_loadconf(co, c)