libsrx: new function, traverse the void to find an interface

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-03-22 13:15:35 +01:00
committed by Tobias Waldekranz
parent 29158ed2ef
commit ce2e15e4d2
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -120,6 +120,24 @@ struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...)
return node;
}
/*
* Similar to lydx_get_decsendant() but for, e.g., finding a named
* interface in ietf-interfaces from the top node.
*/
struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name)
{
struct lyd_node *node;
LY_LIST_FOR(lydx_get_sibling(lyd_child(from), by), node) {
if (strcmp(lydx_get_cattr(node, "name"), name))
continue;
return node;
}
return NULL;
}
const char *lydx_get_mattr(struct lyd_node *node, const char *name)
{
struct lyd_meta *meta;
+1
View File
@@ -36,6 +36,7 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd);
struct lyd_node *lydx_get_sibling(struct lyd_node *sibling, const char *name);
struct lyd_node *lydx_get_child(struct lyd_node *parent, const char *name);
struct lyd_node *lydx_get_descendant(struct lyd_node *from, ...);
struct lyd_node *lydx_find_by_name(struct lyd_node *from, const char *by, const char *name);
const char *lydx_get_mattr(struct lyd_node *node, const char *name);
const char *lydx_get_attr(struct lyd_node *sibling, const char *name);