Skip to content

Commit

Permalink
tree data UPDATE standard functions from static functions (#2101)
Browse files Browse the repository at this point in the history
We need certain functions to be exposed via a public API to make it
 possible to use in other languages such as Rust.

 lyd_parent, lyd_child, and lyd_get_value are defined as static inline
 and is difficult for tools to wrap them.

Co-authored-by: IrfanMohammad <[email protected]>
  • Loading branch information
irfanHaslanded and IrfanMohammad authored Sep 14, 2023
1 parent 0119b92 commit d3b351a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
52 changes: 52 additions & 0 deletions src/tree_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3056,3 +3056,55 @@ lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct
}
return LY_SUCCESS;
}

LIBYANG_API_DEF struct lyd_node *
lyd_parent(const struct lyd_node *node)
{
if (!node || !node->parent) {
return NULL;
}

return &node->parent->node;
}

LIBYANG_API_DEF struct lyd_node *
lyd_child(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
/* opaq node */
return ((const struct lyd_node_opaq *)node)->child;
}

switch (node->schema->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
case LYS_RPC:
case LYS_ACTION:
case LYS_NOTIF:
return ((const struct lyd_node_inner *)node)->child;
default:
return NULL;
}
}

LIBYANG_API_DEF const char *
lyd_get_value(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((const struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;

return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
}

return NULL;
}
52 changes: 3 additions & 49 deletions src/tree_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,7 @@ struct lyd_node_opaq {
* @return Pointer to the parent node of the @p node.
* @return NULL in case of the top-level node or if the @p node is NULL itself.
*/
static inline struct lyd_node *
lyd_parent(const struct lyd_node *node)
{
if (!node || !node->parent) {
return NULL;
}

return &node->parent->node;
}
LIBYANG_API_DECL struct lyd_node *lyd_parent(const struct lyd_node *node);

/**
* @brief Get the child pointer of a generic data node.
Expand All @@ -1024,29 +1016,7 @@ lyd_parent(const struct lyd_node *node)
* @param[in] node Node to use.
* @return Pointer to the first child node (if any) of the @p node.
*/
static inline struct lyd_node *
lyd_child(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
/* opaq node */
return ((const struct lyd_node_opaq *)node)->child;
}

switch (node->schema->nodetype) {
case LYS_CONTAINER:
case LYS_LIST:
case LYS_RPC:
case LYS_ACTION:
case LYS_NOTIF:
return ((const struct lyd_node_inner *)node)->child;
default:
return NULL;
}
}
LIBYANG_API_DECL struct lyd_node *lyd_child(const struct lyd_node *node);

/**
* @brief Get the child pointer of a generic data node but skip its keys in case it is ::LYS_LIST.
Expand Down Expand Up @@ -1141,23 +1111,7 @@ LIBYANG_API_DECL const char *lyd_value_get_canonical(const struct ly_ctx *ctx, c
* @param[in] node Data node to use.
* @return Canonical value.
*/
static inline const char *
lyd_get_value(const struct lyd_node *node)
{
if (!node) {
return NULL;
}

if (!node->schema) {
return ((const struct lyd_node_opaq *)node)->value;
} else if (node->schema->nodetype & LYD_NODE_TERM) {
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;

return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
}

return NULL;
}
LIBYANG_API_DECL const char *lyd_get_value(const struct lyd_node *node);

/**
* @brief Get anydata string value.
Expand Down

0 comments on commit d3b351a

Please sign in to comment.