blob: c06c63180cfa54c00c18d930a1eed8129944d29d [file] [log] [blame]
Radek Krejcie7b95092019-05-15 11:03:07 +02001/**
Michal Vasko52927e22020-03-16 17:26:14 +01002 * @file printer_data.h
Radek Krejcie7b95092019-05-15 11:03:07 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vasko52927e22020-03-16 17:26:14 +01004 * @brief Data printers for libyang
Radek Krejcie7b95092019-05-15 11:03:07 +02005 *
6 * Copyright (c) 2015-2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_PRINTER_DATA_H_
16#define LY_PRINTER_DATA_H_
17
Radek Krejci26da5222020-06-09 17:43:17 +020018#include <stdio.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include <unistd.h>
20
Radek Krejci26da5222020-06-09 17:43:17 +020021#include "log.h"
Michal Vaskoce2b8742020-08-24 13:20:25 +020022#include "printer.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020023#include "tree_data.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020024
Radek Krejcica376bd2020-06-11 16:04:06 +020025#ifdef __cplusplus
26extern "C" {
27#endif
28
Radek Krejci535ea9f2020-05-29 16:01:05 +020029struct ly_out;
Radek Krejcie7b95092019-05-15 11:03:07 +020030
31/**
32 * @defgroup dataprinterflags Data printer flags
33 * @ingroup datatree
34 *
35 * Validity flags for data nodes.
36 *
37 * @{
38 */
Radek Krejci52f65552020-09-01 17:03:35 +020039#define LYD_PRINT_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */
40#define LYD_PRINT_SHRINK LY_PRINT_SHRINK /**< Flag for output without indentation and formatting new lines. */
41#define LYD_PRINT_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */
42#define LYD_PRINT_WD_MASK 0xF0 /**< Mask for with-defaults modes */
43#define LYD_PRINT_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree.
44 Note that this is the default value when no WD option is specified. */
45#define LYD_PRINT_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */
46#define LYD_PRINT_WD_ALL 0x20 /**< Include implicit default nodes */
47#define LYD_PRINT_WD_ALL_TAG 0x40 /**< Same as #LYDP_WD_ALL but also adds attribute 'default' with value 'true' to
48 all nodes that has its default value. The 'default' attribute has namespace:
49 urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are
50 printed only when the ietf-netconf-with-defaults module is present in libyang
51 context (but in that case this namespace is always printed). */
52#define LYD_PRINT_WD_IMPL_TAG 0x80 /**< Same as LYDP_WD_ALL_TAG but the attributes are added only to the nodes that
53 are not explicitly present in the original data tree despite their
54 value is equal to their default value. There is the same limitation regarding
55 the presence of ietf-netconf-with-defaults module in libyang context. */
Radek Krejcie7b95092019-05-15 11:03:07 +020056/**
57 * @}
58 */
59
60/**
Michal Vasko3a41dff2020-07-15 14:30:28 +020061 * @brief Print the whole data tree of the root, including all the siblings.
Radek Krejcie7b95092019-05-15 11:03:07 +020062 *
Radek Krejci241f6b52020-05-21 18:13:49 +020063 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
Michal Vasko3a41dff2020-07-15 14:30:28 +020064 * @param[in] root The root element of the tree to print, can be any sibling.
Radek Krejcia5bba312020-01-09 15:41:20 +010065 * @param[in] format Output format.
Michal Vasko3a41dff2020-07-15 14:30:28 +020066 * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
Michal Vasko63f3d842020-07-08 10:10:14 +020067 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +020068 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020069LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Michal Vasko3a41dff2020-07-15 14:30:28 +020070
71/**
72 * @brief Print the selected data subtree.
73 *
74 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
75 * @param[in] root The root element of the subtree to print.
76 * @param[in] format Output format.
77 * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
78 * @return LY_ERR value.
79 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020080LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejcie7b95092019-05-15 11:03:07 +020081
Radek Krejci26da5222020-06-09 17:43:17 +020082/**
Michal Vaskodcd356f2020-07-14 12:26:51 +020083 * @brief Print data tree in the specified format.
84 *
85 * @param[out] strp Pointer to store the resulting dump.
Radek Krejci26da5222020-06-09 17:43:17 +020086 * @param[in] root The root element of the (sub)tree to print.
87 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020088 * @param[in] options [Data printer flags](@ref dataprinterflags).
89 * @return LY_ERR value.
90 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020091LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejci26da5222020-06-09 17:43:17 +020092
93/**
94 * @brief Print data tree in the specified format.
95 *
96 * @param[in] fd File descriptor where to print the data.
97 * @param[in] root The root element of the (sub)tree to print.
98 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020099 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200100 * @return LY_ERR value.
101 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200102LY_ERR lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejci26da5222020-06-09 17:43:17 +0200103
104/**
105 * @brief Print data tree in the specified format.
106 *
107 * @param[in] f File stream where to print the data.
108 * @param[in] root The root element of the (sub)tree to print.
109 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200110 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200111 * @return LY_ERR value.
112 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200113LY_ERR lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejci26da5222020-06-09 17:43:17 +0200114
115/**
116 * @brief Print data tree in the specified format.
117 *
118 * @param[in] path File path where to print the data.
119 * @param[in] root The root element of the (sub)tree to print.
120 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200121 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200122 * @return LY_ERR value.
123 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200124LY_ERR lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejci26da5222020-06-09 17:43:17 +0200125
126/**
127 * @brief Print data tree in the specified format.
128 *
129 * @param[in] writeclb Callback function to write the data (see write(1)).
Michal Vaskoce2b8742020-08-24 13:20:25 +0200130 * @param[in] user_data Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejci26da5222020-06-09 17:43:17 +0200131 * @param[in] root The root element of the (sub)tree to print.
132 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200133 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200134 * @return LY_ERR value.
135 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200136LY_ERR lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
Radek Krejci26da5222020-06-09 17:43:17 +0200137
138#ifdef __cplusplus
139}
140#endif
141
Radek Krejcie7b95092019-05-15 11:03:07 +0200142#endif /* LY_PRINTER_DATA_H_ */