blob: ac0b1f61fda71e1eda2f132d154c0228625bbb6a [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 Krejcie7b95092019-05-15 11:03:07 +020018#include <stdio.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020019#include <unistd.h>
20
Radek Krejcie7b95092019-05-15 11:03:07 +020021#include "tree_schema.h"
22
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080023
24/**
25 * @defgroup schemaprinterflags Schema output options
26 * @ingroup schema
27 *
28 * @{
29 */
Radek Krejci4fa6ebf2019-11-21 13:34:35 +080030#define LYS_OUTPUT_NO_SUBSTMT 0x10 /**< Print only top-level/referede node information,
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080031 do not print information from the substatements */
32//#define LYS_OUTOPT_TREE_RFC 0x01 /**< Conform to the RFC TODO tree output (only for tree format) */
33//#define LYS_OUTOPT_TREE_GROUPING 0x02 /**< Print groupings separately (only for tree format) */
34//#define LYS_OUTOPT_TREE_USES 0x04 /**< Print only uses instead the resolved grouping nodes (only for tree format) */
35//#define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 /**< Do not print the target of leafrefs (only for tree format) */
36
37/**
38 * @} schemaprinterflags
39 */
40
41
Radek Krejcid3ca0632019-04-16 16:54:54 +020042/**
43 * @brief Print schema tree in the specified format into a memory block.
44 * It is up to caller to free the returned string by free().
45 *
46 * @param[out] strp Pointer to store the resulting dump.
47 * @param[in] module Schema tree to print.
48 * @param[in] format Schema output format.
49 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
50 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020051 * @return Number of printed bytes in case of success.
52 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020053 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020054ssize_t lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020055
56/**
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080057 * @brief Print schema node in the specified format into a memory block.
58 * It is up to caller to free the returned string by free().
59 *
60 * @param[out] strp Pointer to store the resulting dump.
61 * @param[in] ctx libyang context to get schema node in case of missing @p context_node.
62 * @param[in] context_node Context node in case of the relative @p target_node path.
63 * @param[in] format Schema output format.
64 * @param[in] target_node Schema node path, use full module names as node's prefixes.
65 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
66 * @param[in] options Schema output options (see @ref schemaprinterflags).
67 * @return Number of printed bytes in case of success.
68 * @return Negative value failure (absolute value corresponds to LY_ERR values).
69 */
70ssize_t lys_node_print_mem(char **strp, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format,
71 const char *target_node, int line_length, int options);
72
73/**
Radek Krejcid3ca0632019-04-16 16:54:54 +020074 * @brief Print schema tree in the specified format into a file descriptor.
75 *
Radek Krejcid3ca0632019-04-16 16:54:54 +020076 * @param[in] fd File descriptor where to print the data.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080077 * @param[in] module Schema tree to print.
Radek Krejcid3ca0632019-04-16 16:54:54 +020078 * @param[in] format Schema output format.
79 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format.
80 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020081 * @return Number of printed bytes in case of success.
82 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020083 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020084ssize_t lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020085
86/**
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080087 * @brief Print schema tree in the specified format into a file descriptor.
88 *
89 * @param[in] fd File descriptor where to print the data.
90 * @param[in] ctx libyang context to get schema node in case of missing @p context_node.
91 * @param[in] context_node Context node in case of the relative @p target_node path.
92 * @param[in] format Schema output format.
93 * @param[in] target_node Schema node path, use full module names as node's prefixes.
94 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format.
95 * @param[in] options Schema output options (see @ref schemaprinterflags).
96 * @return Number of printed bytes in case of success.
97 * @return Negative value failure (absolute value corresponds to LY_ERR values).
98 */
99ssize_t lys_node_print_fd(int fd, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format,
100 const char *target_node, int line_length, int options);
101
102/**
Radek Krejcid3ca0632019-04-16 16:54:54 +0200103 * @brief Print schema tree in the specified format into a file stream.
104 *
105 * @param[in] module Schema tree to print.
106 * @param[in] f File stream where to print the schema.
107 * @param[in] format Schema output format.
108 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
109 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +0200110 * @return Number of printed bytes in case of success.
111 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +0200112 */
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800113ssize_t lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format,
114 int line_length, int options);
115
116/**
117 * @brief Print schema node in the specified format into a file stream.
118 *
119 * @param[in] f File stream where to print the schema.
120 * @param[in] ctx libyang context to get schema node in case of missing @p context_node.
121 * @param[in] context_node Context node in case of the relative @p target_node path.
122 * @param[in] format Schema output format.
123 * @param[in] target_node Schema node path, use full module names as node's prefixes.
124 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
125 * @param[in] options Schema output options (see @ref schemaprinterflags).
126 * @return Number of printed bytes in case of success.
127 * @return Negative value failure (absolute value corresponds to LY_ERR values).
128 */
129ssize_t lys_node_print_file(FILE *f, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format,
130 const char *target_node, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200131
132/**
133 * @brief Print schema tree in the specified format into a file.
134 *
135 * @param[in] path File where to print the schema.
136 * @param[in] module Schema tree to print.
137 * @param[in] format Schema output format.
138 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
139 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +0200140 * @return Number of printed bytes in case of success.
141 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +0200142 */
Radek Krejci897ad2e2019-04-29 16:43:07 +0200143ssize_t lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200144
145/**
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800146 * @brief Print schema tree in the specified format into a file.
147 *
148 * @param[in] path File where to print the schema.
149 * @param[in] ctx libyang context to get schema node in case of missing @p context_node.
150 * @param[in] context_node Context node in case of the relative @p target_node path.
151 * @param[in] format Schema output format.
152 * @param[in] target_node Schema node path, use full module names as node's prefixes.
153 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
154 * @param[in] options Schema output options (see @ref schemaprinterflags).
155 * @return Number of printed bytes in case of success.
156 * @return Negative value failure (absolute value corresponds to LY_ERR values).
157 */
158ssize_t lys_node_print_path(const char *path, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format,
159 const char *target_node, int line_length, int options);
160
161/**
Radek Krejcid3ca0632019-04-16 16:54:54 +0200162 * @brief Print schema tree in the specified format using a provided callback.
163 *
Radek Krejcid3ca0632019-04-16 16:54:54 +0200164 * @param[in] writeclb Callback function to write the data (see write(1)).
165 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800166 * @param[in] module Schema tree to print.
Radek Krejcid3ca0632019-04-16 16:54:54 +0200167 * @param[in] format Schema output format.
168 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
169 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +0200170 * @return Number of printed bytes in case of success.
171 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +0200172 */
Radek Krejci897ad2e2019-04-29 16:43:07 +0200173ssize_t lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200174 const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
175
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800176/**
177 * @brief Print schema node in the specified format using a provided callback.
178 *
179 * @param[in] writeclb Callback function to write the data (see write(1)).
180 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
181 * @param[in] ctx libyang context to get schema node in case of missing @p context_node.
182 * @param[in] context_node Context node in case of the relative @p target_node path.
183 * @param[in] format Schema output format.
184 * @param[in] target_node Schema node path, use full module names as node's prefixes.
185 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
186 * @param[in] options Schema output options (see @ref schemaprinterflags).
187 * @return Number of printed bytes in case of success.
188 * @return Negative value failure (absolute value corresponds to LY_ERR values).
189 */
190ssize_t lys_node_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
191 struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format,
192 const char *target_node, int line_length, int options);
193
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194#endif /* LY_PRINTER_SCHEMA_H_ */