diff options
Diffstat (limited to 'src/ucl_schema.c')
| -rw-r--r-- | src/ucl_schema.c | 697 |
1 files changed, 347 insertions, 350 deletions
diff --git a/src/ucl_schema.c b/src/ucl_schema.c index f4ec0ed3284a..02362d16b838 100644 --- a/src/ucl_schema.c +++ b/src/ucl_schema.c @@ -41,11 +41,11 @@ #endif #include <inttypes.h> -static bool ucl_schema_validate (const ucl_object_t *schema, - const ucl_object_t *obj, bool try_array, - struct ucl_schema_error *err, - const ucl_object_t *root, - ucl_object_t *ext_ref); +static bool ucl_schema_validate(const ucl_object_t *schema, + const ucl_object_t *obj, bool try_array, + struct ucl_schema_error *err, + const ucl_object_t *root, + ucl_object_t *ext_ref); /* * Create validation error @@ -53,25 +53,25 @@ static bool ucl_schema_validate (const ucl_object_t *schema, #ifdef __GNUC__ static inline void -ucl_schema_create_error (struct ucl_schema_error *err, - enum ucl_schema_error_code code, const ucl_object_t *obj, - const char *fmt, ...) -__attribute__ (( format( printf, 4, 5) )); +ucl_schema_create_error(struct ucl_schema_error *err, + enum ucl_schema_error_code code, const ucl_object_t *obj, + const char *fmt, ...) + __attribute__((format(printf, 4, 5))); #endif static inline void -ucl_schema_create_error (struct ucl_schema_error *err, - enum ucl_schema_error_code code, const ucl_object_t *obj, - const char *fmt, ...) +ucl_schema_create_error(struct ucl_schema_error *err, + enum ucl_schema_error_code code, const ucl_object_t *obj, + const char *fmt, ...) { va_list va; if (err != NULL) { err->code = code; err->obj = obj; - va_start (va, fmt); - vsnprintf (err->msg, sizeof (err->msg), fmt, va); - va_end (va); + va_start(va, fmt); + vsnprintf(err->msg, sizeof(err->msg), fmt, va); + va_end(va); } } @@ -79,7 +79,7 @@ ucl_schema_create_error (struct ucl_schema_error *err, * Check whether we have a pattern specified */ static const ucl_object_t * -ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern, bool recursive) +ucl_schema_test_pattern(const ucl_object_t *obj, const char *pattern, bool recursive) { const ucl_object_t *res = NULL; #ifdef HAVE_REGEX_H @@ -87,19 +87,20 @@ ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern, bool recu const ucl_object_t *elt; ucl_object_iter_t iter = NULL; - if (regcomp (®, pattern, REG_EXTENDED | REG_NOSUB) == 0) { + if (regcomp(®, pattern, REG_EXTENDED | REG_NOSUB) == 0) { if (recursive) { - while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) { - if (regexec (®, ucl_object_key (elt), 0, NULL, 0) == 0) { + while ((elt = ucl_object_iterate(obj, &iter, true)) != NULL) { + if (regexec(®, ucl_object_key(elt), 0, NULL, 0) == 0) { res = elt; break; } } - } else { - if (regexec (®, ucl_object_key (obj), 0, NULL, 0) == 0) + } + else { + if (regexec(®, ucl_object_key(obj), 0, NULL, 0) == 0) res = obj; } - regfree (®); + regfree(®); } #endif return res; @@ -109,33 +110,33 @@ ucl_schema_test_pattern (const ucl_object_t *obj, const char *pattern, bool recu * Check dependencies for an object */ static bool -ucl_schema_validate_dependencies (const ucl_object_t *deps, - const ucl_object_t *obj, struct ucl_schema_error *err, - const ucl_object_t *root, - ucl_object_t *ext_ref) +ucl_schema_validate_dependencies(const ucl_object_t *deps, + const ucl_object_t *obj, struct ucl_schema_error *err, + const ucl_object_t *root, + ucl_object_t *ext_ref) { const ucl_object_t *elt, *cur, *cur_dep; ucl_object_iter_t iter = NULL, piter; bool ret = true; - while (ret && (cur = ucl_object_iterate (deps, &iter, true)) != NULL) { - elt = ucl_object_lookup (obj, ucl_object_key (cur)); + while (ret && (cur = ucl_object_iterate(deps, &iter, true)) != NULL) { + elt = ucl_object_lookup(obj, ucl_object_key(cur)); if (elt != NULL) { /* Need to check dependencies */ if (cur->type == UCL_ARRAY) { piter = NULL; - while (ret && (cur_dep = ucl_object_iterate (cur, &piter, true)) != NULL) { - if (ucl_object_lookup (obj, ucl_object_tostring (cur_dep)) == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_MISSING_DEPENDENCY, elt, - "dependency %s is missing for key %s", - ucl_object_tostring (cur_dep), ucl_object_key (cur)); + while (ret && (cur_dep = ucl_object_iterate(cur, &piter, true)) != NULL) { + if (ucl_object_lookup(obj, ucl_object_tostring(cur_dep)) == NULL) { + ucl_schema_create_error(err, UCL_SCHEMA_MISSING_DEPENDENCY, elt, + "dependency %s is missing for key %s", + ucl_object_tostring(cur_dep), ucl_object_key(cur)); ret = false; break; } } } else if (cur->type == UCL_OBJECT) { - ret = ucl_schema_validate (cur, obj, true, err, root, ext_ref); + ret = ucl_schema_validate(cur, obj, true, err, root, ext_ref); } } } @@ -147,32 +148,32 @@ ucl_schema_validate_dependencies (const ucl_object_t *deps, * Validate object */ static bool -ucl_schema_validate_object (const ucl_object_t *schema, - const ucl_object_t *obj, struct ucl_schema_error *err, - const ucl_object_t *root, - ucl_object_t *ext_ref) +ucl_schema_validate_object(const ucl_object_t *schema, + const ucl_object_t *obj, struct ucl_schema_error *err, + const ucl_object_t *root, + ucl_object_t *ext_ref) { const ucl_object_t *elt, *prop, *found, *additional_schema = NULL, - *required = NULL, *pat, *pelt; + *required = NULL, *pat, *pelt; ucl_object_iter_t iter = NULL, piter = NULL; bool ret = true, allow_additional = true; int64_t minmax; - while (ret && (elt = ucl_object_iterate (schema, &iter, true)) != NULL) { + while (ret && (elt = ucl_object_iterate(schema, &iter, true)) != NULL) { if (elt->type == UCL_OBJECT && - strcmp (ucl_object_key (elt), "properties") == 0) { + strcmp(ucl_object_key(elt), "properties") == 0) { piter = NULL; - while (ret && (prop = ucl_object_iterate (elt, &piter, true)) != NULL) { - found = ucl_object_lookup (obj, ucl_object_key (prop)); + while (ret && (prop = ucl_object_iterate(elt, &piter, true)) != NULL) { + found = ucl_object_lookup(obj, ucl_object_key(prop)); if (found) { - ret = ucl_schema_validate (prop, found, true, err, root, - ext_ref); + ret = ucl_schema_validate(prop, found, true, err, root, + ext_ref); } } } - else if (strcmp (ucl_object_key (elt), "additionalProperties") == 0) { + else if (strcmp(ucl_object_key(elt), "additionalProperties") == 0) { if (elt->type == UCL_BOOLEAN) { - if (!ucl_object_toboolean (elt)) { + if (!ucl_object_toboolean(elt)) { /* Deny additional fields completely */ allow_additional = false; } @@ -182,62 +183,60 @@ ucl_schema_validate_object (const ucl_object_t *schema, additional_schema = elt; } else { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "additionalProperties attribute is invalid in schema"); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "additionalProperties attribute is invalid in schema"); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "required") == 0) { + else if (strcmp(ucl_object_key(elt), "required") == 0) { if (elt->type == UCL_ARRAY) { required = elt; } else { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "required attribute is invalid in schema"); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "required attribute is invalid in schema"); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "minProperties") == 0 - && ucl_object_toint_safe (elt, &minmax)) { + else if (strcmp(ucl_object_key(elt), "minProperties") == 0 && ucl_object_toint_safe(elt, &minmax)) { if (obj->len < minmax) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object has not enough properties: %u, minimum is: %u", - obj->len, (unsigned)minmax); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object has not enough properties: %u, minimum is: %u", + obj->len, (unsigned) minmax); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "maxProperties") == 0 - && ucl_object_toint_safe (elt, &minmax)) { + else if (strcmp(ucl_object_key(elt), "maxProperties") == 0 && ucl_object_toint_safe(elt, &minmax)) { if (obj->len > minmax) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object has too many properties: %u, maximum is: %u", - obj->len, (unsigned)minmax); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object has too many properties: %u, maximum is: %u", + obj->len, (unsigned) minmax); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "patternProperties") == 0) { + else if (strcmp(ucl_object_key(elt), "patternProperties") == 0) { const ucl_object_t *vobj; ucl_object_iter_t viter; piter = NULL; - while (ret && (prop = ucl_object_iterate (elt, &piter, true)) != NULL) { + while (ret && (prop = ucl_object_iterate(elt, &piter, true)) != NULL) { viter = NULL; - while (ret && (vobj = ucl_object_iterate (obj, &viter, true)) != NULL) { - found = ucl_schema_test_pattern (vobj, ucl_object_key (prop), false); + while (ret && (vobj = ucl_object_iterate(obj, &viter, true)) != NULL) { + found = ucl_schema_test_pattern(vobj, ucl_object_key(prop), false); if (found) { - ret = ucl_schema_validate (prop, found, true, err, root, - ext_ref); + ret = ucl_schema_validate(prop, found, true, err, root, + ext_ref); } } } } else if (elt->type == UCL_OBJECT && - strcmp (ucl_object_key (elt), "dependencies") == 0) { - ret = ucl_schema_validate_dependencies (elt, obj, err, root, - ext_ref); + strcmp(ucl_object_key(elt), "dependencies") == 0) { + ret = ucl_schema_validate_dependencies(elt, obj, err, root, + ext_ref); } } @@ -245,51 +244,51 @@ ucl_schema_validate_object (const ucl_object_t *schema, /* Additional properties */ if (!allow_additional || additional_schema != NULL) { /* Check if we have exactly the same properties in schema and object */ - iter = ucl_object_iterate_new (obj); - prop = ucl_object_lookup (schema, "properties"); - while ((elt = ucl_object_iterate_safe (iter, true)) != NULL) { - found = ucl_object_lookup (prop, ucl_object_key (elt)); + iter = ucl_object_iterate_new(obj); + prop = ucl_object_lookup(schema, "properties"); + while ((elt = ucl_object_iterate_safe(iter, true)) != NULL) { + found = ucl_object_lookup(prop, ucl_object_key(elt)); if (found == NULL) { /* Try patternProperties */ - pat = ucl_object_lookup (schema, "patternProperties"); - piter = ucl_object_iterate_new (pat); - while ((pelt = ucl_object_iterate_safe (piter, true)) != NULL) { - found = ucl_schema_test_pattern (obj, ucl_object_key (pelt), true); + pat = ucl_object_lookup(schema, "patternProperties"); + piter = ucl_object_iterate_new(pat); + while ((pelt = ucl_object_iterate_safe(piter, true)) != NULL) { + found = ucl_schema_test_pattern(obj, ucl_object_key(pelt), true); if (found != NULL) { break; } } - ucl_object_iterate_free (piter); + ucl_object_iterate_free(piter); piter = NULL; } if (found == NULL) { if (!allow_additional) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object has non-allowed property %s", - ucl_object_key (elt)); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object has non-allowed property %s", + ucl_object_key(elt)); ret = false; break; } else if (additional_schema != NULL) { - if (!ucl_schema_validate (additional_schema, elt, - true, err, root, ext_ref)) { + if (!ucl_schema_validate(additional_schema, elt, + true, err, root, ext_ref)) { ret = false; break; } } } } - ucl_object_iterate_free (iter); + ucl_object_iterate_free(iter); iter = NULL; } /* Required properties */ if (required != NULL) { iter = NULL; - while ((elt = ucl_object_iterate (required, &iter, true)) != NULL) { - if (ucl_object_lookup (obj, ucl_object_tostring (elt)) == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_MISSING_PROPERTY, obj, - "object has missing property %s", - ucl_object_tostring (elt)); + while ((elt = ucl_object_iterate(required, &iter, true)) != NULL) { + if (ucl_object_lookup(obj, ucl_object_tostring(elt)) == NULL) { + ucl_schema_create_error(err, UCL_SCHEMA_MISSING_PROPERTY, obj, + "object has missing property %s", + ucl_object_tostring(elt)); ret = false; break; } @@ -302,8 +301,8 @@ ucl_schema_validate_object (const ucl_object_t *schema, } static bool -ucl_schema_validate_number (const ucl_object_t *schema, - const ucl_object_t *obj, struct ucl_schema_error *err) +ucl_schema_validate_number(const ucl_object_t *schema, + const ucl_object_t *obj, struct ucl_schema_error *err) { const ucl_object_t *elt, *test; ucl_object_iter_t iter = NULL; @@ -311,53 +310,53 @@ ucl_schema_validate_number (const ucl_object_t *schema, double constraint, val; const double alpha = 1e-16; - while (ret && (elt = ucl_object_iterate (schema, &iter, true)) != NULL) { + while (ret && (elt = ucl_object_iterate(schema, &iter, true)) != NULL) { if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) && - strcmp (ucl_object_key (elt), "multipleOf") == 0) { - constraint = ucl_object_todouble (elt); + strcmp(ucl_object_key(elt), "multipleOf") == 0) { + constraint = ucl_object_todouble(elt); if (constraint <= 0) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "multipleOf must be greater than zero"); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "multipleOf must be greater than zero"); ret = false; break; } - val = ucl_object_todouble (obj); - if (fabs (remainder (val, constraint)) > alpha) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "number %.4f is not multiple of %.4f, remainder is %.7f", - val, constraint, remainder (val, constraint)); + val = ucl_object_todouble(obj); + if (fabs(remainder(val, constraint)) > alpha) { + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "number %.4f is not multiple of %.4f, remainder is %.7f", + val, constraint, remainder(val, constraint)); ret = false; break; } } else if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) && - strcmp (ucl_object_key (elt), "maximum") == 0) { - constraint = ucl_object_todouble (elt); - test = ucl_object_lookup (schema, "exclusiveMaximum"); + strcmp(ucl_object_key(elt), "maximum") == 0) { + constraint = ucl_object_todouble(elt); + test = ucl_object_lookup(schema, "exclusiveMaximum"); if (test && test->type == UCL_BOOLEAN) { - exclusive = ucl_object_toboolean (test); + exclusive = ucl_object_toboolean(test); } - val = ucl_object_todouble (obj); + val = ucl_object_todouble(obj); if (val > constraint || (exclusive && val >= constraint)) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "number is too big: %.3f, maximum is: %.3f", - val, constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "number is too big: %.3f, maximum is: %.3f", + val, constraint); ret = false; break; } } else if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) && - strcmp (ucl_object_key (elt), "minimum") == 0) { - constraint = ucl_object_todouble (elt); - test = ucl_object_lookup (schema, "exclusiveMinimum"); + strcmp(ucl_object_key(elt), "minimum") == 0) { + constraint = ucl_object_todouble(elt); + test = ucl_object_lookup(schema, "exclusiveMinimum"); if (test && test->type == UCL_BOOLEAN) { - exclusive = ucl_object_toboolean (test); + exclusive = ucl_object_toboolean(test); } - val = ucl_object_todouble (obj); + val = ucl_object_todouble(obj); if (val < constraint || (exclusive && val <= constraint)) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "number is too small: %.3f, minimum is: %.3f", - val, constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "number is too small: %.3f, minimum is: %.3f", + val, constraint); ret = false; break; } @@ -368,8 +367,8 @@ ucl_schema_validate_number (const ucl_object_t *schema, } static bool -ucl_schema_validate_string (const ucl_object_t *schema, - const ucl_object_t *obj, struct ucl_schema_error *err) +ucl_schema_validate_string(const ucl_object_t *schema, + const ucl_object_t *obj, struct ucl_schema_error *err) { const ucl_object_t *elt; ucl_object_iter_t iter = NULL; @@ -379,46 +378,46 @@ ucl_schema_validate_string (const ucl_object_t *schema, regex_t re; #endif - while (ret && (elt = ucl_object_iterate (schema, &iter, true)) != NULL) { + while (ret && (elt = ucl_object_iterate(schema, &iter, true)) != NULL) { if (elt->type == UCL_INT && - strcmp (ucl_object_key (elt), "maxLength") == 0) { - constraint = ucl_object_toint (elt); + strcmp(ucl_object_key(elt), "maxLength") == 0) { + constraint = ucl_object_toint(elt); if (obj->len > constraint) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "string is too big: %u, maximum is: %" PRId64, - obj->len, constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "string is too big: %u, maximum is: %" PRId64, + obj->len, constraint); ret = false; break; } } else if (elt->type == UCL_INT && - strcmp (ucl_object_key (elt), "minLength") == 0) { - constraint = ucl_object_toint (elt); + strcmp(ucl_object_key(elt), "minLength") == 0) { + constraint = ucl_object_toint(elt); if (obj->len < constraint) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "string is too short: %u, minimum is: %" PRId64, - obj->len, constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "string is too short: %u, minimum is: %" PRId64, + obj->len, constraint); ret = false; break; } } #ifdef HAVE_REGEX_H else if (elt->type == UCL_STRING && - strcmp (ucl_object_key (elt), "pattern") == 0) { - if (regcomp (&re, ucl_object_tostring (elt), - REG_EXTENDED | REG_NOSUB) != 0) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "cannot compile pattern %s", ucl_object_tostring (elt)); + strcmp(ucl_object_key(elt), "pattern") == 0) { + if (regcomp(&re, ucl_object_tostring(elt), + REG_EXTENDED | REG_NOSUB) != 0) { + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "cannot compile pattern %s", ucl_object_tostring(elt)); ret = false; break; } - if (regexec (&re, ucl_object_tostring (obj), 0, NULL, 0) != 0) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "string doesn't match regexp %s", - ucl_object_tostring (elt)); + if (regexec(&re, ucl_object_tostring(obj), 0, NULL, 0) != 0) { + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "string doesn't match regexp %s", + ucl_object_tostring(elt)); ret = false; } - regfree (&re); + regfree(&re); } #endif } @@ -428,7 +427,8 @@ ucl_schema_validate_string (const ucl_object_t *schema, struct ucl_compare_node { const ucl_object_t *obj; - TREE_ENTRY(ucl_compare_node) link; + TREE_ENTRY(ucl_compare_node) + link; struct ucl_compare_node *next; }; @@ -437,72 +437,73 @@ typedef TREE_HEAD(_tree, ucl_compare_node) ucl_compare_tree_t; TREE_DEFINE(ucl_compare_node, link) static int -ucl_schema_elt_compare (struct ucl_compare_node *n1, struct ucl_compare_node *n2) +ucl_schema_elt_compare(struct ucl_compare_node *n1, struct ucl_compare_node *n2) { const ucl_object_t *o1 = n1->obj, *o2 = n2->obj; - return ucl_object_compare (o1, o2); + return ucl_object_compare(o1, o2); } static bool -ucl_schema_array_is_unique (const ucl_object_t *obj, struct ucl_schema_error *err) +ucl_schema_array_is_unique(const ucl_object_t *obj, struct ucl_schema_error *err) { - ucl_compare_tree_t tree = TREE_INITIALIZER (ucl_schema_elt_compare); + ucl_compare_tree_t tree = TREE_INITIALIZER(ucl_schema_elt_compare); ucl_object_iter_t iter = NULL; const ucl_object_t *elt; struct ucl_compare_node *node, test, *nodes = NULL, *tmp; bool ret = true; - while ((elt = ucl_object_iterate (obj, &iter, true)) != NULL) { + while ((elt = ucl_object_iterate(obj, &iter, true)) != NULL) { test.obj = elt; - node = TREE_FIND (&tree, ucl_compare_node, link, &test); + node = TREE_FIND(&tree, ucl_compare_node, link, &test); if (node != NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, elt, - "duplicate values detected while uniqueItems is true"); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, elt, + "duplicate values detected while uniqueItems is true"); ret = false; break; } - node = calloc (1, sizeof (*node)); + node = calloc(1, sizeof(*node)); if (node == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_UNKNOWN, elt, - "cannot allocate tree node"); + ucl_schema_create_error(err, UCL_SCHEMA_UNKNOWN, elt, + "cannot allocate tree node"); ret = false; break; } node->obj = elt; - TREE_INSERT (&tree, ucl_compare_node, link, node); - LL_PREPEND (nodes, node); + TREE_INSERT(&tree, ucl_compare_node, link, node); + LL_PREPEND(nodes, node); } - LL_FOREACH_SAFE (nodes, node, tmp) { - free (node); + LL_FOREACH_SAFE(nodes, node, tmp) + { + free(node); } return ret; } static bool -ucl_schema_validate_array (const ucl_object_t *schema, - const ucl_object_t *obj, struct ucl_schema_error *err, - const ucl_object_t *root, - ucl_object_t *ext_ref) +ucl_schema_validate_array(const ucl_object_t *schema, + const ucl_object_t *obj, struct ucl_schema_error *err, + const ucl_object_t *root, + ucl_object_t *ext_ref) { const ucl_object_t *elt, *it, *found, *additional_schema = NULL, - *first_unvalidated = NULL; + *first_unvalidated = NULL; ucl_object_iter_t iter = NULL, piter = NULL; bool ret = true, allow_additional = true, need_unique = false; int64_t minmax; unsigned int idx = 0; - while (ret && (elt = ucl_object_iterate (schema, &iter, true)) != NULL) { - if (strcmp (ucl_object_key (elt), "items") == 0) { + while (ret && (elt = ucl_object_iterate(schema, &iter, true)) != NULL) { + if (strcmp(ucl_object_key(elt), "items") == 0) { if (elt->type == UCL_ARRAY) { - found = ucl_array_head (obj); - while (ret && (it = ucl_object_iterate (elt, &piter, true)) != NULL) { + found = ucl_array_head(obj); + while (ret && (it = ucl_object_iterate(elt, &piter, true)) != NULL) { if (found) { - ret = ucl_schema_validate (it, found, false, err, - root, ext_ref); - found = ucl_array_find_index (obj, ++idx); + ret = ucl_schema_validate(it, found, false, err, + root, ext_ref); + found = ucl_array_find_index(obj, ++idx); } } if (found != NULL) { @@ -512,21 +513,21 @@ ucl_schema_validate_array (const ucl_object_t *schema, } else if (elt->type == UCL_OBJECT) { /* Validate all items using the specified schema */ - while (ret && (it = ucl_object_iterate (obj, &piter, true)) != NULL) { - ret = ucl_schema_validate (elt, it, false, err, root, - ext_ref); + while (ret && (it = ucl_object_iterate(obj, &piter, true)) != NULL) { + ret = ucl_schema_validate(elt, it, false, err, root, + ext_ref); } } else { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "items attribute is invalid in schema"); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "items attribute is invalid in schema"); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "additionalItems") == 0) { + else if (strcmp(ucl_object_key(elt), "additionalItems") == 0) { if (elt->type == UCL_BOOLEAN) { - if (!ucl_object_toboolean (elt)) { + if (!ucl_object_toboolean(elt)) { /* Deny additional fields completely */ allow_additional = false; } @@ -536,32 +537,30 @@ ucl_schema_validate_array (const ucl_object_t *schema, additional_schema = elt; } else { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt, - "additionalItems attribute is invalid in schema"); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, elt, + "additionalItems attribute is invalid in schema"); ret = false; break; } } else if (elt->type == UCL_BOOLEAN && - strcmp (ucl_object_key (elt), "uniqueItems") == 0) { - need_unique = ucl_object_toboolean (elt); + strcmp(ucl_object_key(elt), "uniqueItems") == 0) { + need_unique = ucl_object_toboolean(elt); } - else if (strcmp (ucl_object_key (elt), "minItems") == 0 - && ucl_object_toint_safe (elt, &minmax)) { + else if (strcmp(ucl_object_key(elt), "minItems") == 0 && ucl_object_toint_safe(elt, &minmax)) { if (obj->len < minmax) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "array has not enough items: %u, minimum is: %u", - obj->len, (unsigned)minmax); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "array has not enough items: %u, minimum is: %u", + obj->len, (unsigned) minmax); ret = false; break; } } - else if (strcmp (ucl_object_key (elt), "maxItems") == 0 - && ucl_object_toint_safe (elt, &minmax)) { + else if (strcmp(ucl_object_key(elt), "maxItems") == 0 && ucl_object_toint_safe(elt, &minmax)) { if (obj->len > minmax) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "array has too many items: %u, maximum is: %u", - obj->len, (unsigned)minmax); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "array has too many items: %u, maximum is: %u", + obj->len, (unsigned) minmax); ret = false; break; } @@ -573,26 +572,26 @@ ucl_schema_validate_array (const ucl_object_t *schema, if (!allow_additional || additional_schema != NULL) { if (first_unvalidated != NULL) { if (!allow_additional) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "array has undefined item"); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "array has undefined item"); ret = false; } else if (additional_schema != NULL) { - elt = ucl_array_find_index (obj, idx); + elt = ucl_array_find_index(obj, idx); while (elt) { - if (!ucl_schema_validate (additional_schema, elt, false, - err, root, ext_ref)) { + if (!ucl_schema_validate(additional_schema, elt, false, + err, root, ext_ref)) { ret = false; break; } - elt = ucl_array_find_index (obj, idx ++); + elt = ucl_array_find_index(obj, idx++); } } } } /* Required properties */ if (ret && need_unique) { - ret = ucl_schema_array_is_unique (obj, err); + ret = ucl_schema_array_is_unique(obj, err); } } @@ -603,8 +602,8 @@ ucl_schema_validate_array (const ucl_object_t *schema, * Returns whether this object is allowed for this type */ static bool -ucl_schema_type_is_allowed (const ucl_object_t *type, const ucl_object_t *obj, - struct ucl_schema_error *err) +ucl_schema_type_is_allowed(const ucl_object_t *type, const ucl_object_t *obj, + struct ucl_schema_error *err) { ucl_object_iter_t iter = NULL; const ucl_object_t *elt; @@ -618,17 +617,17 @@ ucl_schema_type_is_allowed (const ucl_object_t *type, const ucl_object_t *obj, if (type->type == UCL_ARRAY) { /* One of allowed types */ - while ((elt = ucl_object_iterate (type, &iter, true)) != NULL) { - if (ucl_schema_type_is_allowed (elt, obj, err)) { + while ((elt = ucl_object_iterate(type, &iter, true)) != NULL) { + if (ucl_schema_type_is_allowed(elt, obj, err)) { return true; } } } else if (type->type == UCL_STRING) { - type_str = ucl_object_tostring (type); - if (!ucl_object_string_to_type (type_str, &t)) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, type, - "Type attribute is invalid in schema"); + type_str = ucl_object_tostring(type); + if (!ucl_object_string_to_type(type_str, &t)) { + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, type, + "Type attribute is invalid in schema"); return false; } if (obj->type != t) { @@ -640,10 +639,10 @@ ucl_schema_type_is_allowed (const ucl_object_t *type, const ucl_object_t *obj, return true; } else { - ucl_schema_create_error (err, UCL_SCHEMA_TYPE_MISMATCH, obj, - "Invalid type of %s, expected %s", - ucl_object_type_to_string (obj->type), - ucl_object_type_to_string (t)); + ucl_schema_create_error(err, UCL_SCHEMA_TYPE_MISMATCH, obj, + "Invalid type of %s, expected %s", + ucl_object_type_to_string(obj->type), + ucl_object_type_to_string(t)); } } else { @@ -659,23 +658,23 @@ ucl_schema_type_is_allowed (const ucl_object_t *type, const ucl_object_t *obj, * Check if object is equal to one of elements of enum */ static bool -ucl_schema_validate_enum (const ucl_object_t *en, const ucl_object_t *obj, - struct ucl_schema_error *err) +ucl_schema_validate_enum(const ucl_object_t *en, const ucl_object_t *obj, + struct ucl_schema_error *err) { ucl_object_iter_t iter = NULL; const ucl_object_t *elt; bool ret = false; - while ((elt = ucl_object_iterate (en, &iter, true)) != NULL) { - if (ucl_object_compare (elt, obj) == 0) { + while ((elt = ucl_object_iterate(en, &iter, true)) != NULL) { + if (ucl_object_compare(elt, obj) == 0) { ret = true; break; } } if (!ret) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object is not one of enumerated patterns"); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object is not one of enumerated patterns"); } return ret; @@ -686,9 +685,9 @@ ucl_schema_validate_enum (const ucl_object_t *en, const ucl_object_t *obj, * Check a single ref component */ static const ucl_object_t * -ucl_schema_resolve_ref_component (const ucl_object_t *cur, - const char *refc, int len, - struct ucl_schema_error *err) +ucl_schema_resolve_ref_component(const ucl_object_t *cur, + const char *refc, int len, + struct ucl_schema_error *err) { const ucl_object_t *res = NULL; char *err_str; @@ -696,22 +695,22 @@ ucl_schema_resolve_ref_component (const ucl_object_t *cur, if (cur->type == UCL_OBJECT) { /* Find a key inside an object */ - res = ucl_object_lookup_len (cur, refc, len); + res = ucl_object_lookup_len(cur, refc, len); if (res == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur, - "reference %s is invalid, missing path component", refc); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, cur, + "reference %s is invalid, missing path component", refc); return NULL; } } else if (cur->type == UCL_ARRAY) { /* We must figure out a number inside array */ - num = strtoul (refc, &err_str, 10); + num = strtoul(refc, &err_str, 10); if (err_str != NULL && *err_str != '/' && *err_str != '\0') { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur, - "reference %s is invalid, invalid item number", refc); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, cur, + "reference %s is invalid, invalid item number", refc); return NULL; } - res = ucl_array_head (cur); + res = ucl_array_head(cur); i = 0; while (res != NULL) { if (i == num) { @@ -720,16 +719,16 @@ ucl_schema_resolve_ref_component (const ucl_object_t *cur, res = res->next; } if (res == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur, - "reference %s is invalid, item number %d does not exist", - refc, num); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, cur, + "reference %s is invalid, item number %d does not exist", + refc, num); return NULL; } } else { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res, - "reference %s is invalid, contains primitive object in the path", - refc); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, res, + "reference %s is invalid, contains primitive object in the path", + refc); return NULL; } @@ -739,9 +738,9 @@ ucl_schema_resolve_ref_component (const ucl_object_t *cur, * Find reference schema */ static const ucl_object_t * -ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref, - struct ucl_schema_error *err, ucl_object_t *ext_ref, - ucl_object_t const ** nroot) +ucl_schema_resolve_ref(const ucl_object_t *root, const char *ref, + struct ucl_schema_error *err, ucl_object_t *ext_ref, + ucl_object_t const **nroot) { UT_string *url_err = NULL; struct ucl_parser *parser; @@ -753,18 +752,18 @@ ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref, size_t url_buflen; if (ref[0] != '#') { - hash_ptr = strrchr (ref, '#'); + hash_ptr = strrchr(ref, '#'); if (hash_ptr) { - url_copy = malloc (hash_ptr - ref + 1); + url_copy = malloc(hash_ptr - ref + 1); if (url_copy == NULL) { - ucl_schema_create_error (err, UCL_SCHEMA_INTERNAL_ERROR, root, - "cannot allocate memory"); + ucl_schema_create_error(err, UCL_SCHEMA_INTERNAL_ERROR, root, + "cannot allocate memory"); return NULL; } - ucl_strlcpy (url_copy, ref, hash_ptr - ref + 1); + ucl_strlcpy(url_copy, ref, hash_ptr - ref + 1); p = url_copy; } else { @@ -772,59 +771,59 @@ ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref, p = ref; } - ext_obj = ucl_object_lookup (ext_ref, p); + ext_obj = ucl_object_lookup(ext_ref, p); if (ext_obj == NULL) { - if (ucl_strnstr (p, "://", strlen (p)) != NULL) { - if (!ucl_fetch_url (p, &url_buf, &url_buflen, &url_err, true)) { - - ucl_schema_create_error (err, - UCL_SCHEMA_INVALID_SCHEMA, - root, - "cannot fetch reference %s: %s", - p, - url_err != NULL ? utstring_body (url_err) - : "unknown"); - free (url_copy); + if (ucl_strnstr(p, "://", strlen(p)) != NULL) { + if (!ucl_fetch_url(p, &url_buf, &url_buflen, &url_err, true)) { + + ucl_schema_create_error(err, + UCL_SCHEMA_INVALID_SCHEMA, + root, + "cannot fetch reference %s: %s", + p, + url_err != NULL ? utstring_body(url_err) + : "unknown"); + free(url_copy); return NULL; } } else { - if (!ucl_fetch_file (p, &url_buf, &url_buflen, &url_err, - true)) { - ucl_schema_create_error (err, - UCL_SCHEMA_INVALID_SCHEMA, - root, - "cannot fetch reference %s: %s", - p, - url_err != NULL ? utstring_body (url_err) - : "unknown"); - free (url_copy); + if (!ucl_fetch_file(p, &url_buf, &url_buflen, &url_err, + true)) { + ucl_schema_create_error(err, + UCL_SCHEMA_INVALID_SCHEMA, + root, + "cannot fetch reference %s: %s", + p, + url_err != NULL ? utstring_body(url_err) + : "unknown"); + free(url_copy); return NULL; } } - parser = ucl_parser_new (0); + parser = ucl_parser_new(0); - if (!ucl_parser_add_chunk (parser, url_buf, url_buflen)) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, root, - "cannot fetch reference %s: %s", p, - ucl_parser_get_error (parser)); - ucl_parser_free (parser); - free (url_copy); + if (!ucl_parser_add_chunk(parser, url_buf, url_buflen)) { + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, root, + "cannot fetch reference %s: %s", p, + ucl_parser_get_error(parser)); + ucl_parser_free(parser); + free(url_copy); return NULL; } - url_obj = ucl_parser_get_object (parser); + url_obj = ucl_parser_get_object(parser); ext_obj = url_obj; - ucl_object_insert_key (ext_ref, url_obj, p, 0, true); - free (url_buf); + ucl_object_insert_key(ext_ref, url_obj, p, 0, true); + free(url_buf); } - free (url_copy); + free(url_copy); if (hash_ptr) { p = hash_ptr + 1; @@ -852,28 +851,28 @@ ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref, while (*p != '\0') { if (*p == '/') { if (p - c == 0) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res, - "reference %s is invalid, empty path component", ref); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, res, + "reference %s is invalid, empty path component", ref); return NULL; } /* Now we have some url part, so we need to figure out where we are */ - res = ucl_schema_resolve_ref_component (res, c, p - c, err); + res = ucl_schema_resolve_ref_component(res, c, p - c, err); if (res == NULL) { return NULL; } c = p + 1; } - p ++; + p++; } if (p - c != 0) { - res = ucl_schema_resolve_ref_component (res, c, p - c, err); + res = ucl_schema_resolve_ref_component(res, c, p - c, err); } if (res == NULL || res->type != UCL_OBJECT) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, res, - "reference %s is invalid, cannot find specified object", - ref); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, res, + "reference %s is invalid, cannot find specified object", + ref); return NULL; } @@ -881,44 +880,44 @@ ucl_schema_resolve_ref (const ucl_object_t *root, const char *ref, } static bool -ucl_schema_validate_values (const ucl_object_t *schema, const ucl_object_t *obj, - struct ucl_schema_error *err) +ucl_schema_validate_values(const ucl_object_t *schema, const ucl_object_t *obj, + struct ucl_schema_error *err) { const ucl_object_t *elt, *cur; int64_t constraint, i; - elt = ucl_object_lookup (schema, "maxValues"); + elt = ucl_object_lookup(schema, "maxValues"); if (elt != NULL && elt->type == UCL_INT) { - constraint = ucl_object_toint (elt); + constraint = ucl_object_toint(elt); cur = obj; i = 0; while (cur) { if (i > constraint) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object has more values than defined: %ld", - (long int)constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object has more values than defined: %ld", + (long int) constraint); return false; } - i ++; + i++; cur = cur->next; } } - elt = ucl_object_lookup (schema, "minValues"); + elt = ucl_object_lookup(schema, "minValues"); if (elt != NULL && elt->type == UCL_INT) { - constraint = ucl_object_toint (elt); + constraint = ucl_object_toint(elt); cur = obj; i = 0; while (cur) { if (i >= constraint) { break; } - i ++; + i++; cur = cur->next; } if (i < constraint) { - ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj, - "object has less values than defined: %ld", - (long int)constraint); + ucl_schema_create_error(err, UCL_SCHEMA_CONSTRAINT, obj, + "object has less values than defined: %ld", + (long int) constraint); return false; } } @@ -927,20 +926,20 @@ ucl_schema_validate_values (const ucl_object_t *schema, const ucl_object_t *obj, } static bool -ucl_schema_validate (const ucl_object_t *schema, - const ucl_object_t *obj, bool try_array, - struct ucl_schema_error *err, - const ucl_object_t *root, - ucl_object_t *external_refs) +ucl_schema_validate(const ucl_object_t *schema, + const ucl_object_t *obj, bool try_array, + struct ucl_schema_error *err, + const ucl_object_t *root, + ucl_object_t *external_refs) { const ucl_object_t *elt, *cur, *ref_root; ucl_object_iter_t iter = NULL; bool ret; if (schema->type != UCL_OBJECT) { - ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, schema, - "schema is %s instead of object", - ucl_object_type_to_string (schema->type)); + ucl_schema_create_error(err, UCL_SCHEMA_INVALID_SCHEMA, schema, + "schema is %s instead of object", + ucl_object_type_to_string(schema->type)); return false; } @@ -948,40 +947,41 @@ ucl_schema_validate (const ucl_object_t *schema, /* * Special case for multiple values */ - if (!ucl_schema_validate_values (schema, obj, err)) { + if (!ucl_schema_validate_values(schema, obj, err)) { return false; } - LL_FOREACH (obj, cur) { - if (!ucl_schema_validate (schema, cur, false, err, root, external_refs)) { + LL_FOREACH(obj, cur) + { + if (!ucl_schema_validate(schema, cur, false, err, root, external_refs)) { return false; } } return true; } - elt = ucl_object_lookup (schema, "enum"); + elt = ucl_object_lookup(schema, "enum"); if (elt != NULL && elt->type == UCL_ARRAY) { - if (!ucl_schema_validate_enum (elt, obj, err)) { + if (!ucl_schema_validate_enum(elt, obj, err)) { return false; } } - elt = ucl_object_lookup (schema, "allOf"); + elt = ucl_object_lookup(schema, "allOf"); if (elt != NULL && elt->type == UCL_ARRAY) { iter = NULL; - while ((cur = ucl_object_iterate (elt, &iter, true)) != NULL) { - ret = ucl_schema_validate (cur, obj, true, err, root, external_refs); + while ((cur = ucl_object_iterate(elt, &iter, true)) != NULL) { + ret = ucl_schema_validate(cur, obj, true, err, root, external_refs); if (!ret) { return false; } } } - elt = ucl_object_lookup (schema, "anyOf"); + elt = ucl_object_lookup(schema, "anyOf"); if (elt != NULL && elt->type == UCL_ARRAY) { iter = NULL; - while ((cur = ucl_object_iterate (elt, &iter, true)) != NULL) { - ret = ucl_schema_validate (cur, obj, true, err, root, external_refs); + while ((cur = ucl_object_iterate(elt, &iter, true)) != NULL) { + ret = ucl_schema_validate(cur, obj, true, err, root, external_refs); if (ret) { break; } @@ -995,15 +995,15 @@ ucl_schema_validate (const ucl_object_t *schema, } } - elt = ucl_object_lookup (schema, "oneOf"); + elt = ucl_object_lookup(schema, "oneOf"); if (elt != NULL && elt->type == UCL_ARRAY) { iter = NULL; ret = false; - while ((cur = ucl_object_iterate (elt, &iter, true)) != NULL) { + while ((cur = ucl_object_iterate(elt, &iter, true)) != NULL) { if (!ret) { - ret = ucl_schema_validate (cur, obj, true, err, root, external_refs); + ret = ucl_schema_validate(cur, obj, true, err, root, external_refs); } - else if (ucl_schema_validate (cur, obj, true, err, root, external_refs)) { + else if (ucl_schema_validate(cur, obj, true, err, root, external_refs)) { ret = false; break; } @@ -1013,9 +1013,9 @@ ucl_schema_validate (const ucl_object_t *schema, } } - elt = ucl_object_lookup (schema, "not"); + elt = ucl_object_lookup(schema, "not"); if (elt != NULL && elt->type == UCL_OBJECT) { - if (ucl_schema_validate (elt, obj, true, err, root, external_refs)) { + if (ucl_schema_validate(elt, obj, true, err, root, external_refs)) { return false; } else { @@ -1024,39 +1024,39 @@ ucl_schema_validate (const ucl_object_t *schema, } } - elt = ucl_object_lookup (schema, "$ref"); + elt = ucl_object_lookup(schema, "$ref"); if (elt != NULL) { ref_root = root; - cur = ucl_schema_resolve_ref (root, ucl_object_tostring (elt), - err, external_refs, &ref_root); + cur = ucl_schema_resolve_ref(root, ucl_object_tostring(elt), + err, external_refs, &ref_root); if (cur == NULL) { return false; } - if (!ucl_schema_validate (cur, obj, try_array, err, ref_root, - external_refs)) { + if (!ucl_schema_validate(cur, obj, try_array, err, ref_root, + external_refs)) { return false; } } - elt = ucl_object_lookup (schema, "type"); - if (!ucl_schema_type_is_allowed (elt, obj, err)) { + elt = ucl_object_lookup(schema, "type"); + if (!ucl_schema_type_is_allowed(elt, obj, err)) { return false; } switch (obj->type) { case UCL_OBJECT: - return ucl_schema_validate_object (schema, obj, err, root, external_refs); + return ucl_schema_validate_object(schema, obj, err, root, external_refs); break; case UCL_ARRAY: - return ucl_schema_validate_array (schema, obj, err, root, external_refs); + return ucl_schema_validate_array(schema, obj, err, root, external_refs); break; case UCL_INT: case UCL_FLOAT: - return ucl_schema_validate_number (schema, obj, err); + return ucl_schema_validate_number(schema, obj, err); break; case UCL_STRING: - return ucl_schema_validate_string (schema, obj, err); + return ucl_schema_validate_string(schema, obj, err); break; default: break; @@ -1065,40 +1065,37 @@ ucl_schema_validate (const ucl_object_t *schema, return true; } -bool -ucl_object_validate (const ucl_object_t *schema, - const ucl_object_t *obj, struct ucl_schema_error *err) +bool ucl_object_validate(const ucl_object_t *schema, + const ucl_object_t *obj, struct ucl_schema_error *err) { - return ucl_object_validate_root_ext (schema, obj, schema, NULL, err); + return ucl_object_validate_root_ext(schema, obj, schema, NULL, err); } -bool -ucl_object_validate_root (const ucl_object_t *schema, - const ucl_object_t *obj, - const ucl_object_t *root, - struct ucl_schema_error *err) +bool ucl_object_validate_root(const ucl_object_t *schema, + const ucl_object_t *obj, + const ucl_object_t *root, + struct ucl_schema_error *err) { - return ucl_object_validate_root_ext (schema, obj, root, NULL, err); + return ucl_object_validate_root_ext(schema, obj, root, NULL, err); } -bool -ucl_object_validate_root_ext (const ucl_object_t *schema, - const ucl_object_t *obj, - const ucl_object_t *root, - ucl_object_t *ext_refs, - struct ucl_schema_error *err) +bool ucl_object_validate_root_ext(const ucl_object_t *schema, + const ucl_object_t *obj, + const ucl_object_t *root, + ucl_object_t *ext_refs, + struct ucl_schema_error *err) { bool ret, need_unref = false; if (ext_refs == NULL) { - ext_refs = ucl_object_typed_new (UCL_OBJECT); + ext_refs = ucl_object_typed_new(UCL_OBJECT); need_unref = true; } - ret = ucl_schema_validate (schema, obj, true, err, root, ext_refs); + ret = ucl_schema_validate(schema, obj, true, err, root, ext_refs); if (need_unref) { - ucl_object_unref (ext_refs); + ucl_object_unref(ext_refs); } return ret; |
