* luci/libs/uvl:
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 3 Sep 2008 21:49:13 +0000 (21:49 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 3 Sep 2008 21:49:13 +0000 (21:49 +0000)
- implement host datatype which matches hostname, ip4addr or ip6addr datatype
- implement multival flag for options
- fix handling of OPT_BADVALUE errors
- add multival flag spec to reference scheme

libs/uvl/luasrc/uvl.lua
libs/uvl/luasrc/uvl/datatypes.lua
libs/uvl/luasrc/uvl/errors.lua
libs/uvl/root/lib/uci/schema/default/firewall
libs/uvl/root/lib/uci/schema/meta/schema

index 908cfd7..007a37d 100644 (file)
@@ -296,14 +296,16 @@ function UVL._validate_option( self, option, nodeps )
                        if option:scheme('type') == "reference" or
                           option:scheme('type') == "enum"
                        then
                        if option:scheme('type') == "reference" or
                           option:scheme('type') == "enum"
                        then
-                               if not option:scheme('values') or
-                                  not option:scheme('values')[val]
-                               then
-                                       return false, option:error( ERR.OPT_BADVALUE(
-                                               option, luci.util.serialize_data(
-                                                       luci.util.keys(option:scheme('values') or {})
-                                               )
-                                       ) )
+                               local scheme_values = option:scheme('values') or { }
+                               local config_values = ( type(val) == "table" and val or { val } )
+                               for _, v in ipairs(config_values) do
+                                       if not scheme_values[v] then
+                                               return false, option:error( ERR.OPT_BADVALUE(
+                                                       option, { v, luci.util.serialize_data(
+                                                               luci.util.keys(scheme_values)
+                                                       ) }
+                                               ) )
+                                       end
                                end
                        elseif option:scheme('type') == "list" then
                                if type(val) ~= "table" and STRICT_LIST_TYPE then
                                end
                        elseif option:scheme('type') == "list" then
                                if type(val) ~= "table" and STRICT_LIST_TYPE then
@@ -1103,7 +1105,11 @@ end
 --- Get the value of this option.
 -- @return     The associated configuration value
 function option.value(self)
 --- Get the value of this option.
 -- @return     The associated configuration value
 function option.value(self)
-       return self:config()
+       local v = self:config()
+       if v and self:scheme('multival') then
+               v = luci.util.split( v, "%s+", nil, true )
+       end
+       return v
 end
 
 --- Get the associated section information in scheme.
 end
 
 --- Get the associated section information in scheme.
index 3dfe37d..ce18d47 100644 (file)
@@ -111,6 +111,10 @@ function hostname( val )
        return false
 end
 
        return false
 end
 
+function host( val )
+       return hostname(val) or ipaddr(val)
+end
+
 function string( val )
        return true             -- Everything qualifies as valid string
 end
 function string( val )
        return true             -- Everything qualifies as valid string
 end
index 2ababaa..c53a4ab 100644 (file)
@@ -53,7 +53,7 @@ ERRCODES = {
 
        { 'OPT_UNKNOWN',        'Option "%i" (%I) not found in scheme' },
        { 'OPT_REQUIRED',       'Required option "%i" has no value' },
 
        { 'OPT_UNKNOWN',        'Option "%i" (%I) not found in scheme' },
        { 'OPT_REQUIRED',       'Required option "%i" has no value' },
-       { 'OPT_BADVALUE',       'Value "%v" of option "%i" is not defined in enum %1' },
+       { 'OPT_BADVALUE',       'Value "%1" of option "%i" is not defined in enum %2' },
        { 'OPT_INVVALUE',       'Value "%v" of given option "%i" does not validate as datatype "%1"' },
        { 'OPT_NOTLIST',        'Option "%i" is defined as list but stored as plain value' },
        { 'OPT_DATATYPE',       'Option "%i" has unknown datatype "%1"' },
        { 'OPT_INVVALUE',       'Value "%v" of given option "%i" does not validate as datatype "%1"' },
        { 'OPT_NOTLIST',        'Option "%i" is defined as list but stored as plain value' },
        { 'OPT_DATATYPE',       'Option "%i" has unknown datatype "%1"' },
index dc488d4..e421b11 100644 (file)
@@ -15,8 +15,8 @@ config variable
        option name     'network'
        option title    'Associated network of this firewall zone'
        option section  'firewall.zone'
        option name     'network'
        option title    'Associated network of this firewall zone'
        option section  'firewall.zone'
-#      option valueof  'network.interface'
-#      option type     'lazylist'
+       option valueof  'network.interface'
+       option multival true
 
 config variable
        option name     'forward'
 
 config variable
        option name     'forward'
index 9068124..1d673d3 100644 (file)
@@ -210,6 +210,15 @@ config variable
        option datatype 'boolean'
        option required false
 
        option datatype 'boolean'
        option required false
 
+# Variable multiple values flag (schema.@variable.multival)
+config variable
+       option name             'multival'
+       option title    'Specify whether this variable may contain multiple values separated by space'
+       option section  'schema.variable'
+       option type             'variable'
+       option datatype 'boolean'
+       option required false
+
 # Variable type (schema.@variable.type)
 config variable
        option name             'type'
 # Variable type (schema.@variable.type)
 config variable
        option name             'type'