blob: c64880991646835a9c1b4f5520ef89b2130db2d6 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Internal structures and functions 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_INTERNAL_H_
16#define LY_PRINTER_INTERNAL_H_
17
Michal Vaskoafac7822020-10-20 14:22:26 +020018#include "out.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include "printer_data.h"
Michal Vasko69730152020-10-09 16:30:07 +020020#include "printer_schema.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020021
Michal Vasko7c8439f2020-08-05 13:25:19 +020022struct lysp_module;
23struct lysp_submodule;
24
Radek Krejcie7b95092019-05-15 11:03:07 +020025/**
Radek Krejcie7b95092019-05-15 11:03:07 +020026 * @brief Informational structure for YANG statements
27 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020028struct ext_substmt_info_s {
Radek Krejcie7b95092019-05-15 11:03:07 +020029 const char *name; /**< name of the statement */
30 const char *arg; /**< name of YIN's attribute to present the statement */
Radek Krejci1deb5be2020-08-26 16:43:36 +020031 uint8_t flags; /**< various flags to clarify printing of the statement */
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#define SUBST_FLAG_YIN 0x1 /**< has YIN element */
33#define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */
34};
35
Michal Vaskoafac7822020-10-20 14:22:26 +020036/* filled in out.c */
Radek Krejcid3ca0632019-04-16 16:54:54 +020037extern struct ext_substmt_info_s ext_substmt_info[];
38
Radek Krejcie7b95092019-05-15 11:03:07 +020039/**
Michal Vasko7c8439f2020-08-05 13:25:19 +020040 * @brief YANG printer of the parsed module. Full YANG printer.
Radek Krejcie7b95092019-05-15 11:03:07 +020041 *
42 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +020043 * @param[in] module Main module.
44 * @param[in] modp Parsed module to print.
Radek Krejci5536d282020-08-04 23:27:44 +020045 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020046 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid3ca0632019-04-16 16:54:54 +020047 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020048LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options);
Radek Krejci5536d282020-08-04 23:27:44 +020049
50/**
51 * @brief Helper macros for data printers
52 */
Radek Krejci52f65552020-09-01 17:03:35 +020053#define DO_FORMAT (!(ctx->options & LY_PRINT_SHRINK))
Radek Krejci5536d282020-08-04 23:27:44 +020054#define LEVEL ctx->level /**< current level */
55#define INDENT (DO_FORMAT ? (LEVEL)*2 : 0),"" /**< indentation parameters for printer functions */
56#define LEVEL_INC LEVEL++ /**< increase indentation level */
57#define LEVEL_DEC LEVEL-- /**< decrease indentation level */
Michal Vasko7c8439f2020-08-05 13:25:19 +020058
Radek Krejcif13b87b2020-12-01 22:02:17 +010059#define XML_NS_INDENT 8
60
Michal Vasko7c8439f2020-08-05 13:25:19 +020061/**
62 * @brief YANG printer of the parsed submodule. Full YANG printer.
63 *
64 * @param[in] out Output specification.
65 * @param[in] module Main module.
66 * @param[in] submodp Parsed submodule to print.
Radek Krejci5536d282020-08-04 23:27:44 +020067 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020068 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko7c8439f2020-08-05 13:25:19 +020069 */
Michal Vaskoafac7822020-10-20 14:22:26 +020070LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module,
71 const struct lysp_submodule *submodp, uint32_t options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020072
73/**
Radek Krejcie7b95092019-05-15 11:03:07 +020074 * @brief YANG printer of the compiled schemas.
75 *
76 * This printer provides information about modules how they are understood by libyang.
77 * Despite the format is inspired by YANG, it is not fully compatible and should not be
78 * used as a standard YANG format.
79 *
80 * @param[in] out Output specification.
81 * @param[in] module Schema to be printed (the compiled member is used).
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080082 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020083 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid3ca0632019-04-16 16:54:54 +020084 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020085LY_ERR yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080086
87/**
88 * @brief YANG printer of the compiled schema node
89 *
90 * This printer provides information about modules how they are understood by libyang.
91 * Despite the format is inspired by YANG, it is not fully compatible and should not be
92 * used as a standard YANG format.
93 *
94 * @param[in] out Output specification.
95 * @param[in] node Schema node to be printed including all its substatements.
96 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +020097 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcid8c0f5e2019-11-17 12:18:34 +080098 */
Radek Krejci1deb5be2020-08-26 16:43:36 +020099LY_ERR yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200100
Radek Krejcie7b95092019-05-15 11:03:07 +0200101/**
Michal Vasko7c8439f2020-08-05 13:25:19 +0200102 * @brief YIN printer of the parsed module. Full YIN printer.
FredGand944bdc2019-11-05 21:57:07 +0800103 *
104 * @param[in] out Output specification.
Michal Vasko7c8439f2020-08-05 13:25:19 +0200105 * @param[in] module Main module.
106 * @param[in] modp Parsed module to print.
Radek Krejci5536d282020-08-04 23:27:44 +0200107 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200108 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
FredGand944bdc2019-11-05 21:57:07 +0800109 */
Michal Vaskoafac7822020-10-20 14:22:26 +0200110LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp,
111 uint32_t options);
Michal Vasko7c8439f2020-08-05 13:25:19 +0200112
113/**
114 * @brief YIN printer of the parsed submodule. Full YIN printer.
115 *
116 * @param[in] out Output specification.
117 * @param[in] module Main module.
118 * @param[in] submodp Parsed submodule to print.
Radek Krejci5536d282020-08-04 23:27:44 +0200119 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200120 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko7c8439f2020-08-05 13:25:19 +0200121 */
Michal Vaskoafac7822020-10-20 14:22:26 +0200122LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module,
123 const struct lysp_submodule *submodp, uint32_t options);
FredGand944bdc2019-11-05 21:57:07 +0800124
125/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200126 * @brief XML printer of YANG data.
Radek Krejcie7b95092019-05-15 11:03:07 +0200127 *
128 * @param[in] out Output specification.
129 * @param[in] root The root element of the (sub)tree to print.
130 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200131 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejcie7b95092019-05-15 11:03:07 +0200132 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200133LY_ERR xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Radek Krejcie7b95092019-05-15 11:03:07 +0200134
135/**
Radek Krejci5536d282020-08-04 23:27:44 +0200136 * @brief JSON printer of YANG data.
137 *
138 * @param[in] out Output specification.
139 * @param[in] root The root element of the (sub)tree to print.
140 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200141 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Radek Krejci5536d282020-08-04 23:27:44 +0200142 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200143LY_ERR json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Radek Krejci5536d282020-08-04 23:27:44 +0200144
145/**
Michal Vasko60ea6352020-06-29 13:39:39 +0200146 * @brief LYB printer of YANG data.
147 *
148 * @param[in] out Output structure.
149 * @param[in] root The root element of the (sub)tree to print.
150 * @param[in] options [Data printer flags](@ref dataprinterflags).
Radek Krejci8678fa42020-08-18 16:07:28 +0200151 * @return LY_ERR value, number of the printed bytes is updated in ::ly_out.printed.
Michal Vasko60ea6352020-06-29 13:39:39 +0200152 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200153LY_ERR lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
Michal Vasko60ea6352020-06-29 13:39:39 +0200154
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155#endif /* LY_PRINTER_INTERNAL_H_ */