mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-25 07:28:41 +00:00
lib: add yang function for counting data nodes
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
parent
63ca751c11
commit
e39b60bac1
24
lib/yang.c
24
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;
|
||||
|
15
lib/yang.h
15
lib/yang.h
@ -420,6 +420,21 @@ void yang_dnode_iterate(yang_dnode_iter_cb cb, void *arg,
|
||||
const struct lyd_node *dnode, const char *xpath_fmt,
|
||||
...) PRINTFRR(4, 5);
|
||||
|
||||
/*
|
||||
* Count the number of data nodes that satisfy an XPath query.
|
||||
*
|
||||
* dnode
|
||||
* Base libyang data node to operate on.
|
||||
*
|
||||
* xpath_fmt
|
||||
* XPath expression (absolute or relative).
|
||||
*
|
||||
* ...
|
||||
* any parameters for xpath_fmt.
|
||||
*/
|
||||
uint32_t yang_dnode_count(const struct lyd_node *dnode, const char *xpath_fmt,
|
||||
...) PRINTFRR(2, 3);
|
||||
|
||||
/*
|
||||
* Check if the libyang data node contains a default value. Non-presence
|
||||
* containers are assumed to always contain a default value.
|
||||
|
Loading…
Reference in New Issue
Block a user