data tree CHANGE move macros to functions to cleanup API
Remove lyd_node_children() since it is just an old duplication of
LYD_CHILD and LYD_CHILD_NO_KEYS macros. As a consequence, these macros
are converted to the functions together with LYD_PARENT (same names, but
lowercase) since they have similar functionality in the API.
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index a3e331f..712f300 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -83,21 +83,56 @@
}
API struct lyd_node *
-lyd_node_children(const struct lyd_node *node, uint32_t options)
+lyd_parent(const struct lyd_node *node)
{
- struct lyd_node **children, *child;
+ if (!node) {
+ return NULL;
+ }
+
+ return (struct lyd_node *)(node)->parent;
+}
+
+API struct lyd_node *
+lyd_child(const struct lyd_node *node)
+{
+ struct lyd_node **children;
if (!node) {
return NULL;
}
+ if (!node->schema) {
+ /* opaq node */
+ return ((struct lyd_node_opaq *)(node))->child;
+ }
+
children = lyd_node_children_p((struct lyd_node *)node);
if (children) {
- child = *children;
- if (options & LYD_CHILDREN_SKIP_KEYS) {
- while (child && child->schema && (child->schema->flags & LYS_KEY)) {
- child = child->next;
- }
+ return *children;
+ } else {
+ return NULL;
+ }
+}
+
+API struct lyd_node *
+lyd_child_no_keys(const struct lyd_node *node)
+{
+ struct lyd_node **children;
+
+ if (!node) {
+ return NULL;
+ }
+
+ if (!node->schema) {
+ /* opaq node */
+ return ((struct lyd_node_opaq *)(node))->child;
+ }
+
+ children = lyd_node_children_p((struct lyd_node *)node);
+ if (children) {
+ struct lyd_node *child = *children;
+ while (child && child->schema && (child->schema->flags & LYS_KEY)) {
+ child = child->next;
}
return child;
} else {
@@ -185,7 +220,7 @@
assert(node->schema->nodetype == LYS_LIST);
- key = lyd_node_children(node, 0);
+ key = lyd_child(node);
while ((skey = lys_getnext(skey, node->schema, NULL, 0)) && (skey->flags & LYS_KEY)) {
if (!key || (key->schema != skey)) {
LOGVAL(LYD_CTX(node), LY_VLOG_LYD, node, LY_VCODE_NOKEY, skey->name);