Skip to content

Commit 2dc27c4

Browse files
committed
tree schema REFACTOR remove redundant ext-specific flags
1 parent 8892da8 commit 2dc27c4

14 files changed

Lines changed: 139 additions & 172 deletions

src/parser_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ lyd_parser_node_schema(const struct lyd_node *node)
182182
}
183183

184184
/* get schema node */
185-
schema = lys_find_child(NULL, schema, mod, LYD_NAME(iter), 0, 0);
185+
schema = lys_find_child(NULL, schema, mod, NULL, 0, LYD_NAME(iter), 0, 0);
186186

187187
/* move to the descendant */
188188
++i;

src/parser_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ lydjson_get_snode(struct lyd_json_ctx *lydctx, ly_bool is_attr, const char *pref
266266
}
267267

268268
/* try to find parent schema node */
269-
r = lys_find_child_node(parent ? LYD_CTX(parent) : lydctx->jsonctx->ctx, NULL, lyd_parser_node_schema(parent),
269+
r = lys_find_child_node(parent ? LYD_CTX(parent) : lydctx->jsonctx->ctx, lyd_parser_node_schema(parent), NULL,
270270
prefix, prefix_len, LY_VALUE_JSON, NULL, name, name_len, getnext_opts, snode, ext);
271271
LY_CHECK_RET(r && (r != LY_ENOT), r);
272272

src/parser_xml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ lydxml_subtree_get_snode(struct lyd_xml_ctx *lydctx, const struct lyd_node *pare
570570
*ext = NULL;
571571

572572
/* try to find parent schema node */
573-
r = lys_find_child_node(parent ? LYD_CTX(parent) : ctx, NULL, lyd_parser_node_schema(parent), prefix, prefix_len,
573+
r = lys_find_child_node(parent ? LYD_CTX(parent) : ctx, lyd_parser_node_schema(parent), NULL, prefix, prefix_len,
574574
LY_VALUE_XML, &lydctx->xmlctx->ns, name, name_len, getnext_opts, snode, ext);
575575
LY_CHECK_RET(r && (r != LY_ENOT), r);
576576

src/path.c

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
525526
static 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);

src/plugins_exts/schema_mount.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ schema_mount_get_content_id(struct lysc_ext_instance *ext, const struct lyd_node
434434
*content_id = NULL;
435435

436436
/* find the content-id node */
437-
snode = lys_find_child(NULL, ext_yl_data->schema, ext_yl_data->schema->module, "content-id", 0, 0);
437+
snode = lys_find_child(NULL, ext_yl_data->schema, ext_yl_data->schema->module, NULL, 0, "content-id", 0, 0);
438438
assert(snode);
439439

440440
/* get yang-library content-id */
@@ -946,7 +946,7 @@ schema_mount_snode_xpath(struct lysc_ext_instance *ext, const char *prefix, uint
946946
}
947947

948948
/* get the top-level schema node */
949-
*snode = lys_find_child(NULL, NULL, mod, name, name_len, 0);
949+
*snode = lys_find_child(NULL, NULL, mod, NULL, 0, name, name_len, 0);
950950
return *snode ? LY_SUCCESS : LY_ENOT;
951951
}
952952

@@ -984,7 +984,7 @@ schema_mount_snode(struct lysc_ext_instance *ext, const struct lyd_node *parent,
984984
}
985985

986986
/* get the top-level schema node */
987-
*snode = lys_find_child(NULL, NULL, mod, name, name_len, 0);
987+
*snode = lys_find_child(NULL, NULL, mod, NULL, 0, name, name_len, 0);
988988
return *snode ? LY_SUCCESS : LY_ENOT;
989989
}
990990

src/schema_compile_node.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ lysc_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t node
30493049
ctx_node = NULL;
30503050
}
30513051
} else {
3052-
ctx_node = lys_find_child(ctx->ctx, ctx_node, mod, name, name_len,
3052+
ctx_node = lys_find_child(ctx->ctx, ctx_node, mod, NULL, 0, name, name_len,
30533053
getnext_extra_flag | LYS_GETNEXT_WITHCHOICE | LYS_GETNEXT_WITHCASE);
30543054
getnext_extra_flag = 0;
30553055
}
@@ -3257,7 +3257,7 @@ lys_compile_node_list(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc
32573257
}
32583258

32593259
/* key node must be present */
3260-
key = (struct lysc_node_leaf *)lys_find_child(NULL, node, node->module, keystr, len, LYS_GETNEXT_NOCHOICE);
3260+
key = (struct lysc_node_leaf *)lys_find_child(NULL, node, node->module, NULL, 0, keystr, len, LYS_GETNEXT_NOCHOICE);
32613261
if (key && (key->nodetype != LYS_LEAF)) {
32623262
key = NULL;
32633263
}
@@ -3414,7 +3414,7 @@ lys_compile_node_choice_dflt(struct lysc_ctx *ctx, struct lysp_qname *dflt, stru
34143414
mod = ch->module;
34153415
}
34163416

3417-
ch->dflt = (struct lysc_node_case *)lys_find_child(NULL, &ch->node, mod, name, 0, LYS_GETNEXT_WITHCASE);
3417+
ch->dflt = (struct lysc_node_case *)lys_find_child(NULL, &ch->node, mod, NULL, 0, name, 0, LYS_GETNEXT_WITHCASE);
34183418
if (ch->dflt && (ch->dflt->nodetype != LYS_CASE)) {
34193419
ch->dflt = NULL;
34203420
}

src/tree_data_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,10 @@ lyd_parse_opaq_error(const struct lyd_node *node)
945945
}
946946

