blob: aecd3774fa5575f71039daddc64b17c969fba150 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Internal structures and functions 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_INTERNAL_H_
16#define LY_PRINTER_INTERNAL_H_
17
Michal Vaskoafac7822020-10-20 14:22:26 +020018#include "out.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include "printer_data.h"
Michal Vasko69730152020-10-09 16:30:07 +020020#include "printer_schema.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020021
Michal Vasko7c8439f2020-08-05 13:25:19 +020022struct lysp_module;
23struct lysp_submodule;
24
Radek Krejcie7b95092019-05-15 11:03:07 +020025/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010026 * @brief Generic YANG schema printer context
27 *
28 * Note that the YANG extensions API provides getter to the members for the extension plugins.
29 */
30struct lyspr_ctx {
31 struct ly_out *out; /**< output specification */
32 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
33 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
34 const struct lys_module *module; /**< schema to print */
35};
36
37/**
Michal Vasko7c8439f2020-08-05 13:25:19 +020038 * @brief YANG printer of the parsed module. Full YANG printer.
Radek Krejcie7b95092019-05-15 11:03:07 +020039 *
40 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +020041 * @param[in] modp Parsed module to print.
Radek Krejci5536d282020-08-04 23:27:44 +020042 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020043 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid3ca0632019-04-16 16:54:54 +020044 */
Michal Vasko7997d5a2021-02-22 10:55:56 +010045LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options);
Radek Krejci5536d282020-08-04 23:27:44 +020046
47/**
48 * @brief Helper macros for data printers
49 */
Radek Krejci52f65552020-09-01 17:03:35 +020050#define DO_FORMAT (!(ctx->options & LY_PRINT_SHRINK))
Radek Krejci5536d282020-08-04 23:27:44 +020051#define LEVEL ctx->level /**< current level */
52#define INDENT (DO_FORMAT ? (LEVEL)*2 : 0),"" /**< indentation parameters for printer functions */
53#define LEVEL_INC LEVEL++ /**< increase indentation level */
54#define LEVEL_DEC LEVEL-- /**< decrease indentation level */
Michal Vasko7c8439f2020-08-05 13:25:19 +020055
Radek Krejcif13b87b2020-12-01 22:02:17 +010056#define XML_NS_INDENT 8
57
Michal Vasko7c8439f2020-08-05 13:25:19 +020058/**
59 * @brief YANG printer of the parsed submodule. Full YANG printer.
60 *
61 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +020062 * @param[in] submodp Parsed submodule to print.
Radek Krejci5536d282020-08-04 23:27:44 +020063 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020064 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko7c8439f2020-08-05 13:25:19 +020065 */
Michal Vasko7997d5a2021-02-22 10:55:56 +010066LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020067
68/**
Radek Krejcie7b95092019-05-15 11:03:07 +020069 * @brief YANG printer of the compiled schemas.
70 *
71 * This printer provides information about modules how they are understood by libyang.
72 * Despite the format is inspired by YANG, it is not fully compatible and should not be
73 * used as a standard YANG format.
74 *
75 * @param[in] out Output specification.
76 * @param[in] module Schema to be printed (the compiled member is used).
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080077 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020078 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid3ca0632019-04-16 16:54:54 +020079 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020080LY_ERR yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080081
82/**
83 * @brief YANG printer of the compiled schema node
84 *
85 * This printer provides information about modules how they are understood by libyang.
86 * Despite the format is inspired by YANG, it is not fully compatible and should not be
87 * used as a standard YANG format.
88 *
89 * @param[in] out Output specification.
90 * @param[in] node Schema node to be printed including all its substatements.
91 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020092 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080093 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020094LY_ERR yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020095
Radek Krejcie7b95092019-05-15 11:03:07 +020096/**
Michal Vasko7c8439f2020-08-05 13:25:19 +020097 * @brief YIN printer of the parsed module. Full YIN printer.
FredGand944bdc2019-11-05 21:57:07 +080098 *
99 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +0200100 * @param[in] modp Parsed module to print.
Radek Krejci5536d282020-08-04 23:27:44 +0200101 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200102 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
FredGand944bdc2019-11-05 21:57:07 +0800103 */
Michal Vasko7997d5a2021-02-22 10:55:56 +0100104LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options);
Michal Vasko7c8439f2020-08-05 13:25:19 +0200105
106/**
107 * @brief YIN printer of the parsed submodule. Full YIN printer.
108 *
109 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +0200110 * @param[in] submodp Parsed submodule to print.
Radek Krejci5536d282020-08-04 23:27:44 +0200111 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200112 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko7c8439f2020-08-05 13:25:19 +0200113 */
Michal Vasko7997d5a2021-02-22 10:55:56 +0100114LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options);
FredGand944bdc2019-11-05 21:57:07 +0800115
116/**
aPiecek3f247652021-04-19 13:40:25 +0200117 * @brief Full YANG Tree Diagram printer.
118 *
119 * The module should be compiled and the @ref contextoptions must be set to LY_CTX_SET_PRIV_PARSED.
120 * If not, the printer will use parsed (unresolved) YANG schema tree, which means,
121 * for example, that `grouping` sections will be on the output.
aPiecek61d062b2020-11-02 11:05:09 +0100122 *
123 * @param[in] out Output specification.
124 * @param[in] module Main module.
125 * @param[in] options Schema output options (see @ref schemaprinterflags).
126 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer.
127 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
128 */
aPiecek3f247652021-04-19 13:40:25 +0200129LY_ERR tree_print_module(struct ly_out *out, const struct lys_module *module, uint32_t options,
aPiecek61d062b2020-11-02 11:05:09 +0100130 size_t line_length);
131
132/**
aPiecek9f792e52021-04-21 08:33:56 +0200133 * @brief YANG Tree Diagram printer of the parsed submodule. Full Tree printer.
134 *
135 * @param[in] out Output specification.
136 * @param[in] submodp Parsed submodule to print.
137 * @param[in] options Schema output options (see @ref schemaprinterflags).
138 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer.
139 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
140 */
141LY_ERR tree_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options,
142 size_t line_length);
143
144/**
145 * @brief YANG Tree Diagram printer of the compiled schema node.
aPiecek153b00f2021-04-20 13:52:57 +0200146 *
147 * @param[in] out Output specification.
148 * @param[in] node Schema node to be printed including all its substatements.
149 * @param[in] options Schema output options (see @ref schemaprinterflags).
150 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer.
151 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
152 */
153LY_ERR tree_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options,
154 size_t line_length);
155
156/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200157 * @brief XML printer of YANG data.
Radek Krejcie7b95092019-05-15 11:03:07 +0200158 *
159 * @param[in] out Output specification.
160 * @param[in] root The root element of the (sub)tree to print.
161 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200162 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcie7b95092019-05-15 11:03:07 +0200163 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200164LY_ERR xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Radek Krejcie7b95092019-05-15 11:03:07 +0200165
166/**
Radek Krejci5536d282020-08-04 23:27:44 +0200167 * @brief JSON printer of YANG data.
168 *
169 * @param[in] out Output specification.
170 * @param[in] root The root element of the (sub)tree to print.
171 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200172 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejci5536d282020-08-04 23:27:44 +0200173 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200174LY_ERR json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Radek Krejci5536d282020-08-04 23:27:44 +0200175
176/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200177 * @brief LYB printer of YANG data.
178 *
179 * @param[in] out Output structure.
180 * @param[in] root The root element of the (sub)tree to print.
181 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200182 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko60ea6352020-06-29 13:39:39 +0200183 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200184LY_ERR lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Michal Vasko60ea6352020-06-29 13:39:39 +0200185
Radek Krejcid3ca0632019-04-16 16:54:54 +0200186#endif /* LY_PRINTER_INTERNAL_H_ */