mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 23:42:15 +00:00
lib: actually create the tree for the conversion
Before this fix would always return empty results b/c there was no
libyang tree to print to output format.
Signed-off-by: Christian Hopps <chopps@labn.net>
(cherry picked from commit dff28248c3
)
This commit is contained in:
parent
ca30662b7f
commit
2d3b40dce6
21
lib/yang.c
21
lib/yang.c
@ -795,23 +795,38 @@ char *yang_convert_lyd_format(const uint8_t *data, size_t data_len,
|
|||||||
LYD_FORMAT out_format, bool shrink)
|
LYD_FORMAT out_format, bool shrink)
|
||||||
{
|
{
|
||||||
struct lyd_node *tree = NULL;
|
struct lyd_node *tree = NULL;
|
||||||
uint8_t *result = NULL;
|
|
||||||
uint32_t options = LYD_PRINT_WD_EXPLICIT | LYD_PRINT_WITHSIBLINGS;
|
uint32_t options = LYD_PRINT_WD_EXPLICIT | LYD_PRINT_WITHSIBLINGS;
|
||||||
|
uint8_t *result = NULL;
|
||||||
|
LY_ERR err;
|
||||||
|
|
||||||
assert(out_format != LYD_LYB);
|
assert(out_format != LYD_LYB);
|
||||||
|
|
||||||
if (!MGMT_MSG_VALIDATE_NUL_TERM(data, data_len))
|
if (in_format != LYD_LYB && !MGMT_MSG_VALIDATE_NUL_TERM(data, data_len)) {
|
||||||
|
zlog_err("Corrupt input data, no NUL terminating byte");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (in_format == out_format)
|
if (in_format == out_format)
|
||||||
return darr_strdup((const char *)data);
|
return darr_strdup((const char *)data);
|
||||||
|
|
||||||
|
err = lyd_parse_data_mem(ly_native_ctx, (const char *)data, in_format,
|
||||||
|
LYD_PARSE_ONLY, 0, &tree);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
flog_err_sys(EC_LIB_LIBYANG,
|
||||||
|
"cannot parse input data to convert: %s",
|
||||||
|
ly_last_errmsg());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (shrink)
|
if (shrink)
|
||||||
options |= LYD_PRINT_SHRINK;
|
options |= LYD_PRINT_SHRINK;
|
||||||
|
|
||||||
/* Take a guess at the initial capacity based on input data size */
|
/* Take a guess at the initial capacity based on input data size */
|
||||||
darr_ensure_cap(result, data_len);
|
darr_ensure_cap(result, data_len);
|
||||||
if (yang_print_tree_append(&result, tree, out_format, options)) {
|
err = yang_print_tree_append(&result, tree, out_format, options);
|
||||||
|
lyd_free_all(tree);
|
||||||
|
if (err) {
|
||||||
darr_free(result);
|
darr_free(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user