blob: d9065bbcc0b0e30354f9782b342eb04878173630 [file] [log] [blame]
Radek Krejcie7b95092019-05-15 11:03:07 +02001/**
Michal Vasko52927e22020-03-16 17:26:14 +01002 * @file printer_data.h
Radek Krejcie7b95092019-05-15 11:03:07 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vasko52927e22020-03-16 17:26:14 +01004 * @brief Data printers for libyang
Radek Krejcie7b95092019-05-15 11:03:07 +02005 *
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"
Radek Krejcia5bba312020-01-09 15:41:20 +010022#include "printer.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020023
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 Krejci241f6b52020-05-21 18:13:49 +020040#define LYDP_WD_ALL_TAG 0x40 /**< Same as #LYDP_WD_ALL but also adds attribute 'default' with value 'true' to
Radek Krejcie7b95092019-05-15 11:03:07 +020041 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 Krejci241f6b52020-05-21 18:13:49 +020045#define LYDP_WD_IMPL_TAG 0x80 /**< Same as LYDP_WD_ALL_TAG but the attributes are added only to the nodes that
Radek Krejcie7b95092019-05-15 11:03:07 +020046 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 Krejcie7b95092019-05-15 11:03:07 +020049/**
50 * @}
51 */
52
53/**
Radek Krejcia5bba312020-01-09 15:41:20 +010054 * @brief Common YANG data printer.
Radek Krejcie7b95092019-05-15 11:03:07 +020055 *
Radek Krejci241f6b52020-05-21 18:13:49 +020056 * @param[in] out Printer handler for a specific output. Use ly_out_*() functions to create and free the handler.
Radek Krejcia5bba312020-01-09 15:41:20 +010057 * @param[in] root The root element of the (sub)tree to print.
58 * @param[in] format Output format.
Radek Krejci241f6b52020-05-21 18:13:49 +020059 * @param[in] options [Data printer flags](@ref dataprinterflags). With \p format LYD_LYB, only #LYDP_WITHSIBLINGS option is accepted.
Radek Krejci26a5dfb2019-07-26 14:51:06 +020060 * @return Number of printed characters (excluding the null byte used to end the string) in case of success.
Radek Krejcie7b95092019-05-15 11:03:07 +020061 * @return Negative value failure (absolute value corresponds to LY_ERR values).
62 */
Radek Krejci241f6b52020-05-21 18:13:49 +020063ssize_t lyd_print(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
Radek Krejcie7b95092019-05-15 11:03:07 +020064
65#endif /* LY_PRINTER_DATA_H_ */