@@ -4052,9 +4052,8 @@ resolve_instid_predicate(const struct lys_module *prev_mod, const char *pred, st
40524052int
40534053lys_check_xpath (struct lys_node * node , int check_place , int warn_on_fwd_ref )
40544054{
4055- struct lys_node * parent , * elem ;
4055+ struct lys_node * parent ;
40564056 struct lyxp_set set ;
4057- uint32_t i ;
40584057 int ret ;
40594058
40604059 if (check_place ) {
@@ -4077,33 +4076,11 @@ lys_check_xpath(struct lys_node *node, int check_place, int warn_on_fwd_ref)
40774076 }
40784077 }
40794078
4080- ret = lyxp_node_atomize (node , & set , warn_on_fwd_ref );
4079+ ret = lyxp_node_atomize (node , & set , warn_on_fwd_ref , 1 );
40814080 if (ret == -1 ) {
40824081 return -1 ;
40834082 }
40844083
4085- for (parent = node ; parent && !(parent -> nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF )); parent = lys_parent (parent ));
4086-
4087- for (i = 0 ; i < set .used ; ++ i ) {
4088- /* skip roots'n'stuff */
4089- if (set .val .snodes [i ].type == LYXP_NODE_ELEM ) {
4090- /* XPath expression cannot reference "lower" status than the node that has the definition */
4091- if (lyp_check_status (node -> flags , lys_node_module (node ), node -> name , set .val .snodes [i ].snode -> flags ,
4092- lys_node_module (set .val .snodes [i ].snode ), set .val .snodes [i ].snode -> name , node )) {
4093- return -1 ;
4094- }
4095-
4096- if (parent ) {
4097- for (elem = set .val .snodes [i ].snode ; elem && (elem != parent ); elem = lys_parent (elem ));
4098- if (!elem ) {
4099- /* not in node's RPC or notification subtree, set the flag */
4100- node -> flags |= LYS_XPATH_DEP ;
4101- break ;
4102- }
4103- }
4104- }
4105- }
4106-
41074084 free (set .val .snodes );
41084085 return ret ;
41094086}
@@ -5554,7 +5531,6 @@ resolve_list_keys(struct lys_node_list *list, const char *keys_str)
55545531static int
55555532resolve_must (struct lyd_node * node , int inout_parent , int ignore_fail )
55565533{
5557- int node_flags ;
55585534 uint8_t i , must_size ;
55595535 struct lys_node * schema ;
55605536 struct lys_restr * must ;
@@ -5574,8 +5550,6 @@ resolve_must(struct lyd_node *node, int inout_parent, int ignore_fail)
55745550 must_size = ((struct lys_node_inout * )schema )-> must_size ;
55755551 must = ((struct lys_node_inout * )schema )-> must ;
55765552
5577- node_flags = schema -> flags ;
5578-
55795553 /* context node is the RPC/action */
55805554 node = node -> parent ;
55815555 if (!(node -> schema -> nodetype & (LYS_RPC | LYS_ACTION ))) {
@@ -5613,8 +5587,6 @@ resolve_must(struct lyd_node *node, int inout_parent, int ignore_fail)
56135587 must_size = 0 ;
56145588 break ;
56155589 }
5616-
5617- node_flags = node -> schema -> flags ;
56185590 }
56195591
56205592 for (i = 0 ; i < must_size ; ++ i ) {
@@ -5625,7 +5597,7 @@ resolve_must(struct lyd_node *node, int inout_parent, int ignore_fail)
56255597 lyxp_set_cast (& set , LYXP_SET_BOOLEAN , node , lyd_node_module (node ), LYXP_MUST );
56265598
56275599 if (!set .val .bool ) {
5628- if ((ignore_fail == 1 ) || ((node_flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
5600+ if ((ignore_fail == 1 ) || ((must [ i ]. flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
56295601 LOGVRB ("Must condition \"%s\" not satisfied, but it is not required." , must [i ].expr );
56305602 } else {
56315603 LOGVAL (LYE_NOMUST , LY_VLOG_LYD , node , must [i ].expr );
@@ -5979,12 +5951,12 @@ resolve_applies_when(const struct lys_node *schema, int mode, const struct lys_n
59795951 *
59805952 * @return
59815953 * -1 - error, ly_errno is set
5982- * 0 - true "when" statement
5983- * 0, ly_vecode = LYVE_NOWHEN - false "when" statement
5954+ * 0 - all "when" statements true
5955+ * 0, ly_vecode = LYVE_NOWHEN - some "when" statement false, returned in failed_when
59845956 * 1, ly_vecode = LYVE_INWHEN - nodes needed to resolve are conditional and not yet resolved (under another "when")
59855957 */
59865958int
5987- resolve_when (struct lyd_node * node , int ignore_fail )
5959+ resolve_when (struct lyd_node * node , int ignore_fail , struct lys_when * * failed_when )
59885960{
59895961 struct lyd_node * ctx_node = NULL , * unlinked_nodes , * tmp_node ;
59905962 struct lys_node * sparent ;
@@ -6012,11 +5984,15 @@ resolve_when(struct lyd_node *node, int ignore_fail)
60125984 lyxp_set_cast (& set , LYXP_SET_BOOLEAN , node , lyd_node_module (node ), LYXP_WHEN );
60135985 if (!set .val .bool ) {
60145986 node -> when_status |= LYD_WHEN_FALSE ;
6015- if ((ignore_fail == 1 ) || ((node -> schema -> flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
5987+ if ((ignore_fail == 1 )
5988+ || ((((struct lys_node_container * )node -> schema )-> when -> flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
60165989 LOGVRB ("When condition \"%s\" is not satisfied, but it is not required." ,
60175990 ((struct lys_node_container * )node -> schema )-> when -> cond );
60185991 } else {
60195992 LOGVAL (LYE_NOWHEN , LY_VLOG_LYD , node , ((struct lys_node_container * )node -> schema )-> when -> cond );
5993+ if (failed_when ) {
5994+ * failed_when = ((struct lys_node_container * )node -> schema )-> when ;
5995+ }
60205996 goto cleanup ;
60215997 }
60225998 }
@@ -6066,12 +6042,16 @@ resolve_when(struct lyd_node *node, int ignore_fail)
60666042
60676043 lyxp_set_cast (& set , LYXP_SET_BOOLEAN , ctx_node , lys_node_module (sparent ), LYXP_WHEN );
60686044 if (!set .val .bool ) {
6069- if ((ignore_fail == 1 ) || ((sparent -> flags & LYS_XPATH_DEP ) || (ignore_fail == 2 ))) {
6045+ if ((ignore_fail == 1 )
6046+ || ((((struct lys_node_uses * )sparent )-> when -> flags & LYS_XPATH_DEP ) || (ignore_fail == 2 ))) {
60706047 LOGVRB ("When condition \"%s\" is not satisfied, but it is not required." ,
60716048 ((struct lys_node_uses * )sparent )-> when -> cond );
60726049 } else {
60736050 node -> when_status |= LYD_WHEN_FALSE ;
60746051 LOGVAL (LYE_NOWHEN , LY_VLOG_LYD , node , ((struct lys_node_uses * )sparent )-> when -> cond );
6052+ if (failed_when ) {
6053+ * failed_when = ((struct lys_node_uses * )sparent )-> when ;
6054+ }
60756055 goto cleanup ;
60766056 }
60776057 }
@@ -6120,11 +6100,15 @@ resolve_when(struct lyd_node *node, int ignore_fail)
61206100 lyxp_set_cast (& set , LYXP_SET_BOOLEAN , ctx_node , lys_node_module (sparent -> parent ), LYXP_WHEN );
61216101 if (!set .val .bool ) {
61226102 node -> when_status |= LYD_WHEN_FALSE ;
6123- if ((ignore_fail == 1 ) || ((sparent -> parent -> flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
6103+ if ((ignore_fail == 1 )
6104+ || ((((struct lys_node_augment * )sparent -> parent )-> when -> flags & LYS_XPATH_DEP ) && (ignore_fail == 2 ))) {
61246105 LOGVRB ("When condition \"%s\" is not satisfied, but it is not required." ,
61256106 ((struct lys_node_augment * )sparent -> parent )-> when -> cond );
61266107 } else {
61276108 LOGVAL (LYE_NOWHEN , LY_VLOG_LYD , node , ((struct lys_node_augment * )sparent -> parent )-> when -> cond );
6109+ if (failed_when ) {
6110+ * failed_when = ((struct lys_node_augment * )sparent -> parent )-> when ;
6111+ }
61286112 goto cleanup ;
61296113 }
61306114 }
@@ -7586,7 +7570,7 @@ resolve_union(struct lyd_node_leaf_list *leaf, struct lys_type *type, int store,
75867570 * @return EXIT_SUCCESS on success, EXIT_FAILURE on forward reference, -1 on error.
75877571 */
75887572int
7589- resolve_unres_data_item (struct lyd_node * node , enum UNRES_ITEM type , int ignore_fail )
7573+ resolve_unres_data_item (struct lyd_node * node , enum UNRES_ITEM type , int ignore_fail , struct lys_when * * failed_when )
75907574{
75917575 int rc , req_inst , ext_dep ;
75927576 struct lyd_node_leaf_list * leaf ;
@@ -7661,7 +7645,7 @@ resolve_unres_data_item(struct lyd_node *node, enum UNRES_ITEM type, int ignore_
76617645 return resolve_union (leaf , & sleaf -> type , 1 , ignore_fail , NULL );
76627646
76637647 case UNRES_WHEN :
7664- if ((rc = resolve_when (node , ignore_fail ))) {
7648+ if ((rc = resolve_when (node , ignore_fail , failed_when ))) {
76657649 return rc ;
76667650 }
76677651 break ;
@@ -7737,6 +7721,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
77377721 uint32_t i , j , first , resolved , del_items , stmt_count ;
77387722 int rc , progress , ignore_fail ;
77397723 struct lyd_node * parent ;
7724+ struct lys_when * when ;
77407725
77417726 assert (root );
77427727 assert (unres );
@@ -7791,12 +7776,12 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
77917776 continue ;
77927777 }
77937778
7794- rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail );
7779+ rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail , & when );
77957780 if (!rc ) {
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 ) */
7781+ /* finish with error/delete the node only if when was false, an external dependency was not required,
7782+ * or it was not provided (the flag would not be passed down otherwise, checked in upper functions ) */
77987783 if ((unres -> node [i ]-> when_status & LYD_WHEN_FALSE )
7799- && (!(unres -> node [ i ] -> schema -> flags & LYS_XPATH_DEP ) || !(options & LYD_OPT_NOEXTDEPS ))) {
7784+ && (!(when -> flags & LYS_XPATH_DEP ) || !(options & LYD_OPT_NOEXTDEPS ))) {
78007785 if ((options & LYD_OPT_NOAUTODEL ) && !unres -> node [i ]-> dflt ) {
78017786 /* false when condition */
78027787 ly_vlog_hide (0 );
@@ -7859,7 +7844,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
78597844 } else if (rc == -1 ) {
78607845 ly_vlog_hide (0 );
78617846 /* print only this last error */
7862- resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail );
7847+ resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail , NULL );
78637848 return -1 ;
78647849 } /* else forward reference */
78657850 }
@@ -7905,7 +7890,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
79057890 stmt_count ++ ;
79067891 }
79077892
7908- rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail );
7893+ rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail , NULL );
79097894 if (!rc ) {
79107895 unres -> type [i ] = UNRES_RESOLVED ;
79117896 ly_err_clean (1 );
@@ -7914,7 +7899,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
79147899 } else if (rc == -1 ) {
79157900 ly_vlog_hide (0 );
79167901 /* print only this last error */
7917- resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail );
7902+ resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail , NULL );
79187903 return -1 ;
79197904 } /* else forward reference */
79207905 }
@@ -7937,7 +7922,7 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
79377922 }
79387923 assert (!(options & LYD_OPT_TRUSTED ) || ((unres -> type [i ] != UNRES_MUST ) && (unres -> type [i ] != UNRES_MUST_INOUT )));
79397924
7940- rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail );
7925+ rc = resolve_unres_data_item (unres -> node [i ], unres -> type [i ], ignore_fail , NULL );
79417926 if (rc ) {
79427927 /* since when was already resolved, a forward reference is an error */
79437928 return -1 ;
0 commit comments