aboutsummaryrefslogtreecommitdiffstats
path: root/include/qpdf/JSON.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-22 20:33:26 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commit8dea480c9f065fdac76f848ed9ec7a07fd1e9870 (patch)
tree8334231ae683dcf239f439f1602268fa98f39f10 /include/qpdf/JSON.hh
parent558ba2823e40867eac47686edea3fe318ce3c446 (diff)
downloadqpdf-8dea480c9f065fdac76f848ed9ec7a07fd1e9870.tar.zst
Allow optional fields in json "schema" checks
Diffstat (limited to 'include/qpdf/JSON.hh')
-rw-r--r--include/qpdf/JSON.hh23
1 files changed, 21 insertions, 2 deletions
diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh
index 3b13b4fe..d45fb3e1 100644
--- a/include/qpdf/JSON.hh
+++ b/include/qpdf/JSON.hh
@@ -107,21 +107,39 @@ class JSON
// single-element arrays, and strings only.
// * Recursively walk the schema
// * If the current value is a dictionary, this object must have
- // a dictionary in the same place with the same keys
+ // a dictionary in the same place with the same keys. If flags
+ // contains f_optional, a key in the schema does not have to
+ // be present in the object. Otherwise, all keys have to be
+ // present. Any key in the object must be present in the
+ // schema.
// * If the current value is an array, this object must have an
// array in the same place. The schema's array must contain a
// single element, which is used as a schema to validate each
// element of this object's corresponding array.
- // * Otherwise, the value is ignored.
+ // * Otherwise, the value must be a string whose value is a
+ // description of the object's corresponding value, which may
+ // have any type.
//
// QPDF's JSON output conforms to certain strict compatibility
// rules as discussed in the manual. The idea is that a JSON
// structure created manually in qpdf.cc doubles as both JSON help
// information and a schema for validating the JSON that qpdf
// generates. Any discrepancies are a bug in qpdf.
+ //
+ // Flags is a bitwise or of values from check_flags_e.
+ enum check_flags_e {
+ f_none = 0,
+ f_optional = 1 << 0,
+ };
+ QPDF_DLL
+ bool checkSchema(JSON schema, unsigned long flags,
+ std::list<std::string>& errors);
+
+ // Same as passing 0 for flags
QPDF_DLL
bool checkSchema(JSON schema, std::list<std::string>& errors);
+
// Create a JSON object from a string.
QPDF_DLL
static JSON parse(std::string const&);
@@ -180,6 +198,7 @@ class JSON
static bool
checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,
+ unsigned long flags,
std::list<std::string>& errors,
std::string prefix);