3 UCI Validation Layer - Dependency helper
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
17 module( "luci.uvl.dependencies", package.seeall )
19 function _parse_reference( r, c, s, o )
27 for i, v in ipairs(luci.util.split(r,".")) do
28 table.insert( ref, (v:gsub( "%$(.+)", function(n) return vars[n] end )) )
31 if #ref == 1 and c and s then
32 ref = { c, s, ref[1] }
33 elseif #ref == 2 and c then
34 ref = { c, unpack(ref) }
42 function check( self, object, nodeps )
44 if not self.beenthere[object:cid()] then
45 self.beenthere[object:cid()] = true
47 return false, "Recursive dependency for '" .. object:sid() .. "' found"
50 local item = object.type == luci.uvl.TYPE_SECTION
51 and object:section() or object:option()
55 local valid, err = false,
56 string.format( 'In dependency check for %s "%s":',
57 ( object.type == luci.uvl.TYPE_SECTION and "section" or "option" ),
60 for _, dep in ipairs(item.depends) do
61 local subcondition = true
62 for k, v in pairs(dep) do
64 local ref = _parse_reference( k, unpack(object.cref) )
67 return false, "Ambiguous dependency reference '" .. k ..
68 "' for object '" .. object:sid() .. "' given"
71 local option = luci.uvl.option(
74 and object.config[ref[2]]['.type']
76 ref[1], ref[2], ref[3]
79 valid, err2 = self:_validate_option( option, true )
82 ( type(v) == "boolean" and object.config[ref[2]][ref[3]] ) or
83 ( ref[3] and object.config[ref[2]][ref[3]] ) == v
87 self.log.dump_dependency( dep, ref, v )
93 self.log.dump_dependency( dep, ref, nil, err2 )