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 local function _assert( condition, fmt, ... )
21 return assert( nil, string.format( fmt, ... ) )
28 function _parse_reference( r, c, s, o )
36 for i, v in ipairs(luci.util.split(r,".")) do
37 table.insert( ref, (v:gsub( "%$(.+)", function(n) return vars[n] end )) )
40 if #ref == 1 and c and s then
41 ref = { c, s, ref[1] }
42 elseif #ref == 2 and c then
43 ref = { c, unpack(ref) }
51 function check( self, object, nodeps )
53 if not self.beenthere[object:cid()] then
54 self.beenthere[object:cid()] = true
56 return false, "Recursive dependency for '" .. object:sid() .. "' found"
59 local item = object.type == luci.uvl.TYPE_SECTION
60 and object:section() or object:option()
64 local valid, err = false,
65 string.format( 'In dependency check for %s "%s":',
66 ( object.type == luci.uvl.TYPE_SECTION and "section" or "option" ),
69 for _, dep in ipairs(item.depends) do
70 local subcondition = true
71 for k, v in pairs(dep) do
73 local ref = _parse_reference( k, unpack(object.cref) )
76 return false, "Ambiguous dependency reference '" .. k ..
77 "' for object '" .. object:sid() .. "' given"
80 local option = luci.uvl.option(
83 and object.config[ref[2]]['.type']
85 ref[1], ref[2], ref[3]
88 valid, err2 = self:_validate_option( option, true )
91 ( type(v) == "boolean" and object.config[ref[2]][ref[3]] ) or
92 ( ref[3] and object.config[ref[2]][ref[3]] ) == v
96 self.log.dump_dependency( dep, ref, v )
102 self.log.dump_dependency( dep, ref, nil, err2 )