Skip to content

Commit 271b0cf

Browse files
committed
yanglint UPDATE top-level list of ext-inst data support
Refs #2403
1 parent 1e8a4a0 commit 271b0cf

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

tools/lint/cmd_data.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -639,17 +639,20 @@ parse_input_by_type(struct ly_ctx *ctx, enum lyd_type type, struct cmdline_file
639639
* @brief Parses and validates data for a specific YANG extension instance.
640640
*
641641
* @param[in] ctx libyang context with schema.
642-
* @param[in] yo context for yanglint.
642+
* @param[in] yo Context for yanglint.
643643
* @param[in] input_f Data input file.
644-
* @param[out] tree Extension data tree.
645-
* @param[in] oper_tree operational data tree.
644+
* @param[in] oper_tree Operational data tree.
645+
* @param[out] tree Extension instance data tree.
646646
* @return LY_ERR value.
647647
*/
648648
static LY_ERR
649-
parse_extension_instance(struct ly_ctx *ctx, struct yl_opt *yo, struct cmdline_file *input_f, struct lyd_node **tree,
650-
struct lyd_node *oper_tree)
649+
parse_ext_inst_data(struct ly_ctx *ctx, struct yl_opt *yo, struct cmdline_file *input_f,
650+
struct lyd_node *oper_tree, struct lyd_node **tree)
651651
{
652652
LY_ERR ret = LY_SUCCESS;
653+
struct ly_set tree_nodes = {0};
654+
struct lyd_node *iter;
655+
uint32_t i;
653656

654657
if (find_extension(ctx, yo)) {
655658
YLMSG_E("Extension '%s:%s:%s' not found in module.", yo->mod_name, yo->name, yo->argument);
@@ -666,21 +669,31 @@ parse_extension_instance(struct ly_ctx *ctx, struct yl_opt *yo, struct cmdline_f
666669
return LY_EDENIED;
667670
}
668671

669-
if ((*tree)->next) {
670-
YLMSG_E("Yanglint does not support more than one top-level node in extension data.");
671-
return LY_EDENIED;
672-
}
673-
674-
/* operational data are present */
675672
if (oper_tree) {
676-
lyd_insert_sibling(*tree, oper_tree, &oper_tree);
673+
/* remember data top-level nodes */
674+
LY_LIST_FOR(*tree, iter) {
675+
ly_set_add(&tree_nodes, iter, 1, NULL);
676+
}
677+
678+
/* connect data with operational data for validation */
679+
lyd_insert_sibling(*tree, oper_tree, tree);
677680
ret = lyd_validate_all(tree, ctx, yo->data_validate_options, NULL);
678-
lyd_unlink_tree(*tree);
681+
682+
/* disconnect data and operational data */
683+
*tree = NULL;
684+
for (i = 0; i < tree_nodes.count; ++i) {
685+
iter = tree_nodes.dnodes[i];
686+
lyd_unlink_tree(iter);
687+
lyd_insert_sibling(*tree, iter, tree);
688+
}
679689
} else {
690+
/* validate extension instance data */
680691
ret = lyd_validate_all(tree, ctx, yo->data_validate_options, NULL);
681692
}
682693

683694
yo->data_ext = 0;
695+
696+
ly_set_erase(&tree_nodes, NULL);
684697
return ret;
685698
}
686699

@@ -706,7 +719,7 @@ cmd_data_process(struct ly_ctx *ctx, struct yl_opt *yo)
706719
struct cmdline_file *input_f = (struct cmdline_file *)yo->data_inputs.objs[u];
707720

708721
if (yo->data_ext) {
709-
ret = parse_extension_instance(ctx, yo, input_f, &tree, oper_tree);
722+
ret = parse_ext_inst_data(ctx, yo, input_f, oper_tree, &tree);
710723
} else {
711724
ret = parse_input_by_type(ctx, yo->data_type, input_f, yo->data_parse_options, yo->data_validate_options,
712725
&tree, &op, &yo->reply_rpc);

0 commit comments

Comments
 (0)