summaryrefslogtreecommitdiffstats
path: root/src/validation.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-17 02:59:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-17 02:59:54 +0000
commit5bc4f4fb5b383ca32b382b6c0d09602346064414 (patch)
treec741e5844c2815679107d648a15841653b9b01a5 /src/validation.c
parentAdding upstream version 3.1.0+dfsg. (diff)
downloadlibyang3-upstream.tar.xz
libyang3-upstream.zip
Adding upstream version 3.4.2+dfsg.upstream/3.4.2+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/validation.c')
-rw-r--r--src/validation.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/validation.c b/src/validation.c
index 501dd69..a950c54 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -197,13 +197,14 @@ lyd_validate_node_when(const struct lyd_node *tree, const struct lyd_node *node,
* @param[in] np_cont_diff Whether to put NP container into diff or only its children.
* @param[in,out] node Optional current iteration node, update it if it is deleted.
* @param[in,out] node_when Optional set with nodes with "when" conditions, may be removed from.
+ * @param[in,out] node_types Optional set with unresolved type nodes, may be removed from.
* @param[in,out] diff Validation diff.
* @return 1 if @p node auto-deleted and updated to its next sibling.
* @return 0 if @p node was not auto-deleted.
*/
static ly_bool
lyd_validate_autodel_node_del(struct lyd_node **first, struct lyd_node *del, const struct lys_module *mod,
- int np_cont_diff, struct lyd_node **node, struct ly_set *node_types, struct lyd_node **diff)
+ int np_cont_diff, struct lyd_node **node, struct ly_set *node_when, struct ly_set *node_types, struct lyd_node **diff)
{
struct lyd_node *iter;
ly_bool node_autodel = 0;
@@ -228,6 +229,16 @@ lyd_validate_autodel_node_del(struct lyd_node **first, struct lyd_node *del, con
}
}
+ if (node_when && node_when->count) {
+ /* remove nested from node_when set */
+ LYD_TREE_DFS_BEGIN(del, iter) {
+ if ((del != iter) && ly_set_contains(node_when, iter, &idx)) {
+ ly_set_rm_index(node_when, idx, NULL);
+ }
+ LYD_TREE_DFS_END(del, iter);
+ }
+ }
+
if (node_types && node_types->count) {
/* remove from node_types set */
LYD_TREE_DFS_BEGIN(del, iter) {
@@ -264,7 +275,7 @@ lyd_validate_unres_when(struct lyd_node **tree, const struct lys_module *mod, st
uint32_t xpath_options, struct ly_set *node_types, struct lyd_node **diff)
{
LY_ERR rc = LY_SUCCESS, r;
- uint32_t i;
+ uint32_t i, count;
const struct lysc_when *disabled;
struct lyd_node *node = NULL;
@@ -285,7 +296,12 @@ lyd_validate_unres_when(struct lyd_node **tree, const struct lys_module *mod, st
/* when false */
if (node->flags & LYD_WHEN_TRUE) {
/* autodelete */
- lyd_validate_autodel_node_del(tree, node, mod, 1, NULL, node_types, diff);
+ count = node_when->count;
+ lyd_validate_autodel_node_del(tree, node, mod, 1, NULL, node_when, node_types, diff);
+ if (count > node_when->count) {
+ /* nested nodes removed, we lost the index */
+ ly_set_contains(node_when, node, &i);
+ }
} else if (val_opts & LYD_VALIDATE_OPERATIONAL) {
/* only a warning */
LOGWRN(LYD_CTX(node), "When condition \"%s\" not satisfied.", disabled->cond->expr);
@@ -640,7 +656,7 @@ lyd_validate_autodel_leaflist_dflt(struct lyd_node **first, struct lyd_node **no
LYD_LIST_FOR_INST_SAFE(*first, schema, next, iter) {
if (iter->flags & LYD_DEFAULT) {
/* default instance found, remove it */
- if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
+ if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, NULL, diff)) {
node_autodel = 1;
}
}
@@ -685,7 +701,7 @@ lyd_validate_autodel_cont_leaf_dflt(struct lyd_node **first, struct lyd_node **n
LYD_LIST_FOR_INST_SAFE(*first, schema, next, iter) {
if (iter->flags & LYD_DEFAULT) {
/* default instance, remove it */
- if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
+ if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, NULL, diff)) {
node_autodel = 1;
}
}
@@ -695,7 +711,7 @@ lyd_validate_autodel_cont_leaf_dflt(struct lyd_node **first, struct lyd_node **n
LYD_LIST_FOR_INST(*first, schema, iter) {
if ((iter->flags & LYD_DEFAULT) && !(iter->flags & LYD_NEW)) {
/* old default instance, remove it */
- if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
+ if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, NULL, diff)) {
node_autodel = 1;
}
break;
@@ -753,7 +769,7 @@ lyd_validate_autodel_case_dflt(struct lyd_node **first, struct lyd_node **node,
if (!iter) {
/* there are only default nodes of the case meaning it does not exist and neither should any default nodes
* of the case, remove this one default node */
- if (lyd_validate_autodel_node_del(first, *node, mod, 0, node, NULL, diff)) {
+ if (lyd_validate_autodel_node_del(first, *node, mod, 0, node, NULL, NULL, diff)) {
node_autodel = 1;
}
}