@@ -512,25 +512,28 @@ ly_path_parse_predicate(const struct ly_ctx *ctx, const struct lysc_node *cur_no
512512 *
513513 * @param[in] ctx libyang context.
514514 * @param[in] cur_node Current (original context) node.
515- * @param[in] prev_ctx_node Previous context node.
515+ * @param[in] ctx_node Context node.
516516 * @param[in] expr Parsed path.
517517 * @param[in] tok_idx Index in @p expr.
518518 * @param[in] format Format of the path.
519519 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
520- * @param[in] getnext_opts Options to be used for ::lys_getnext() calls.
520+ * @param[in] is_xpath Set if the schema node is part of any XPath expression.
521+ * @param[in] is_output Set if the schema node is in an output of an operation instead of input.
521522 * @param[out] snode Resolved schema node.
522523 * @param[out] ext Optional extension instance of @p snode, if any.
523524 * @return LY_ERR value.
524525 */
525526static LY_ERR
526- ly_path_compile_snode (const struct ly_ctx * ctx , const struct lysc_node * cur_node , const struct lysc_node * prev_ctx_node ,
527+ ly_path_compile_snode (const struct ly_ctx * ctx , const struct lysc_node * cur_node , const struct lysc_node * ctx_node ,
527528 const struct lyxp_expr * expr , uint32_t tok_idx , LY_VALUE_FORMAT format , void * prefix_data ,
528- uint32_t getnext_opts , const struct lysc_node * * snode , struct lysc_ext_instance * * ext )
529+ ly_bool is_xpath , ly_bool is_output , const struct lysc_node * * snode , struct lysc_ext_instance * * ext )
529530{
530531 LY_ERR rc = LY_SUCCESS , r ;
531532 const char * pref , * name ;
532533 size_t len , name_len ;
533534 const struct lys_module * mod ;
535+ const struct lysc_node * node = NULL ;
536+ uint32_t getnext_opts = 0 ;
534537
535538 assert (expr -> tokens [tok_idx ] == LYXP_TOKEN_NAMETEST );
536539
@@ -556,25 +559,51 @@ ly_path_compile_snode(const struct ly_ctx *ctx, const struct lysc_node *cur_node
556559 name_len = expr -> tok_len [tok_idx ];
557560 }
558561
559- /* find schema node */
560- r = lys_find_child_node (prev_ctx_node ? prev_ctx_node -> module -> ctx : ctx , NULL , prev_ctx_node , pref , len , format ,
561- prefix_data , name , name_len , getnext_opts , snode , ext );
562- if (r == LY_ENOT ) {
563- mod = lys_find_module (prev_ctx_node ? prev_ctx_node -> module -> ctx : ctx , prev_ctx_node , pref , len , format ,
564- prefix_data );
565- if (!mod ) {
566- LOGVAL_PATH (ctx , cur_node , prev_ctx_node , LYVE_XPATH ,
567- "No module connected with the prefix \"%.*s\" found (prefix format %s)." , (int )len , pref ,
568- ly_format2str (format ));
569- } else if (!mod -> implemented ) {
570- LOGVAL_PATH (ctx , cur_node , prev_ctx_node , LYVE_XPATH , "Not implemented module \"%s\" in path." , mod -> name );
571- } else {
572- LOGVAL_PATH (ctx , cur_node , prev_ctx_node , LYVE_XPATH , "Not found node \"%.*s\" in path." , (int )name_len , name );
573- }
562+ /* find the module */
563+ mod = lys_find_module (ctx_node ? ctx_node -> module -> ctx : ctx , ctx_node , pref , len , format , prefix_data );
564+ if (!mod ) {
565+ LOGVAL_PATH (ctx , cur_node , ctx_node , LYVE_XPATH ,
566+ "No module connected with the prefix \"%.*s\" found (prefix format %s)." , (int )len , pref ,
567+ ly_format2str (format ));
568+ rc = LY_ENOTFOUND ;
569+ goto cleanup ;
570+ } else if (!mod -> implemented ) {
571+ LOGVAL_PATH (ctx , cur_node , ctx_node , LYVE_XPATH , "Not implemented module \"%s\" in path." , mod -> name );
574572 rc = LY_ENOTFOUND ;
575573 goto cleanup ;
576- } else if (r ) {
577- rc = r ;
574+ }
575+
576+ /* set getnext options */
577+ if (is_output ) {
578+ getnext_opts |= LYS_GETNEXT_OUTPUT ;
579+ }
580+
581+ /* find a standard schema node */
582+ while ((node = lys_getnext (node , ctx_node , mod -> compiled , getnext_opts ))) {
583+ if (node -> module != mod ) {
584+ continue ;
585+ }
586+
587+ if (!ly_strncmp (node -> name , name , name_len )) {
588+ break ;
589+ }
590+ }
591+
592+ if (!node ) {
593+ /* find a node in an extension */
594+ r = lys_find_child_node_ext (NULL , mod , NULL , ctx_node , pref , len , format , prefix_data , name , name_len , is_xpath ,
595+ & node , ext );
596+ if (r && (r != LY_ENOT )) {
597+ rc = r ;
598+ goto cleanup ;
599+ }
600+ }
601+
602+ if (node ) {
603+ * snode = node ;
604+ } else {
605+ LOGVAL_PATH (ctx , cur_node , ctx_node , LYVE_XPATH , "Not found node \"%.*s\" in path." , (int )name_len , name );
606+ rc = LY_ENOTFOUND ;
578607 goto cleanup ;
579608 }
580609
@@ -617,7 +646,7 @@ ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lysc_node *cur_
617646
618647 do {
619648 /* NameTest, find the key */
620- rc = ly_path_compile_snode (ctx , cur_node , ctx_node , expr , * tok_idx , format , prefix_data , 0 , & key , NULL );
649+ rc = ly_path_compile_snode (ctx , cur_node , ctx_node , expr , * tok_idx , format , prefix_data , 0 , 0 , & key , NULL );
621650 LY_CHECK_GOTO (rc , cleanup );
622651 if ((key -> nodetype != LYS_LEAF ) || !(key -> flags & LYS_KEY )) {
623652 LOGVAL_PATH (ctx , cur_node , ctx_node , LYVE_XPATH , "Key expected instead of %s \"%s\" in path." ,
@@ -796,7 +825,7 @@ ly_path_compile_predicate_leafref(const struct lysc_node *ctx_node, const struct
796825
797826 do {
798827 /* NameTest, find the key */
799- rc = ly_path_compile_snode (ctx , cur_node , ctx_node , expr , * tok_idx , format , prefix_data , 0 , & key , NULL );
828+ rc = ly_path_compile_snode (ctx , cur_node , ctx_node , expr , * tok_idx , format , prefix_data , 0 , 0 , & key , NULL );
800829 LY_CHECK_GOTO (rc , cleanup );
801830 if ((key -> nodetype != LYS_LEAF ) || !(key -> flags & LYS_KEY )) {
802831 LOGVAL_PATH (ctx , cur_node , ctx_node , LYVE_XPATH , "Key expected instead of %s \"%s\" in path." ,
@@ -853,7 +882,7 @@ ly_path_compile_predicate_leafref(const struct lysc_node *ctx_node, const struct
853882
854883 /* NameTest */
855884 assert (expr -> tokens [* tok_idx ] == LYXP_TOKEN_NAMETEST );
856- rc = ly_path_compile_snode (ctx , cur_node , node , expr , * tok_idx , format , prefix_data , 0 , & node2 , NULL );
885+ rc = ly_path_compile_snode (ctx , cur_node , node , expr , * tok_idx , format , prefix_data , 0 , 0 , & node2 , NULL );
857886 LY_CHECK_GOTO (rc , cleanup );
858887 node = node2 ;
859888 ++ (* tok_idx );
@@ -1151,7 +1180,7 @@ _ly_path_compile(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, con
11511180 struct ly_path * * path )
11521181{
11531182 LY_ERR rc = LY_SUCCESS ;
1154- uint32_t tok_idx = 0 , getnext_opts ;
1183+ uint32_t tok_idx = 0 ;
11551184 const struct lysc_node * node2 , * cur_node , * op , * prev_ctx_node = NULL ;
11561185 struct ly_path * p = NULL ;
11571186 struct lysc_ext_instance * ext = NULL ;
@@ -1174,14 +1203,6 @@ _ly_path_compile(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, con
11741203 /* remember original context node */
11751204 cur_node = ctx_node ;
11761205
1177- if (oper == LY_PATH_OPER_OUTPUT ) {
1178- getnext_opts = LYS_GETNEXT_OUTPUT ;
1179- } else if (is_xpath ) {
1180- getnext_opts = LYS_GETNEXT_EXT_XPATH ;
1181- } else {
1182- getnext_opts = 0 ;
1183- }
1184-
11851206 if (lref && (ly_ctx_get_options (ctx ) & LY_CTX_LEAFREF_EXTENDED ) &&
11861207 (expr -> tokens [tok_idx ] == LYXP_TOKEN_FUNCNAME )) {
11871208 /* deref function */
@@ -1235,7 +1256,7 @@ _ly_path_compile(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, con
12351256
12361257 /* get schema node */
12371258 LY_CHECK_GOTO (rc = ly_path_compile_snode (ctx , cur_node , ctx_node , expr , tok_idx , format , prefix_data ,
1238- getnext_opts , & node2 , & ext ), cleanup );
1259+ is_xpath , ( oper == LY_PATH_OPER_OUTPUT ) , & node2 , & ext ), cleanup );
12391260 ++ tok_idx ;
12401261 if ((op && (node2 -> nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF )) && (node2 != op ))) {
12411262 LOGVAL_PATH (ctx , cur_node , prev_ctx_node , LYVE_XPATH , "Not found node \"%s\" in path." , node2 -> name );
0 commit comments