From 8dea480c9f065fdac76f848ed9ec7a07fd1e9870 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jan 2022 14:33:26 -0500 Subject: Allow optional fields in json "schema" checks --- include/qpdf/JSON.hh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'include') 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& errors); + + // Same as passing 0 for flags QPDF_DLL bool checkSchema(JSON schema, std::list& 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& errors, std::string prefix); -- cgit v1.2.3-54-g00ecf