Skip to content

Commit e446b09

Browse files
committed
resolve BUGFIX do not delete false when data when not possible to check when
1 parent e746a50 commit e446b09

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/parser_xml.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem **root, int options, ...)
618618
LOGERR(LY_EINVAL, "%s: invalid parameter (variable arg const struct lyd_node *data_tree with LYD_OPT_NOSIBLINGS).", __func__);
619619
goto error;
620620
}
621+
} else if (options & LYD_OPT_NOEXTDEPS) {
622+
LOGERR(LY_EINVAL, "%s: invalid parameter (no variable arg const struct lyd_node *data_tree but LYD_OPT_NOEXTDEPS set).",
623+
__func__);
624+
goto error;
621625
}
622626
}
623627

src/resolve.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5974,6 +5974,8 @@ resolve_applies_when(const struct lys_node *schema, int mode, const struct lys_n
59745974
* Logs directly.
59755975
*
59765976
* @param[in] node Data node, whose conditional reference, if such, is being decided.
5977+
* @param[in] ignore_fail 1 if when does not have to be satisfied, 2 if it does not have to be satisfied
5978+
* only when requiring external dependencies.
59775979
*
59785980
* @return
59795981
* -1 - error, ly_errno is set
@@ -5982,7 +5984,7 @@ resolve_applies_when(const struct lys_node *schema, int mode, const struct lys_n
59825984
* 1, ly_vecode = LYVE_INWHEN - nodes needed to resolve are conditional and not yet resolved (under another "when")
59835985
*/
59845986
int
5985-
resolve_when(struct lyd_node *node, int *result, int ignore_fail)
5987+
resolve_when(struct lyd_node *node, int ignore_fail)
59865988
{
59875989
struct lyd_node *ctx_node = NULL, *unlinked_nodes, *tmp_node;
59885990
struct lys_node *sparent;
@@ -6139,15 +6141,6 @@ resolve_when(struct lyd_node *node, int *result, int ignore_fail)
61396141
cleanup:
61406142
/* free xpath set content */
61416143
lyxp_set_cast(&set, LYXP_SET_EMPTY, ctx_node ? ctx_node : node, NULL, 0);
6142-
6143-
if (result) {
6144-
if (node->when_status & LYD_WHEN_TRUE) {
6145-
*result = 1;
6146-
} else {
6147-
*result = 0;
6148-
}
6149-
}
6150-
61516144
return rc;
61526145
}
61536146

@@ -7668,7 +7661,7 @@ resolve_unres_data_item(struct lyd_node *node, enum UNRES_ITEM type, int ignore_
76687661
return resolve_union(leaf, &sleaf->type, 1, ignore_fail, NULL);
76697662

76707663
case UNRES_WHEN:
7671-
if ((rc = resolve_when(node, NULL, ignore_fail))) {
7664+
if ((rc = resolve_when(node, ignore_fail))) {
76727665
return rc;
76737666
}
76747667
break;
@@ -7786,7 +7779,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
77867779
parent = parent->parent) {
77877780
if (!parent->parent && (parent->when_status & LYD_WHEN_FALSE)) {
77887781
/* the parent node was already unlinked, do not resolve this node,
7789-
* it will be removed anyway, so just mark it as resolved
7782+
* it will be removed anyway, so just mark it as resolved
77907783
*/
77917784
unres->node[i]->when_status |= LYD_WHEN_FALSE;
77927785
unres->type[i] = UNRES_RESOLVED;
@@ -7800,7 +7793,10 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
78007793

78017794
rc = resolve_unres_data_item(unres->node[i], unres->type[i], ignore_fail);
78027795
if (!rc) {
7803-
if (unres->node[i]->when_status & LYD_WHEN_FALSE) {
7796+
/* finish with error/delete the node only if when was false, an external dependency was required,
7797+
* and it was not provided (the flag would not be passed down otherwise, checked in upper fucntions) */
7798+
if ((unres->node[i]->when_status & LYD_WHEN_FALSE)
7799+
&& (!(unres->node[i]->schema->flags & LYS_XPATH_DEP) || !(options & LYD_OPT_NOEXTDEPS))) {
78047800
if ((options & LYD_OPT_NOAUTODEL) && !unres->node[i]->dflt) {
78057801
/* false when condition */
78067802
ly_vlog_hide(0);

src/resolve.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ struct lys_ident *resolve_identref(struct lys_type *type, const char *ident_name
208208

209209
int resolve_unres_schema(struct lys_module *mod, struct unres_schema *unres);
210210

211-
int resolve_when(struct lyd_node *node, int *result, int ignore_fail);
211+
int resolve_when(struct lyd_node *node, int ignore_fail);
212212

213213
int unres_schema_add_str(struct lys_module *mod, struct unres_schema *unres, void *item, enum UNRES_ITEM type,
214214
const char *str);

src/tree_data.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ lyd_check_mandatory_data(struct lyd_node *root, struct lyd_node *last_parent,
7676
struct ly_set *instances, struct lys_node *schema, int options)
7777
{
7878
struct lyd_node *dummy, *current;
79-
int state;
8079
uint32_t limit;
8180

8281
if (!instances->number) {
@@ -104,9 +103,9 @@ lyd_check_mandatory_data(struct lyd_node *root, struct lyd_node *last_parent,
104103
}
105104
for (current = dummy; current; current = current->child) {
106105
ly_vlog_hide(1);
107-
resolve_when(current, &state, 0);
106+
resolve_when(current, 0);
108107
ly_vlog_hide(0);
109-
if (!state) {
108+
if (current->when_status & LYD_WHEN_FALSE) {
110109
/* when evaluates to false */
111110
lyd_free(dummy);
112111
ly_err_clean(1);
@@ -479,6 +478,10 @@ lyd_parse_data_(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int opt
479478
LOGERR(LY_EINVAL, "%s: invalid parameter (variable arg const struct lyd_node *data_tree with LYD_OPT_NOSIBLINGS).", __func__);
480479
return NULL;
481480
}
481+
} else if (options & LYD_OPT_NOEXTDEPS) {
482+
LOGERR(LY_EINVAL, "%s: invalid parameter (no variable arg const struct lyd_node *data_tree but LYD_OPT_NOEXTDEPS set).",
483+
__func__);
484+
return NULL;
482485
}
483486
}
484487

@@ -4170,6 +4173,10 @@ lyd_validate(struct lyd_node **node, int options, void *var_arg)
41704173

41714174
/* move it to the beginning */
41724175
for (; data_tree->prev->next; data_tree = data_tree->prev);
4176+
} else if (options & LYD_OPT_NOEXTDEPS) {
4177+
LOGERR(LY_EINVAL, "%s: invalid parameter (no variable arg const struct lyd_node *data_tree but LYD_OPT_NOEXTDEPS set).",
4178+
__func__);
4179+
goto cleanup;
41734180
}
41744181
}
41754182

0 commit comments

Comments
 (0)