Deleted Added
full compact
ucl_schema.c (264789) ucl_schema.c (279549)
1/*
2 * Copyright (c) 2014, Vsevolod Stakhov
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright

--- 511 unchanged lines hidden (view full) ---

520 const ucl_object_t *obj, struct ucl_schema_error *err,
521 const ucl_object_t *root)
522{
523 const ucl_object_t *elt, *it, *found, *additional_schema = NULL,
524 *first_unvalidated = NULL;
525 ucl_object_iter_t iter = NULL, piter = NULL;
526 bool ret = true, allow_additional = true, need_unique = false;
527 int64_t minmax;
1/*
2 * Copyright (c) 2014, Vsevolod Stakhov
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright

--- 511 unchanged lines hidden (view full) ---

520 const ucl_object_t *obj, struct ucl_schema_error *err,
521 const ucl_object_t *root)
522{
523 const ucl_object_t *elt, *it, *found, *additional_schema = NULL,
524 *first_unvalidated = NULL;
525 ucl_object_iter_t iter = NULL, piter = NULL;
526 bool ret = true, allow_additional = true, need_unique = false;
527 int64_t minmax;
528 unsigned int idx = 0;
528
529 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
530 if (strcmp (ucl_object_key (elt), "items") == 0) {
531 if (elt->type == UCL_ARRAY) {
529
530 while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
531 if (strcmp (ucl_object_key (elt), "items") == 0) {
532 if (elt->type == UCL_ARRAY) {
532 found = obj->value.av;
533 found = ucl_array_head (obj);
533 while (ret && (it = ucl_iterate_object (elt, &piter, true)) != NULL) {
534 if (found) {
535 ret = ucl_schema_validate (it, found, false, err, root);
534 while (ret && (it = ucl_iterate_object (elt, &piter, true)) != NULL) {
535 if (found) {
536 ret = ucl_schema_validate (it, found, false, err, root);
536 found = found->next;
537 found = ucl_array_find_index (obj, ++idx);
537 }
538 }
539 if (found != NULL) {
540 /* The first element that is not validated */
541 first_unvalidated = found;
542 }
543 }
544 else if (elt->type == UCL_OBJECT) {

--- 58 unchanged lines hidden (view full) ---

603 if (!allow_additional || additional_schema != NULL) {
604 if (first_unvalidated != NULL) {
605 if (!allow_additional) {
606 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
607 "array has undefined item");
608 ret = false;
609 }
610 else if (additional_schema != NULL) {
538 }
539 }
540 if (found != NULL) {
541 /* The first element that is not validated */
542 first_unvalidated = found;
543 }
544 }
545 else if (elt->type == UCL_OBJECT) {

--- 58 unchanged lines hidden (view full) ---

604 if (!allow_additional || additional_schema != NULL) {
605 if (first_unvalidated != NULL) {
606 if (!allow_additional) {
607 ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
608 "array has undefined item");
609 ret = false;
610 }
611 else if (additional_schema != NULL) {
611 elt = first_unvalidated;
612 elt = ucl_array_find_index (obj, idx);
612 while (elt) {
613 if (!ucl_schema_validate (additional_schema, elt, false,
614 err, root)) {
615 ret = false;
616 break;
617 }
613 while (elt) {
614 if (!ucl_schema_validate (additional_schema, elt, false,
615 err, root)) {
616 ret = false;
617 break;
618 }
618 elt = elt->next;
619 elt = ucl_array_find_index (obj, idx ++);
619 }
620 }
621 }
622 }
623 /* Required properties */
624 if (ret && need_unique) {
625 ret = ucl_schema_array_is_unique (obj, err);
626 }

--- 109 unchanged lines hidden (view full) ---

736 else if (cur->type == UCL_ARRAY) {
737 /* We must figure out a number inside array */
738 num = strtoul (refc, &err_str, 10);
739 if (err_str != NULL && *err_str != '/' && *err_str != '\0') {
740 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur,
741 "reference %s is invalid, invalid item number", refc);
742 return NULL;
743 }
620 }
621 }
622 }
623 }
624 /* Required properties */
625 if (ret && need_unique) {
626 ret = ucl_schema_array_is_unique (obj, err);
627 }

--- 109 unchanged lines hidden (view full) ---

737 else if (cur->type == UCL_ARRAY) {
738 /* We must figure out a number inside array */
739 num = strtoul (refc, &err_str, 10);
740 if (err_str != NULL && *err_str != '/' && *err_str != '\0') {
741 ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, cur,
742 "reference %s is invalid, invalid item number", refc);
743 return NULL;
744 }
744 res = cur->value.av;
745 res = ucl_array_head (cur);
745 i = 0;
746 while (res != NULL) {
747 if (i == num) {
748 break;
749 }
750 res = res->next;
751 }
752 if (res == NULL) {

--- 262 unchanged lines hidden ---
746 i = 0;
747 while (res != NULL) {
748 if (i == num) {
749 break;
750 }
751 res = res->next;
752 }
753 if (res == NULL) {

--- 262 unchanged lines hidden ---