+ return (type(val) == "table" and val or { val })
+ end
+ return { }
+end
+
+
+function section(self, config, stype, name, values)
+ local rv, err = util.ubus("uci", "add", {
+ config = config,
+ type = stype,
+ name = name,
+ values = values
+ })
+
+ if type(rv) == "table" then
+ return rv.section
+ elseif err then
+ return false, ERRSTR[err]
+ else
+ return nil
+ end
+end
+
+
+function add(self, config, stype)
+ return self:section(config, stype)
+end
+
+function set(self, config, section, option, value)
+ if value == nil then
+ local sname, err = self:section(config, option, section)
+ return (not not sname), err
+ else
+ local _, err = util.ubus("uci", "set", {
+ config = config,
+ section = section,
+ values = { [option] = value }
+ })
+ return (err == nil), ERRSTR[err]
+ end
+end
+
+function set_list(self, config, section, option, value)
+ if section == nil or option == nil then
+ return false
+ elseif value == nil or (type(value) == "table" and #value == 0) then
+ return self:delete(config, section, option)
+ elseif type(value) == "table" then
+ return self:set(config, section, option, value)
+ else
+ return self:set(config, section, option, { value })