[luci] How to perform data integrity checking?

Jo-Philipp Wich xm at subsignal.org
Wed Nov 4 18:32:44 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

> This is the kind of thing I want but it's not clear how this checking
>  is done.  I'm using version luci-0.8.7, any insight would be 
> appreciated.

The mechanism responsible for this is called "uvl" - UCI Validation
Layer. It is a library which takes uci schema descriptions from
/lib/uci/schema/default/<configname> and applies them against the
configuration provided by the user. You need to provide such a
definition for your configuration in order to enable the checking.

Take a look at the other schema files to see what's the correct syntax
etc. If something is not clear, ask here - there is no written
documentation about it yet.

Another approach is to define a .validate function for each field:

  port = s:option(Value, "port", "Port")
  function port.validate(self, value)
    if not value or value:match("%D") then
      return false
    else
      return true
    end
  end

> For the listboxes that depended on the enable, they show whatever the
> first item in there list is, but for my value box it's just empty
> which is not what I want.  Any idea what would cause this behavior?

Yes, unfortunately the form mapper in LuCI 0.8.7 contained some bugs in
the processing of the .default property, it is not applied in all fields
leading to empty values as you have noticed. There is a workaround for
this, you can override the .cfgvalue function of the affected options to
inject a default value as needed, example:

  field = s:option(Value, "blah", "blah")
  function field.cfgvalue(...)
    return Value.cfgvalue(...) or "my_default_value"
  end


HTH,
JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrxursACgkQdputYINPTPMJygCbBmduQ92df6j/cn5k4YHnZd/z
A2cAnihH3MDi9lFukd77igeyF8iY1fnC
=mQnW
-----END PGP SIGNATURE-----


More information about the luci mailing list