Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 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 Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 19 | #include <unistd.h> |
| 20 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 21 | #include "log.h" |
Michal Vasko | ce2b874 | 2020-08-24 13:20:25 +0200 | [diff] [blame] | 22 | #include "printer.h" |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 28 | struct ly_out; |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 29 | struct lys_module; |
| 30 | struct lysc_node; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 31 | struct lysp_submodule; |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 32 | |
Radek Krejci | 2ff0d57 | 2020-05-21 15:27:28 +0200 | [diff] [blame] | 33 | /** |
| 34 | * @addtogroup schematree |
| 35 | * @{ |
| 36 | */ |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * @defgroup schemaprinterflags Schema output options |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 40 | * @{ |
| 41 | */ |
Radek Krejci | 5536d28 | 2020-08-04 23:27:44 +0200 | [diff] [blame] | 42 | /* Keep the value 0x02 reserver for implicit LYS_PRINT_FORMAT */ |
Radek Krejci | 4fa6ebf | 2019-11-21 13:34:35 +0800 | [diff] [blame] | 43 | #define LYS_OUTPUT_NO_SUBSTMT 0x10 /**< Print only top-level/referede node information, |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 44 | do not print information from the substatements */ |
Michal Vasko | 033278d | 2020-08-24 11:24:52 +0200 | [diff] [blame] | 45 | // #define LYS_OUTOPT_TREE_RFC 0x01 /**< Conform to the RFC TODO tree output (only for tree format) */ |
| 46 | // #define LYS_OUTOPT_TREE_GROUPING 0x02 /**< Print groupings separately (only for tree format) */ |
| 47 | // #define LYS_OUTOPT_TREE_USES 0x04 /**< Print only uses instead the resolved grouping nodes (only for tree format) */ |
| 48 | // #define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 /**< Do not print the target of leafrefs (only for tree format) */ |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 49 | |
Radek Krejci | 2ff0d57 | 2020-05-21 15:27:28 +0200 | [diff] [blame] | 50 | /** @} schemaprinterflags */ |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 51 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 52 | /** |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 53 | * @brief Schema output formats accepted by libyang [printer functions](@ref howtoschemasprinters). |
| 54 | */ |
| 55 | typedef enum { |
| 56 | LYS_OUT_UNKNOWN = 0, /**< unknown format, used as return value in case of error */ |
| 57 | LYS_OUT_YANG = 1, /**< YANG schema output format */ |
| 58 | LYS_OUT_YANG_COMPILED = 2, /**< YANG schema output format of the compiled schema tree */ |
| 59 | LYS_OUT_YIN = 3, /**< YIN schema output format */ |
| 60 | |
| 61 | LYS_OUT_TREE, /**< Tree schema output format, for more information see the [printers](@ref howtoschemasprinters) page */ |
| 62 | } LYS_OUTFORMAT; |
| 63 | |
| 64 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 65 | * @brief Schema module printer. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 66 | * |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 67 | * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler. |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 68 | * @param[in] module Main module with the parsed schema to print. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 69 | * @param[in] format Output format. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 70 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 71 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 72 | * @return LY_ERR value. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 73 | */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 74 | LY_ERR lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options); |
| 75 | |
| 76 | /** |
| 77 | * @brief Schema submodule printer. |
| 78 | * |
| 79 | * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler. |
| 80 | * @param[in] module Main module of the submodule to print. |
| 81 | * @param[in] submodule Parsed submodule to print. |
| 82 | * @param[in] format Output format. |
| 83 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 84 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 85 | * @return LY_ERR value. |
| 86 | */ |
| 87 | LY_ERR lys_print_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodule, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 88 | LYS_OUTFORMAT format, int line_length, int options); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 89 | |
| 90 | /** |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 91 | * @brief Print schema tree in the specified format into a memory block. |
| 92 | * It is up to caller to free the returned string by free(). |
| 93 | * |
| 94 | * This is just a wrapper around lys_print() for simple use cases. |
| 95 | * In case of a complex use cases, use lys_print with ly_out output handler. |
| 96 | * |
| 97 | * @param[out] strp Pointer to store the resulting dump. |
| 98 | * @param[in] module Schema tree to print. |
| 99 | * @param[in] format Schema output format. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 100 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 101 | * @return LY_ERR value. |
| 102 | */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 103 | LY_ERR lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @brief Print schema tree in the specified format into a file descriptor. |
| 107 | * |
| 108 | * This is just a wrapper around lys_print() for simple use cases. |
| 109 | * In case of a complex use cases, use lys_print with ly_out output handler. |
| 110 | * |
| 111 | * @param[in] fd File descriptor where to print the data. |
| 112 | * @param[in] module Schema tree to print. |
| 113 | * @param[in] format Schema output format. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 114 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 115 | * @return LY_ERR value. |
| 116 | */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 117 | LY_ERR lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * @brief Print schema tree in the specified format into a file stream. |
| 121 | * |
| 122 | * This is just a wrapper around lys_print() for simple use cases. |
| 123 | * In case of a complex use cases, use lys_print with ly_out output handler. |
| 124 | * |
| 125 | * @param[in] module Schema tree to print. |
| 126 | * @param[in] f File stream where to print the schema. |
| 127 | * @param[in] format Schema output format. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 128 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 129 | * @return LY_ERR value. |
| 130 | */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 131 | LY_ERR lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * @brief Print schema tree in the specified format into a file. |
| 135 | * |
| 136 | * This is just a wrapper around lys_print() for simple use cases. |
| 137 | * In case of a complex use cases, use lys_print with ly_out output handler. |
| 138 | * |
| 139 | * @param[in] path File where to print the schema. |
| 140 | * @param[in] module Schema tree to print. |
| 141 | * @param[in] format Schema output format. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 142 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 143 | * @return LY_ERR value. |
| 144 | */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 145 | LY_ERR lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * @brief Print schema tree in the specified format using a provided callback. |
| 149 | * |
| 150 | * This is just a wrapper around lys_print() for simple use cases. |
| 151 | * In case of a complex use cases, use lys_print with ly_out output handler. |
| 152 | * |
| 153 | * @param[in] module Schema tree to print. |
| 154 | * @param[in] writeclb Callback function to write the data (see write(1)). |
Michal Vasko | ce2b874 | 2020-08-24 13:20:25 +0200 | [diff] [blame] | 155 | * @param[in] user_data Optional caller-specific argument to be passed to the \p writeclb callback. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 156 | * @param[in] format Schema output format. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 157 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 158 | * @return LY_ERR value. |
| 159 | */ |
Michal Vasko | ce2b874 | 2020-08-24 13:20:25 +0200 | [diff] [blame] | 160 | LY_ERR lys_print_clb(ly_write_clb writeclb, void *user_data, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 161 | const struct lys_module *module, LYS_OUTFORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 162 | |
| 163 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 164 | * @brief Schema node printer. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 165 | * |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 166 | * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 167 | * @param[in] node Schema node to print, lys_find_node() can be used to get it from a path string. |
| 168 | * @param[in] format Output format. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 169 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 170 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 171 | * @return LY_ERR value. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 172 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 173 | LY_ERR lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, int line_length, int options); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 174 | |
Radek Krejci | 2ff0d57 | 2020-05-21 15:27:28 +0200 | [diff] [blame] | 175 | /** @} schematree */ |
| 176 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 177 | #ifdef __cplusplus |
| 178 | } |
| 179 | #endif |
| 180 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 181 | #endif /* LY_PRINTER_SCHEMA_H_ */ |