0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

jsonfile: added read_fast_dict() function

read_fast_dict() is a convenience function that reads JSON
from a file, but also validates that the top-level construct
of the file is a JSON dictionary.

Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
James Yonan 2023-09-15 11:53:38 -06:00
parent 64a535c65d
commit 133bcec850

View File

@ -37,6 +37,18 @@ inline Json::Value read_fast(const std::string &fn,
return parse_from_buffer(*bp, fn);
}
inline Json::Value read_fast_dict(const std::string &fn,
const bool optional = true,
std::uint64_t *mtime_ns = nullptr)
{
Json::Value jret = read_fast(fn, optional, mtime_ns);
if (!jret)
return jret;
if (!jret.isObject())
throw json_parse("read_fast_dict: json file " + fn + " does not contain a top-level dictionary");
return jret;
}
inline void write_atomic(const std::string &fn,
const std::string &tmpdir,
const mode_t mode,