From 7b611145c86857f28cdd736a85a2e29b78e8582c Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 7 Nov 2019 16:55:18 -0300 Subject: lib: introduce the yang_dnode_iterate helper Implement helper function that iterates over data nodes that satisfy XPath query. Signed-off-by: Renato Westphal --- lib/yang.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/yang.c') diff --git a/lib/yang.c b/lib/yang.c index c80bf20306..7ac39f4182 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -448,6 +448,32 @@ bool yang_dnode_exists(const struct lyd_node *dnode, const char *xpath_fmt, ...) return found; } +void yang_dnode_iterate(yang_dnode_iter_cb cb, void *arg, + const struct lyd_node *dnode, const char *xpath_fmt, + ...) +{ + va_list ap; + char xpath[XPATH_MAXLEN]; + struct ly_set *set; + + va_start(ap, xpath_fmt); + vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap); + va_end(ap); + + set = lyd_find_path(dnode, xpath); + assert(set); + for (unsigned int i = 0; i < set->number; i++) { + int ret; + + dnode = set->set.d[i]; + ret = (*cb)(dnode, arg); + if (ret == YANG_ITER_STOP) + return; + } + + ly_set_free(set); +} + bool yang_dnode_is_default(const struct lyd_node *dnode, const char *xpath_fmt, ...) { -- cgit v1.2.3