1
0
Fork 0

Adding upstream version 3.7.8.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-05 08:08:41 +01:00
parent 338ffded6d
commit 76b2c91d7e
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
52 changed files with 13518 additions and 998 deletions

View file

@ -3,7 +3,7 @@
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief Validation
*
* Copyright (c) 2019 - 2023 CESNET, z.s.p.o.
* Copyright (c) 2019 - 2024 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@ -56,6 +56,109 @@
} \
}
/**
* @brief Callback for freeing getnext HT values.
*/
static void
lyd_val_getnext_ht_free_cb(void *val_p)
{
struct lyd_val_getnext *val = val_p;
free(val->snodes);
free(val->choices);
}
/**
* @brief Callback for checking getnext HT value equality.
*/
static ly_bool
lyd_val_getnext_ht_equal_cb(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *UNUSED(cb_data))
{
struct lyd_val_getnext *val1 = val1_p;
struct lyd_val_getnext *val2 = val2_p;
if (val1->sparent == val2->sparent) {
return 1;
}
return 0;
}
LY_ERR
lyd_val_getnext_ht_new(struct ly_ht **getnext_ht_p)
{
*getnext_ht_p = lyht_new(32, sizeof(struct lyd_val_getnext), lyd_val_getnext_ht_equal_cb, NULL, 1);
if (!*getnext_ht_p) {
LOGMEM(NULL);
return LY_EMEM;
}
return LY_SUCCESS;
}
void
lyd_val_getnext_ht_free(struct ly_ht *getnext_ht)
{
lyht_free(getnext_ht, lyd_val_getnext_ht_free_cb);
}
LY_ERR
lyd_val_getnext_get(const struct lysc_node *sparent, const struct lys_module *mod, const struct lysc_ext_instance *ext,
ly_bool output, struct ly_ht *getnext_ht, const struct lysc_node ***choices, const struct lysc_node ***snodes)
{
LY_ERR rc = LY_SUCCESS;
struct lyd_val_getnext val = {0}, *getnext = NULL;
const struct lysc_node *snode = NULL;
uint32_t getnext_opts, snode_count = 0, choice_count = 0;
/* try to find the entry for this schema parent */
val.sparent = sparent;
if (!lyht_find(getnext_ht, &val, (uintptr_t)sparent, (void **)&getnext)) {
goto cleanup;
}
/* traverse all the children using getnext and store them */
getnext_opts = LYS_GETNEXT_WITHCHOICE | (output ? LYS_GETNEXT_OUTPUT : 0);
while (ext ? (snode = lys_getnext_ext(snode, sparent, ext, getnext_opts)) :
(snode = lys_getnext(snode, sparent, mod ? mod->compiled : NULL, getnext_opts))) {
if (snode->nodetype == LYS_CHOICE) {
/* store a choice node */
val.choices = ly_realloc(val.choices, (choice_count + 2) * sizeof *val.choices);
LY_CHECK_ERR_GOTO(!val.choices, LOGMEM(NULL); rc = LY_EMEM, cleanup);
val.choices[choice_count] = snode;
++choice_count;
} else {
/* store other nodes */
val.snodes = ly_realloc(val.snodes, (snode_count + 2) * sizeof *val.snodes);
LY_CHECK_ERR_GOTO(!val.snodes, LOGMEM(NULL); rc = LY_EMEM, cleanup);
val.snodes[snode_count] = snode;
++snode_count;
}
}
/* add terminating NULL items */
if (choice_count) {
val.choices[choice_count] = NULL;
}
if (snode_count) {
val.snodes[snode_count] = NULL;
}
/* add into the hash table */
if ((rc = lyht_insert(getnext_ht, &val, (uintptr_t)sparent, (void **)&getnext))) {
goto cleanup;
}
cleanup:
if (rc) {
free(val.snodes);
free(val.choices);
} else {
*choices = getnext->choices;
*snodes = getnext->snodes;
}
return rc;
}
LY_ERR
lyd_val_diff_add(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node **diff)
{
@ -434,6 +537,18 @@ cleanup:
return rc;
}
/**
* @brief Compare callback for finding duplicates in hash table.
*
* Implementation of ::lyht_value_equal_cb.
*/
static ly_bool
lyd_val_dup_val_equal(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *cb_data)
{
/* always find the same instance, not the exact same pointer (set mod = 0) */
return lyd_hash_table_val_equal(val1_p, val2_p, 0, cb_data);
}
/**
* @brief Validate instance duplication.
*
@ -445,7 +560,6 @@ cleanup:
static LY_ERR
lyd_validate_duplicates(const struct lyd_node *first, const struct lyd_node *node, uint32_t val_opts)
{
struct lyd_node **match_p, *match;
ly_bool fail = 0;
assert(node->flags & LYD_NEW);
@ -458,12 +572,9 @@ lyd_validate_duplicates(const struct lyd_node *first, const struct lyd_node *nod
/* find exactly the same next instance using hashes if possible */
if (node->parent && node->parent->children_ht) {
lyd_find_sibling_first(first, node, &match);
assert(match);
if (match != node) {
fail = 1;
} else if (!lyht_find_next(node->parent->children_ht, &node, node->hash, (void **)&match_p)) {
/* because of the callback used, an instance must always be found (pointer may or may not be equal to node),
* so if we find another instance, there is a duplicate */
if (!lyht_find_next_with_collision_cb(node->parent->children_ht, &node, node->hash, lyd_val_dup_val_equal, NULL)) {
fail = 1;
}
} else {
@ -783,27 +894,37 @@ lyd_validate_autodel_case_dflt(struct lyd_node **first, struct lyd_node **node,
* @param[in,out] first First sibling.
* @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
* @param[in] mod Module of the siblings, NULL for nested siblings.
* @param[in] ext Extension instance to use, if relevant.
* @param[in] val_opts Validation options.
* @param[in] int_opts Internal parser options.
* @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it.
* @param[in,out] diff Validation diff.
* @return LY_ERR value.
*/
static LY_ERR
lyd_validate_choice_r(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod,
uint32_t val_opts, struct lyd_node **diff)
const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht,
struct lyd_node **diff)
{
LY_ERR r, rc = LY_SUCCESS;
const struct lysc_node *snode = NULL;
const struct lysc_node **choices, **snodes;
uint32_t i;
while (*first && (snode = lys_getnext(snode, sparent, mod ? mod->compiled : NULL, LYS_GETNEXT_WITHCHOICE))) {
/* get cached getnext schema nodes */
rc = lyd_val_getnext_get(sparent, mod, ext, int_opts & LYD_INTOPT_REPLY, getnext_ht, &choices, &snodes);
LY_CHECK_GOTO(rc, cleanup);
if (!choices) {
goto cleanup;
}
for (i = 0; *first && choices[i]; ++i) {
/* check case duplicites */
if (snode->nodetype == LYS_CHOICE) {
r = lyd_validate_cases(first, mod, (struct lysc_node_choice *)snode, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
r = lyd_validate_cases(first, mod, (struct lysc_node_choice *)choices[i], diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
/* check for nested choice */
r = lyd_validate_choice_r(first, snode, mod, val_opts, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
/* check for nested choice */
r = lyd_validate_choice_r(first, choices[i], mod, ext, val_opts, int_opts, getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
cleanup:
@ -812,7 +933,8 @@ cleanup:
LY_ERR
lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const struct lys_module *mod,
uint32_t val_opts, struct lyd_node **diff)
const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht,
struct lyd_node **diff)
{
LY_ERR r, rc = LY_SUCCESS;
struct lyd_node *node;
@ -821,7 +943,7 @@ lyd_validate_new(struct lyd_node **first, const struct lysc_node *sparent, const
assert(first && (sparent || mod));
/* validate choices */
r = lyd_validate_choice_r(first, sparent, mod, val_opts, diff);
r = lyd_validate_choice_r(first, sparent, mod, ext, val_opts, int_opts, getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
node = *first;
@ -1369,38 +1491,76 @@ cleanup:
* @param[in] parent Data parent.
* @param[in] sparent Schema parent of the nodes to check.
* @param[in] mod Module of the nodes to check.
* @param[in] ext Extension instance to use, if relevant.
* @param[in] val_opts Validation options, see @ref datavalidationoptions.
* @param[in] int_opts Internal parser options.
* @param[in,out] getnext_ht Getnext HT to use, new @p sparent is added to it.
* @return LY_ERR value.
*/
static LY_ERR
lyd_validate_siblings_schema_r(const struct lyd_node *first, const struct lyd_node *parent,
const struct lysc_node *sparent, const struct lysc_module *mod, uint32_t val_opts, uint32_t int_opts)
const struct lysc_node *sparent, const struct lys_module *mod, const struct lysc_ext_instance *ext,
uint32_t val_opts, uint32_t int_opts, struct ly_ht *getnext_ht)
{
LY_ERR r, rc = LY_SUCCESS;
const struct lysc_node *snode = NULL, *scase;
const struct lysc_node *snode, *scase, **choices, **snodes;
struct lysc_node_list *slist;
struct lysc_node_leaflist *sllist;
uint32_t getnext_opts;
uint32_t i;
getnext_opts = LYS_GETNEXT_WITHCHOICE | (int_opts & LYD_INTOPT_REPLY ? LYS_GETNEXT_OUTPUT : 0);
/* get cached getnext schema nodes */
rc = lyd_val_getnext_get(sparent, mod, ext, int_opts & LYD_INTOPT_REPLY, getnext_ht, &choices, &snodes);
LY_CHECK_GOTO(rc, cleanup);
for (i = 0; choices && choices[i]; ++i) {
snode = choices[i];
/* disabled nodes are skipped by lys_getnext */
while ((snode = lys_getnext(snode, sparent, mod, getnext_opts))) {
if ((val_opts & LYD_VALIDATE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
/* skip state nodes */
continue;
}
if (snode->flags & LYS_MAND_TRUE) {
/* check generic mandatory existence */
r = lyd_validate_mandatory(first, parent, snode, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
/* find the existing case, if any */
LY_LIST_FOR(lysc_node_child(snode), scase) {
if (lys_getnext_data(NULL, first, NULL, scase, NULL)) {
/* validate only this case */
r = lyd_validate_siblings_schema_r(first, parent, scase, mod, ext, val_opts, int_opts, getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
break;
}
}
}
for (i = 0; snodes && snodes[i]; ++i) {
snode = snodes[i];
if ((val_opts & LYD_VALIDATE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
/* skip state nodes */
continue;
}
/* check min-elements and max-elements */
if (snode->nodetype == LYS_LIST) {
slist = (struct lysc_node_list *)snode;
if (slist->min || slist->max) {
if (slist->min || (slist->max < UINT32_MAX)) {
r = lyd_validate_minmax(first, parent, snode, slist->min, slist->max, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
/* check unique */
if (slist->uniques) {
r = lyd_validate_unique(first, snode, (const struct lysc_node_leaf ***)slist->uniques, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
} else if (snode->nodetype == LYS_LEAFLIST) {
sllist = (struct lysc_node_leaflist *)snode;
if (sllist->min || sllist->max) {
if (sllist->min || (sllist->max < UINT32_MAX)) {
r = lyd_validate_minmax(first, parent, snode, sllist->min, sllist->max, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
@ -1410,27 +1570,6 @@ lyd_validate_siblings_schema_r(const struct lyd_node *first, const struct lyd_no
r = lyd_validate_mandatory(first, parent, snode, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
/* check unique */
if (snode->nodetype == LYS_LIST) {
slist = (struct lysc_node_list *)snode;
if (slist->uniques) {
r = lyd_validate_unique(first, snode, (const struct lysc_node_leaf ***)slist->uniques, val_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
}
if (snode->nodetype == LYS_CHOICE) {
/* find the existing case, if any */
LY_LIST_FOR(lysc_node_child(snode), scase) {
if (lys_getnext_data(NULL, first, NULL, scase, NULL)) {
/* validate only this case */
r = lyd_validate_siblings_schema_r(first, parent, scase, mod, val_opts, int_opts);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
break;
}
}
}
}
cleanup:
@ -1557,14 +1696,17 @@ cleanup:
* @param[in] parent Data parent.
* @param[in] sparent Schema parent of the siblings, NULL for top-level siblings.
* @param[in] mod Module of the siblings, NULL for nested siblings.
* @param[in] ext Extension instance to use, if relevant.
* @param[in] val_opts Validation options (@ref datavalidationoptions).
* @param[in] int_opts Internal parser options.
* @param[in] must_xp_opts Additional XPath options to use for evaluating "must".
* @param[in,out] getnext_ht Getnext HT to use.
* @return LY_ERR value.
*/
static LY_ERR
lyd_validate_final_r(struct lyd_node *first, const struct lyd_node *parent, const struct lysc_node *sparent,
const struct lys_module *mod, uint32_t val_opts, uint32_t int_opts, uint32_t must_xp_opts)
const struct lys_module *mod, const struct lysc_ext_instance *ext, uint32_t val_opts, uint32_t int_opts,
uint32_t must_xp_opts, struct ly_ht *getnext_ht)
{
LY_ERR r, rc = LY_SUCCESS;
const char *innode;
@ -1626,7 +1768,7 @@ next_iter:
}
/* validate schema-based restrictions */
r = lyd_validate_siblings_schema_r(first, parent, sparent, mod ? mod->compiled : NULL, val_opts, int_opts);
r = lyd_validate_siblings_schema_r(first, parent, sparent, mod, ext, val_opts, int_opts, getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
LY_LIST_FOR(first, node) {
@ -1636,11 +1778,12 @@ next_iter:
}
/* validate all children recursively */
r = lyd_validate_final_r(lyd_child(node), node, node->schema, NULL, val_opts, int_opts, must_xp_opts);
r = lyd_validate_final_r(lyd_child(node), node, node->schema, NULL, NULL, val_opts, int_opts, must_xp_opts,
getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
/* set default for containers */
lyd_cont_set_dflt(node);
lyd_np_cont_dflt_set(node);
}
cleanup:
@ -1731,13 +1874,15 @@ lyd_validate_node_ext(struct lyd_node *node, struct ly_set *ext_node)
* @param[in,out] ext_node Set with nodes with extensions to validate.
* @param[in,out] ext_val Set for parsed extension data to validate.
* @param[in] val_opts Validation options.
* @param[in] int_opts Internal parser options.
* @param[in,out] getnext_ht Getnext HT to use.
* @param[in,out] diff Validation diff.
* @return LY_ERR value.
*/
static LY_ERR
lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_set *node_types,
struct ly_set *meta_types, struct ly_set *ext_node, struct ly_set *ext_val, uint32_t val_opts,
struct lyd_node **diff)
uint32_t int_opts, struct ly_ht *getnext_ht, struct lyd_node **diff)
{
LY_ERR r, rc = LY_SUCCESS;
const struct lyd_meta *meta;
@ -1771,7 +1916,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
} else if (node->schema->nodetype & LYD_NODE_INNER) {
/* new node validation, autodelete */
r = lyd_validate_new(lyd_node_child_p(node), node->schema, NULL, val_opts, diff);
r = lyd_validate_new(lyd_node_child_p(node), node->schema, NULL, NULL, val_opts, int_opts, getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
/* add nested defaults */
@ -1782,7 +1927,7 @@ lyd_validate_subtree(struct lyd_node *root, struct ly_set *node_when, struct ly_
if (val_opts & LYD_VALIDATE_NO_DEFAULTS) {
impl_opts |= LYD_IMPLICIT_NO_DEFAULTS;
}
r = lyd_new_implicit_r(node, lyd_node_child_p(node), NULL, NULL, NULL, NULL, NULL, impl_opts, diff);
r = lyd_new_implicit(node, lyd_node_child_p(node), NULL, NULL, NULL, NULL, NULL, impl_opts, getnext_ht, diff);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
}
@ -1814,6 +1959,7 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru
const struct lys_module *mod;
struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0};
uint32_t i = 0, impl_opts;
struct ly_ht *getnext_ht = NULL;
assert(tree && ctx);
assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) ||
@ -1844,8 +1990,13 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru
first2 = &first;
}
/* create the getnext hash table for this module */
r = lyd_val_getnext_ht_new(&getnext_ht);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
/* validate new top-level nodes of this module, autodelete */
r = lyd_validate_new(first2, *first2 ? lysc_data_parent((*first2)->schema) : NULL, mod, val_opts, diff);
r = lyd_validate_new(first2, *first2 ? lysc_data_parent((*first2)->schema) : NULL, mod, NULL, val_opts, 0,
getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
/* add all top-level defaults for this module, if going to validate subtree, do not add into unres sets
@ -1857,9 +2008,15 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru
if (val_opts & LYD_VALIDATE_NO_DEFAULTS) {
impl_opts |= LYD_IMPLICIT_NO_DEFAULTS;
}
r = lyd_new_implicit_r(lyd_parent(*first2), first2, NULL, mod, validate_subtree ? NULL : node_when_p,
validate_subtree ? NULL : node_types_p, validate_subtree ? NULL : ext_node_p, impl_opts, diff);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
if (validate_subtree) {
r = lyd_new_implicit(lyd_parent(*first2), first2, NULL, mod, NULL, NULL, NULL, impl_opts, getnext_ht, diff);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
} else {
/* descendants will not be validated, create them all */
r = lyd_new_implicit_r(lyd_parent(*first2), first2, NULL, mod, node_when_p, node_types_p, ext_node_p,
impl_opts, getnext_ht, diff);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
}
/* our first module node pointer may no longer be the first */
first = *first2;
@ -1878,7 +2035,7 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru
}
r = lyd_validate_subtree(iter, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p,
val_opts, diff);
val_opts, 0, getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
}
@ -1890,9 +2047,13 @@ lyd_validate(struct lyd_node **tree, const struct lys_module *module, const stru
if (!(val_opts & LYD_VALIDATE_NOT_FINAL)) {
/* perform final validation that assumes the data tree is final */
r = lyd_validate_final_r(*first2, NULL, NULL, mod, val_opts, 0, 0);
r = lyd_validate_final_r(*first2, NULL, NULL, mod, NULL, val_opts, 0, 0, getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
/* free the getnext hash table */
lyht_free(getnext_ht, lyd_val_getnext_ht_free_cb);
getnext_ht = NULL;
}
cleanup:
@ -1901,6 +2062,63 @@ cleanup:
ly_set_erase(&meta_types, NULL);
ly_set_erase(&ext_node, free);
ly_set_erase(&ext_val, free);
lyd_val_getnext_ht_free(getnext_ht);
return rc;
}
LY_ERR
lyd_validate_ext(struct lyd_node **tree, const struct lysc_ext_instance *ext, uint32_t val_opts,
ly_bool validate_subtree, struct ly_set *node_when_p, struct ly_set *node_types_p, struct ly_set *meta_types_p,
struct ly_set *ext_node_p, struct ly_set *ext_val_p, struct lyd_node **diff)
{
LY_ERR r, rc = LY_SUCCESS;
struct lyd_node *iter;
struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0};
struct ly_ht *getnext_ht = NULL;
assert(tree);
assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) ||
(!node_when_p && !node_types_p && !meta_types_p && !ext_node_p && !ext_val_p));
if (!node_when_p) {
node_when_p = &node_when;
node_types_p = &node_types;
meta_types_p = &meta_types;
ext_node_p = &ext_node;
ext_val_p = &ext_val;
}
/* create the getnext hash table for these data */
r = lyd_val_getnext_ht_new(&getnext_ht);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
if (validate_subtree) {
/* process nested nodes */
LY_LIST_FOR(*tree, iter) {
r = lyd_validate_subtree(iter, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p,
val_opts, 0, getnext_ht, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
}
/* finish incompletely validated terminal values/attributes and when conditions */
r = lyd_validate_unres(tree, NULL, LYD_TYPE_DATA_YANG, node_when_p, 0, node_types_p, meta_types_p,
ext_node_p, ext_val_p, val_opts, diff);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
if (!(val_opts & LYD_VALIDATE_NOT_FINAL)) {
/* perform final validation that assumes the data tree is final */
r = lyd_validate_final_r(*tree, NULL, NULL, NULL, ext, val_opts, 0, 0, getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
}
cleanup:
ly_set_erase(&node_when, NULL);
ly_set_erase(&node_types, NULL);
ly_set_erase(&meta_types, NULL);
ly_set_erase(&ext_node, free);
ly_set_erase(&ext_val, free);
lyd_val_getnext_ht_free(getnext_ht);
return rc;
}
@ -1938,6 +2156,7 @@ lyd_validate_module_final(struct lyd_node *tree, const struct lys_module *module
struct lyd_node *first;
const struct lys_module *mod;
uint32_t i = 0;
struct ly_ht *getnext_ht = NULL;
LY_CHECK_ARG_RET(NULL, module, !(val_opts & (LYD_VALIDATE_PRESENT | LYD_VALIDATE_NOT_FINAL)), LY_EINVAL);
LY_CHECK_CTX_EQUAL_RET(tree ? LYD_CTX(tree) : NULL, module->ctx, LY_EINVAL);
@ -1946,11 +2165,16 @@ lyd_validate_module_final(struct lyd_node *tree, const struct lys_module *module
mod = lyd_mod_next_module(tree, module, module->ctx, &i, &first);
assert(mod);
/* create the getnext hash table for this module */
r = lyd_val_getnext_ht_new(&getnext_ht);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
/* perform final validation that assumes the data tree is final */
r = lyd_validate_final_r(first, NULL, NULL, mod, val_opts, 0, 0);
r = lyd_validate_final_r(first, NULL, NULL, mod, NULL, val_opts, 0, 0, getnext_ht);
LY_VAL_ERR_GOTO(r, rc = r, val_opts, cleanup);
cleanup:
lyd_val_getnext_ht_free(getnext_ht);
return rc;
}
@ -2043,6 +2267,7 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc
LY_ERR rc = LY_SUCCESS;
struct lyd_node *tree_sibling, *tree_parent, *op_subtree, *op_parent, *op_sibling_before, *op_sibling_after, *child;
struct ly_set node_types = {0}, meta_types = {0}, node_when = {0}, ext_node = {0}, ext_val = {0};
struct ly_ht *getnext_ht = NULL;
assert(op_tree && op_node);
assert((node_when_p && node_types_p && meta_types_p && ext_node_p && ext_val_p) ||
@ -2068,23 +2293,34 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc
dep_tree = tree_sibling;
}
if (int_opts & LYD_INTOPT_REPLY) {
/* add output children defaults */
rc = lyd_new_implicit_r(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p,
ext_node_p, LYD_IMPLICIT_OUTPUT, diff);
LY_CHECK_GOTO(rc, cleanup);
/* create the getnext hash table for this module */
rc = lyd_val_getnext_ht_new(&getnext_ht);
LY_CHECK_GOTO(rc, cleanup);
if (int_opts & LYD_INTOPT_REPLY) {
if (validate_subtree) {
/* add output children defaults */
rc = lyd_new_implicit(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p,
ext_node_p, LYD_IMPLICIT_OUTPUT, getnext_ht, diff);
LY_CHECK_GOTO(rc, cleanup);
/* skip validating the operation itself, go to children directly */
LY_LIST_FOR(lyd_child(op_node), child) {
rc = lyd_validate_subtree(child, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, diff);
rc = lyd_validate_subtree(child, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0,
int_opts, getnext_ht, diff);
LY_CHECK_GOTO(rc, cleanup);
}
} else {
/* add output children defaults and their descendants */
rc = lyd_new_implicit_r(op_node, lyd_node_child_p(op_node), NULL, NULL, node_when_p, node_types_p,
ext_node_p, LYD_IMPLICIT_OUTPUT, getnext_ht, diff);
LY_CHECK_GOTO(rc, cleanup);
}
} else {
if (validate_subtree) {
/* prevalidate whole operation subtree */
rc = lyd_validate_subtree(op_node, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0, diff);
rc = lyd_validate_subtree(op_node, node_when_p, node_types_p, meta_types_p, ext_node_p, ext_val_p, 0,
int_opts, getnext_ht, diff);
LY_CHECK_GOTO(rc, cleanup);
}
}
@ -2099,7 +2335,8 @@ _lyd_validate_op(struct lyd_node *op_tree, struct lyd_node *op_node, const struc
LY_CHECK_GOTO(rc = lyd_validate_must(op_node, 0, int_opts, LYXP_IGNORE_WHEN), cleanup);
/* final validation of all the descendants */
rc = lyd_validate_final_r(lyd_child(op_node), op_node, op_node->schema, NULL, 0, int_opts, LYXP_IGNORE_WHEN);
rc = lyd_validate_final_r(lyd_child(op_node), op_node, op_node->schema, NULL, NULL, 0, int_opts, LYXP_IGNORE_WHEN,
getnext_ht);
LY_CHECK_GOTO(rc, cleanup);
cleanup:
@ -2120,6 +2357,7 @@ cleanup:
ly_set_erase(&meta_types, NULL);
ly_set_erase(&ext_node, free);
ly_set_erase(&ext_val, free);
lyd_val_getnext_ht_free(getnext_ht);
return rc;
}