summaryrefslogtreecommitdiff
path: root/lib/yang.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2024-01-26 16:54:36 +0200
committerChristian Hopps <chopps@labn.net>2024-01-26 12:34:23 -0500
commite39b60bac1e8f99ad9053e7d7d7cb73c2f1cc414 (patch)
treee5f14c1a8b961696ddde34fcd4088456ca698b8d /lib/yang.c
parent63ca751c1186483f82f0d464bc1c8c43e3a2755f (diff)
lib: add yang function for counting data nodes
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 7d35fb0d3d..ed855c8498 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -508,6 +508,30 @@ void yang_dnode_iterate(yang_dnode_iter_cb cb, void *arg,
ly_set_free(set, NULL);
}
+uint32_t yang_dnode_count(const struct lyd_node *dnode, const char *xpath_fmt,
+ ...)
+{
+ va_list ap;
+ char xpath[XPATH_MAXLEN];
+ struct ly_set *set;
+ uint32_t count;
+
+ va_start(ap, xpath_fmt);
+ vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap);
+ va_end(ap);
+
+ if (lyd_find_xpath(dnode, xpath, &set)) {
+ assert(0);
+ return 0;
+ }
+
+ count = set->count;
+
+ ly_set_free(set, NULL);
+
+ return count;
+}
+
bool yang_dnode_is_default(const struct lyd_node *dnode, const char *xpath)
{
const struct lysc_node *snode;