Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +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_DATA_H_ |
| 16 | #define LY_PRINTER_DATA_H_ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include "tree_data.h" |
| 22 | |
| 23 | /** |
| 24 | * @defgroup dataprinterflags Data printer flags |
| 25 | * @ingroup datatree |
| 26 | * |
| 27 | * Validity flags for data nodes. |
| 28 | * |
| 29 | * @{ |
| 30 | */ |
| 31 | #define LYDP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 32 | #define LYDP_FORMAT 0x02 /**< Flag for formatted output. */ |
| 33 | #define LYDP_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */ |
| 34 | #define LYDP_WD_MASK 0xF0 /**< Mask for with-defaults modes */ |
| 35 | #define LYDP_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree. |
| 36 | Note that this is the default value when no WD option is specified. */ |
| 37 | #define LYDP_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */ |
| 38 | #define LYDP_WD_ALL 0x20 /**< Include implicit default nodes */ |
| 39 | #define LYDP_WD_ALL_TAG 0x40 /**< Same as #LYP_WD_ALL but also adds attribute 'default' with value 'true' to |
| 40 | all nodes that has its default value. The 'default' attribute has namespace: |
| 41 | urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are |
| 42 | printed only when the ietf-netconf-with-defaults module is present in libyang |
| 43 | context (but in that case this namespace is always printed). */ |
| 44 | #define LYDP_WD_IMPL_TAG 0x80 /**< Same as LYP_WD_ALL_TAG but the attributes are added only to the nodes that |
| 45 | are not explicitly present in the original data tree despite their |
| 46 | value is equal to their default value. There is the same limitation regarding |
| 47 | the presence of ietf-netconf-with-defaults module in libyang context. */ |
| 48 | #define LYDP_NETCONF 0x100 /**< Print the data tree for use in NETCONF meaning: |
| 49 | - for RPC output - skip the top-level RPC node, |
| 50 | - for action output - skip all the parents of and the action node itself, |
| 51 | - for action input - enclose the data in an action element in the base YANG namespace, |
| 52 | - for all other data - print the whole data tree normally. */ |
| 53 | /** |
| 54 | * @} |
| 55 | */ |
| 56 | |
| 57 | /** |
| 58 | * @brief Print data tree in the specified format into a memory block. |
| 59 | * It is up to caller to free the returned string by free(). |
| 60 | * |
| 61 | * @param[out] strp Pointer to store the resulting dump. |
| 62 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 63 | * node of the data tree to print the specific subtree. |
| 64 | * @param[in] format Data output format. |
| 65 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 66 | * @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] | 67 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 68 | */ |
| 69 | ssize_t lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 70 | |
| 71 | /** |
| 72 | * @brief Print data tree in the specified format into a file descriptor. |
| 73 | * |
| 74 | * @param[in] fd File descriptor where to print the data. |
| 75 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 76 | * node of the data tree to print the specific subtree. |
| 77 | * @param[in] format Data output format. |
| 78 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 79 | * @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] | 80 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 81 | */ |
| 82 | ssize_t lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 83 | |
| 84 | /** |
| 85 | * @brief Print data tree in the specified format into a file stream. |
| 86 | * |
| 87 | * @param[in] f File stream where to print the schema. |
| 88 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 89 | * node of the data tree to print the specific subtree. |
| 90 | * @param[in] format Data output format. |
| 91 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 92 | * @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] | 93 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 94 | */ |
| 95 | ssize_t lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 96 | |
| 97 | /** |
| 98 | * @brief Print data tree in the specified format into a file. |
| 99 | * |
| 100 | * @param[in] path File where to print the schema. |
| 101 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 102 | * node of the data tree to print the specific subtree. |
| 103 | * @param[in] format Data output format. |
| 104 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 105 | * @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] | 106 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 107 | */ |
| 108 | ssize_t lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 109 | |
| 110 | /** |
| 111 | * @brief Print data tree in the specified format using the provided callback. |
| 112 | * |
| 113 | * @param[in] writeclb Callback function to write the data (see write(2)). |
| 114 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
| 115 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 116 | * node of the data tree to print the specific subtree. |
| 117 | * @param[in] format Data output format. |
| 118 | * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYP_WITHSIBLINGS option is accepted. |
Radek Krejci | 26a5dfb | 2019-07-26 14:51:06 +0200 | [diff] [blame] | 119 | * @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] | 120 | * @return Negative value failure (absolute value corresponds to LY_ERR values). |
| 121 | */ |
| 122 | ssize_t lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyd_node *root, |
| 123 | LYD_FORMAT format, int options); |
| 124 | |
| 125 | #endif /* LY_PRINTER_DATA_H_ */ |