diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2019-01-04 22:08:10 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2019-01-18 19:15:41 +0100 |
commit | fcb7bffdda0b122c34978e3f7390b6f26689848a (patch) | |
tree | 882984513c5a7f469f9a3e1fd8c4af398279dd41 /lib/yang.c | |
parent | lib: constify a few parameters in the VRF code (diff) | |
download | frr-fcb7bffdda0b122c34978e3f7390b6f26689848a.tar.xz frr-fcb7bffdda0b122c34978e3f7390b6f26689848a.zip |
lib: introduce new YANG helper function
One use case for the new yang_data_list_find() function is to find
input parameters in RPC northbound callbacks easily, without the
need to iterate over the input parameters manually.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/yang.c')
-rw-r--r-- | lib/yang.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c index 71b41c35d..4077b2974 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -608,6 +608,25 @@ struct list *yang_data_list_new(void) return list; } +struct yang_data *yang_data_list_find(const struct list *list, + const char *xpath_fmt, ...) +{ + char xpath[XPATH_MAXLEN]; + struct yang_data *data; + struct listnode *node; + va_list ap; + + va_start(ap, xpath_fmt); + vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap); + va_end(ap); + + for (ALL_LIST_ELEMENTS_RO(list, node, data)) + if (strmatch(data->xpath, xpath)) + return data; + + return NULL; +} + static void *ly_dup_cb(const void *priv) { /* Make a shallow copy of the priv pointer. */ |