* luci-0.8: merge r3692, r3695 and r3699-r3702
This commit is contained in:
parent
fbeebdac7e
commit
2f4957fc3c
3 changed files with 97 additions and 9 deletions
|
@ -8,7 +8,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
|
@ -292,6 +292,18 @@ function UVL._validate_option( self, option, nodeps )
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif option:scheme() then
|
elseif option:scheme() then
|
||||||
|
if not nodeps then
|
||||||
|
local ok, err = dependencies.check( self, option )
|
||||||
|
if not ok then
|
||||||
|
if not err:is_all(ERR.ERR_DEP_NOTEQUAL,ERR.ERR_DEP_NOVALUE) then
|
||||||
|
option:error(err)
|
||||||
|
return false, option:errors()
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if option:scheme('required') and not option:value() then
|
if option:scheme('required') and not option:value() then
|
||||||
return false, option:error(ERR.OPT_REQUIRED(option))
|
return false, option:error(ERR.OPT_REQUIRED(option))
|
||||||
|
|
||||||
|
@ -335,10 +347,32 @@ function UVL._validate_option( self, option, nodeps )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not nodeps then
|
val = ( type(val) == "table" and val or { val } )
|
||||||
local ok, err = dependencies.check( self, option )
|
for _, v in ipairs(val) do
|
||||||
if not ok then
|
if option:scheme('minlength') then
|
||||||
option:error(err)
|
if #v < option:scheme('minlength') then
|
||||||
|
return false, option:error(ERR.OPT_RANGE(option))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if option:scheme('maxlength') then
|
||||||
|
if #v > option:scheme('maxlength') then
|
||||||
|
return false, option:error(ERR.OPT_RANGE(option))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
v = tonumber(v)
|
||||||
|
|
||||||
|
if option:scheme('minimum') then
|
||||||
|
if not v or v < option:scheme('minimum') then
|
||||||
|
return false, option:error(ERR.OPT_RANGE(option))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if option:scheme('maximum') then
|
||||||
|
if not v or v > option:scheme('maximum') then
|
||||||
|
return false, option:error(ERR.OPT_RANGE(option))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -525,8 +559,7 @@ function UVL._parse_section(self, scheme, k, v)
|
||||||
s.named = s.named or false
|
s.named = s.named or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Step 2: get all variables
|
||||||
-- Step 2: get all variables
|
|
||||||
function UVL._parse_var(self, scheme, k, v)
|
function UVL._parse_var(self, scheme, k, v)
|
||||||
local ok, err = _req( TYPE_OPTION, k, v, { "name", "section" } )
|
local ok, err = _req( TYPE_OPTION, k, v, { "name", "section" } )
|
||||||
if err then error(scheme:error(err)) end
|
if err then error(scheme:error(err)) end
|
||||||
|
@ -582,6 +615,10 @@ function UVL._parse_var(self, scheme, k, v)
|
||||||
t.valueof = type(v2) == "table" and v2 or {v2}
|
t.valueof = type(v2) == "table" and v2 or {v2}
|
||||||
elseif k == "required" then
|
elseif k == "required" then
|
||||||
t[k] = _bool(v2)
|
t[k] = _bool(v2)
|
||||||
|
elseif k == "minlength" or k == "maxlength" or
|
||||||
|
k == "minimum" or k == "maximum"
|
||||||
|
then
|
||||||
|
t[k] = tonumber(v2)
|
||||||
else
|
else
|
||||||
t[k] = t[k] or v2
|
t[k] = t[k] or v2
|
||||||
end
|
end
|
||||||
|
@ -813,7 +850,7 @@ function uvlitem.cid(self)
|
||||||
local c = self.c
|
local c = self.c
|
||||||
if c and c[r[2]] and c[r[2]]['.anonymous'] and c[r[2]]['.index'] then
|
if c and c[r[2]] and c[r[2]]['.anonymous'] and c[r[2]]['.index'] then
|
||||||
r[2] = '@' .. c[r[2]]['.type'] ..
|
r[2] = '@' .. c[r[2]]['.type'] ..
|
||||||
'[' .. tostring(c[r[2]]['.index']) .. ']'
|
'[' .. tostring(c[r[2]]['.index']) .. ']'
|
||||||
end
|
end
|
||||||
return table.concat( r, '.' )
|
return table.concat( r, '.' )
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ local uvl = require "luci.uvl"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
|
|
||||||
local ipairs, error, type = ipairs, error, type
|
local ipairs, error, type = ipairs, error, type
|
||||||
local tonumber, unpack = tonumber, unpack
|
local tonumber, unpack = tonumber, unpack
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ ERRCODES = {
|
||||||
{ 'OPT_NOTLIST', 'Option "%i" is defined as list but stored as plain value' },
|
{ 'OPT_NOTLIST', 'Option "%i" is defined as list but stored as plain value' },
|
||||||
{ 'OPT_DATATYPE', 'Option "%i" has unknown datatype "%1"' },
|
{ 'OPT_DATATYPE', 'Option "%i" has unknown datatype "%1"' },
|
||||||
{ 'OPT_NOTFOUND', 'Option "%p.%s.%o" not found in config' },
|
{ 'OPT_NOTFOUND', 'Option "%p.%s.%o" not found in config' },
|
||||||
|
{ 'OPT_RANGE', 'Option "%p.%s.%o" is not within the specified range' },
|
||||||
|
|
||||||
{ 'DEP_NOTEQUAL', 'Dependency (%1) failed:\nOption "%i" is not eqal "%2"' },
|
{ 'DEP_NOTEQUAL', 'Dependency (%1) failed:\nOption "%i" is not eqal "%2"' },
|
||||||
{ 'DEP_NOVALUE', 'Dependency (%1) failed:\nOption "%i" has no value' },
|
{ 'DEP_NOVALUE', 'Dependency (%1) failed:\nOption "%i" has no value' },
|
||||||
|
@ -183,3 +184,17 @@ function error.is(self, code)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function error.is_all(self, ...)
|
||||||
|
local codes = { ... }
|
||||||
|
|
||||||
|
if util.contains(codes, self.code) then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
local equal = false
|
||||||
|
for _, c in ipairs(self.childs) do
|
||||||
|
equal = util.contains(codes, c.code)
|
||||||
|
end
|
||||||
|
return equal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -275,6 +275,42 @@ config variable
|
||||||
option type 'variable'
|
option type 'variable'
|
||||||
option datatype 'string'
|
option datatype 'string'
|
||||||
option required false
|
option required false
|
||||||
|
|
||||||
|
# Variable minimum length (schema.@variable.minlength)
|
||||||
|
config variable
|
||||||
|
option name 'minlength'
|
||||||
|
option title 'Minimum length of this variable'
|
||||||
|
option section 'schema.variable'
|
||||||
|
option type 'variable'
|
||||||
|
option datatype 'uint'
|
||||||
|
option required false
|
||||||
|
|
||||||
|
# Variable maximum length (schema.@variable.minlength)
|
||||||
|
config variable
|
||||||
|
option name 'maxlength'
|
||||||
|
option title 'Maximum length of this variable'
|
||||||
|
option section 'schema.variable'
|
||||||
|
option type 'variable'
|
||||||
|
option datatype 'uint'
|
||||||
|
option required false
|
||||||
|
|
||||||
|
# Variable minimum value (schema.@variable.minlength)
|
||||||
|
config variable
|
||||||
|
option name 'minimum'
|
||||||
|
option title 'Minimum value of this variable'
|
||||||
|
option section 'schema.variable'
|
||||||
|
option type 'variable'
|
||||||
|
option datatype 'integer'
|
||||||
|
option required false
|
||||||
|
|
||||||
|
# Variable maximum value (schema.@variable.minlength)
|
||||||
|
config variable
|
||||||
|
option name 'maximum'
|
||||||
|
option title 'Maximum value of this variable'
|
||||||
|
option section 'schema.variable'
|
||||||
|
option type 'variable'
|
||||||
|
option datatype 'integer'
|
||||||
|
option required false
|
||||||
|
|
||||||
# Variable validators (schema.@variable.validator)
|
# Variable validators (schema.@variable.validator)
|
||||||
config variable
|
config variable
|
||||||
|
|
Loading…
Reference in a new issue