diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2024-01-26 15:54:36 +0100 |
---|---|---|
committer | Christian Hopps <chopps@labn.net> | 2024-01-26 18:34:23 +0100 |
commit | e39b60bac1e8f99ad9053e7d7d7cb73c2f1cc414 (patch) | |
tree | e5f14c1a8b961696ddde34fcd4088456ca698b8d /lib/yang.c | |
parent | lib: convert filters to mgmtd (diff) | |
download | frr-e39b60bac1e8f99ad9053e7d7d7cb73c2f1cc414.tar.xz frr-e39b60bac1e8f99ad9053e7d7d7cb73c2f1cc414.zip |
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.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c index 7d35fb0d3..ed855c849 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; |