blob: f2cc238ae769b64422130d50c11e6e87d811724d [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;
Michal Vasko7c8439f2020-08-05 13:25:19 +020030struct lysp_submodule;
Radek Krejci535ea9f2020-05-29 16:01:05 +020031
Radek Krejci2ff0d572020-05-21 15:27:28 +020032/**
33 * @addtogroup schematree
34 * @{
35 */
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080036
37/**
38 * @defgroup schemaprinterflags Schema output options
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080039 * @{
40 */
Radek Krejci4fa6ebf2019-11-21 13:34:35 +080041#define LYS_OUTPUT_NO_SUBSTMT 0x10 /**< Print only top-level/referede node information,
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080042 do not print information from the substatements */
43//#define LYS_OUTOPT_TREE_RFC 0x01 /**< Conform to the RFC TODO tree output (only for tree format) */
44//#define LYS_OUTOPT_TREE_GROUPING 0x02 /**< Print groupings separately (only for tree format) */
45//#define LYS_OUTOPT_TREE_USES 0x04 /**< Print only uses instead the resolved grouping nodes (only for tree format) */
46//#define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 /**< Do not print the target of leafrefs (only for tree format) */
47
Radek Krejci2ff0d572020-05-21 15:27:28 +020048/** @} schemaprinterflags */
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080049
Radek Krejcid3ca0632019-04-16 16:54:54 +020050/**
Radek Krejcif0e1ba52020-05-22 15:14:35 +020051 * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters).
52 */
53typedef enum {
54 LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
55 LYS_OUT_YANG = 1, /**< YANG schema output format */
56 LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */
57 LYS_OUT_YIN = 3, /**< YIN schema output format */
58
59 LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */
60} LYS_OUTFORMAT;
61
62/**
Radek Krejcia5bba312020-01-09 15:41:20 +010063 * @brief Schema module printer.
Radek Krejcid3ca0632019-04-16 16:54:54 +020064 *
Radek Krejci241f6b52020-05-21 18:13:49 +020065 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
Michal Vasko7c8439f2020-08-05 13:25:19 +020066 * @param[in] module Main module with the parsed schema to print.
Radek Krejcia5bba312020-01-09 15:41:20 +010067 * @param[in] format Output format.
Radek Krejcid3ca0632019-04-16 16:54:54 +020068 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
69 * @param[in] options Schema output options (see @ref schemaprinterflags).
Michal Vasko63f3d842020-07-08 10:10:14 +020070 * @return LY_ERR value.
Radek Krejcid3ca0632019-04-16 16:54:54 +020071 */
Michal Vasko7c8439f2020-08-05 13:25:19 +020072LY_ERR lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
73
74/**
75 * @brief Schema submodule printer.
76 *
77 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
78 * @param[in] module Main module of the submodule to print.
79 * @param[in] submodule Parsed submodule to print.
80 * @param[in] format Output format.
81 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
82 * @param[in] options Schema output options (see @ref schemaprinterflags).
83 * @return LY_ERR value.
84 */
85LY_ERR lys_print_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodule,
86 LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020087
88/**
Radek Krejci26da5222020-06-09 17:43:17 +020089 * @brief Print schema tree in the specified format into a memory block.
90 * It is up to caller to free the returned string by free().
91 *
92 * This is just a wrapper around lys_print() for simple use cases.
93 * In case of a complex use cases, use lys_print with ly_out output handler.
94 *
95 * @param[out] strp Pointer to store the resulting dump.
96 * @param[in] module Schema tree to print.
97 * @param[in] format Schema output format.
Radek Krejci26da5222020-06-09 17:43:17 +020098 * @param[in] options Schema output options (see @ref schemaprinterflags).
99 * @return LY_ERR value.
100 */
Michal Vasko7c8439f2020-08-05 13:25:19 +0200101LY_ERR lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int options);
Radek Krejci26da5222020-06-09 17:43:17 +0200102
103/**
104 * @brief Print schema tree in the specified format into a file descriptor.
105 *
106 * This is just a wrapper around lys_print() for simple use cases.
107 * In case of a complex use cases, use lys_print with ly_out output handler.
108 *
109 * @param[in] fd File descriptor where to print the data.
110 * @param[in] module Schema tree to print.
111 * @param[in] format Schema output format.
Radek Krejci26da5222020-06-09 17:43:17 +0200112 * @param[in] options Schema output options (see @ref schemaprinterflags).
113 * @return LY_ERR value.
114 */
Michal Vasko7c8439f2020-08-05 13:25:19 +0200115LY_ERR lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int options);
Radek Krejci26da5222020-06-09 17:43:17 +0200116
117/**
118 * @brief Print schema tree in the specified format into a file stream.
119 *
120 * This is just a wrapper around lys_print() for simple use cases.
121 * In case of a complex use cases, use lys_print with ly_out output handler.
122 *
123 * @param[in] module Schema tree to print.
124 * @param[in] f File stream where to print the schema.
125 * @param[in] format Schema output format.
Radek Krejci26da5222020-06-09 17:43:17 +0200126 * @param[in] options Schema output options (see @ref schemaprinterflags).
127 * @return LY_ERR value.
128 */
Michal Vasko7c8439f2020-08-05 13:25:19 +0200129LY_ERR lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int options);
Radek Krejci26da5222020-06-09 17:43:17 +0200130
131/**
132 * @brief Print schema tree in the specified format into a file.
133 *
134 * This is just a wrapper around lys_print() for simple use cases.
135 * In case of a complex use cases, use lys_print with ly_out output handler.
136 *
137 * @param[in] path File where to print the schema.
138 * @param[in] module Schema tree to print.
139 * @param[in] format Schema output format.
Radek Krejci26da5222020-06-09 17:43:17 +0200140 * @param[in] options Schema output options (see @ref schemaprinterflags).
141 * @return LY_ERR value.
142 */
Michal Vasko7c8439f2020-08-05 13:25:19 +0200143LY_ERR lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int options);
Radek Krejci26da5222020-06-09 17:43:17 +0200144
145/**
146 * @brief Print schema tree in the specified format using a provided callback.
147 *
148 * This is just a wrapper around lys_print() for simple use cases.
149 * In case of a complex use cases, use lys_print with ly_out output handler.
150 *
151 * @param[in] module Schema tree to print.
152 * @param[in] writeclb Callback function to write the data (see write(1)).
153 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
154 * @param[in] format Schema output format.
Radek Krejci26da5222020-06-09 17:43:17 +0200155 * @param[in] options Schema output options (see @ref schemaprinterflags).
156 * @return LY_ERR value.
157 */
158LY_ERR lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
Michal Vasko7c8439f2020-08-05 13:25:19 +0200159 const struct lys_module *module, LYS_OUTFORMAT format, int options);
Radek Krejci26da5222020-06-09 17:43:17 +0200160
161/**
Radek Krejcia5bba312020-01-09 15:41:20 +0100162 * @brief Schema node printer.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800163 *
Radek Krejci241f6b52020-05-21 18:13:49 +0200164 * @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 +0100165 * @param[in] node Schema node to print, lys_find_node() can be used to get it from a path string.
166 * @param[in] format Output format.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800167 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
168 * @param[in] options Schema output options (see @ref schemaprinterflags).
Michal Vasko63f3d842020-07-08 10:10:14 +0200169 * @return LY_ERR value.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +0800170 */
Michal Vasko63f3d842020-07-08 10:10:14 +0200171LY_ERR 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 +0800172
Radek Krejci2ff0d572020-05-21 15:27:28 +0200173/** @} schematree */
174
Radek Krejcica376bd2020-06-11 16:04:06 +0200175#ifdef __cplusplus
176}
177#endif
178
Radek Krejcid3ca0632019-04-16 16:54:54 +0200179#endif /* LY_PRINTER_SCHEMA_H_ */