blob: 09fe8f5708ce8bf7e9fbecbfc7847c54c9bd786a [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"
Radek Krejcie7b95092019-05-15 11:03:07 +020022#include "tree_data.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020023
Radek Krejcica376bd2020-06-11 16:04:06 +020024#ifdef __cplusplus
25extern "C" {
26#endif
27
Radek Krejci535ea9f2020-05-29 16:01:05 +020028struct ly_out;
Radek Krejcie7b95092019-05-15 11:03:07 +020029
30/**
31 * @defgroup dataprinterflags Data printer flags
32 * @ingroup datatree
33 *
34 * Validity flags for data nodes.
35 *
36 * @{
37 */
Radek Krejci7931b192020-06-25 17:05:03 +020038#define LYD_PRINT_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */
39#define LYD_PRINT_FORMAT 0x02 /**< Flag for formatted output. */
40#define LYD_PRINT_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */
41#define LYD_PRINT_WD_MASK 0xF0 /**< Mask for with-defaults modes */
42#define LYD_PRINT_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree.
43 Note that this is the default value when no WD option is specified. */
44#define LYD_PRINT_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */
45#define LYD_PRINT_WD_ALL 0x20 /**< Include implicit default nodes */
46#define LYD_PRINT_WD_ALL_TAG 0x40 /**< Same as #LYDP_WD_ALL but also adds attribute 'default' with value 'true' to
47 all nodes that has its default value. The 'default' attribute has namespace:
48 urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are
49 printed only when the ietf-netconf-with-defaults module is present in libyang
50 context (but in that case this namespace is always printed). */
51#define LYD_PRINT_WD_IMPL_TAG 0x80 /**< Same as LYDP_WD_ALL_TAG but the attributes are added only to the nodes that
52 are not explicitly present in the original data tree despite their
53 value is equal to their default value. There is the same limitation regarding
54 the presence of ietf-netconf-with-defaults module in libyang context. */
Radek Krejcie7b95092019-05-15 11:03:07 +020055/**
56 * @}
57 */
58
59/**
Michal Vasko3a41dff2020-07-15 14:30:28 +020060 * @brief Print the whole data tree of the root, including all the siblings.
Radek Krejcie7b95092019-05-15 11:03:07 +020061 *
Radek Krejci241f6b52020-05-21 18:13:49 +020062 * @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 +020063 * @param[in] root The root element of the tree to print, can be any sibling.
Radek Krejcia5bba312020-01-09 15:41:20 +010064 * @param[in] format Output format.
Michal Vasko3a41dff2020-07-15 14:30:28 +020065 * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
Michal Vasko63f3d842020-07-08 10:10:14 +020066 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +020067 */
Michal Vasko3a41dff2020-07-15 14:30:28 +020068LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
69
70/**
71 * @brief Print the selected data subtree.
72 *
73 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
74 * @param[in] root The root element of the subtree to print.
75 * @param[in] format Output format.
76 * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
77 * @return LY_ERR value.
78 */
79LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
Radek Krejcie7b95092019-05-15 11:03:07 +020080
Radek Krejci26da5222020-06-09 17:43:17 +020081/**
Michal Vaskodcd356f2020-07-14 12:26:51 +020082 * @brief Print data tree in the specified format.
83 *
84 * @param[out] strp Pointer to store the resulting dump.
Radek Krejci26da5222020-06-09 17:43:17 +020085 * @param[in] root The root element of the (sub)tree to print.
86 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020087 * @param[in] options [Data printer flags](@ref dataprinterflags).
88 * @return LY_ERR value.
89 */
Radek Krejci26da5222020-06-09 17:43:17 +020090LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options);
91
92/**
93 * @brief Print data tree in the specified format.
94 *
95 * @param[in] fd File descriptor where to print the data.
96 * @param[in] root The root element of the (sub)tree to print.
97 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020098 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +020099 * @return LY_ERR value.
100 */
101LY_ERR lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options);
102
103/**
104 * @brief Print data tree in the specified format.
105 *
106 * @param[in] f File stream where to print the data.
107 * @param[in] root The root element of the (sub)tree to print.
108 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200109 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200110 * @return LY_ERR value.
111 */
112LY_ERR lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options);
113
114/**
115 * @brief Print data tree in the specified format.
116 *
117 * @param[in] path File path where to print the data.
118 * @param[in] root The root element of the (sub)tree to print.
119 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200120 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200121 * @return LY_ERR value.
122 */
123LY_ERR lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options);
124
125/**
126 * @brief Print data tree in the specified format.
127 *
128 * @param[in] writeclb Callback function to write the data (see write(1)).
129 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
130 * @param[in] root The root element of the (sub)tree to print.
131 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +0200132 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci26da5222020-06-09 17:43:17 +0200133 * @return LY_ERR value.
134 */
135LY_ERR lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
136 const struct lyd_node *root, LYD_FORMAT format, int options);
137
138#ifdef __cplusplus
139}
140#endif
141
Radek Krejcie7b95092019-05-15 11:03:07 +0200142#endif /* LY_PRINTER_DATA_H_ */