blob: 6d5ad50e4377f0b27f45d369e351a2cef94a23be [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Schema printers for libyang
5 *
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_SCHEMA_H_
16#define LY_PRINTER_SCHEMA_H_
17
Radek Krejcica376bd2020-06-11 16:04:06 +020018#include <stdio.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020019#include <unistd.h>
20
Radek Krejcica376bd2020-06-11 16:04:06 +020021#include "log.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
Radek Krejcie7b95092019-05-15 11:03:07 +020026
Radek Krejci535ea9f2020-05-29 16:01:05 +020027struct ly_out;
Radek Krejcica376bd2020-06-11 16:04:06 +020028struct lys_module;
29struct lysc_node;
Radek Krejci535ea9f2020-05-29 16:01:05 +020030
Radek Krejci2ff0d572020-05-21 15:27:28 +020031/**
32 * @addtogroup schematree
33 * @{
34 */
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080035
36/**
37 * @defgroup schemaprinterflags Schema output options
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080038 * @{
39 */
Radek Krejci4fa6ebf2019-11-21 13:34:35 +080040#define LYS_OUTPUT_NO_SUBSTMT 0x10 /**< Print only top-level/referede node information,
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080041 do not print information from the substatements */
42//#define LYS_OUTOPT_TREE_RFC 0x01 /**< Conform to the RFC TODO tree output (only for tree format) */
43//#define LYS_OUTOPT_TREE_GROUPING 0x02 /**< Print groupings separately (only for tree format) */
44//#define LYS_OUTOPT_TREE_USES 0x04 /**< Print only uses instead the resolved grouping nodes (only for tree format) */
45//#define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 /**< Do not print the target of leafrefs (only for tree format) */
46
Radek Krejci2ff0d572020-05-21 15:27:28 +020047/** @} schemaprinterflags */
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080048
Radek Krejcid3ca0632019-04-16 16:54:54 +020049/**
Radek Krejcif0e1ba52020-05-22 15:14:35 +020050 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
51 */
52typedef enum {
53 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
54 LYS_OUT_YANG = 1, /**< YANG schema output format */
55 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
56 LYS_OUT_YIN = 3, /**< YIN schema output format */
57
58 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
59} LYS_OUTFORMAT;
60
61/**
Radek Krejcia5bba312020-01-09 15:41:20 +010062 * @brief Schema module printer.
Radek Krejcid3ca0632019-04-16 16:54:54 +020063 *
Radek Krejci241f6b52020-05-21 18:13:49 +020064 * @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 +010065 * @param[in] module Schema to print.
66 * @param[in] format Output format.
Radek Krejcid3ca0632019-04-16 16:54:54 +020067 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
68 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020069 * @return Number of printed bytes in case of success.
70 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020071 */
Radek Krejci241f6b52020-05-21 18:13:49 +020072ssize_t lys_print(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020073
74/**
Radek Krejci26da5222020-06-09 17:43:17 +020075 * @brief Print schema tree in the specified format into a memory block.
76 * It is up to caller to free the returned string by free().
77 *
78 * This is just a wrapper around lys_print() for simple use cases.
79 * In case of a complex use cases, use lys_print with ly_out output handler.
80 *
81 * @param[out] strp Pointer to store the resulting dump.
82 * @param[in] module Schema tree to print.
83 * @param[in] format Schema output format.
84 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
85 * @param[in] options Schema output options (see @ref schemaprinterflags).
86 * @return LY_ERR value.
87 */
88LY_ERR lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
89
90/**
91 * @brief Print schema tree in the specified format into a file descriptor.
92 *
93 * This is just a wrapper around lys_print() for simple use cases.
94 * In case of a complex use cases, use lys_print with ly_out output handler.
95 *
96 * @param[in] fd File descriptor where to print the data.
97 * @param[in] module Schema tree to print.
98 * @param[in] format Schema output format.
99 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format.
100 * @param[in] options Schema output options (see @ref schemaprinterflags).
101 * @return LY_ERR value.
102 */
103LY_ERR lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
104
105/**
106 * @brief Print schema tree in the specified format into a file stream.
107 *
108 * This is just a wrapper around lys_print() for simple use cases.
109 * In case of a complex use cases, use lys_print with ly_out output handler.
110 *
111 * @param[in] module Schema tree to print.
112 * @param[in] f File stream where to print the schema.
113 * @param[in] format Schema output format.
114 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
115 * @param[in] options Schema output options (see @ref schemaprinterflags).
116 * @return LY_ERR value.
117 */
118LY_ERR lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
119
120/**
121 * @brief Print schema tree in the specified format into a file.
122 *
123 * This is just a wrapper around lys_print() for simple use cases.
124 * In case of a complex use cases, use lys_print with ly_out output handler.
125 *
126 * @param[in] path File where to print the schema.
127 * @param[in] module Schema tree to print.
128 * @param[in] format Schema output format.
129 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
130 * @param[in] options Schema output options (see @ref schemaprinterflags).
131 * @return LY_ERR value.
132 */
133LY_ERR lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
134
135/**
136 * @brief Print schema tree in the specified format using a provided callback.
137 *
138 * This is just a wrapper around lys_print() for simple use cases.
139 * In case of a complex use cases, use lys_print with ly_out output handler.
140 *
141 * @param[in] module Schema tree to print.
142 * @param[in] writeclb Callback function to write the data (see write(1)).
143 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
144 * @param[in] format Schema output format.
145 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
146 * @param[in] options Schema output options (see @ref schemaprinterflags).
147 * @return LY_ERR value.
148 */
149LY_ERR lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
150 const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
151
152/**
Radek Krejcia5bba312020-01-09 15:41:20 +0100153 * @brief Schema node printer.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800154 *
Radek Krejci241f6b52020-05-21 18:13:49 +0200155 * @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 +0100156 * @param[in] node Schema node to print, lys_find_node() can be used to get it from a path string.
157 * @param[in] format Output format.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800158 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
159 * @param[in] options Schema output options (see @ref schemaprinterflags).
160 * @return Number of printed bytes in case of success.
161 * @return Negative value failure (absolute value corresponds to LY_ERR values).
162 */
Radek Krejci241f6b52020-05-21 18:13:49 +0200163ssize_t lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800164
Radek Krejci2ff0d572020-05-21 15:27:28 +0200165/** @} schematree */
166
Radek Krejcica376bd2020-06-11 16:04:06 +0200167#ifdef __cplusplus
168}
169#endif
170
Radek Krejcid3ca0632019-04-16 16:54:54 +0200171#endif /* LY_PRINTER_SCHEMA_H_ */