947947
/* schema */
948-
snode = lys_find_child(LYD_CTX(node), sparent, mod, opaq->name.name, 0, 0);
948+
snode = lys_find_child(LYD_CTX(node), sparent, mod, NULL, 0, opaq->name.name, 0, 0);
949949
if (!snode && sparent && (sparent->nodetype & (LYS_RPC | LYS_ACTION))) {
950950
/* maybe output node */
951-
snode = lys_find_child(LYD_CTX(node), sparent, mod, opaq->name.name, 0, LYS_GETNEXT_OUTPUT);
951+
snode = lys_find_child(LYD_CTX(node), sparent, mod, NULL, 0, opaq->name.name, 0, LYS_GETNEXT_OUTPUT);
952952
}
953953
if (!snode) {
954954
if (sparent) {
@@ -1134,7 +1134,7 @@ lyd_node_schema(const struct lyd_node *node)
11341134
}
11351135

11361136
/* get schema node */
1137-
schema = lys_find_child(LYD_CTX(node), schema, mod, LYD_NAME(iter), 0, 0);
1137+
schema = lys_find_child(LYD_CTX(node), schema, mod, NULL, 0, LYD_NAME(iter), 0, 0);
11381138

11391139
/* move to the descendant */
11401140
prev_iter = iter;

src/tree_data_new.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const ch
467467
module = parent->schema->module;
468468
}
469469

470-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, name, 0, output ? LYS_GETNEXT_OUTPUT : 0);
470+
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, output ? LYS_GETNEXT_OUTPUT : 0);
471471
if (schema && !(schema->nodetype & (LYS_CONTAINER | LYS_NOTIF | LYS_RPC | LYS_ACTION))) {
472472
schema = NULL;
473473
}
@@ -512,7 +512,7 @@ _lyd_new_list_node(const struct ly_ctx *ctx, const struct lyd_node *parent, cons
512512
module = parent->schema->module;
513513
}
514514

515-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, name, 0, getnext_opts);
515+
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, getnext_opts);
516516
if (schema && (schema->nodetype != LYS_LIST)) {
517517
schema = NULL;
518518
}
@@ -602,7 +602,7 @@ lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const ch
602602
}
603603

604604
/* find schema node */
605-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, name, 0, getnext_opts);
605+
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, getnext_opts);
606606
if (schema && (schema->nodetype != LYS_LIST)) {
607607
schema = NULL;
608608
}
@@ -716,7 +716,7 @@ _lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const ch
716716
module = parent->schema->module;
717717
}
718718

719-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, name, 0, getnext_opts);
719+
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, getnext_opts);
720720
if (schema && !(schema->nodetype & LYD_NODE_TERM)) {
721721
schema = NULL;
722722
}
@@ -776,7 +776,7 @@ lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char
776776
module = parent->schema->module;
777777
}
778778

779-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, name, 0, getnext_opts);
779+
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, getnext_opts);
780780
if (schema && !(schema->nodetype & LYD_NODE_ANY)) {
781781
schema = NULL;
782782
}

0 commit comments

Comments
 (0)