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 | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 18 | #include <unistd.h> |
| 19 | |
| 20 | #include "tree_data.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame^] | 21 | |
| 22 | struct ly_out; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * @defgroup dataprinterflags Data printer flags |
| 26 | * @ingroup datatree |
| 27 | * |
| 28 | * Validity flags for data nodes. |
| 29 | * |
| 30 | * @{ |
| 31 | */ |
| 32 | #define LYDP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 33 | #define LYDP_FORMAT 0x02 /**< Flag for formatted output. */ |
| 34 | #define LYDP_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */ |
| 35 | #define LYDP_WD_MASK 0xF0 /**< Mask for with-defaults modes */ |
| 36 | #define LYDP_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree. |
| 37 | Note that this is the default value when no WD option is specified. */ |
| 38 | #define LYDP_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */ |
| 39 | #define LYDP_WD_ALL 0x20 /**< Include implicit default nodes */ |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 40 | #define LYDP_WD_ALL_TAG 0x40 /**< Same as #LYDP_WD_ALL but also adds attribute 'default' with value 'true' to |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 41 | all nodes that has its default value. The 'default' attribute has namespace: |
| 42 | urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are |
| 43 | printed only when the ietf-netconf-with-defaults module is present in libyang |
| 44 | context (but in that case this namespace is always printed). */ |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 45 | #define LYDP_WD_IMPL_TAG 0x80 /**< Same as LYDP_WD_ALL_TAG but the attributes are added only to the nodes that |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 46 | are not explicitly present in the original data tree despite their |
| 47 | value is equal to their default value. There is the same limitation regarding |
| 48 | the presence of ietf-netconf-with-defaults module in libyang context. */ |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 49 | /** |
| 50 | * @} |
| 51 | */ |
| 52 | |
| 53 | /** |
Radek Krejci | a5bba31 | 2020-01-09 15:41:20 +0100 | [diff] [blame] | 54 | * @brief Common YANG data printer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 55 | * |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 56 | * @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] | 57 | * @param[in] root The root element of the (sub)tree to print. |
| 58 | * @param[in] format Output format. |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 59 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYDP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 60 | * @return Number of printed characters (excluding the null byte used to end the string) in case of success. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 61 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 62 | */ |
Radek Krejci | 241f6b5 | 2020-05-21 18:13:49 +0200 | [diff] [blame] | 63 | ssize_t lyd_print(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] | 64 | |
| 65 | #endif /* LY_PRINTER_DATA_H_ */ |