diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2019-01-04 19:08:10 -0200 |
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2019-01-18 16:15:41 -0200 |
| commit | fcb7bffdda0b122c34978e3f7390b6f26689848a (patch) | |
| tree | 882984513c5a7f469f9a3e1fd8c4af398279dd41 /lib/yang.c | |
| parent | 02fe07c7b8f2191d1f53b31888e95d6c12c48ad9 (diff) | |
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 71b41c35d8..4077b29746 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. */ |
