blob: ea643ac7d2652705e7b3c4c207c5fb4465300047 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoedb0fa52022-10-04 10:36:00 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejcid3ca0632019-04-16 16:54:54 +02005 * @brief YANG printer
6 *
Michal Vaskob26d09d2022-08-22 09:52:19 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Radek Krejcid3ca0632019-04-16 16:54:54 +02008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
Radek Krejci535ea9f2020-05-29 16:01:05 +020016#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020017
Michal Vaskoa0ba01e2022-10-19 13:26:57 +020018#include <assert.h>
Radek Krejci693262f2019-04-29 15:23:20 +020019#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020020#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010024#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020025
Radek Krejci535ea9f2020-05-29 16:01:05 +020026#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020027#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020028#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010029#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020030#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010031#include "plugins_exts.h"
Radek Krejci47fab892020-11-05 17:02:41 +010032#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020033#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020034#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020035#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020036#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020037#include "tree_schema.h"
38#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020039#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020040
Radek Krejcie7b95092019-05-15 11:03:07 +020041/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010042 * @brief Types of the YANG printers
43 */
44enum lys_ypr_schema_type {
45 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
46 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
47};
48
Radek Krejciaa14a0c2020-09-04 11:16:47 +020049#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
50
Michal Vasko61ad1ff2022-02-10 15:48:39 +010051#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
52#define YPR_EXTRA_LINE_PRINT(PCTX) \
53 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
54 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020055 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010056 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020057 } \
58 }
59
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010060/**
61 * @brief Compiled YANG printer context
62 *
63 * Note that the YANG extensions API provides getter to the members for the extension plugins.
64 */
65struct lys_ypr_ctx {
66 union {
67 struct {
68 struct ly_out *out; /**< output specification */
69 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020070 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010071 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
72 const struct lys_module *module; /**< schema to print */
73 };
74 struct lyspr_ctx printer_ctx;
75 };
76
77 /* YANG printer specific members */
78 enum lys_ypr_schema_type schema; /**< type of the schema to print */
79};
80
81/**
Radek Krejcie7b95092019-05-15 11:03:07 +020082 * @brief Print the given text as content of a double quoted YANG string,
83 * including encoding characters that have special meanings. The quotation marks
84 * are not printed.
85 *
86 * Follows RFC 7950, section 6.1.3.
87 *
88 * @param[in] out Output specification.
89 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020090 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020091 * the @p text is printed completely as a NULL-terminated string.
92 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020093static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020094ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020095{
Radek Krejci1deb5be2020-08-26 16:43:36 +020096 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020097 const char *start;
98 char special = 0;
99
100 if (!len) {
101 return;
102 }
103
104 if (len < 0) {
105 len = strlen(text);
106 }
107
108 start = text;
109 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200110 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200111 switch (text[i]) {
112 case '\n':
113 case '\t':
114 case '\"':
115 case '\\':
116 special = text[i];
117 break;
118 default:
119 ++start_len;
120 break;
121 }
122
123 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200124 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200125 switch (special) {
126 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200127 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200128 break;
129 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200130 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200131 break;
132 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200133 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200134 break;
135 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200136 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200137 break;
138 }
139
140 start += start_len + 1;
141 start_len = 0;
142
143 special = 0;
144 }
145 }
146
Michal Vasko5233e962020-08-14 14:26:20 +0200147 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200148}
149
150static void
Radek Krejci857189e2020-09-01 13:26:36 +0200151ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200152{
153 if (flag && !*flag) {
154 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200155 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200156 }
157}
158
159static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100160ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200161{
162 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100163 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200164 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100165 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200166 }
167}
168
169static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100170ypr_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 +0200171{
172 const char *s, *t;
173
174 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100175 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200176 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100177 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200178 LEVEL++;
179
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100180 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200181 }
182 t = text;
183 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100184 ypr_encode(pctx->out, t, s - t);
185 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200186 t = s + 1;
187 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100188 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200189 }
190 }
191
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100192 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200193 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100194 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200195 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100196 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200197 }
198 if (!singleline) {
199 LEVEL--;
200 }
201}
202
203static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100204yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200205{
206 struct lysp_stmt *childstmt;
207 const char *s, *t;
208
209 if (stmt->arg) {
210 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100211 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200212 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100213 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200214 t = stmt->arg;
215 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100216 ypr_encode(pctx->out, t, s - t);
217 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200218 t = s + 1;
219 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100220 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200221 }
222 }
223 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100224 ypr_encode(pctx->out, t, strlen(t));
225 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200226 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100227 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200228 }
229 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100230 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200231 }
232
233 if (stmt->child) {
234 LEVEL++;
235 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100236 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200237 }
238 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100239 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200240 }
241}
242
Radek Krejcid3ca0632019-04-16 16:54:54 +0200243static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200244yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
245 struct lysp_ext_instance *ext, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200246{
Radek Krejcid3ca0632019-04-16 16:54:54 +0200247 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200248 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200249
Michal Vaskob26d09d2022-08-22 09:52:19 +0200250 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
251 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200252 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100253
Michal Vaskob26d09d2022-08-22 09:52:19 +0200254 ypr_open(pctx->out, flag);
255
Michal Vasko193dacd2022-10-13 08:43:05 +0200256 if (ext->def->argname) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200257 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200258 ypr_encode(pctx->out, ext->argument, -1);
259 ly_print_(pctx->out, "\"");
260 } else {
261 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
262 }
263
264 child_presence = 0;
265 LEVEL++;
266 LY_LIST_FOR(ext->child, stmt) {
267 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200268 continue;
269 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200270 if (!child_presence) {
271 ly_print_(pctx->out, " {\n");
272 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200273 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200274 yprp_stmt(pctx, stmt);
275 }
276 LEVEL--;
277 if (child_presence) {
278 ly_print_(pctx->out, "%*s}\n", INDENT);
279 } else {
280 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 }
282}
283
Radek Krejci693262f2019-04-29 15:23:20 +0200284static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200285yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
286 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200288 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200289
290 LY_ARRAY_FOR(exts, u) {
291 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
292 }
293}
294
295static void
296yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
297 struct lysc_ext_instance *exts, ly_bool *flag)
298{
299 LY_ARRAY_COUNT_TYPE u;
300 ly_bool inner_flag;
301
302 LY_ARRAY_FOR(exts, u) {
303 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
304 return;
305 }
306
307 ypr_open(pctx->out, flag);
308 if (exts[u].argument) {
309 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
310 ypr_encode(pctx->out, exts[u].argument, -1);
311 ly_print_(pctx->out, "\"");
312 } else {
313 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
314 }
315
316 LEVEL++;
317 inner_flag = 0;
318 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
319
Michal Vasko941e0562022-10-18 10:35:00 +0200320 if (exts[u].def->plugin && exts[u].def->plugin->printer_info) {
321 exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200322 }
323
324 LEVEL--;
325 ypr_close(pctx, inner_flag);
326 }
327}
328
329static void
330ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
331{
Radek Krejci857189e2020-09-01 13:26:36 +0200332 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200333
334 if (!text) {
335 /* nothing to print */
336 return;
337 }
338
Michal Vaskob872d0f2022-12-08 09:36:54 +0100339 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) {
340 ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200341 } else {
Michal Vaskob872d0f2022-12-08 09:36:54 +0100342 ypr_text(pctx, lys_stmt_str(substmt), text, (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200343 }
344
345 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200346 if (pctx->schema == LYS_YPR_PARSED) {
347 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
348 } else {
349 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200350 }
351 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100352 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353}
354
355static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100356ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
Michal Vasko2bf4af42023-01-04 12:08:38 +0100357 unsigned long attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358{
359 char *str;
360
Radek Krejci1deb5be2020-08-26 16:43:36 +0200361 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100362 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200363 return;
364 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100365 ypr_open(pctx->out, flag);
366 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200367 free(str);
368}
369
370static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100371ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value,
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100372 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373{
374 char *str;
375
Radek Krejci1deb5be2020-08-26 16:43:36 +0200376 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100377 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378 return;
379 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100380 ypr_open(pctx->out, flag);
381 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 free(str);
383}
384
385static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100386yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200387{
388 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100389 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200390 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200391 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100392 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
393 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200394 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100395 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200396 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398 }
399}
400
401static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100402ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403{
404 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100405 ypr_open(pctx->out, flag);
406 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407 }
408}
409
410static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100411ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412{
413 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 ypr_open(pctx->out, flag);
415 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 }
417}
418
419static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100420ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200421{
422 const char *status = NULL;
423
424 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200426 status = "current";
427 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429 status = "deprecated";
430 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100431 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200432 status = "obsolete";
433 }
Radek Krejci693262f2019-04-29 15:23:20 +0200434
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100435 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200436}
437
438static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100439ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200440{
441 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100442 ypr_open(pctx->out, flag);
443 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 }
445}
446
447static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100448ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449{
450 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100451 ypr_open(pctx->out, flag);
452 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453 }
454}
455
456static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100457yprp_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 +0200458{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200459 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200460 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461
Michal Vasko7f45cf22020-10-01 12:49:44 +0200462 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464 extflag = 0;
465
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100466 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467
468 /* extensions */
469 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200470 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100472 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200473 }
474}
475
476static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100477yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478{
Radek Krejci857189e2020-09-01 13:26:36 +0200479 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200480 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100482 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 LEVEL++;
484
Michal Vaskob26d09d2022-08-22 09:52:19 +0200485 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100487 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100488 ypr_open(pctx->out, &flag);
489 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200490 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200492 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100493 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200494 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200496 }
497 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100498 (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 +0100499 ypr_open(pctx->out, &flag2);
500 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200501 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200502 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100503 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200504 }
505
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100506 ypr_status(pctx, ext->flags, ext->exts, &flag);
507 ypr_description(pctx, ext->dsc, ext->exts, &flag);
508 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200509
510 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512}
513
514static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100515yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516{
Radek Krejci857189e2020-09-01 13:26:36 +0200517 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100519 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200521 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100522 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
523 ypr_status(pctx, feat->flags, feat->exts, &flag);
524 ypr_description(pctx, feat->dsc, feat->exts, &flag);
525 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200526 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100527 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200528}
529
530static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100531yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200532{
Radek Krejci857189e2020-09-01 13:26:36 +0200533 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200534 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100536 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200537 LEVEL++;
538
Michal Vaskob26d09d2022-08-22 09:52:19 +0200539 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100540 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541
542 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100543 ypr_open(pctx->out, &flag);
544 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200545 }
546
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100547 ypr_status(pctx, ident->flags, ident->exts, &flag);
548 ypr_description(pctx, ident->dsc, ident->exts, &flag);
549 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200550
551 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100552 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553}
554
555static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200557{
Radek Krejci857189e2020-09-01 13:26:36 +0200558 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200559 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200560
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100561 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200562 LEVEL++;
563
Michal Vaskob26d09d2022-08-22 09:52:19 +0200564 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200565
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100566 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200567 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100568 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200569 }
570
Radek Krejci693262f2019-04-29 15:23:20 +0200571 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100572 if (pctx->module != ident->derived[u]->module) {
573 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 +0200574 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100575 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200576 }
577 }
578
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100579 ypr_status(pctx, ident->flags, ident->exts, &flag);
580 ypr_description(pctx, ident->dsc, ident->exts, &flag);
581 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200582
583 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100584 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200585}
586
587static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100588yprp_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 +0200589{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100590 ly_bool inner_flag = 0, singleline;
591 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200592
593 if (!restr) {
594 return;
595 }
596
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100597 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100598 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
599 restr->arg.str : restr->arg.str + 1;
600 singleline = strchr(text, '\n') ? 0 : 1;
Michal Vasko193dacd2022-10-13 08:43:05 +0200601 ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200602
603 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200604 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100605 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200606 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100607 ypr_open(pctx->out, &inner_flag);
608 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609 }
610 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100611 ypr_open(pctx->out, &inner_flag);
612 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613 }
614 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100615 ypr_open(pctx->out, &inner_flag);
616 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200617 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100618 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
619 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200620
Radek Krejcid3ca0632019-04-16 16:54:54 +0200621 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100622 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200623}
624
625static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100626yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200627{
Radek Krejci857189e2020-09-01 13:26:36 +0200628 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200629
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100630 ypr_open(pctx->out, flag);
631 ly_print_(pctx->out, "%*smust \"", INDENT);
632 ypr_encode(pctx->out, must->cond->expr, -1);
633 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200634
635 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200636 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100638 ypr_open(pctx->out, &inner_flag);
639 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200640 }
641 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100642 ypr_open(pctx->out, &inner_flag);
643 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200644 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100645 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
646 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200647
648 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100649 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200650}
651
652static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100653yprc_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 +0200654{
Radek Krejci857189e2020-09-01 13:26:36 +0200655 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200656 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200657
Radek Krejci334ccc72019-06-12 13:49:29 +0200658 if (!range) {
659 return;
660 }
661
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100662 ypr_open(pctx->out, flag);
663 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200664 LY_ARRAY_FOR(range->parts, u) {
665 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200667 }
668 if (range->parts[u].max_64 == range->parts[u].min_64) {
669 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100670 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200671 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100672 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200673 }
674 } else {
675 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100676 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200677 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100678 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200679 }
680 }
681 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100682 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200683
684 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200685 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200686 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100687 ypr_open(pctx->out, &inner_flag);
688 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200689 }
690 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100691 ypr_open(pctx->out, &inner_flag);
692 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200693 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100694 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
695 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200696
697 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100698 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200699}
700
701static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200703{
Radek Krejci857189e2020-09-01 13:26:36 +0200704 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200705
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100706 ypr_open(pctx->out, flag);
707 ly_print_(pctx->out, "%*spattern \"", INDENT);
708 ypr_encode(pctx->out, pattern->expr, -1);
709 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200710
711 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200712 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200713 if (pattern->inverted) {
714 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100715 ypr_open(pctx->out, &inner_flag);
716 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200717 }
718 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100719 ypr_open(pctx->out, &inner_flag);
720 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200721 }
722 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100723 ypr_open(pctx->out, &inner_flag);
724 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200725 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100726 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
727 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200728
729 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100730 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200731}
732
733static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200734yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag)
735{
736 LY_ARRAY_COUNT_TYPE u;
737 const struct lysc_type_bitenum_item *item;
738 ly_bool inner_flag;
739
740 assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM));
741
742 LY_ARRAY_FOR(items, u) {
743 item = &items[u];
744 inner_flag = 0;
745
746 ypr_open(pctx->out, flag);
747 ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum");
748 ypr_encode(pctx->out, item->name, -1);
749 ly_print_(pctx->out, "\"");
750 LEVEL++;
751 if (basetype == LY_TYPE_BITS) {
752 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
753 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
754 } else { /* LY_TYPE_ENUM */
755 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
756 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
757 }
758 ypr_status(pctx, item->flags, item->exts, &inner_flag);
759 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
760 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
761 LEVEL--;
762 ypr_close(pctx, inner_flag);
763 }
764}
765
766static void
767yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768{
Radek Krejci857189e2020-09-01 13:26:36 +0200769 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200770
771 if (!when) {
772 return;
773 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100774 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200775
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100776 ly_print_(pctx->out, "%*swhen \"", INDENT);
777 ypr_encode(pctx->out, when->cond, -1);
778 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200779
780 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200781 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100782 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
783 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200784 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100785 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200786}
787
788static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200789yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200790{
Radek Krejci857189e2020-09-01 13:26:36 +0200791 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200792
793 if (!when) {
794 return;
795 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100796 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200797
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100798 ly_print_(pctx->out, "%*swhen \"", INDENT);
799 ypr_encode(pctx->out, when->cond->expr, -1);
800 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200801
802 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200803 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100804 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
805 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200806 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100807 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200808}
809
810static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200811yprp_bits_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 +0200812{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200813 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200814 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200815
816 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100817 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200818 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100819 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200820 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100821 ly_print_(pctx->out, "%*senum \"", INDENT);
822 ypr_encode(pctx->out, items[u].name, -1);
823 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200824 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825 inner_flag = 0;
826 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200827 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100828 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200829 if (items[u].flags & LYS_SET_VALUE) {
830 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100831 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200832 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100833 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 }
835 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100836 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
837 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
838 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200839 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100840 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200841 }
842}
843
844static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100845yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200846{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200847 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200848 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200849
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100850 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200851 LEVEL++;
852
Michal Vaskob26d09d2022-08-22 09:52:19 +0200853 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200854
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100855 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
856 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200857 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100858 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200859 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200860 yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
861 yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200862
863 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100864 ypr_open(pctx->out, &flag);
865 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200866 }
867 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100868 ypr_open(pctx->out, &flag);
869 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200870 }
871 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100872 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200873 }
874 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100875 ypr_open(pctx->out, &flag);
876 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200877 }
878 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100879 ypr_open(pctx->out, &flag);
880 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200881 }
882
883 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100884 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200885}
886
887static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100888yprc_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 +0200889 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200890{
Radek Krejci857189e2020-09-01 13:26:36 +0200891 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200892 const char *str;
893
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100894 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
895 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200896 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200897 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200898 }
899}
900
901static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100902yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200903{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200904 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200905 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200906
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100907 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200908 LEVEL++;
909
Michal Vaskob26d09d2022-08-22 09:52:19 +0200910 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200911
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200912 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200913 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200914 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200915
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100916 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200917 break;
918 }
919 case LY_TYPE_UINT8:
920 case LY_TYPE_UINT16:
921 case LY_TYPE_UINT32:
922 case LY_TYPE_UINT64:
923 case LY_TYPE_INT8:
924 case LY_TYPE_INT16:
925 case LY_TYPE_INT32:
926 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200927 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200928
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100929 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200930 break;
931 }
932 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200933 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200934
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100935 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200936 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100937 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200938 }
939 break;
940 }
941 case LY_TYPE_BITS:
942 case LY_TYPE_ENUM: {
943 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200944 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200945
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200946 yprc_bits_enum(pctx, bits->bits, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200947 break;
948 }
949 case LY_TYPE_BOOL:
950 case LY_TYPE_EMPTY:
951 /* nothing to do */
952 break;
953 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200954 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200955
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100956 ypr_open(pctx->out, &flag);
957 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
958 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200959 break;
960 }
961 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200962 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200963
Radek Krejci693262f2019-04-29 15:23:20 +0200964 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100965 ypr_open(pctx->out, &flag);
966 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200967 }
968 break;
969 }
970 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200971 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200972
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100973 ypr_open(pctx->out, &flag);
974 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200975 break;
976 }
977 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200978 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200979
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100980 ypr_open(pctx->out, &flag);
981 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
982 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
983 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200984 break;
985 }
986 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200987 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200988
Radek Krejci693262f2019-04-29 15:23:20 +0200989 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100990 ypr_open(pctx->out, &flag);
991 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200992 }
993 break;
994 }
995 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100996 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200997 }
998
999 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001000 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001001}
1002
1003static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001004yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001005{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001006 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001007 LEVEL++;
1008
Michal Vaskob26d09d2022-08-22 09:52:19 +02001009 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001010
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001011 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001012
1013 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001014 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001015 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001016 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001017 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001018 }
1019
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001020 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1021 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1022 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001023
1024 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001025 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026}
1027
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001028static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1029static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1030static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1031static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032
1033static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001034yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001035{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001036 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001037 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001039 struct lysp_node_action *action;
1040 struct lysp_node_notif *notif;
1041 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001043 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044 LEVEL++;
1045
Michal Vaskob26d09d2022-08-22 09:52:19 +02001046 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001047 ypr_status(pctx, grp->flags, grp->exts, &flag);
1048 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1049 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001050
1051 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001052 ypr_open(pctx->out, &flag);
1053 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001054 }
1055
Radek Krejci2a9fc652021-01-22 17:44:34 +01001056 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001057 ypr_open(pctx->out, &flag);
1058 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001059 }
1060
Radek Krejci01180ac2021-01-27 08:48:22 +01001061 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001062 ypr_open(pctx->out, &flag);
1063 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001064 }
1065
Radek Krejci2a9fc652021-01-22 17:44:34 +01001066 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001067 ypr_open(pctx->out, &flag);
1068 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001069 }
1070
1071 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001072 ypr_open(pctx->out, &flag);
1073 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074 }
1075
1076 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001077 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078}
1079
1080static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001081yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001083 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001085 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001086
Radek Krejci01180ac2021-01-27 08:48:22 +01001087 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001088 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089 return;
1090 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001091 ypr_open(pctx->out, flag);
1092 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001093
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001094 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001095 LEVEL++;
1096
Michal Vaskob26d09d2022-08-22 09:52:19 +02001097 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001099 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 }
1101 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001102 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001103 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001104 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 }
1107
Radek Krejci01180ac2021-01-27 08:48:22 +01001108 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001109 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110 }
1111
1112 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001113 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001114}
1115
1116static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001117yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001118{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001119 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001120 struct lysc_node *data;
1121
Radek Krejci01180ac2021-01-27 08:48:22 +01001122 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001123 /* input/output is empty */
1124 return;
1125 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001126 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001127
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001129 LEVEL++;
1130
Michal Vasko193dacd2022-10-13 08:43:05 +02001131 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001132 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001133 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001134 }
1135
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001136 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001137 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001138 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001139 }
Radek Krejci693262f2019-04-29 15:23:20 +02001140 }
1141
1142 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001143 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001144}
1145
1146static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001147yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001148{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001149 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001150 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001151 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001152 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001154 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001155
1156 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001157 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001158 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001159
1160 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001161 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001163 ypr_status(pctx, notif->flags, notif->exts, &flag);
1164 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1165 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001166
1167 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001168 ypr_open(pctx->out, &flag);
1169 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001170 }
1171
Radek Krejci2a9fc652021-01-22 17:44:34 +01001172 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001173 ypr_open(pctx->out, &flag);
1174 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001175 }
1176
Radek Krejci01180ac2021-01-27 08:48:22 +01001177 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001178 ypr_open(pctx->out, &flag);
1179 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001180 }
1181
1182 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001183 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001184}
1185
1186static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001187yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001188{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001189 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001190 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001191 struct lysc_node *data;
1192
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001193 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001194
1195 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001196 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001197
1198 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001199 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001200 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 ypr_status(pctx, notif->flags, notif->exts, &flag);
1202 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1203 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001204
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001205 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001206 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001207 ypr_open(pctx->out, &flag);
1208 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001209 }
Radek Krejci693262f2019-04-29 15:23:20 +02001210 }
1211
1212 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001213 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001214}
1215
1216static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001217yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001218{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001219 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001220 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001221 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001222
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001223 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001224
1225 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001226 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001227 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1228 ypr_status(pctx, action->flags, action->exts, &flag);
1229 ypr_description(pctx, action->dsc, action->exts, &flag);
1230 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001231
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001232 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001233
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001235 ypr_open(pctx->out, &flag);
1236 YPR_EXTRA_LINE_PRINT(pctx);
1237 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001238 }
1239
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001240 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001241
Radek Krejci2a9fc652021-01-22 17:44:34 +01001242 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001243 ypr_open(pctx->out, &flag);
1244 YPR_EXTRA_LINE_PRINT(pctx);
1245 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001246 }
1247
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001248 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001249
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001250 yprp_inout(pctx, &action->input, &flag);
1251 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001252
1253 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001254 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255}
1256
1257static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001259{
Radek Krejci857189e2020-09-01 13:26:36 +02001260 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001261
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001262 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001263
1264 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001265 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001266 ypr_status(pctx, action->flags, action->exts, &flag);
1267 ypr_description(pctx, action->dsc, action->exts, &flag);
1268 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001269
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001270 yprc_inout(pctx, &action->input, &flag);
1271 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001272
1273 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001274 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001275}
1276
1277static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001278yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001279{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001280 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281 LEVEL++;
1282
Michal Vasko193dacd2022-10-13 08:43:05 +02001283 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001284 yprp_when(pctx, lysp_node_when(node), flag);
1285 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286}
1287
1288static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001289yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001291 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001292 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001293
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001294 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001295 LEVEL++;
1296
Michal Vasko193dacd2022-10-13 08:43:05 +02001297 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001298
1299 when = lysc_node_when(node);
1300 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001301 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001302 }
Radek Krejci693262f2019-04-29 15:23:20 +02001303}
1304
Michal Vaskob26d09d2022-08-22 09:52:19 +02001305/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001306#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001307 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001308 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001309 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001310 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001311 ypr_status(pctx, node->flags, node->exts, flag); \
1312 ypr_description(pctx, node->dsc, node->exts, flag); \
1313 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001314
1315static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001316yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001317{
1318 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001319}
1320
1321static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001322yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001323{
1324 YPR_NODE_COMMON2;
1325}
1326
1327#undef YPR_NODE_COMMON2
1328
1329static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001330yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001331{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001332 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001333 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001334 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001335 struct lysp_node_action *action;
1336 struct lysp_node_notif *notif;
1337 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001338 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1339
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001340 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001341
1342 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001343 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001344 }
1345 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346 ypr_open(pctx->out, &flag);
1347 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001348 }
1349
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001350 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001351
1352 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001353 ypr_open(pctx->out, &flag);
1354 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001355 }
1356
Radek Krejci2a9fc652021-01-22 17:44:34 +01001357 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001358 ypr_open(pctx->out, &flag);
1359 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001360 }
1361
1362 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001363 ypr_open(pctx->out, &flag);
1364 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001365 }
1366
Radek Krejci2a9fc652021-01-22 17:44:34 +01001367 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001368 ypr_open(pctx->out, &flag);
1369 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001370 }
1371
Radek Krejci2a9fc652021-01-22 17:44:34 +01001372 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001373 ypr_open(pctx->out, &flag);
1374 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001375 }
1376
1377 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001378 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001379}
1380
1381static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001382yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001383{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001384 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001385 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001386 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001387 struct lysc_node_action *action;
1388 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001389 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1390
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001391 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001392
1393 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001394 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001395 }
1396 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001397 ypr_open(pctx->out, &flag);
1398 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001399 }
1400
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001401 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001402
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001403 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001404 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001405 ypr_open(pctx->out, &flag);
1406 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001407 }
Radek Krejci693262f2019-04-29 15:23:20 +02001408
Radek Krejci2a9fc652021-01-22 17:44:34 +01001409 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001410 ypr_open(pctx->out, &flag);
1411 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001412 }
Radek Krejci693262f2019-04-29 15:23:20 +02001413
Radek Krejci2a9fc652021-01-22 17:44:34 +01001414 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001415 ypr_open(pctx->out, &flag);
1416 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001417 }
Radek Krejci693262f2019-04-29 15:23:20 +02001418 }
1419
1420 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001421 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001422}
1423
1424static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001425yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001426{
Radek Krejci857189e2020-09-01 13:26:36 +02001427 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001428 struct lysp_node *child;
1429 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1430
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001431 yprp_node_common1(pctx, node, &flag);
1432 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001433
1434 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001435 ypr_open(pctx->out, &flag);
1436 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001437 }
1438
1439 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001440 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001441}
1442
1443static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001444yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001445{
Radek Krejci857189e2020-09-01 13:26:36 +02001446 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001447 struct lysc_node *child;
1448
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001449 yprc_node_common1(pctx, &cs->node, &flag);
1450 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001451
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001452 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001453 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001454 ypr_open(pctx->out, &flag);
1455 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001456 }
Radek Krejci693262f2019-04-29 15:23:20 +02001457 }
1458
1459 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001460 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001461}
1462
1463static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001464yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001465{
Radek Krejci857189e2020-09-01 13:26:36 +02001466 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001467 struct lysp_node *child;
1468 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1469
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001470 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471
Michal Vasko7f45cf22020-10-01 12:49:44 +02001472 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001473 ypr_open(pctx->out, &flag);
1474 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001475 }
1476
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001477 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478
1479 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001480 ypr_open(pctx->out, &flag);
1481 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001482 }
1483
1484 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001485 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001486}
1487
1488static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001489yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001490{
Radek Krejci857189e2020-09-01 13:26:36 +02001491 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001492 struct lysc_node_case *cs;
1493 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1494
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001495 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001496
1497 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001498 ypr_open(pctx->out, &flag);
1499 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001500 }
1501
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001502 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001503
Michal Vasko22df3f02020-08-24 13:29:22 +02001504 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001505 ypr_open(pctx->out, &flag);
1506 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001507 }
1508
1509 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001510 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001511}
1512
1513static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001514yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001516 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1518
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001519 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001521 yprp_type(pctx, &leaf->type);
1522 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001524 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001525 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001526 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001528 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001529
1530 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001531 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001532}
1533
1534static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001535yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001536{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001537 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001538 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1539
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001540 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001541
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001542 yprc_type(pctx, leaf->type);
1543 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001544 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001545 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001546 }
Radek Krejcia1911222019-07-22 17:24:50 +02001547
1548 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001549 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001550 }
Radek Krejci693262f2019-04-29 15:23:20 +02001551
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001552 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001553
1554 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001555 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001556}
1557
1558static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001559yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001560{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001561 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1563
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001564 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 yprp_type(pctx, &llist->type);
1567 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001568 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001569 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001570 }
1571 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001572 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573 }
1574
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001575 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576
1577 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001578 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 }
1580 if (llist->flags & LYS_SET_MAX) {
1581 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001582 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001584 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585 }
1586 }
1587
1588 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590 }
1591
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 ypr_status(pctx, node->flags, node->exts, NULL);
1593 ypr_description(pctx, node->dsc, node->exts, NULL);
1594 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001595
1596 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001597 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001598}
1599
1600static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001601yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001602{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001603 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001604 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1605
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001606 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001607
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001608 yprc_type(pctx, llist->type);
1609 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001610 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001611 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001612 }
1613 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001614 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001615 }
1616
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001617 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001618
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001619 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001620 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001621 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001622 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001623 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001624 }
1625
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001626 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001627
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001628 ypr_status(pctx, node->flags, node->exts, NULL);
1629 ypr_description(pctx, node->dsc, node->exts, NULL);
1630 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001631
1632 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001633 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001634}
1635
1636static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001637yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001639 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001640 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001641 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001642 struct lysp_node_action *action;
1643 struct lysp_node_notif *notif;
1644 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645 struct lysp_node_list *list = (struct lysp_node_list *)node;
1646
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001647 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648
1649 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001650 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001651 }
1652 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001653 ypr_open(pctx->out, &flag);
1654 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001655 }
1656 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001657 ypr_open(pctx->out, &flag);
1658 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001661 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001662
1663 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001665 }
1666 if (list->flags & LYS_SET_MAX) {
1667 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001668 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001669 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001670 ypr_open(pctx->out, &flag);
1671 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001672 }
1673 }
1674
1675 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001676 ypr_open(pctx->out, &flag);
1677 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001678 }
1679
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001680 ypr_status(pctx, node->flags, node->exts, &flag);
1681 ypr_description(pctx, node->dsc, node->exts, &flag);
1682 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683
1684 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001685 ypr_open(pctx->out, &flag);
1686 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001687 }
1688
Radek Krejci2a9fc652021-01-22 17:44:34 +01001689 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001690 ypr_open(pctx->out, &flag);
1691 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001692 }
1693
1694 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001695 ypr_open(pctx->out, &flag);
1696 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001697 }
1698
Radek Krejci2a9fc652021-01-22 17:44:34 +01001699 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001700 ypr_open(pctx->out, &flag);
1701 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001702 }
1703
Radek Krejci2a9fc652021-01-22 17:44:34 +01001704 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001705 ypr_open(pctx->out, &flag);
1706 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001707 }
1708
1709 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001710 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001711}
1712
1713static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001714yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001715{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001716 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001717 struct lysc_node_list *list = (struct lysc_node_list *)node;
1718
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001720
1721 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001722 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001723 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001724 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001725 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001726 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 +01001727 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001728 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001729 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001730 }
1731 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001732 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001733 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001734 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001735 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001736 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001737 }
1738
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001739 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001740
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001741 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001742 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001743 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001744 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001745 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001746 }
1747
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001748 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001749
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001750 ypr_status(pctx, node->flags, node->exts, NULL);
1751 ypr_description(pctx, node->dsc, node->exts, NULL);
1752 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001753
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001754 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001755 struct lysc_node *child;
1756 struct lysc_node_action *action;
1757 struct lysc_node_notif *notif;
1758
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001759 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001760 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001761 }
Radek Krejci693262f2019-04-29 15:23:20 +02001762
Radek Krejci2a9fc652021-01-22 17:44:34 +01001763 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001764 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001765 }
Radek Krejci693262f2019-04-29 15:23:20 +02001766
Radek Krejci2a9fc652021-01-22 17:44:34 +01001767 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001768 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001769 }
Radek Krejci693262f2019-04-29 15:23:20 +02001770 }
1771
1772 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001773 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001774}
1775
1776static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001777yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001778{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001779 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001780 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001782 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783 LEVEL++;
1784
Michal Vaskob26d09d2022-08-22 09:52:19 +02001785 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001786 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787
1788 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001789 ypr_open(pctx->out, &flag);
1790 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791 }
1792
1793 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001794 ypr_open(pctx->out, &flag);
1795 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796 }
1797
1798 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001799 ypr_open(pctx->out, &flag);
1800 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801 }
1802
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001803 ypr_config(pctx, refine->flags, refine->exts, &flag);
1804 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001805
1806 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001807 ypr_open(pctx->out, &flag);
1808 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809 }
1810 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001811 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001813 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001815 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816 }
1817 }
1818
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001819 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1820 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001821
1822 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001823 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001824}
1825
1826static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001827yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001829 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001830 struct lysp_node_action *action;
1831 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001832
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001833 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001834 LEVEL++;
1835
Michal Vaskob26d09d2022-08-22 09:52:19 +02001836 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001837 yprp_when(pctx, aug->when, NULL);
1838 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1839 ypr_status(pctx, aug->flags, aug->exts, NULL);
1840 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1841 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842
1843 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001844 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845 }
1846
Radek Krejci2a9fc652021-01-22 17:44:34 +01001847 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001848 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 }
1850
Radek Krejci2a9fc652021-01-22 17:44:34 +01001851 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001852 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853 }
1854
1855 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001856 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857}
1858
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001860yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001862 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001863 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001865 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001867 yprp_node_common1(pctx, node, &flag);
1868 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869
1870 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001871 ypr_open(pctx->out, &flag);
1872 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873 }
1874
Radek Krejci2a9fc652021-01-22 17:44:34 +01001875 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001876 ypr_open(pctx->out, &flag);
1877 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001878 }
1879
1880 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001881 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882}
1883
1884static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001885yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001886{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001887 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001888 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1890
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001891 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001892
1893 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001894 ypr_open(pctx->out, &flag);
1895 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001896 }
1897
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001898 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899
1900 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001901 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001902}
1903
1904static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001905yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001907 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001908 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001909 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001911 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912
Radek Krejci693262f2019-04-29 15:23:20 +02001913 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001914 ypr_open(pctx->out, &flag);
1915 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 }
1917
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001918 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001919
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001921 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922}
1923
1924static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001925yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001926{
1927 switch (node->nodetype) {
1928 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001929 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930 break;
1931 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001932 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933 break;
1934 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001935 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 break;
1937 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001938 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 break;
1940 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001941 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942 break;
1943 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001944 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 break;
1946 case LYS_ANYXML:
1947 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001948 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001949 break;
1950 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001951 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001952 break;
1953 default:
1954 break;
1955 }
1956}
1957
1958static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001959yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001960{
1961 switch (node->nodetype) {
1962 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001963 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001964 break;
1965 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001966 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001967 break;
1968 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001969 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001970 break;
1971 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001972 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001973 break;
1974 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001975 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001976 break;
1977 case LYS_ANYXML:
1978 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001979 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001980 break;
1981 default:
1982 break;
1983 }
1984}
1985
1986static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001987yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001988{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001989 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 struct lysp_deviate_add *add;
1991 struct lysp_deviate_rpl *rpl;
1992 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001993 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001994
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001995 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001996 LEVEL++;
1997
Michal Vaskob26d09d2022-08-22 09:52:19 +02001998 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001999 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
2000 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001
fredgan2b11ddb2019-10-21 11:03:39 +08002002 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002003 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08002004 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2005 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 LEVEL++;
2008
Michal Vaskob26d09d2022-08-22 09:52:19 +02002009 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002011 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 continue;
2013 }
fredgan2b11ddb2019-10-21 11:03:39 +08002014 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002015 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002016 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 LEVEL++;
2018
Michal Vaskob26d09d2022-08-22 09:52:19 +02002019 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002020 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002021 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002022 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002024 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002025 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002027 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002028 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002029 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002030 ypr_config(pctx, add->flags, add->exts, NULL);
2031 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002033 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
2035 if (add->flags & LYS_SET_MAX) {
2036 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002037 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 }
2041 }
fredgan2b11ddb2019-10-21 11:03:39 +08002042 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002043 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002044 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 LEVEL++;
2046
Michal Vaskob26d09d2022-08-22 09:52:19 +02002047 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002048 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002049 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002050 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002051 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2052 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2053 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2054 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002056 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 }
2058 if (rpl->flags & LYS_SET_MAX) {
2059 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002060 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002062 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 }
2064 }
fredgan2b11ddb2019-10-21 11:03:39 +08002065 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002066 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002067 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 LEVEL++;
2069
Michal Vaskob26d09d2022-08-22 09:52:19 +02002070 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002071 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002072 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002073 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002075 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002076 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002077 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002078 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002079 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002080 }
2081 }
2082
2083 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002084 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085 }
2086
2087 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002088 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089}
2090
Michal Vasko7c8439f2020-08-05 13:25:19 +02002091static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002092yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002094 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002095
Radek Krejcid3ca0632019-04-16 16:54:54 +02002096 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002097 if (modp->imports[u].flags & LYS_INTERNAL) {
2098 continue;
2099 }
2100
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002101 YPR_EXTRA_LINE_PRINT(pctx);
2102 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002103 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002104 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002105 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002107 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002108 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002109 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2110 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002112 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002113 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002114 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002115
Radek Krejcid3ca0632019-04-16 16:54:54 +02002116 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002117 if (modp->includes[u].injected) {
2118 /* do not print the includes injected from submodules */
2119 continue;
2120 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002121 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 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 +01002123 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002124 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002125 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002126 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002127 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002129 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2130 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002131 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002132 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002134 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 }
2136 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002137 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002138}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139
Michal Vasko7c8439f2020-08-05 13:25:19 +02002140static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002141yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002142{
2143 LY_ARRAY_COUNT_TYPE u;
2144 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002145 struct lysp_node_action *action;
2146 struct lysp_node_notif *notif;
2147 struct lysp_node_grp *grp;
2148 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002149
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002151 YPR_EXTRA_LINE_PRINT(pctx);
2152 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002153 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002154
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002155 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002156
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002158 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002159 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 }
2161
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002162 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002163
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002165 YPR_EXTRA_LINE_PRINT(pctx);
2166 yprp_feature(pctx, &modp->features[u]);
2167 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 }
2169
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002170 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002171
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002173 YPR_EXTRA_LINE_PRINT(pctx);
2174 yprp_identity(pctx, &modp->identities[u]);
2175 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002176 }
2177
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002178 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002179
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002181 YPR_EXTRA_LINE_PRINT(pctx);
2182 yprp_typedef(pctx, &modp->typedefs[u]);
2183 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002184 }
2185
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002186 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002187
Radek Krejci2a9fc652021-01-22 17:44:34 +01002188 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE_PRINT(pctx);
2190 yprp_grouping(pctx, grp);
2191 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002192 }
2193
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002194 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002195
Radek Krejcid3ca0632019-04-16 16:54:54 +02002196 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002197 YPR_EXTRA_LINE_PRINT(pctx);
2198 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199 }
2200
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002201 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002202
Radek Krejci2a9fc652021-01-22 17:44:34 +01002203 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002204 YPR_EXTRA_LINE_PRINT(pctx);
2205 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002206 }
2207
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002208 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002209
Radek Krejci2a9fc652021-01-22 17:44:34 +01002210 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002211 YPR_EXTRA_LINE_PRINT(pctx);
2212 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002213 }
2214
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002215 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002216
Radek Krejci2a9fc652021-01-22 17:44:34 +01002217 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002218 YPR_EXTRA_LINE_PRINT(pctx);
2219 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002220 }
2221
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002222 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002223
Radek Krejcid3ca0632019-04-16 16:54:54 +02002224 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002225 YPR_EXTRA_LINE_PRINT(pctx);
2226 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002227 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002228
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002229 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002230}
2231
2232LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002233yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002234{
2235 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002236 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002237 struct lys_ypr_ctx pctx_ = {
2238 .out = out,
2239 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002240 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002241 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002242 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002243 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002244
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002245 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002246 LEVEL++;
2247
2248 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002249 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002250 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 +02002251 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002252 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2253 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002254
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002255 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002256
Michal Vasko7c8439f2020-08-05 13:25:19 +02002257 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002258 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002259
2260 /* meta-stmts */
2261 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002262 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002263 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002264 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2265 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2266 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2267 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002268
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002269 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002270
Michal Vasko7c8439f2020-08-05 13:25:19 +02002271 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002272 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002273 YPR_EXTRA_LINE_PRINT(pctx);
2274 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002275 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002276
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002277 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002278
Michal Vasko7c8439f2020-08-05 13:25:19 +02002279 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002280 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002281
2282 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002283 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002284 ly_print_flush(out);
2285
2286 return LY_SUCCESS;
2287}
2288
2289static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002290yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002291{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002292 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002293 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002294 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002295 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002296 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002297 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002298}
2299
2300LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002301yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002302{
2303 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002304 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002305 .out = out,
2306 .level = 0,
2307 .options = options,
2308 .module = submodp->mod,
2309 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002310 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002311
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002312 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002313 LEVEL++;
2314
2315 /* submodule-header-stmts */
2316 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002317 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 +02002318 }
2319
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002320 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002321
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002322 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002323
Michal Vasko7c8439f2020-08-05 13:25:19 +02002324 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002325 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002326
2327 /* meta-stmts */
2328 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002329 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002330 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002331 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2332 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2333 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2334 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002335
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002336 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002337
Michal Vasko7c8439f2020-08-05 13:25:19 +02002338 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002339 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002340 YPR_EXTRA_LINE_PRINT(pctx);
2341 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002342 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002343
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002344 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002345
Michal Vasko7c8439f2020-08-05 13:25:19 +02002346 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002347 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002348
2349 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002350 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002351 ly_print_flush(out);
2352
2353 return LY_SUCCESS;
2354}
2355
2356LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002357yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002358{
Michal Vasko331303f2022-08-22 09:51:57 +02002359 struct lys_ypr_ctx pctx_ = {
2360 .out = out,
2361 .level = 0,
2362 .options = options,
2363 .module = node->module,
2364 .schema = LYS_YPR_COMPILED
2365 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002366
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002367 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002368
2369 ly_print_flush(out);
2370 return LY_SUCCESS;
2371}
2372
2373LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002374yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002375{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002376 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002377 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002378 struct lys_ypr_ctx pctx_ = {
2379 .out = out,
2380 .level = 0,
2381 .options = options,
2382 .module = module,
2383 .schema = LYS_YPR_COMPILED
2384 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002385
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002386 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002387 LEVEL++;
2388
Radek Krejci693262f2019-04-29 15:23:20 +02002389 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002390 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2391 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002392
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002393 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002394
Michal Vasko7c8439f2020-08-05 13:25:19 +02002395 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002396
2397 /* meta-stmts */
2398 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002399 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002400 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002401 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2402 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2403 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2404 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002405
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002406 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002407
Radek Krejci693262f2019-04-29 15:23:20 +02002408 /* revision-stmts */
2409 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002410 YPR_EXTRA_LINE_PRINT(pctx);
2411 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2412 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002413 }
2414
2415 /* body-stmts */
2416 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002417 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002418 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002419 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002420 }
2421
Radek Krejci80d281e2020-09-14 17:42:54 +02002422 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002423 YPR_EXTRA_LINE_PRINT(pctx);
2424 yprc_identity(pctx, &module->identities[u]);
2425 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002426 }
2427
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002428 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002429 struct lysc_node *data;
2430 struct lysc_node_action *rpc;
2431 struct lysc_node_notif *notif;
2432
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002433 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002434 YPR_EXTRA_LINE_PRINT(pctx);
2435 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002436 }
Radek Krejci693262f2019-04-29 15:23:20 +02002437
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002438 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002439
Radek Krejci2a9fc652021-01-22 17:44:34 +01002440 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002441 YPR_EXTRA_LINE_PRINT(pctx);
2442 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002443 }
Radek Krejci693262f2019-04-29 15:23:20 +02002444
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002445 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002446
Radek Krejci2a9fc652021-01-22 17:44:34 +01002447 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002448 YPR_EXTRA_LINE_PRINT(pctx);
2449 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002450 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002451
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002452 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002453 }
2454
2455 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002456 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002457 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002458
2459 return LY_SUCCESS;
2460}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002461
Michal Vaskocc28b152022-08-23 14:44:54 +02002462LIBYANG_API_DEF void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002463lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002464{
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002465 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002466 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002467 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002468
2469 LY_ARRAY_FOR(ext->substmts, u) {
2470 switch (ext->substmts[u].stmt) {
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002471 case LY_STMT_NOTIFICATION:
2472 case LY_STMT_INPUT:
2473 case LY_STMT_OUTPUT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002474 case LY_STMT_ACTION:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002475 case LY_STMT_RPC:
2476 case LY_STMT_ANYDATA:
2477 case LY_STMT_ANYXML:
2478 case LY_STMT_CASE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002479 case LY_STMT_CHOICE:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002480 case LY_STMT_CONTAINER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002481 case LY_STMT_LEAF:
2482 case LY_STMT_LEAF_LIST:
2483 case LY_STMT_LIST:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002484 case LY_STMT_USES: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002485 const struct lysc_node *node;
2486
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002487 if (data_printed) {
2488 break;
2489 }
2490
Radek Krejciadcf63d2021-02-09 10:21:18 +01002491 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002492 ypr_open(pctx->out, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002493 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002494 yprc_notification(pctx, (struct lysc_node_notif *)node);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002495 } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) {
2496 yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag);
2497 } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) {
2498 yprc_action(pctx, (struct lysc_node_action *)node);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002499 } else {
2500 yprc_node(pctx, node);
2501 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002502 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002503
2504 /* all data nodes are stored in a linked list so all were printed */
2505 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002506 break;
2507 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002508 case LY_STMT_ARGUMENT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002509 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002510 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002511 case LY_STMT_ERROR_APP_TAG:
2512 case LY_STMT_ERROR_MESSAGE:
2513 case LY_STMT_KEY:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002514 case LY_STMT_MODIFIER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002515 case LY_STMT_NAMESPACE:
2516 case LY_STMT_ORGANIZATION:
2517 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002518 case LY_STMT_REFERENCE:
2519 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002520 if (*(const char **)ext->substmts[u].storage) {
2521 ypr_open(pctx->out, flag);
2522 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002523 }
2524 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002525 case LY_STMT_BIT:
2526 case LY_STMT_ENUM: {
2527 const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage;
2528
2529 yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
2530 break;
2531 }
2532 case LY_STMT_CONFIG:
2533 ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2534 break;
2535 case LY_STMT_EXTENSION_INSTANCE:
2536 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0,
2537 *(struct lysc_ext_instance **)ext->substmts[u].storage, flag);
2538 break;
2539 case LY_STMT_FRACTION_DIGITS:
2540 if (*(uint8_t *)ext->substmts[u].storage) {
2541 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag);
2542 }
2543 break;
2544 case LY_STMT_IDENTITY: {
2545 const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage;
2546
2547 LY_ARRAY_FOR(idents, v) {
2548 yprc_identity(pctx, &idents[v]);
2549 }
2550 break;
2551 }
2552 case LY_STMT_LENGTH:
2553 if (*(struct lysc_range **)ext->substmts[u].storage) {
2554 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag);
2555 }
2556 break;
2557 case LY_STMT_MANDATORY:
2558 ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2559 break;
2560 case LY_STMT_MAX_ELEMENTS: {
2561 uint32_t max = *(uint32_t *)ext->substmts[u].storage;
2562
2563 if (max) {
2564 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
2565 } else {
2566 ypr_open(pctx->out, flag);
2567 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", ext->exts);
2568 }
2569 break;
2570 }
2571 case LY_STMT_MIN_ELEMENTS:
2572 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag);
2573 break;
2574 case LY_STMT_ORDERED_BY:
2575 ypr_open(pctx->out, flag);
2576 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
2577 (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", ext->exts);
2578 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002579 case LY_STMT_MUST: {
2580 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2581
2582 LY_ARRAY_FOR(musts, v) {
2583 yprc_must(pctx, &musts[v], flag);
2584 }
2585 break;
2586 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002587 case LY_STMT_PATTERN: {
2588 const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage;
2589
2590 LY_ARRAY_FOR(patterns, v) {
2591 yprc_pattern(pctx, &patterns[v], flag);
2592 }
2593 break;
2594 }
2595 case LY_STMT_POSITION:
2596 if (*(int64_t *)ext->substmts[u].storage) {
2597 ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2598 }
2599 break;
2600 case LY_STMT_VALUE:
2601 if (*(int64_t *)ext->substmts[u].storage) {
2602 ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2603 }
2604 break;
2605 case LY_STMT_RANGE:
2606 if (*(struct lysc_range **)ext->substmts[u].storage) {
2607 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag);
2608 }
2609 break;
2610 case LY_STMT_REQUIRE_INSTANCE:
2611 ypr_open(pctx->out, flag);
2612 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false",
2613 ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002614 break;
2615 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002616 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002617 break;
2618 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002619 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2620 ypr_open(pctx->out, flag);
2621 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002622 }
2623 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002624 case LY_STMT_WHEN:
2625 yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag);
2626 break;
2627 case LY_STMT_AUGMENT:
2628 case LY_STMT_BASE:
2629 case LY_STMT_BELONGS_TO:
2630 case LY_STMT_DEFAULT:
2631 case LY_STMT_DEVIATE:
2632 case LY_STMT_DEVIATION:
2633 case LY_STMT_EXTENSION:
2634 case LY_STMT_FEATURE:
2635 case LY_STMT_GROUPING:
2636 case LY_STMT_IF_FEATURE:
2637 case LY_STMT_IMPORT:
2638 case LY_STMT_INCLUDE:
2639 case LY_STMT_MODULE:
2640 case LY_STMT_PATH:
2641 case LY_STMT_PREFIX:
2642 case LY_STMT_REFINE:
2643 case LY_STMT_REVISION:
2644 case LY_STMT_REVISION_DATE:
2645 case LY_STMT_SUBMODULE:
2646 case LY_STMT_TYPEDEF:
2647 case LY_STMT_UNIQUE:
2648 case LY_STMT_YANG_VERSION:
2649 case LY_STMT_YIN_ELEMENT:
2650 /* nothing to do */
2651 break;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002652 default:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002653 LOGINT(pctx->module->ctx);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002654 break;
2655 }
2656 }
2657}