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 | e7b9509 | 2019-05-15 11:03:07 +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 | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 21 | #include "tree_schema.h" |
| 22 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * @defgroup schemaprinterflags Schema output options |
| 26 | * @ingroup schema |
| 27 | * |
| 28 | * @{ |
| 29 | */ |
Radek Krejci | 4fa6ebf | 2019-11-21 13:34:35 +0800 | [diff] [blame^] | 30 | #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] | 31 | do not print information from the substatements */ |
| 32 | //#define LYS_OUTOPT_TREE_RFC 0x01 /**< Conform to the RFC TODO tree output (only for tree format) */ |
| 33 | //#define LYS_OUTOPT_TREE_GROUPING 0x02 /**< Print groupings separately (only for tree format) */ |
| 34 | //#define LYS_OUTOPT_TREE_USES 0x04 /**< Print only uses instead the resolved grouping nodes (only for tree format) */ |
| 35 | //#define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 /**< Do not print the target of leafrefs (only for tree format) */ |
| 36 | |
| 37 | /** |
| 38 | * @} schemaprinterflags |
| 39 | */ |
| 40 | |
| 41 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 42 | /** |
| 43 | * @brief Print schema tree in the specified format into a memory block. |
| 44 | * It is up to caller to free the returned string by free(). |
| 45 | * |
| 46 | * @param[out] strp Pointer to store the resulting dump. |
| 47 | * @param[in] module Schema tree to print. |
| 48 | * @param[in] format Schema output format. |
| 49 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 50 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 51 | * @return Number of printed bytes in case of success. |
| 52 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 53 | */ |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 54 | ssize_t lys_print_mem(char **strp, 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] | 55 | |
| 56 | /** |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 57 | * @brief Print schema node in the specified format into a memory block. |
| 58 | * It is up to caller to free the returned string by free(). |
| 59 | * |
| 60 | * @param[out] strp Pointer to store the resulting dump. |
| 61 | * @param[in] ctx libyang context to get schema node in case of missing @p context_node. |
| 62 | * @param[in] context_node Context node in case of the relative @p target_node path. |
| 63 | * @param[in] format Schema output format. |
| 64 | * @param[in] target_node Schema node path, use full module names as node's prefixes. |
| 65 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 66 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 67 | * @return Number of printed bytes in case of success. |
| 68 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 69 | */ |
| 70 | ssize_t lys_node_print_mem(char **strp, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format, |
| 71 | const char *target_node, int line_length, int options); |
| 72 | |
| 73 | /** |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 74 | * @brief Print schema tree in the specified format into a file descriptor. |
| 75 | * |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 76 | * @param[in] fd File descriptor where to print the data. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 77 | * @param[in] module Schema tree to print. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 78 | * @param[in] format Schema output format. |
| 79 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format. |
| 80 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 81 | * @return Number of printed bytes in case of success. |
| 82 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 83 | */ |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 84 | ssize_t lys_print_fd(int fd, 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] | 85 | |
| 86 | /** |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 87 | * @brief Print schema tree in the specified format into a file descriptor. |
| 88 | * |
| 89 | * @param[in] fd File descriptor where to print the data. |
| 90 | * @param[in] ctx libyang context to get schema node in case of missing @p context_node. |
| 91 | * @param[in] context_node Context node in case of the relative @p target_node path. |
| 92 | * @param[in] format Schema output format. |
| 93 | * @param[in] target_node Schema node path, use full module names as node's prefixes. |
| 94 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format. |
| 95 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 96 | * @return Number of printed bytes in case of success. |
| 97 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 98 | */ |
| 99 | ssize_t lys_node_print_fd(int fd, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format, |
| 100 | const char *target_node, int line_length, int options); |
| 101 | |
| 102 | /** |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 103 | * @brief Print schema tree in the specified format into a file stream. |
| 104 | * |
| 105 | * @param[in] module Schema tree to print. |
| 106 | * @param[in] f File stream where to print the schema. |
| 107 | * @param[in] format Schema output format. |
| 108 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 109 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 110 | * @return Number of printed bytes in case of success. |
| 111 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 112 | */ |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 113 | ssize_t lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, |
| 114 | int line_length, int options); |
| 115 | |
| 116 | /** |
| 117 | * @brief Print schema node in the specified format into a file stream. |
| 118 | * |
| 119 | * @param[in] f File stream where to print the schema. |
| 120 | * @param[in] ctx libyang context to get schema node in case of missing @p context_node. |
| 121 | * @param[in] context_node Context node in case of the relative @p target_node path. |
| 122 | * @param[in] format Schema output format. |
| 123 | * @param[in] target_node Schema node path, use full module names as node's prefixes. |
| 124 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 125 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 126 | * @return Number of printed bytes in case of success. |
| 127 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 128 | */ |
| 129 | ssize_t lys_node_print_file(FILE *f, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format, |
| 130 | const char *target_node, int line_length, int options); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * @brief Print schema tree in the specified format into a file. |
| 134 | * |
| 135 | * @param[in] path File where to print the schema. |
| 136 | * @param[in] module Schema tree to print. |
| 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). |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 140 | * @return Number of printed bytes in case of success. |
| 141 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 142 | */ |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 143 | ssize_t lys_print_path(const char *path, 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] | 144 | |
| 145 | /** |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 146 | * @brief Print schema tree in the specified format into a file. |
| 147 | * |
| 148 | * @param[in] path File where to print the schema. |
| 149 | * @param[in] ctx libyang context to get schema node in case of missing @p context_node. |
| 150 | * @param[in] context_node Context node in case of the relative @p target_node path. |
| 151 | * @param[in] format Schema output format. |
| 152 | * @param[in] target_node Schema node path, use full module names as node's prefixes. |
| 153 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 154 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 155 | * @return Number of printed bytes in case of success. |
| 156 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 157 | */ |
| 158 | ssize_t lys_node_print_path(const char *path, struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format, |
| 159 | const char *target_node, int line_length, int options); |
| 160 | |
| 161 | /** |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 162 | * @brief Print schema tree in the specified format using a provided callback. |
| 163 | * |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 164 | * @param[in] writeclb Callback function to write the data (see write(1)). |
| 165 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 166 | * @param[in] module Schema tree to print. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 167 | * @param[in] format Schema output format. |
| 168 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 169 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 170 | * @return Number of printed bytes in case of success. |
| 171 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 172 | */ |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 173 | ssize_t lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 174 | const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options); |
| 175 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 176 | /** |
| 177 | * @brief Print schema node in the specified format using a provided callback. |
| 178 | * |
| 179 | * @param[in] writeclb Callback function to write the data (see write(1)). |
| 180 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
| 181 | * @param[in] ctx libyang context to get schema node in case of missing @p context_node. |
| 182 | * @param[in] context_node Context node in case of the relative @p target_node path. |
| 183 | * @param[in] format Schema output format. |
| 184 | * @param[in] target_node Schema node path, use full module names as node's prefixes. |
| 185 | * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer. |
| 186 | * @param[in] options Schema output options (see @ref schemaprinterflags). |
| 187 | * @return Number of printed bytes in case of success. |
| 188 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 189 | */ |
| 190 | ssize_t lys_node_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
| 191 | struct ly_ctx *ctx, const struct lysc_node *context_node, LYS_OUTFORMAT format, |
| 192 | const char *target_node, int line_length, int options); |
| 193 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 194 | #endif /* LY_PRINTER_SCHEMA_H_ */ |