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