tree data FEATURE lyd_new_path() relative paths for opaque parents
Fixes #1726
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 9ffb489..754bc55 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -560,6 +560,40 @@
return LY_SUCCESS;
}
+const struct lysc_node *
+lyd_node_schema(const struct lyd_node *node)
+{
+ const struct lysc_node *schema = NULL;
+ const struct lyd_node *prev_iter = NULL, *iter;
+ const struct lys_module *mod;
+
+ if (!node) {
+ return NULL;
+ } else if (node->schema) {
+ return node->schema;
+ }
+
+ /* get schema node of an opaque node */
+ do {
+ /* get next data node */
+ for (iter = node; lyd_parent(iter) != prev_iter; iter = lyd_parent(iter)) {}
+
+ /* get equivalent schema node */
+ if (iter->schema) {
+ schema = iter->schema;
+ } else {
+ /* get module */
+ mod = lyd_owner_module(iter);
+
+ /* get schema node */
+ schema = lys_find_child(schema, mod ? mod : schema->module, LYD_NAME(iter), 0, 0, 0);
+ }
+
+ } while (schema && (iter != node));
+
+ return schema;
+}
+
void
lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const struct lys_module *mod)
{