blob: afe04188121c6f772251072e8bbb2fdb62d42b1f [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/**
Radek Krejcia5bba312020-01-09 15:41:20 +010060 * @brief Common YANG data printer.
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.
Radek Krejcia5bba312020-01-09 15:41:20 +010063 * @param[in] root The root element of the (sub)tree to print.
64 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020065 * @param[in] options [Data printer flags](@ref dataprinterflags).
Michal Vasko63f3d842020-07-08 10:10:14 +020066 * @return LY_ERR value.
Radek Krejcie7b95092019-05-15 11:03:07 +020067 */
Michal Vasko63f3d842020-07-08 10:10:14 +020068LY_ERR lyd_print(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
Radek Krejcie7b95092019-05-15 11:03:07 +020069
Radek Krejci26da5222020-06-09 17:43:17 +020070/**
Michal Vaskodcd356f2020-07-14 12:26:51 +020071 * @brief Print data tree in the specified format.
72 *
73 * @param[out] strp Pointer to store the resulting dump.
Radek Krejci26da5222020-06-09 17:43:17 +020074 * @param[in] root The root element of the (sub)tree to print.
75 * @param[in] format Output format.
Michal Vaskodcd356f2020-07-14 12:26:51 +020076 * @param[in] options [Data printer flags](@ref dataprinterflags).
77 * @return LY_ERR value.
78 */
Radek Krejci26da5222020-06-09 17:43:17 +020079LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options);
80
81/**
82 * @brief Print data tree in the specified format.
83 *
84 * @param[in] fd File descriptor where to print the data.
85 * @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).
Radek Krejci26da5222020-06-09 17:43:17 +020088 * @return LY_ERR value.
89 */
90LY_ERR lyd_print_fd(int fd, 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] f File stream 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_file(FILE *f, 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] path File path 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_path(const char *path, 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] writeclb Callback function to write the data (see write(1)).
118 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
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 */
124LY_ERR lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
125 const struct lyd_node *root, LYD_FORMAT format, int options);
126
127#ifdef __cplusplus
128}
129#endif
130
Radek Krejcie7b95092019-05-15 11:03:07 +0200131#endif /* LY_PRINTER_DATA_H_ */