Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 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 Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 18 | #include "out.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 19 | #include "printer_data.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 20 | #include "printer_schema.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 21 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 22 | struct lysp_module; |
| 23 | struct lysp_submodule; |
| 24 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 25 | /** |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 26 | * @brief Generic YANG schema printer context |
| 27 | * |
| 28 | * Note that the YANG extensions API provides getter to the members for the extension plugins. |
| 29 | */ |
| 30 | struct lyspr_ctx { |
| 31 | struct ly_out *out; /**< output specification */ |
| 32 | uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 33 | uint16_t flags; /**< internal flags for use by printer */ |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 34 | uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */ |
| 35 | const struct lys_module *module; /**< schema to print */ |
| 36 | }; |
| 37 | |
| 38 | /** |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 39 | * @brief YANG printer of the parsed module. Full YANG printer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 40 | * |
| 41 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 42 | * @param[in] modp Parsed module to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 43 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 44 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 45 | */ |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 46 | LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options); |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * @brief Helper macros for data printers |
| 50 | */ |
Michal Vasko | c08b9d2 | 2022-02-10 15:48:39 +0100 | [diff] [blame^] | 51 | #define DO_FORMAT (!(pctx->options & LY_PRINT_SHRINK)) |
| 52 | #define LEVEL pctx->level /**< current level */ |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 53 | #define INDENT (DO_FORMAT ? (LEVEL)*2 : 0),"" /**< indentation parameters for printer functions */ |
| 54 | #define LEVEL_INC LEVEL++ /**< increase indentation level */ |
| 55 | #define LEVEL_DEC LEVEL-- /**< decrease indentation level */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 56 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 57 | #define XML_NS_INDENT 8 |
| 58 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 59 | /** |
| 60 | * @brief YANG printer of the parsed submodule. Full YANG printer. |
| 61 | * |
| 62 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 63 | * @param[in] submodp Parsed submodule to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 64 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 65 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 66 | */ |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 67 | LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 68 | |
| 69 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 70 | * @brief YANG printer of the compiled schemas. |
| 71 | * |
| 72 | * This printer provides information about modules how they are understood by libyang. |
| 73 | * Despite the format is inspired by YANG, it is not fully compatible and should not be |
| 74 | * used as a standard YANG format. |
| 75 | * |
| 76 | * @param[in] out Output specification. |
| 77 | * @param[in] module Schema to be printed (the compiled member is used). |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 78 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 79 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 80 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 81 | LY_ERR yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * @brief YANG printer of the compiled schema node |
| 85 | * |
| 86 | * This printer provides information about modules how they are understood by libyang. |
| 87 | * Despite the format is inspired by YANG, it is not fully compatible and should not be |
| 88 | * used as a standard YANG format. |
| 89 | * |
| 90 | * @param[in] out Output specification. |
| 91 | * @param[in] node Schema node to be printed including all its substatements. |
| 92 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 93 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 94 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 95 | LY_ERR yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 96 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 97 | /** |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 98 | * @brief YIN printer of the parsed module. Full YIN printer. |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 99 | * |
| 100 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 101 | * @param[in] modp Parsed module to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 102 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 103 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 104 | */ |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 105 | LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * @brief YIN printer of the parsed submodule. Full YIN printer. |
| 109 | * |
| 110 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 111 | * @param[in] submodp Parsed submodule to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 112 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 113 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 114 | */ |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 115 | LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 116 | |
| 117 | /** |
aPiecek | 3f24765 | 2021-04-19 13:40:25 +0200 | [diff] [blame] | 118 | * @brief Full YANG Tree Diagram printer. |
| 119 | * |
| 120 | * The module should be compiled and the @ref contextoptions must be set to LY_CTX_SET_PRIV_PARSED. |
| 121 | * If not, the printer will use parsed (unresolved) YANG schema tree, which means, |
| 122 | * for example, that `grouping` sections will be on the output. |
aPiecek | 61d062b | 2020-11-02 11:05:09 +0100 | [diff] [blame] | 123 | * |
| 124 | * @param[in] out Output specification. |
| 125 | * @param[in] module Main module. |
| 126 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 127 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer. |
| 128 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
| 129 | */ |
aPiecek | 3f24765 | 2021-04-19 13:40:25 +0200 | [diff] [blame] | 130 | LY_ERR tree_print_module(struct ly_out *out, const struct lys_module *module, uint32_t options, |
aPiecek | 61d062b | 2020-11-02 11:05:09 +0100 | [diff] [blame] | 131 | size_t line_length); |
| 132 | |
| 133 | /** |
aPiecek | 9f792e5 | 2021-04-21 08:33:56 +0200 | [diff] [blame] | 134 | * @brief YANG Tree Diagram printer of the parsed submodule. Full Tree printer. |
| 135 | * |
| 136 | * @param[in] out Output specification. |
| 137 | * @param[in] submodp Parsed submodule to print. |
| 138 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 139 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer. |
| 140 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
| 141 | */ |
| 142 | LY_ERR tree_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options, |
| 143 | size_t line_length); |
| 144 | |
| 145 | /** |
| 146 | * @brief YANG Tree Diagram printer of the compiled schema node. |
aPiecek | 153b00f | 2021-04-20 13:52:57 +0200 | [diff] [blame] | 147 | * |
| 148 | * @param[in] out Output specification. |
| 149 | * @param[in] node Schema node to be printed including all its substatements. |
| 150 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 151 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for ::LYS_OUT_TREE printer. |
| 152 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
| 153 | */ |
| 154 | LY_ERR tree_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options, |
| 155 | size_t line_length); |
| 156 | |
| 157 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 158 | * @brief XML printer of YANG data. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 159 | * |
| 160 | * @param[in] out Output specification. |
| 161 | * @param[in] root The root element of the (sub)tree to print. |
| 162 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 163 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 164 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 165 | LY_ERR xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 166 | |
| 167 | /** |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 168 | * @brief JSON printer of YANG data. |
| 169 | * |
| 170 | * @param[in] out Output specification. |
| 171 | * @param[in] root The root element of the (sub)tree to print. |
| 172 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 173 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 174 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 175 | LY_ERR json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options); |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 176 | |
| 177 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 178 | * @brief LYB printer of YANG data. |
| 179 | * |
| 180 | * @param[in] out Output structure. |
| 181 | * @param[in] root The root element of the (sub)tree to print. |
| 182 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 183 | * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 184 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 185 | LY_ERR lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 186 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 187 | #endif /* LY_PRINTER_INTERNAL_H_ */ |