lyb BUGFIX support for opaque nodes with schema children
Module is printed for all opaque and top-level
nodes. Also, data models are collected from
schema children of opaque nodes.
Fixes cesnet/netopeer2#981
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index fa983ef..18ff56c 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -473,29 +473,34 @@
LY_ARRAY_COUNT_TYPE u;
LY_ERR ret = LY_SUCCESS;
struct lys_module *mod;
- const struct lyd_node *node;
+ const struct lyd_node *elem, *node;
uint32_t i;
LY_CHECK_RET(ly_set_new(&set));
/* collect all data node modules */
- LY_LIST_FOR(root, node) {
- if (!node->schema) {
- continue;
- }
+ LY_LIST_FOR(root, elem) {
+ LYD_TREE_DFS_BEGIN(elem, node) {
+ if (node->schema) {
+ mod = node->schema->module;
+ ret = ly_set_add(set, mod, 0, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
- mod = node->schema->module;
- ret = ly_set_add(set, mod, 0, NULL);
- LY_CHECK_GOTO(ret, cleanup);
+ /* add also their modules deviating or augmenting them */
+ LY_ARRAY_FOR(mod->deviated_by, u) {
+ ret = ly_set_add(set, mod->deviated_by[u], 0, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
+ }
+ LY_ARRAY_FOR(mod->augmented_by, u) {
+ ret = ly_set_add(set, mod->augmented_by[u], 0, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
+ }
- /* add also their modules deviating or augmenting them */
- LY_ARRAY_FOR(mod->deviated_by, u) {
- ret = ly_set_add(set, mod->deviated_by[u], 0, NULL);
- LY_CHECK_GOTO(ret, cleanup);
- }
- LY_ARRAY_FOR(mod->augmented_by, u) {
- ret = ly_set_add(set, mod->augmented_by[u], 0, NULL);
- LY_CHECK_GOTO(ret, cleanup);
+ /* only top-level nodes are processed */
+ LYD_TREE_DFS_continue = 1;
+ }
+
+ LYD_TREE_DFS_END(elem, node);
}
}
@@ -921,10 +926,10 @@
/* register a new subtree */
LY_CHECK_RET(lyb_write_start_subtree(out, lybctx->lybctx));
- /* write model info first */
- if (!node->schema && !lyd_parent(node)) {
+ /* write model info first, for all opaque and top-level nodes */
+ if (!node->schema) {
LY_CHECK_RET(lyb_print_model(out, NULL, lybctx->lybctx));
- } else if (node->schema && !lysc_data_parent(node->schema)) {
+ } else if (!lysc_data_parent(node->schema)) {
LY_CHECK_RET(lyb_print_model(out, node->schema->module, lybctx->lybctx));
}