diff options
| author | Christian Hopps <chopps@labn.net> | 2023-07-09 05:51:20 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2023-12-26 08:34:56 -0500 |
| commit | 80cac370d065d4275da9a8e8d776735bebd4483e (patch) | |
| tree | abc4e8bc845536532bb7cdb10e991c40c0da60ef /lib/yang.c | |
| parent | 8790457c463476a4ecec0edff07482f707b84fc2 (diff) | |
lib: yang: add tree "printing" utility functions
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/yang.c')
| -rw-r--r-- | lib/yang.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c index 131d89cdfa..b0a8698303 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -6,6 +6,7 @@ #include <zebra.h> +#include "darr.h" #include "log.h" #include "lib_errors.h" #include "yang.h" @@ -673,6 +674,37 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path) zlog(priority, "libyang: %s", msg); } +static ssize_t yang_print_darr(void *arg, const void *buf, size_t count) +{ + uint8_t *dst = darr_append_n(*(uint8_t **)arg, count); + + memcpy(dst, buf, count); + return count; +} + +LY_ERR yang_print_tree_append(uint8_t **darr, const struct lyd_node *root, + LYD_FORMAT format, uint32_t options) +{ + LY_ERR err; + + err = lyd_print_clb(yang_print_darr, darr, root, format, options); + if (err) + zlog_err("Failed to save yang tree: %s", ly_last_errmsg()); + else if (format != LYD_LYB) + *darr_append(*darr) = 0; + return err; +} + +uint8_t *yang_print_tree(const struct lyd_node *root, LYD_FORMAT format, + uint32_t options) +{ + uint8_t *darr = NULL; + + if (yang_print_tree_append(&darr, root, format, options)) + return NULL; + return darr; +} + const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len) { struct ly_err_item *ei; |
