diff options
author | Christian Hopps <chopps@labn.net> | 2024-01-30 09:05:18 +0100 |
---|---|---|
committer | Christian Hopps <chopps@labn.net> | 2024-01-30 10:57:10 +0100 |
commit | 25bb8b203cdbf3b40f938add7352666146183c03 (patch) | |
tree | 90ba100c73a7f97401bd9362daa9a0a86a9f957c /lib/yang.c | |
parent | Merge pull request #15238 from louis-6wind/bgp-leak-network (diff) | |
download | frr-25bb8b203cdbf3b40f938add7352666146183c03.tar.xz frr-25bb8b203cdbf3b40f938add7352666146183c03.zip |
lib: mgmtd: add YANG notification support
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/yang.c')
-rw-r--r-- | lib/yang.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c index 3dd2513a4..2b360376d 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -744,6 +744,34 @@ uint8_t *yang_print_tree(const struct lyd_node *root, LYD_FORMAT format, return darr; } +char *yang_convert_lyd_format(const uint8_t *data, size_t data_len, + LYD_FORMAT in_format, + LYD_FORMAT out_format, bool shrink) +{ + struct lyd_node *tree = NULL; + uint8_t *result = NULL; + uint32_t options = LYD_PRINT_WD_EXPLICIT | LYD_PRINT_WITHSIBLINGS; + + assert(out_format != LYD_LYB); + + if (!MGMT_MSG_VALIDATE_NUL_TERM(data, data_len)) + return NULL; + + if (in_format == out_format) + return darr_strdup((const char *)data); + + if (shrink) + options |= LYD_PRINT_SHRINK; + + /* Take a guess at the initial capacity based on input data size */ + darr_ensure_cap(result, data_len); + if (yang_print_tree_append(&result, tree, out_format, options)) { + darr_free(result); + return NULL; + } + return (char *)result; +} + const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len) { struct ly_err_item *ei; |