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 | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 26 | * @brief Informational structure for YANG statements |
| 27 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 28 | struct ext_substmt_info_s { |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 29 | const char *name; /**< name of the statement */ |
| 30 | const char *arg; /**< name of YIN's attribute to present the statement */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 31 | uint8_t flags; /**< various flags to clarify printing of the statement */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 32 | #define SUBST_FLAG_YIN 0x1 /**< has YIN element */ |
| 33 | #define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */ |
| 34 | }; |
| 35 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame^] | 36 | /* filled in out.c */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 37 | extern struct ext_substmt_info_s ext_substmt_info[]; |
| 38 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 39 | /** |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 40 | * @brief YANG printer of the parsed module. Full YANG printer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 41 | * |
| 42 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 43 | * @param[in] module Main module. |
| 44 | * @param[in] modp Parsed module to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 45 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 46 | * @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] | 47 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 48 | LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options); |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * @brief Helper macros for data printers |
| 52 | */ |
Radek Krejci | 52f6555 | 2020-09-01 17:03:35 +0200 | [diff] [blame] | 53 | #define DO_FORMAT (!(ctx->options & LY_PRINT_SHRINK)) |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 54 | #define LEVEL ctx->level /**< current level */ |
| 55 | #define INDENT (DO_FORMAT ? (LEVEL)*2 : 0),"" /**< indentation parameters for printer functions */ |
| 56 | #define LEVEL_INC LEVEL++ /**< increase indentation level */ |
| 57 | #define LEVEL_DEC LEVEL-- /**< decrease indentation level */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * @brief YANG printer of the parsed submodule. Full YANG printer. |
| 61 | * |
| 62 | * @param[in] out Output specification. |
| 63 | * @param[in] module Main module. |
| 64 | * @param[in] submodp Parsed submodule to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 65 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 66 | * @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] | 67 | */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame^] | 68 | LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, |
| 69 | const struct lysp_submodule *submodp, uint32_t options); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 70 | |
| 71 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 72 | * @brief YANG printer of the compiled schemas. |
| 73 | * |
| 74 | * This printer provides information about modules how they are understood by libyang. |
| 75 | * Despite the format is inspired by YANG, it is not fully compatible and should not be |
| 76 | * used as a standard YANG format. |
| 77 | * |
| 78 | * @param[in] out Output specification. |
| 79 | * @param[in] module Schema to be printed (the compiled member is used). |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 80 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 81 | * @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] | 82 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 83 | 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] | 84 | |
| 85 | /** |
| 86 | * @brief YANG printer of the compiled schema node |
| 87 | * |
| 88 | * This printer provides information about modules how they are understood by libyang. |
| 89 | * Despite the format is inspired by YANG, it is not fully compatible and should not be |
| 90 | * used as a standard YANG format. |
| 91 | * |
| 92 | * @param[in] out Output specification. |
| 93 | * @param[in] node Schema node to be printed including all its substatements. |
| 94 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 95 | * @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] | 96 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 97 | 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] | 98 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 99 | /** |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 100 | * @brief YIN printer of the parsed module. Full YIN printer. |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 101 | * |
| 102 | * @param[in] out Output specification. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 103 | * @param[in] module Main module. |
| 104 | * @param[in] modp Parsed module to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 105 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 106 | * @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] | 107 | */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame^] | 108 | LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, |
| 109 | uint32_t options); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * @brief YIN printer of the parsed submodule. Full YIN printer. |
| 113 | * |
| 114 | * @param[in] out Output specification. |
| 115 | * @param[in] module Main module. |
| 116 | * @param[in] submodp Parsed submodule to print. |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 117 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 118 | * @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] | 119 | */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame^] | 120 | LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, |
| 121 | const struct lysp_submodule *submodp, uint32_t options); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 122 | |
| 123 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 124 | * @brief XML printer of YANG data. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 125 | * |
| 126 | * @param[in] out Output specification. |
| 127 | * @param[in] root The root element of the (sub)tree to print. |
| 128 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 129 | * @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] | 130 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 131 | 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] | 132 | |
| 133 | /** |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 134 | * @brief JSON printer of YANG data. |
| 135 | * |
| 136 | * @param[in] out Output specification. |
| 137 | * @param[in] root The root element of the (sub)tree to print. |
| 138 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 139 | * @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] | 140 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 141 | 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] | 142 | |
| 143 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 144 | * @brief LYB printer of YANG data. |
| 145 | * |
| 146 | * @param[in] out Output structure. |
| 147 | * @param[in] root The root element of the (sub)tree to print. |
| 148 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 149 | * @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] | 150 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 151 | 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] | 152 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 153 | #endif /* LY_PRINTER_INTERNAL_H_ */ |