Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 2 | * @file printer_data.h |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 4 | * @brief Data printers for libyang |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 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_DATA_H_ |
| 16 | #define LY_PRINTER_DATA_H_ |
| 17 | |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 19 | #include <unistd.h> |
| 20 | |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 21 | #include "log.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 22 | #include "tree_data.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 23 | |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 28 | struct ly_out; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * @defgroup dataprinterflags Data printer flags |
| 32 | * @ingroup datatree |
| 33 | * |
| 34 | * Validity flags for data nodes. |
| 35 | * |
| 36 | * @{ |
| 37 | */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 38 | #define LYD_PRINT_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 39 | #define LYD_PRINT_FORMAT 0x02 /**< Flag for formatted output. */ |
| 40 | #define LYD_PRINT_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */ |
| 41 | #define LYD_PRINT_WD_MASK 0xF0 /**< Mask for with-defaults modes */ |
| 42 | #define LYD_PRINT_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree. |
| 43 | Note that this is the default value when no WD option is specified. */ |
| 44 | #define LYD_PRINT_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */ |
| 45 | #define LYD_PRINT_WD_ALL 0x20 /**< Include implicit default nodes */ |
| 46 | #define LYD_PRINT_WD_ALL_TAG 0x40 /**< Same as #LYDP_WD_ALL but also adds attribute 'default' with value 'true' to |
| 47 | all nodes that has its default value. The 'default' attribute has namespace: |
| 48 | urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are |
| 49 | printed only when the ietf-netconf-with-defaults module is present in libyang |
| 50 | context (but in that case this namespace is always printed). */ |
| 51 | #define LYD_PRINT_WD_IMPL_TAG 0x80 /**< Same as LYDP_WD_ALL_TAG but the attributes are added only to the nodes that |
| 52 | are not explicitly present in the original data tree despite their |
| 53 | value is equal to their default value. There is the same limitation regarding |
| 54 | the presence of ietf-netconf-with-defaults module in libyang context. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 55 | /** |
| 56 | * @} |
| 57 | */ |
| 58 | |
| 59 | /** |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 60 | * @brief Print the whole data tree of the root, including all the siblings. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 61 | * |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 62 | * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler. |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 63 | * @param[in] root The root element of the tree to print, can be any sibling. |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 64 | * @param[in] format Output format. |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 65 | * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 66 | * @return LY_ERR value. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 67 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 68 | LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 69 | |
| 70 | /** |
| 71 | * @brief Print the selected data subtree. |
| 72 | * |
| 73 | * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler. |
| 74 | * @param[in] root The root element of the subtree to print. |
| 75 | * @param[in] format Output format. |
| 76 | * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS. |
| 77 | * @return LY_ERR value. |
| 78 | */ |
| 79 | LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 80 | |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 81 | /** |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 82 | * @brief Print data tree in the specified format. |
| 83 | * |
| 84 | * @param[out] strp Pointer to store the resulting dump. |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 85 | * @param[in] root The root element of the (sub)tree to print. |
| 86 | * @param[in] format Output format. |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 87 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
| 88 | * @return LY_ERR value. |
| 89 | */ |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 90 | LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 91 | |
| 92 | /** |
| 93 | * @brief Print data tree in the specified format. |
| 94 | * |
| 95 | * @param[in] fd File descriptor where to print the data. |
| 96 | * @param[in] root The root element of the (sub)tree to print. |
| 97 | * @param[in] format Output format. |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 98 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 99 | * @return LY_ERR value. |
| 100 | */ |
| 101 | LY_ERR lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 102 | |
| 103 | /** |
| 104 | * @brief Print data tree in the specified format. |
| 105 | * |
| 106 | * @param[in] f File stream where to print the data. |
| 107 | * @param[in] root The root element of the (sub)tree to print. |
| 108 | * @param[in] format Output format. |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 109 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 110 | * @return LY_ERR value. |
| 111 | */ |
| 112 | LY_ERR lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 113 | |
| 114 | /** |
| 115 | * @brief Print data tree in the specified format. |
| 116 | * |
| 117 | * @param[in] path File path where to print the data. |
| 118 | * @param[in] root The root element of the (sub)tree to print. |
| 119 | * @param[in] format Output format. |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 120 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 121 | * @return LY_ERR value. |
| 122 | */ |
| 123 | LY_ERR lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 124 | |
| 125 | /** |
| 126 | * @brief Print data tree in the specified format. |
| 127 | * |
| 128 | * @param[in] writeclb Callback function to write the data (see write(1)). |
| 129 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
| 130 | * @param[in] root The root element of the (sub)tree to print. |
| 131 | * @param[in] format Output format. |
Michal Vasko | dcd356f | 2020-07-14 12:26:51 +0200 | [diff] [blame] | 132 | * @param[in] options [Data printer flags](@ref dataprinterflags). |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 133 | * @return LY_ERR value. |
| 134 | */ |
| 135 | LY_ERR lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 136 | const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | 26da522 | 2020-06-09 17:43:17 +0200 | [diff] [blame] | 137 | |
| 138 | #ifdef __cplusplus |
| 139 | } |
| 140 | #endif |
| 141 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 142 | #endif /* LY_PRINTER_DATA_H_ */ |