blob: 8b7e593f0a7946a6102b0eba76978f559de4f5ee [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief YANG printer
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
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010022#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020023
Radek Krejci535ea9f2020-05-29 16:01:05 +020024#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020025#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010027#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020028#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010029#include "plugins_exts.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010030#include "plugins_exts_print.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
Radek Krejciaa14a0c2020-09-04 11:16:47 +020048#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
49
Michal Vasko61ad1ff2022-02-10 15:48:39 +010050#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
51#define YPR_EXTRA_LINE_PRINT(PCTX) \
52 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
53 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020054 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010055 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020056 } \
57 }
58
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010059/**
60 * @brief Compiled YANG printer context
61 *
62 * Note that the YANG extensions API provides getter to the members for the extension plugins.
63 */
64struct lys_ypr_ctx {
65 union {
66 struct {
67 struct ly_out *out; /**< output specification */
68 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020069 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010070 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
71 const struct lys_module *module; /**< schema to print */
72 };
73 struct lyspr_ctx printer_ctx;
74 };
75
76 /* YANG printer specific members */
77 enum lys_ypr_schema_type schema; /**< type of the schema to print */
78};
79
80/**
Radek Krejcie7b95092019-05-15 11:03:07 +020081 * @brief Print the given text as content of a double quoted YANG string,
82 * including encoding characters that have special meanings. The quotation marks
83 * are not printed.
84 *
85 * Follows RFC 7950, section 6.1.3.
86 *
87 * @param[in] out Output specification.
88 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020089 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020090 * the @p text is printed completely as a NULL-terminated string.
91 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020092static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020093ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020094{
Radek Krejci1deb5be2020-08-26 16:43:36 +020095 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 const char *start;
97 char special = 0;
98
99 if (!len) {
100 return;
101 }
102
103 if (len < 0) {
104 len = strlen(text);
105 }
106
107 start = text;
108 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200109 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200110 switch (text[i]) {
111 case '\n':
112 case '\t':
113 case '\"':
114 case '\\':
115 special = text[i];
116 break;
117 default:
118 ++start_len;
119 break;
120 }
121
122 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200123 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200124 switch (special) {
125 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200126 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200127 break;
128 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200129 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130 break;
131 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200132 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200133 break;
134 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200135 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200136 break;
137 }
138
139 start += start_len + 1;
140 start_len = 0;
141
142 special = 0;
143 }
144 }
145
Michal Vasko5233e962020-08-14 14:26:20 +0200146 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200147}
148
149static void
Radek Krejci857189e2020-09-01 13:26:36 +0200150ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 if (flag && !*flag) {
153 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200154 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155 }
156}
157
158static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100159ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200160{
161 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100162 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100164 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 }
166}
167
168static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100169ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200170{
171 const char *s, *t;
172
173 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100174 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200175 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100176 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 LEVEL++;
178
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100179 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 t = text;
182 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100183 ypr_encode(pctx->out, t, s - t);
184 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 t = s + 1;
186 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100187 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200188 }
189 }
190
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100191 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100193 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100195 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 if (!singleline) {
198 LEVEL--;
199 }
200}
201
202static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100203yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200204{
205 struct lysp_stmt *childstmt;
206 const char *s, *t;
207
208 if (stmt->arg) {
209 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100210 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200211 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100212 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213 t = stmt->arg;
214 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100215 ypr_encode(pctx->out, t, s - t);
216 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200217 t = s + 1;
218 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100219 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 }
221 }
222 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100223 ypr_encode(pctx->out, t, strlen(t));
224 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100226 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 }
228 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100229 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230 }
231
232 if (stmt->child) {
233 LEVEL++;
234 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100235 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 }
237 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200239 }
240}
241
242/**
243 * @param[in] count Number of extensions to print, 0 to print them all.
244 */
245static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100246yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejci857189e2020-09-01 13:26:36 +0200247 struct lysp_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200248{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200249 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200251 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200252
253 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200254 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255 }
256 LY_ARRAY_FOR(ext, u) {
Radek Krejci85ac8312021-03-03 20:21:33 +0100257 struct lysp_ext *ext_def = NULL;
258
Radek Krejcid3ca0632019-04-16 16:54:54 +0200259 if (!count) {
260 break;
261 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200262
Radek Krejcid3ca0632019-04-16 16:54:54 +0200263 count--;
Radek Krejciab430862021-03-02 20:13:40 +0100264 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200265 continue;
266 }
267
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100268 lysp_ext_find_definition(pctx->module->ctx, &ext[u], NULL, &ext_def);
Radek Krejci85ac8312021-03-03 20:21:33 +0100269 if (!ext_def) {
270 continue;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200271 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100272
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100273 ypr_open(pctx->out, flag);
Radek Krejci85ac8312021-03-03 20:21:33 +0100274
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100275 if (ext_def->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100276 ly_print_(pctx->out, "%*s%s \"", INDENT, ext[u].name);
277 lysp_ext_instance_resolve_argument(pctx->module->ctx, &ext[u], ext_def);
278 ypr_encode(pctx->out, ext[u].argument, -1);
279 ly_print_(pctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200280 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100281 ly_print_(pctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200282 }
283
284 child_presence = 0;
285 LEVEL++;
286 LY_LIST_FOR(ext[u].child, stmt) {
287 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
288 continue;
289 }
290 if (!child_presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100291 ly_print_(pctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200292 child_presence = 1;
293 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100294 yprp_stmt(pctx, stmt);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200295 }
296 LEVEL--;
297 if (child_presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100298 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200299 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100300 ly_print_(pctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200301 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200302 }
303}
304
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100305static void yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +0100306 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200307
308static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100309ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200310{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200311 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200312 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200313
314 if (!text) {
315 /* nothing to print */
316 return;
317 }
318
Radek Krejcieccf6602021-02-05 19:42:54 +0100319 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100320 ly_print_(pctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200321 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100322 ypr_text(pctx, stmt_attr_info[substmt].name, text,
Radek Krejcieccf6602021-02-05 19:42:54 +0100323 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 }
325
326 LEVEL++;
327 LY_ARRAY_FOR(ext, u) {
Radek Krejciab430862021-03-02 20:13:40 +0100328 if ((((struct lysp_ext_instance *)ext)[u].parent_stmt != substmt) || (((struct lysp_ext_instance *)ext)[u].parent_stmt_index != substmt_index)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200329 continue;
330 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100331 if (pctx->schema == LYS_YPR_PARSED) {
332 yprp_extension_instances(pctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200333 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100334 yprc_extension_instances(pctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200335 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 }
337 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100338 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200339}
340
341static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100342ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
343 unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200344{
345 char *str;
346
Radek Krejci1deb5be2020-08-26 16:43:36 +0200347 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100348 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 return;
350 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100351 ypr_open(pctx->out, flag);
352 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353 free(str);
354}
355
356static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100357ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value,
358 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200359{
360 char *str;
361
Radek Krejci1deb5be2020-08-26 16:43:36 +0200362 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100363 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200364 return;
365 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100366 ypr_open(pctx->out, flag);
367 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200368 free(str);
369}
370
371static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100372yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373{
374 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100375 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200376 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100377 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
378 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
379 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100381 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100383 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384 }
385}
386
387static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100388ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200389{
390 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100391 ypr_open(pctx->out, flag);
392 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393 }
394}
395
396static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398{
399 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100400 ypr_open(pctx->out, flag);
401 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 }
403}
404
405static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100406ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407{
408 const char *status = NULL;
409
410 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100411 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412 status = "current";
413 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200415 status = "deprecated";
416 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100417 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200418 status = "obsolete";
419 }
Radek Krejci693262f2019-04-29 15:23:20 +0200420
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100421 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422}
423
424static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200426{
427 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428 ypr_open(pctx->out, flag);
429 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200430 }
431}
432
433static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100434ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200435{
436 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100437 ypr_open(pctx->out, flag);
438 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439 }
440}
441
442static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100443yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200445 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200446 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447
Michal Vasko7f45cf22020-10-01 12:49:44 +0200448 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100449 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200450 extflag = 0;
451
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100452 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453
454 /* extensions */
455 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200456 LY_ARRAY_FOR(exts, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100457 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200458 }
459 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100460 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462}
463
464static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100465yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466{
Radek Krejci857189e2020-09-01 13:26:36 +0200467 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200468 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200469
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100470 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 LEVEL++;
472
473 if (ext->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100474 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200475 }
476
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100477 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100478 ypr_open(pctx->out, &flag);
479 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200480 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200482 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100483 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100484 yprp_extension_instances(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200485 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486 }
487 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100488 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100489 ypr_open(pctx->out, &flag2);
490 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200492 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100493 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494 }
495
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100496 ypr_status(pctx, ext->flags, ext->exts, &flag);
497 ypr_description(pctx, ext->dsc, ext->exts, &flag);
498 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200499
500 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100501 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200502}
503
504static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100505yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200506{
Radek Krejci857189e2020-09-01 13:26:36 +0200507 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100509 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200510 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
512 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
513 ypr_status(pctx, feat->flags, feat->exts, &flag);
514 ypr_description(pctx, feat->dsc, feat->exts, &flag);
515 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100517 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518}
519
520static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100521yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200522{
Radek Krejci857189e2020-09-01 13:26:36 +0200523 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200524 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200525
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100526 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200527 LEVEL++;
528
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100529 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
530 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531
532 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100533 ypr_open(pctx->out, &flag);
534 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535 }
536
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100537 ypr_status(pctx, ident->flags, ident->exts, &flag);
538 ypr_description(pctx, ident->dsc, ident->exts, &flag);
539 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200540
541 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100542 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200543}
544
545static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100546yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200547{
Radek Krejci857189e2020-09-01 13:26:36 +0200548 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200549 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200550
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100551 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200552 LEVEL++;
553
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100554 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200555
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200557 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100558 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200559 }
560
Radek Krejci693262f2019-04-29 15:23:20 +0200561 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100562 if (pctx->module != ident->derived[u]->module) {
563 ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200564 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100565 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200566 }
567 }
568
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100569 ypr_status(pctx, ident->flags, ident->exts, &flag);
570 ypr_description(pctx, ident->dsc, ident->exts, &flag);
571 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200572
573 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100574 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200575}
576
577static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100578yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200579{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100580 ly_bool inner_flag = 0, singleline;
581 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200582
583 if (!restr) {
584 return;
585 }
586
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100587 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100588 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
589 restr->arg.str : restr->arg.str + 1;
590 singleline = strchr(text, '\n') ? 0 : 1;
591 ypr_text(pctx, ly_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200592
593 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100594 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100595 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200596 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100597 ypr_open(pctx->out, &inner_flag);
598 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200599 }
600 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100601 ypr_open(pctx->out, &inner_flag);
602 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200603 }
604 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100605 ypr_open(pctx->out, &inner_flag);
606 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200607 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100608 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
609 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200610
Radek Krejcid3ca0632019-04-16 16:54:54 +0200611 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100612 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613}
614
615static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100616yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200617{
Radek Krejci857189e2020-09-01 13:26:36 +0200618 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200619
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100620 ypr_open(pctx->out, flag);
621 ly_print_(pctx->out, "%*smust \"", INDENT);
622 ypr_encode(pctx->out, must->cond->expr, -1);
623 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200624
625 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100626 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200627 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100628 ypr_open(pctx->out, &inner_flag);
629 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200630 }
631 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100632 ypr_open(pctx->out, &inner_flag);
633 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200634 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100635 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
636 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637
638 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100639 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200640}
641
642static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200644{
Radek Krejci857189e2020-09-01 13:26:36 +0200645 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200646 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200647
Radek Krejci334ccc72019-06-12 13:49:29 +0200648 if (!range) {
649 return;
650 }
651
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100652 ypr_open(pctx->out, flag);
653 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200654 LY_ARRAY_FOR(range->parts, u) {
655 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200657 }
658 if (range->parts[u].max_64 == range->parts[u].min_64) {
659 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100662 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200663 }
664 } else {
665 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200667 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100668 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200669 }
670 }
671 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100672 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200673
674 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100675 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200676 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100677 ypr_open(pctx->out, &inner_flag);
678 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200679 }
680 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100681 ypr_open(pctx->out, &inner_flag);
682 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200683 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100684 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
685 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200686
687 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100688 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200689}
690
691static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100692yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200693{
Radek Krejci857189e2020-09-01 13:26:36 +0200694 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200695
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100696 ypr_open(pctx->out, flag);
697 ly_print_(pctx->out, "%*spattern \"", INDENT);
698 ypr_encode(pctx->out, pattern->expr, -1);
699 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200700
701 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200703 if (pattern->inverted) {
704 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100705 ypr_open(pctx->out, &inner_flag);
706 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200707 }
708 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100709 ypr_open(pctx->out, &inner_flag);
710 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200711 }
712 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ypr_open(pctx->out, &inner_flag);
714 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200715 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100716 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
717 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200718
719 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100720 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200721}
722
723static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100724yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200725{
Radek Krejci857189e2020-09-01 13:26:36 +0200726 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200727
728 if (!when) {
729 return;
730 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100731 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200732
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100733 ly_print_(pctx->out, "%*swhen \"", INDENT);
734 ypr_encode(pctx->out, when->cond, -1);
735 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200736
737 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
739 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
740 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100742 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743}
744
745static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100746yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200747{
Radek Krejci857189e2020-09-01 13:26:36 +0200748 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200749
750 if (!when) {
751 return;
752 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100753 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200754
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100755 ly_print_(pctx->out, "%*swhen \"", INDENT);
756 ypr_encode(pctx->out, when->cond->expr, -1);
757 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200758
759 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100760 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
761 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
762 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200763 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100764 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200765}
766
767static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100768yprp_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200769{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200770 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200771 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200772
773 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100774 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200775 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100776 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200777 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ly_print_(pctx->out, "%*senum \"", INDENT);
779 ypr_encode(pctx->out, items[u].name, -1);
780 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200781 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782 inner_flag = 0;
783 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100784 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
785 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200786 if (items[u].flags & LYS_SET_VALUE) {
787 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100788 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200789 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100790 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200791 }
792 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100793 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
794 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
795 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100797 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200798 }
799}
800
801static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100802yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200803{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200804 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200805 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200806
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100807 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200808 LEVEL++;
809
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100810 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200811
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100812 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
813 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200814 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100817 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
818 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200819
820 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100821 ypr_open(pctx->out, &flag);
822 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200823 }
824 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100825 ypr_open(pctx->out, &flag);
826 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200827 }
828 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100829 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200830 }
831 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100832 ypr_open(pctx->out, &flag);
833 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 }
835 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100836 ypr_open(pctx->out, &flag);
837 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200838 }
839
840 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100841 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842}
843
844static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100845yprc_dflt_value(struct lys_ypr_ctx *pctx, const struct ly_ctx *ly_pctx, const struct lyd_value *value,
Radek Krejci224d4b42021-04-23 13:54:59 +0200846 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200847{
Radek Krejci857189e2020-09-01 13:26:36 +0200848 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200849 const char *str;
850
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100851 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
852 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200853 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200854 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200855 }
856}
857
858static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100859yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200860{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200861 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200862 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200863
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100864 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200865 LEVEL++;
866
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100867 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200868
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200869 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200870 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200871 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100872 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200873 break;
874 }
875 case LY_TYPE_UINT8:
876 case LY_TYPE_UINT16:
877 case LY_TYPE_UINT32:
878 case LY_TYPE_UINT64:
879 case LY_TYPE_INT8:
880 case LY_TYPE_INT16:
881 case LY_TYPE_INT32:
882 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200883 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100884 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200885 break;
886 }
887 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200888 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100889 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200890 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100891 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200892 }
893 break;
894 }
895 case LY_TYPE_BITS:
896 case LY_TYPE_ENUM: {
897 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200898 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200899 LY_ARRAY_FOR(bits->bits, u) {
900 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200901 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200902
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100903 ypr_open(pctx->out, &flag);
904 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
905 ypr_encode(pctx->out, item->name, -1);
906 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200907 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200908 if (type->basetype == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100909 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
910 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200911 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100912 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
913 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200914 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100915 ypr_status(pctx, item->flags, item->exts, &inner_flag);
916 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
917 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200918 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100919 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200920 }
921 break;
922 }
923 case LY_TYPE_BOOL:
924 case LY_TYPE_EMPTY:
925 /* nothing to do */
926 break;
927 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200928 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100929 ypr_open(pctx->out, &flag);
930 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
931 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200932 break;
933 }
934 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200935 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200936 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100937 ypr_open(pctx->out, &flag);
938 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200939 }
940 break;
941 }
942 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200943 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100944 ypr_open(pctx->out, &flag);
945 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200946 break;
947 }
948 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200949 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100950 ypr_open(pctx->out, &flag);
951 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
952 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
953 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200954 break;
955 }
956 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200957 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200958 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100959 ypr_open(pctx->out, &flag);
960 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200961 }
962 break;
963 }
964 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100965 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200966 }
967
968 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100969 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200970}
971
972static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100973yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200974{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100975 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200976 LEVEL++;
977
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100978 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200979
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100980 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200981
982 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100983 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200984 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200985 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100986 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200987 }
988
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100989 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
990 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
991 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200992
993 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100994 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200995}
996
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100997static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
998static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
999static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1000static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001
1002static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001003yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001005 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001006 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001007 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001008 struct lysp_node_action *action;
1009 struct lysp_node_notif *notif;
1010 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001011
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001012 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001013 LEVEL++;
1014
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001015 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
1016 ypr_status(pctx, grp->flags, grp->exts, &flag);
1017 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1018 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001019
1020 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001021 ypr_open(pctx->out, &flag);
1022 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001023 }
1024
Radek Krejci2a9fc652021-01-22 17:44:34 +01001025 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001026 ypr_open(pctx->out, &flag);
1027 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028 }
1029
Radek Krejci01180ac2021-01-27 08:48:22 +01001030 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001031 ypr_open(pctx->out, &flag);
1032 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001033 }
1034
Radek Krejci2a9fc652021-01-22 17:44:34 +01001035 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001036 ypr_open(pctx->out, &flag);
1037 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001038 }
1039
1040 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001041 ypr_open(pctx->out, &flag);
1042 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001043 }
1044
1045 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001046 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047}
1048
1049static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001050yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001051{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001052 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001054 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055
Radek Krejci01180ac2021-01-27 08:48:22 +01001056 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001057 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001058 return;
1059 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001060 ypr_open(pctx->out, flag);
1061 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001063 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001064 LEVEL++;
1065
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001066 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001068 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001069 }
1070 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001071 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001073 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001074 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 }
1076
Radek Krejci01180ac2021-01-27 08:48:22 +01001077 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001078 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001079 }
1080
1081 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001082 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083}
1084
1085static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001086yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001087{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001088 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001089 struct lysc_node *data;
1090
Radek Krejci01180ac2021-01-27 08:48:22 +01001091 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001092 /* input/output is empty */
1093 return;
1094 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001095 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001096
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001097 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001098 LEVEL++;
1099
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001100 yprc_extension_instances(pctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001101 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001102 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001103 }
1104
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001106 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001107 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001108 }
Radek Krejci693262f2019-04-29 15:23:20 +02001109 }
1110
1111 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001112 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001113}
1114
1115static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001116yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001117{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001118 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001119 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001121 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001123 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001124
1125 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001126 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
1127 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001128
1129 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001130 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001131 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001132 ypr_status(pctx, notif->flags, notif->exts, &flag);
1133 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1134 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001135
1136 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001137 ypr_open(pctx->out, &flag);
1138 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001139 }
1140
Radek Krejci2a9fc652021-01-22 17:44:34 +01001141 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001142 ypr_open(pctx->out, &flag);
1143 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001144 }
1145
Radek Krejci01180ac2021-01-27 08:48:22 +01001146 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001147 ypr_open(pctx->out, &flag);
1148 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001149 }
1150
1151 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001152 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153}
1154
1155static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001156yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001157{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001158 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001159 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001160 struct lysc_node *data;
1161
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001162 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001163
1164 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001165 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001166
1167 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001168 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001169 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001170 ypr_status(pctx, notif->flags, notif->exts, &flag);
1171 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1172 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001173
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001174 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001175 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001176 ypr_open(pctx->out, &flag);
1177 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001178 }
Radek Krejci693262f2019-04-29 15:23:20 +02001179 }
1180
1181 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001182 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001183}
1184
1185static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001186yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001187{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001188 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001189 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001190 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001192 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001193
1194 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195 yprp_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1196 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1197 ypr_status(pctx, action->flags, action->exts, &flag);
1198 ypr_description(pctx, action->dsc, action->exts, &flag);
1199 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001200
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001202
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001204 ypr_open(pctx->out, &flag);
1205 YPR_EXTRA_LINE_PRINT(pctx);
1206 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001207 }
1208
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001209 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001210
Radek Krejci2a9fc652021-01-22 17:44:34 +01001211 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001212 ypr_open(pctx->out, &flag);
1213 YPR_EXTRA_LINE_PRINT(pctx);
1214 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001215 }
1216
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001217 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001218
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001219 yprp_inout(pctx, &action->input, &flag);
1220 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001221
1222 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001223 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001224}
1225
1226static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001227yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001228{
Radek Krejci857189e2020-09-01 13:26:36 +02001229 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001230
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001231 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001232
1233 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001234 yprc_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
1235 ypr_status(pctx, action->flags, action->exts, &flag);
1236 ypr_description(pctx, action->dsc, action->exts, &flag);
1237 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001238
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001239 yprc_inout(pctx, &action->input, &flag);
1240 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001241
1242 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001243 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001244}
1245
1246static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001247yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001249 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001250 LEVEL++;
1251
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001252 yprp_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
1253 yprp_when(pctx, lysp_node_when(node), flag);
1254 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255}
1256
1257static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001259{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001260 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001261 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001262
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001263 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001264 LEVEL++;
1265
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001266 yprc_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001267
1268 when = lysc_node_when(node);
1269 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001270 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001271 }
Radek Krejci693262f2019-04-29 15:23:20 +02001272}
1273
1274/* macr oto unify the code */
1275#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001276 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001277 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001278 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001279 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001280 ypr_status(pctx, node->flags, node->exts, flag); \
1281 ypr_description(pctx, node->dsc, node->exts, flag); \
1282 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001283
1284static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001285yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001286{
1287 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288}
1289
1290static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001291yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001292{
1293 YPR_NODE_COMMON2;
1294}
1295
1296#undef YPR_NODE_COMMON2
1297
1298static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001299yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001300{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001301 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001302 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001303 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001304 struct lysp_node_action *action;
1305 struct lysp_node_notif *notif;
1306 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001307 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1308
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001309 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001310
1311 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001312 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001313 }
1314 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001315 ypr_open(pctx->out, &flag);
1316 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001317 }
1318
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001319 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001320
1321 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001322 ypr_open(pctx->out, &flag);
1323 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001324 }
1325
Radek Krejci2a9fc652021-01-22 17:44:34 +01001326 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001327 ypr_open(pctx->out, &flag);
1328 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329 }
1330
1331 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001332 ypr_open(pctx->out, &flag);
1333 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001334 }
1335
Radek Krejci2a9fc652021-01-22 17:44:34 +01001336 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001337 ypr_open(pctx->out, &flag);
1338 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339 }
1340
Radek Krejci2a9fc652021-01-22 17:44:34 +01001341 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001342 ypr_open(pctx->out, &flag);
1343 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001344 }
1345
1346 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001347 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001348}
1349
1350static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001351yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001352{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001353 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001354 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001355 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001356 struct lysc_node_action *action;
1357 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001358 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1359
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001360 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001361
1362 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001363 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001364 }
1365 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001366 ypr_open(pctx->out, &flag);
1367 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001368 }
1369
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001370 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001371
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001372 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001373 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001374 ypr_open(pctx->out, &flag);
1375 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001376 }
Radek Krejci693262f2019-04-29 15:23:20 +02001377
Radek Krejci2a9fc652021-01-22 17:44:34 +01001378 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001379 ypr_open(pctx->out, &flag);
1380 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001381 }
Radek Krejci693262f2019-04-29 15:23:20 +02001382
Radek Krejci2a9fc652021-01-22 17:44:34 +01001383 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001384 ypr_open(pctx->out, &flag);
1385 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001386 }
Radek Krejci693262f2019-04-29 15:23:20 +02001387 }
1388
1389 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001390 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001391}
1392
1393static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001394yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001395{
Radek Krejci857189e2020-09-01 13:26:36 +02001396 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001397 struct lysp_node *child;
1398 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1399
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001400 yprp_node_common1(pctx, node, &flag);
1401 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001402
1403 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001404 ypr_open(pctx->out, &flag);
1405 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001406 }
1407
1408 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001409 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001410}
1411
1412static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001413yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001414{
Radek Krejci857189e2020-09-01 13:26:36 +02001415 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001416 struct lysc_node *child;
1417
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001418 yprc_node_common1(pctx, &cs->node, &flag);
1419 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001420
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001421 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001422 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001423 ypr_open(pctx->out, &flag);
1424 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001425 }
Radek Krejci693262f2019-04-29 15:23:20 +02001426 }
1427
1428 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001429 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001430}
1431
1432static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001433yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001434{
Radek Krejci857189e2020-09-01 13:26:36 +02001435 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001436 struct lysp_node *child;
1437 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1438
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001439 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001440
Michal Vasko7f45cf22020-10-01 12:49:44 +02001441 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001442 ypr_open(pctx->out, &flag);
1443 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001444 }
1445
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001446 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001447
1448 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001449 ypr_open(pctx->out, &flag);
1450 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001451 }
1452
1453 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001454 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001455}
1456
1457static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001459{
Radek Krejci857189e2020-09-01 13:26:36 +02001460 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001461 struct lysc_node_case *cs;
1462 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1463
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001464 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001465
1466 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001467 ypr_open(pctx->out, &flag);
1468 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001469 }
1470
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001471 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001472
Michal Vasko22df3f02020-08-24 13:29:22 +02001473 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001474 ypr_open(pctx->out, &flag);
1475 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001476 }
1477
1478 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001479 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001480}
1481
1482static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001483yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001484{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001485 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001486 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1487
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001488 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001490 yprp_type(pctx, &leaf->type);
1491 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001492 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001493 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001494 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001495 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001496
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001497 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001498
1499 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001500 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001501}
1502
1503static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001504yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001505{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001506 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001507 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1508
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001509 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001510
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001511 yprc_type(pctx, leaf->type);
1512 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001513 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001514 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001515 }
Radek Krejcia1911222019-07-22 17:24:50 +02001516
1517 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001518 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001519 }
Radek Krejci693262f2019-04-29 15:23:20 +02001520
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001521 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001522
1523 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001524 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001525}
1526
1527static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001528yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001529{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001530 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001531 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1532
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001533 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001535 yprp_type(pctx, &llist->type);
1536 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001537 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001538 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001539 }
1540 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001541 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001542 }
1543
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001544 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001545
1546 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001547 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001548 }
1549 if (llist->flags & LYS_SET_MAX) {
1550 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001551 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554 }
1555 }
1556
1557 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001558 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001559 }
1560
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001561 ypr_status(pctx, node->flags, node->exts, NULL);
1562 ypr_description(pctx, node->dsc, node->exts, NULL);
1563 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001564
1565 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001567}
1568
1569static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001571{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001572 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001573 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1574
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001575 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001576
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001577 yprc_type(pctx, llist->type);
1578 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001579 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001580 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001581 }
1582 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001583 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001584 }
1585
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001586 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001587
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001588 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001589 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001590 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001591 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001593 }
1594
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001595 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001596
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001597 ypr_status(pctx, node->flags, node->exts, NULL);
1598 ypr_description(pctx, node->dsc, node->exts, NULL);
1599 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001600
1601 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001602 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001603}
1604
1605static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001606yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001607{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001608 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001609 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001610 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001611 struct lysp_node_action *action;
1612 struct lysp_node_notif *notif;
1613 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001614 struct lysp_node_list *list = (struct lysp_node_list *)node;
1615
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001616 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001617
1618 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001619 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001620 }
1621 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001622 ypr_open(pctx->out, &flag);
1623 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001624 }
1625 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001626 ypr_open(pctx->out, &flag);
1627 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001628 }
1629
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001630 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001631
1632 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001633 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001634 }
1635 if (list->flags & LYS_SET_MAX) {
1636 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001637 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001639 ypr_open(pctx->out, &flag);
1640 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001641 }
1642 }
1643
1644 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001645 ypr_open(pctx->out, &flag);
1646 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 }
1648
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001649 ypr_status(pctx, node->flags, node->exts, &flag);
1650 ypr_description(pctx, node->dsc, node->exts, &flag);
1651 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652
1653 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001654 ypr_open(pctx->out, &flag);
1655 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001656 }
1657
Radek Krejci2a9fc652021-01-22 17:44:34 +01001658 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001659 ypr_open(pctx->out, &flag);
1660 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001661 }
1662
1663 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_open(pctx->out, &flag);
1665 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666 }
1667
Radek Krejci2a9fc652021-01-22 17:44:34 +01001668 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001669 ypr_open(pctx->out, &flag);
1670 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001671 }
1672
Radek Krejci2a9fc652021-01-22 17:44:34 +01001673 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001674 ypr_open(pctx->out, &flag);
1675 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001676 }
1677
1678 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001679 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001680}
1681
1682static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001683yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001684{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001685 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001686 struct lysc_node_list *list = (struct lysc_node_list *)node;
1687
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001688 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001689
1690 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001691 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001692 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001693 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001694 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001695 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001696 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001697 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001698 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001699 }
1700 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001701 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001702 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001703 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001704 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001705 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001706 }
1707
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001708 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001709
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001710 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001711 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001712 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001713 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001714 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001715 }
1716
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001717 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001718
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 ypr_status(pctx, node->flags, node->exts, NULL);
1720 ypr_description(pctx, node->dsc, node->exts, NULL);
1721 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001722
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001723 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001724 struct lysc_node *child;
1725 struct lysc_node_action *action;
1726 struct lysc_node_notif *notif;
1727
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001728 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001729 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001730 }
Radek Krejci693262f2019-04-29 15:23:20 +02001731
Radek Krejci2a9fc652021-01-22 17:44:34 +01001732 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001733 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001734 }
Radek Krejci693262f2019-04-29 15:23:20 +02001735
Radek Krejci2a9fc652021-01-22 17:44:34 +01001736 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001737 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001738 }
Radek Krejci693262f2019-04-29 15:23:20 +02001739 }
1740
1741 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001742 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001743}
1744
1745static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001746yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001747{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001748 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001749 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001751 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001752 LEVEL++;
1753
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001754 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
1755 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756
1757 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001758 ypr_open(pctx->out, &flag);
1759 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001760 }
1761
1762 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001763 ypr_open(pctx->out, &flag);
1764 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001765 }
1766
1767 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001768 ypr_open(pctx->out, &flag);
1769 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001770 }
1771
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001772 ypr_config(pctx, refine->flags, refine->exts, &flag);
1773 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774
1775 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001776 ypr_open(pctx->out, &flag);
1777 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001778 }
1779 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001780 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001782 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001784 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001785 }
1786 }
1787
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001788 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1789 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790
1791 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001792 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001793}
1794
1795static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001796yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001798 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001799 struct lysp_node_action *action;
1800 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001802 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001803 LEVEL++;
1804
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001805 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
1806 yprp_when(pctx, aug->when, NULL);
1807 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1808 ypr_status(pctx, aug->flags, aug->exts, NULL);
1809 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1810 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001811
1812 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001813 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814 }
1815
Radek Krejci2a9fc652021-01-22 17:44:34 +01001816 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001817 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001818 }
1819
Radek Krejci2a9fc652021-01-22 17:44:34 +01001820 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001821 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822 }
1823
1824 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001825 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826}
1827
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001829yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001831 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001832 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001834 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001835
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001836 yprp_node_common1(pctx, node, &flag);
1837 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838
1839 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001840 ypr_open(pctx->out, &flag);
1841 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842 }
1843
Radek Krejci2a9fc652021-01-22 17:44:34 +01001844 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001845 ypr_open(pctx->out, &flag);
1846 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847 }
1848
1849 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001850 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851}
1852
1853static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001854yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001856 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001857 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1859
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001860 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861
1862 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001863 ypr_open(pctx->out, &flag);
1864 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001865 }
1866
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001867 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868
1869 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001870 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001871}
1872
1873static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001874yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001875{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001876 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001877 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001878 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001879
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001880 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001881
Radek Krejci693262f2019-04-29 15:23:20 +02001882 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001883 ypr_open(pctx->out, &flag);
1884 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 }
1886
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001887 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001888
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001890 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891}
1892
1893static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001894yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895{
1896 switch (node->nodetype) {
1897 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001898 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899 break;
1900 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001901 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001902 break;
1903 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001904 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001905 break;
1906 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001907 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001908 break;
1909 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001910 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001911 break;
1912 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001913 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914 break;
1915 case LYS_ANYXML:
1916 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001917 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 break;
1919 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001920 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921 break;
1922 default:
1923 break;
1924 }
1925}
1926
1927static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001928yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001929{
1930 switch (node->nodetype) {
1931 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001932 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001933 break;
1934 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001935 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001936 break;
1937 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001938 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001939 break;
1940 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001941 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001942 break;
1943 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001944 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001945 break;
1946 case LYS_ANYXML:
1947 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001948 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001949 break;
1950 default:
1951 break;
1952 }
1953}
1954
1955static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001956yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001957{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001958 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001959 struct lysp_deviate_add *add;
1960 struct lysp_deviate_rpl *rpl;
1961 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001962 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001964 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001965 LEVEL++;
1966
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001967 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
1968 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1969 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970
fredgan2b11ddb2019-10-21 11:03:39 +08001971 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001972 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001973 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1974 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001975 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 LEVEL++;
1977
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001978 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001980 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001981 continue;
1982 }
fredgan2b11ddb2019-10-21 11:03:39 +08001983 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001984 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001985 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001986 LEVEL++;
1987
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001988 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
1989 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001990 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001991 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001992 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001993 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001994 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001996 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001997 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001998 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001999 ypr_config(pctx, add->flags, add->exts, NULL);
2000 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002002 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 }
2004 if (add->flags & LYS_SET_MAX) {
2005 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002008 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 }
2010 }
fredgan2b11ddb2019-10-21 11:03:39 +08002011 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002012 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002013 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002014 LEVEL++;
2015
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002016 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002018 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002019 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002020 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2021 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2022 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2023 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002024 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002025 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 }
2027 if (rpl->flags & LYS_SET_MAX) {
2028 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002029 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002031 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 }
2033 }
fredgan2b11ddb2019-10-21 11:03:39 +08002034 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002035 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002036 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 LEVEL++;
2038
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
2040 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002041 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002042 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002044 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002045 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002046 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002047 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002048 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 }
2050 }
2051
2052 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002053 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002054 }
2055
2056 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002057 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058}
2059
Michal Vasko7c8439f2020-08-05 13:25:19 +02002060static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002061yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002063 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002066 if (modp->imports[u].flags & LYS_INTERNAL) {
2067 continue;
2068 }
2069
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002070 YPR_EXTRA_LINE_PRINT(pctx);
2071 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002073 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
2074 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002075 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002076 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002077 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002078 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2079 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002080 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002081 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002082 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002083 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002084
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002086 if (modp->includes[u].injected) {
2087 /* do not print the includes injected from submodules */
2088 continue;
2089 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002090 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002092 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002094 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002095 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002096 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002098 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2099 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002101 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002104 }
2105 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002106 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002107}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002108
Michal Vasko7c8439f2020-08-05 13:25:19 +02002109static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002110yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002111{
2112 LY_ARRAY_COUNT_TYPE u;
2113 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002114 struct lysp_node_action *action;
2115 struct lysp_node_notif *notif;
2116 struct lysp_node_grp *grp;
2117 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002120 YPR_EXTRA_LINE_PRINT(pctx);
2121 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002123
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002124 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002125
Radek Krejcid3ca0632019-04-16 16:54:54 +02002126 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002127 YPR_EXTRA_LINE_PRINT(pctx);
2128 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002129 }
2130
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002131 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002132
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002134 YPR_EXTRA_LINE_PRINT(pctx);
2135 yprp_feature(pctx, &modp->features[u]);
2136 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002137 }
2138
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002139 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002140
Radek Krejcid3ca0632019-04-16 16:54:54 +02002141 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002142 YPR_EXTRA_LINE_PRINT(pctx);
2143 yprp_identity(pctx, &modp->identities[u]);
2144 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145 }
2146
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002147 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002148
Radek Krejcid3ca0632019-04-16 16:54:54 +02002149 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002150 YPR_EXTRA_LINE_PRINT(pctx);
2151 yprp_typedef(pctx, &modp->typedefs[u]);
2152 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002153 }
2154
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002155 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002156
Radek Krejci2a9fc652021-01-22 17:44:34 +01002157 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002158 YPR_EXTRA_LINE_PRINT(pctx);
2159 yprp_grouping(pctx, grp);
2160 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002161 }
2162
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002163 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002164
Radek Krejcid3ca0632019-04-16 16:54:54 +02002165 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002166 YPR_EXTRA_LINE_PRINT(pctx);
2167 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 }
2169
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002170 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002171
Radek Krejci2a9fc652021-01-22 17:44:34 +01002172 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002173 YPR_EXTRA_LINE_PRINT(pctx);
2174 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175 }
2176
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002177 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002178
Radek Krejci2a9fc652021-01-22 17:44:34 +01002179 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002180 YPR_EXTRA_LINE_PRINT(pctx);
2181 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002182 }
2183
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002184 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002185
Radek Krejci2a9fc652021-01-22 17:44:34 +01002186 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002187 YPR_EXTRA_LINE_PRINT(pctx);
2188 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002189 }
2190
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002191 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002192
Radek Krejcid3ca0632019-04-16 16:54:54 +02002193 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002194 YPR_EXTRA_LINE_PRINT(pctx);
2195 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002196 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002197
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002198 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002199}
2200
2201LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002202yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002203{
2204 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002205 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002206 struct lys_ypr_ctx pctx_ = {
2207 .out = out,
2208 .level = 0,
2209 .module = module,
2210 .schema = LYS_YPR_PARSED,
2211 .options = options
2212 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002213
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002214 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002215 LEVEL++;
2216
2217 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002218 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002219 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002220 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002221 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2222 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002223
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002224 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002225
Michal Vasko7c8439f2020-08-05 13:25:19 +02002226 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002227 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002228
2229 /* meta-stmts */
2230 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002231 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002232 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2234 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2235 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2236 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002237
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002238 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002239
Michal Vasko7c8439f2020-08-05 13:25:19 +02002240 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002241 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002242 YPR_EXTRA_LINE_PRINT(pctx);
2243 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002244 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002245
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002246 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002247
Michal Vasko7c8439f2020-08-05 13:25:19 +02002248 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002249 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002250
2251 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002252 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002253 ly_print_flush(out);
2254
2255 return LY_SUCCESS;
2256}
2257
2258static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002259yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002260{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002261 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002262 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002263 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2264 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002265 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002266 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002267}
2268
2269LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002270yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002271{
2272 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002273 struct lys_ypr_ctx pctx_ = {
Radek Krejci07a55962021-03-02 20:16:43 +01002274 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2275 .options = options
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002276 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002277
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002278 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002279 LEVEL++;
2280
2281 /* submodule-header-stmts */
2282 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002283 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002284 }
2285
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002286 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002287
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002288 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002289
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002291 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002292
2293 /* meta-stmts */
2294 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002295 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002296 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002297 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2298 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2299 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2300 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002301
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002302 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002303
Michal Vasko7c8439f2020-08-05 13:25:19 +02002304 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002305 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 YPR_EXTRA_LINE_PRINT(pctx);
2307 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002308 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002309
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002310 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002311
Michal Vasko7c8439f2020-08-05 13:25:19 +02002312 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002313 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002314
2315 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002316 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002317 ly_print_flush(out);
2318
2319 return LY_SUCCESS;
2320}
2321
2322LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002323yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002324{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002325 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002326
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002327 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002328
2329 ly_print_flush(out);
2330 return LY_SUCCESS;
2331}
2332
2333LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002334yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002335{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002336 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002337 struct lysc_module *modc = module->compiled;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002338 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = module, .options = options}, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002339
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002340 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002341 LEVEL++;
2342
Radek Krejci693262f2019-04-29 15:23:20 +02002343 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002344 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2345 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002346
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002347 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002348
Michal Vasko7c8439f2020-08-05 13:25:19 +02002349 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002350
2351 /* meta-stmts */
2352 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002353 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002354 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002355 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2356 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2357 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2358 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002359
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002360 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002361
Radek Krejci693262f2019-04-29 15:23:20 +02002362 /* revision-stmts */
2363 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002364 YPR_EXTRA_LINE_PRINT(pctx);
2365 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2366 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002367 }
2368
2369 /* body-stmts */
2370 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002371 YPR_EXTRA_LINE_PRINT(pctx);
2372 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
2373 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002374 }
2375
Radek Krejci80d281e2020-09-14 17:42:54 +02002376 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002377 YPR_EXTRA_LINE_PRINT(pctx);
2378 yprc_identity(pctx, &module->identities[u]);
2379 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002380 }
2381
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002382 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002383 struct lysc_node *data;
2384 struct lysc_node_action *rpc;
2385 struct lysc_node_notif *notif;
2386
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002387 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002388 YPR_EXTRA_LINE_PRINT(pctx);
2389 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002390 }
Radek Krejci693262f2019-04-29 15:23:20 +02002391
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002392 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002393
Radek Krejci2a9fc652021-01-22 17:44:34 +01002394 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002395 YPR_EXTRA_LINE_PRINT(pctx);
2396 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002397 }
Radek Krejci693262f2019-04-29 15:23:20 +02002398
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002399 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002400
Radek Krejci2a9fc652021-01-22 17:44:34 +01002401 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002402 YPR_EXTRA_LINE_PRINT(pctx);
2403 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002404 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002405
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002406 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002407 }
2408
2409 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002410 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002411 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002412
2413 return LY_SUCCESS;
2414}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002415
2416/**
2417 * @param[in] count Number of extensions to print, 0 to print them all.
2418 */
2419static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002420yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002421 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2422{
2423 LY_ARRAY_COUNT_TYPE u;
2424
2425 if (!count && ext) {
2426 count = LY_ARRAY_COUNT(ext);
2427 }
2428 LY_ARRAY_FOR(ext, u) {
2429 ly_bool inner_flag = 0;
2430
2431 if (!count) {
2432 break;
2433 }
2434
2435 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002436 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002437 continue;
2438 }
2439
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002440 ypr_open(pctx->out, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002441 if (ext[u].argument) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002442 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2443 ypr_encode(pctx->out, ext[u].argument, -1);
2444 ly_print_(pctx->out, "\"");
Radek Krejciadcf63d2021-02-09 10:21:18 +01002445 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002446 ly_print_(pctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002447 }
2448
2449 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002450 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002451
Radek Krejci4a4d1e02021-04-09 14:04:40 +02002452 if (ext[u].def->plugin && ext[u].def->plugin->sprinter) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002453 ext[u].def->plugin->sprinter(&pctx->printer_ctx, &ext[u], &inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002454 }
2455
2456 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002457 ypr_close(pctx, inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002458 }
2459}
2460
2461void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002462lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002463{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002464 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002465 LY_ARRAY_COUNT_TYPE u, v;
2466
2467 LY_ARRAY_FOR(ext->substmts, u) {
2468 switch (ext->substmts[u].stmt) {
2469 case LY_STMT_CHOICE:
2470 case LY_STMT_CONTAINER: {
2471 const struct lysc_node *node;
2472
2473 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002474 ypr_open(pctx->out, flag);
2475 yprc_node(pctx, node);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002476 }
2477 break;
2478 }
2479 case LY_STMT_DESCRIPTION:
2480 case LY_STMT_REFERENCE:
2481 case LY_STMT_UNITS:
2482 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2483 if (*(const char **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002484 ypr_open(pctx->out, flag);
2485 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002486 }
2487 } else {
2488 const char **strings = *(const char ***)ext->substmts[u].storage;
2489 LY_ARRAY_FOR(strings, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002490 ypr_open(pctx->out, flag);
2491 ypr_substmt(pctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002492 }
2493 }
2494 break;
2495 case LY_STMT_IF_FEATURE:
2496 /* nothing to do */
2497 break;
2498 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002499 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002500 break;
2501 case LY_STMT_TYPE:
2502 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2503 if (*(const struct lysc_type **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002504 ypr_open(pctx->out, flag);
2505 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002506 }
2507 } else {
2508 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2509 LY_ARRAY_FOR(types, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002510 ypr_open(pctx->out, flag);
2511 yprc_type(pctx, types[v]);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002512 }
2513 }
2514 break;
2515 /* TODO support other substatements */
2516 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002517 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Radek Krejciadcf63d2021-02-09 10:21:18 +01002518 ly_stmt2str(ext->substmts[u].stmt));
2519 break;
2520 }
2521 }
2522}