return false;
}
+bool JSONParser::parse(const char *buf_, int len)
+{
+ if (nullptr == buf_ || 0 >= len) {
+ return false;
+ }
+
+ if (!parse_json({ buf_, static_cast<size_t>(len) }, data)) {
+ return false;
+ }
+
+ // recursively evaluate the result:
+ handle_value(data);
+
+ if (data.is_object() or data.is_array())
+ return true;
+
+ if (data.is_string()) {
+ val.set(data.as_string(), true);
+ return true;
+ }
+
+ // For any other kind of value:
+ std::string s = boost::json::serialize(data);
+
+ // Was the entire string read?
+ if (s.size() == static_cast<uint64_t>(len)) {
+ val.set(s, false);
+ return true;
+ }
+
+ // Could not parse and convert:
+ return false;
+}
+
// parse a supplied ifstream:
bool JSONParser::parse(const char *file_name)
{
// operate on a string/stringlike range or object:
bool parse(std::string_view sv);
-
- bool parse(const char *buf_, int len) {
- return buf_ ?
- parse(std::string_view { buf_, static_cast<std::string_view::size_type>(len) })
- : false;
- }
+ bool parse(const char *buf_, int len);
// operate on a data file:
bool parse(const char *file_name);
// Without subtracting 1, we wind up sending bad data into the
// parser:
- if (!parser.parse(bl.c_str(), bl.length() - 1)) {
+ if (!parser.parse(bl.c_str(), bl.length())) {
err_msg = "Malformed JSON (RGWPolicy)";
dout(0) << "malformed json (RGWPolicy)" << dendl;
return -EINVAL;