Added UVL values minlength, maxlength, minimum, maximum
authorSteven Barth <steven@midlink.org>
Sun, 2 Nov 2008 21:42:16 +0000 (21:42 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 2 Nov 2008 21:42:16 +0000 (21:42 +0000)
libs/uvl/luasrc/uvl.lua
libs/uvl/luasrc/uvl/errors.lua
libs/uvl/root/lib/uci/schema/meta/schema

index 683d7a9..8275dbb 100644 (file)
@@ -334,6 +334,30 @@ function UVL._validate_option( self, option, nodeps )
                                        return false, option:error(ERR.OPT_DATATYPE(option, dt))
                                end
                        end
+                       
+                       if option:scheme('minlength') then
+                               if #val < option:scheme('minlength') then
+                                       return false, option:error(ERR.OPT_RANGE(option))
+                               end
+                       end
+                       
+                       if option:scheme('maxlength') then
+                               if #val > option:scheme('maxlength') then
+                                       return false, option:error(ERR.OPT_RANGE(option))
+                               end
+                       end
+                       
+                       if option:scheme('minimum') then
+                               if val < option:scheme('minimum') then
+                                       return false, option:error(ERR.OPT_RANGE(option))
+                               end
+                       end
+                       
+                       if option:scheme('maximum') then
+                               if val > option:scheme('maximum') then
+                                       return false, option:error(ERR.OPT_RANGE(option))
+                               end
+                       end
 
                        if not nodeps then
                                local ok, err = dependencies.check( self, option )
@@ -582,6 +606,9 @@ function UVL._parse_var(self, scheme, k, v)
                                t.valueof = type(v2) == "table" and v2 or {v2}
                        elseif k == "required" then
                                t[k] = _bool(v2)
+                       elseif k == "minlength" or k == "maxlength"
+                        or k == "minimum" or k == "maximum" then
+                               t[k] = tonumber(v2)
                        else
                                t[k] = t[k] or v2
                        end
index 242965d..9cd8d19 100644 (file)
@@ -66,6 +66,7 @@ ERRCODES = {
        { 'OPT_NOTLIST',        'Option "%i" is defined as list but stored as plain value' },
        { 'OPT_DATATYPE',       'Option "%i" has unknown datatype "%1"' },
        { '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_NOVALUE',        'Dependency (%1) failed:\nOption "%i" has no value' },
index 3b78725..a4fed42 100644 (file)
@@ -275,6 +275,42 @@ config variable
        option type             'variable'
        option datatype 'string'
        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)
 config variable