blob: 8e0af183dd66eb47775c22c4aca7416acf19cd4e [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);
Michal Vasko2e3af132023-08-11 11:29:26 +0200631 ypr_text(pctx, "must", must->cond->expr, 1, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200632
633 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200634 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200635 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100636 ypr_open(pctx->out, &inner_flag);
637 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200638 }
639 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100640 ypr_open(pctx->out, &inner_flag);
641 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200642 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
644 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200645
646 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100647 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200648}
649
650static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100651yprc_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 +0200652{
Radek Krejci857189e2020-09-01 13:26:36 +0200653 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200654 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200655
Radek Krejci334ccc72019-06-12 13:49:29 +0200656 if (!range) {
657 return;
658 }
659
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 ypr_open(pctx->out, flag);
661 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200662 LY_ARRAY_FOR(range->parts, u) {
663 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100664 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200665 }
666 if (range->parts[u].max_64 == range->parts[u].min_64) {
667 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100668 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200669 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100670 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200671 }
672 } else {
673 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100674 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200675 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100676 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200677 }
678 }
679 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100680 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200681
682 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200683 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200684 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100685 ypr_open(pctx->out, &inner_flag);
686 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200687 }
688 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100689 ypr_open(pctx->out, &inner_flag);
690 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200691 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100692 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
693 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200694
695 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100696 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200697}
698
699static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100700yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200701{
Radek Krejci857189e2020-09-01 13:26:36 +0200702 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200703
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100704 ypr_open(pctx->out, flag);
705 ly_print_(pctx->out, "%*spattern \"", INDENT);
706 ypr_encode(pctx->out, pattern->expr, -1);
707 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200708
709 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200710 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200711 if (pattern->inverted) {
712 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ypr_open(pctx->out, &inner_flag);
714 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200715 }
716 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100717 ypr_open(pctx->out, &inner_flag);
718 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200719 }
720 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100721 ypr_open(pctx->out, &inner_flag);
722 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200723 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100724 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
725 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200726
727 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100728 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200729}
730
731static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200732yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag)
733{
734 LY_ARRAY_COUNT_TYPE u;
735 const struct lysc_type_bitenum_item *item;
736 ly_bool inner_flag;
737
738 assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM));
739
740 LY_ARRAY_FOR(items, u) {
741 item = &items[u];
742 inner_flag = 0;
743
744 ypr_open(pctx->out, flag);
745 ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum");
746 ypr_encode(pctx->out, item->name, -1);
747 ly_print_(pctx->out, "\"");
748 LEVEL++;
749 if (basetype == LY_TYPE_BITS) {
750 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
751 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
752 } else { /* LY_TYPE_ENUM */
753 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
754 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
755 }
756 ypr_status(pctx, item->flags, item->exts, &inner_flag);
757 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
758 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
759 LEVEL--;
760 ypr_close(pctx, inner_flag);
761 }
762}
763
764static void
765yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200766{
Radek Krejci857189e2020-09-01 13:26:36 +0200767 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768
769 if (!when) {
770 return;
771 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100772 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773
Michal Vasko2e3af132023-08-11 11:29:26 +0200774 ypr_text(pctx, "when", when->cond, 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200775
776 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200777 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
779 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200780 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100781 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782}
783
784static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200785yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200786{
Radek Krejci857189e2020-09-01 13:26:36 +0200787 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200788
789 if (!when) {
790 return;
791 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100792 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200793
Michal Vasko2e3af132023-08-11 11:29:26 +0200794 ypr_text(pctx, "when", when->cond->expr, 1, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200795
796 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200797 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100798 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
799 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200800 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100801 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200802}
803
804static void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200805yprp_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 +0200806{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200807 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200808 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809
810 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100811 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200812 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100813 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200814 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100815 ly_print_(pctx->out, "%*senum \"", INDENT);
816 ypr_encode(pctx->out, items[u].name, -1);
817 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200818 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200819 inner_flag = 0;
820 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200821 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100822 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200823 if (items[u].flags & LYS_SET_VALUE) {
824 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100825 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100827 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200828 }
829 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100830 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
831 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
832 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200833 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100834 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200835 }
836}
837
838static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100839yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200841 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200842 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200843
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100844 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200845 LEVEL++;
846
Michal Vaskob26d09d2022-08-22 09:52:19 +0200847 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200848
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100849 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
850 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200851 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100852 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200853 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200854 yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
855 yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200856
857 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100858 ypr_open(pctx->out, &flag);
859 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200860 }
861 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100862 ypr_open(pctx->out, &flag);
863 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200864 }
865 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100866 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200867 }
868 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100869 ypr_open(pctx->out, &flag);
870 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200871 }
872 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100873 ypr_open(pctx->out, &flag);
874 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875 }
876
877 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100878 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200879}
880
881static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100882yprc_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 +0200883 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200884{
Radek Krejci857189e2020-09-01 13:26:36 +0200885 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200886 const char *str;
887
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100888 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
889 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200890 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200891 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200892 }
893}
894
895static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100896yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200897{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200898 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200899 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200900
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100901 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200902 LEVEL++;
903
Michal Vaskob26d09d2022-08-22 09:52:19 +0200904 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200905
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200906 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200907 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200908 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200909
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100910 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200911 break;
912 }
913 case LY_TYPE_UINT8:
914 case LY_TYPE_UINT16:
915 case LY_TYPE_UINT32:
916 case LY_TYPE_UINT64:
917 case LY_TYPE_INT8:
918 case LY_TYPE_INT16:
919 case LY_TYPE_INT32:
920 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200921 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200922
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100923 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200924 break;
925 }
926 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200927 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200928
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100929 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200930 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100931 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200932 }
933 break;
934 }
935 case LY_TYPE_BITS:
936 case LY_TYPE_ENUM: {
937 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200938 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200939
Michal Vaskoa0ba01e2022-10-19 13:26:57 +0200940 yprc_bits_enum(pctx, bits->bits, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200941 break;
942 }
943 case LY_TYPE_BOOL:
944 case LY_TYPE_EMPTY:
945 /* nothing to do */
946 break;
947 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200948 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200949
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100950 ypr_open(pctx->out, &flag);
951 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
952 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200953 break;
954 }
955 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200956 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200957
Radek Krejci693262f2019-04-29 15:23:20 +0200958 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100959 ypr_open(pctx->out, &flag);
960 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200961 }
962 break;
963 }
964 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200965 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200966
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100967 ypr_open(pctx->out, &flag);
968 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200969 break;
970 }
971 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200972 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200973
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100974 ypr_open(pctx->out, &flag);
975 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
976 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
977 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200978 break;
979 }
980 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200981 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200982
Radek Krejci693262f2019-04-29 15:23:20 +0200983 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984 ypr_open(pctx->out, &flag);
985 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200986 }
987 break;
988 }
989 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100990 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200991 }
992
993 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100994 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200995}
996
997static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100998yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200999{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001000 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001 LEVEL++;
1002
Michal Vaskob26d09d2022-08-22 09:52:19 +02001003 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001005 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006
1007 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001008 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001009 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001010 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001011 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001012 }
1013
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001014 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1015 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1016 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001017
1018 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001019 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001020}
1021
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001022static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1023static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1024static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1025static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026
1027static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001028yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001029{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001030 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001031 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001033 struct lysp_node_action *action;
1034 struct lysp_node_notif *notif;
1035 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001036
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001037 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038 LEVEL++;
1039
Michal Vaskob26d09d2022-08-22 09:52:19 +02001040 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001041 ypr_status(pctx, grp->flags, grp->exts, &flag);
1042 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1043 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044
1045 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001046 ypr_open(pctx->out, &flag);
1047 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001048 }
1049
Radek Krejci2a9fc652021-01-22 17:44:34 +01001050 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001051 ypr_open(pctx->out, &flag);
1052 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053 }
1054
Radek Krejci01180ac2021-01-27 08:48:22 +01001055 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001056 ypr_open(pctx->out, &flag);
1057 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001058 }
1059
Radek Krejci2a9fc652021-01-22 17:44:34 +01001060 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001061 ypr_open(pctx->out, &flag);
1062 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001063 }
1064
1065 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001066 ypr_open(pctx->out, &flag);
1067 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001068 }
1069
1070 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001071 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072}
1073
1074static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001075yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001077 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001079 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080
Radek Krejci01180ac2021-01-27 08:48:22 +01001081 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001082 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 return;
1084 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001085 ypr_open(pctx->out, flag);
1086 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001087
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001088 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089 LEVEL++;
1090
Michal Vaskob26d09d2022-08-22 09:52:19 +02001091 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001092 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001093 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 }
1095 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001096 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001097 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001098 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001099 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 }
1101
Radek Krejci01180ac2021-01-27 08:48:22 +01001102 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001103 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001104 }
1105
1106 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001107 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001108}
1109
1110static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001111yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001112{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001113 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001114 struct lysc_node *data;
1115
Radek Krejci01180ac2021-01-27 08:48:22 +01001116 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001117 /* input/output is empty */
1118 return;
1119 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001120 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001121
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001122 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001123 LEVEL++;
1124
Michal Vasko193dacd2022-10-13 08:43:05 +02001125 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001126 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001127 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001128 }
1129
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001130 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001131 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001132 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001133 }
Radek Krejci693262f2019-04-29 15:23:20 +02001134 }
1135
1136 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001137 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001138}
1139
1140static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001141yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001142{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001143 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001144 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001145 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001146 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001148 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001149
1150 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001151 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001152 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153
1154 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001155 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001156 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001157 ypr_status(pctx, notif->flags, notif->exts, &flag);
1158 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1159 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001160
1161 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001162 ypr_open(pctx->out, &flag);
1163 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001164 }
1165
Radek Krejci2a9fc652021-01-22 17:44:34 +01001166 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001167 ypr_open(pctx->out, &flag);
1168 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001169 }
1170
Radek Krejci01180ac2021-01-27 08:48:22 +01001171 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001172 ypr_open(pctx->out, &flag);
1173 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001174 }
1175
1176 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001177 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001178}
1179
1180static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001181yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001182{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001183 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001184 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001185 struct lysc_node *data;
1186
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001187 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001188
1189 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001190 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001191
1192 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001193 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001194 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195 ypr_status(pctx, notif->flags, notif->exts, &flag);
1196 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1197 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001198
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001199 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001200 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 ypr_open(pctx->out, &flag);
1202 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001203 }
Radek Krejci693262f2019-04-29 15:23:20 +02001204 }
1205
1206 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001207 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001208}
1209
1210static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001211yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001212{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001213 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001214 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001215 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001216
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001217 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001218
1219 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001220 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001221 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1222 ypr_status(pctx, action->flags, action->exts, &flag);
1223 ypr_description(pctx, action->dsc, action->exts, &flag);
1224 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001225
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001226 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001227
Radek Krejcid3ca0632019-04-16 16:54:54 +02001228 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001229 ypr_open(pctx->out, &flag);
1230 YPR_EXTRA_LINE_PRINT(pctx);
1231 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001232 }
1233
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001234 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001235
Radek Krejci2a9fc652021-01-22 17:44:34 +01001236 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001237 ypr_open(pctx->out, &flag);
1238 YPR_EXTRA_LINE_PRINT(pctx);
1239 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001240 }
1241
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001242 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001243
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001244 yprp_inout(pctx, &action->input, &flag);
1245 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001246
1247 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001248 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001249}
1250
1251static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001252yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001253{
Radek Krejci857189e2020-09-01 13:26:36 +02001254 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001255
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001256 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001257
1258 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001259 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001260 ypr_status(pctx, action->flags, action->exts, &flag);
1261 ypr_description(pctx, action->dsc, action->exts, &flag);
1262 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001263
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001264 yprc_inout(pctx, &action->input, &flag);
1265 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001266
1267 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001268 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001269}
1270
1271static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001272yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001273{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001274 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275 LEVEL++;
1276
Michal Vasko193dacd2022-10-13 08:43:05 +02001277 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001278 yprp_when(pctx, lysp_node_when(node), flag);
1279 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001280}
1281
1282static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001283yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001284{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001285 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001286 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001287
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001288 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001289 LEVEL++;
1290
Michal Vasko193dacd2022-10-13 08:43:05 +02001291 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001292
1293 when = lysc_node_when(node);
1294 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001295 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001296 }
Radek Krejci693262f2019-04-29 15:23:20 +02001297}
1298
Michal Vaskob26d09d2022-08-22 09:52:19 +02001299/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001300#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001301 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001302 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001303 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001304 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001305 ypr_status(pctx, node->flags, node->exts, flag); \
1306 ypr_description(pctx, node->dsc, node->exts, flag); \
1307 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001308
1309static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001310yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001311{
1312 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001313}
1314
1315static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001316yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001317{
1318 YPR_NODE_COMMON2;
1319}
1320
1321#undef YPR_NODE_COMMON2
1322
1323static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001324yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001325{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001326 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001327 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001328 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001329 struct lysp_node_action *action;
1330 struct lysp_node_notif *notif;
1331 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001332 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1333
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001334 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001335
1336 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001337 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001338 }
1339 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001340 ypr_open(pctx->out, &flag);
1341 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001342 }
1343
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001344 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001345
1346 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001347 ypr_open(pctx->out, &flag);
1348 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001349 }
1350
Radek Krejci2a9fc652021-01-22 17:44:34 +01001351 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001352 ypr_open(pctx->out, &flag);
1353 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001354 }
1355
1356 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001357 ypr_open(pctx->out, &flag);
1358 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001359 }
1360
Radek Krejci2a9fc652021-01-22 17:44:34 +01001361 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001362 ypr_open(pctx->out, &flag);
1363 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001364 }
1365
Radek Krejci2a9fc652021-01-22 17:44:34 +01001366 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001367 ypr_open(pctx->out, &flag);
1368 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001369 }
1370
1371 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001372 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001373}
1374
1375static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001376yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001377{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001378 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001379 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001380 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001381 struct lysc_node_action *action;
1382 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001383 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1384
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001385 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001386
1387 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001388 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001389 }
1390 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001391 ypr_open(pctx->out, &flag);
1392 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001393 }
1394
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001395 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001396
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001397 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001398 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001399 ypr_open(pctx->out, &flag);
1400 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001401 }
Radek Krejci693262f2019-04-29 15:23:20 +02001402
Radek Krejci2a9fc652021-01-22 17:44:34 +01001403 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001404 ypr_open(pctx->out, &flag);
1405 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001406 }
Radek Krejci693262f2019-04-29 15:23:20 +02001407
Radek Krejci2a9fc652021-01-22 17:44:34 +01001408 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001409 ypr_open(pctx->out, &flag);
1410 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001411 }
Radek Krejci693262f2019-04-29 15:23:20 +02001412 }
1413
1414 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001415 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001416}
1417
1418static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001419yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001420{
Radek Krejci857189e2020-09-01 13:26:36 +02001421 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001422 struct lysp_node *child;
1423 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1424
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001425 yprp_node_common1(pctx, node, &flag);
1426 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001427
1428 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001429 ypr_open(pctx->out, &flag);
1430 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001431 }
1432
1433 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001434 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001435}
1436
1437static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001438yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001439{
Radek Krejci857189e2020-09-01 13:26:36 +02001440 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001441 struct lysc_node *child;
1442
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001443 yprc_node_common1(pctx, &cs->node, &flag);
1444 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001445
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001446 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001447 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001448 ypr_open(pctx->out, &flag);
1449 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001450 }
Radek Krejci693262f2019-04-29 15:23:20 +02001451 }
1452
1453 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001454 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001455}
1456
1457static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001459{
Radek Krejci857189e2020-09-01 13:26:36 +02001460 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001461 struct lysp_node *child;
1462 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1463
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001464 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001465
Michal Vasko7f45cf22020-10-01 12:49:44 +02001466 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001467 ypr_open(pctx->out, &flag);
1468 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001469 }
1470
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001471 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001472
1473 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001474 ypr_open(pctx->out, &flag);
1475 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001476 }
1477
1478 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001479 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001480}
1481
1482static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001483yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001484{
Radek Krejci857189e2020-09-01 13:26:36 +02001485 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001486 struct lysc_node_case *cs;
1487 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1488
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001489 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001490
1491 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001492 ypr_open(pctx->out, &flag);
1493 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001494 }
1495
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001496 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001497
Michal Vasko22df3f02020-08-24 13:29:22 +02001498 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001499 ypr_open(pctx->out, &flag);
1500 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001501 }
1502
1503 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001504 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001505}
1506
1507static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001508yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001509{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001510 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1512
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001513 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001515 yprp_type(pctx, &leaf->type);
1516 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001518 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001519 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001520 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001521
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001522 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523
1524 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001525 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001526}
1527
1528static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001529yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001530{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001531 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001532 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1533
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001534 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001535
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001536 yprc_type(pctx, leaf->type);
1537 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001538 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001539 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001540 }
Radek Krejcia1911222019-07-22 17:24:50 +02001541
1542 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001543 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001544 }
Radek Krejci693262f2019-04-29 15:23:20 +02001545
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001546 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001547
1548 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001549 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001550}
1551
1552static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001553yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001555 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1557
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001558 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001559
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001560 yprp_type(pctx, &llist->type);
1561 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001563 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001564 }
1565 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001567 }
1568
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001569 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001570
1571 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001572 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573 }
1574 if (llist->flags & LYS_SET_MAX) {
1575 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001576 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001577 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001578 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 }
1580 }
1581
1582 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001583 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001584 }
1585
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001586 ypr_status(pctx, node->flags, node->exts, NULL);
1587 ypr_description(pctx, node->dsc, node->exts, NULL);
1588 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001589
1590 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001591 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001592}
1593
1594static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001595yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001596{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001597 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001598 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1599
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001600 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001601
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001602 yprc_type(pctx, llist->type);
1603 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001604 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001605 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001606 }
1607 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001608 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001609 }
1610
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001611 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001612
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001613 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001614 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001615 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001616 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001617 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001618 }
1619
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001620 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001621
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001622 ypr_status(pctx, node->flags, node->exts, NULL);
1623 ypr_description(pctx, node->dsc, node->exts, NULL);
1624 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001625
1626 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001627 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001628}
1629
1630static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001631yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001632{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001633 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001634 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001635 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001636 struct lysp_node_action *action;
1637 struct lysp_node_notif *notif;
1638 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001639 struct lysp_node_list *list = (struct lysp_node_list *)node;
1640
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001641 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642
1643 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001644 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645 }
1646 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001647 ypr_open(pctx->out, &flag);
1648 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001649 }
1650 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001651 ypr_open(pctx->out, &flag);
1652 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001653 }
1654
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001655 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001656
1657 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001658 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660 if (list->flags & LYS_SET_MAX) {
1661 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001662 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001663 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_open(pctx->out, &flag);
1665 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666 }
1667 }
1668
1669 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001670 ypr_open(pctx->out, &flag);
1671 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001672 }
1673
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001674 ypr_status(pctx, node->flags, node->exts, &flag);
1675 ypr_description(pctx, node->dsc, node->exts, &flag);
1676 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001677
1678 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001679 ypr_open(pctx->out, &flag);
1680 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001681 }
1682
Radek Krejci2a9fc652021-01-22 17:44:34 +01001683 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001684 ypr_open(pctx->out, &flag);
1685 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001686 }
1687
1688 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001689 ypr_open(pctx->out, &flag);
1690 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001691 }
1692
Radek Krejci2a9fc652021-01-22 17:44:34 +01001693 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001694 ypr_open(pctx->out, &flag);
1695 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001696 }
1697
Radek Krejci2a9fc652021-01-22 17:44:34 +01001698 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001699 ypr_open(pctx->out, &flag);
1700 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001701 }
1702
1703 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001704 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001705}
1706
1707static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001708yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001709{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001710 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001711 struct lysc_node_list *list = (struct lysc_node_list *)node;
1712
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001713 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001714
1715 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001716 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001717 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001718 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001719 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001720 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 +01001721 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001722 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001723 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001724 }
1725 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001726 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001727 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001728 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001729 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001730 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001731 }
1732
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001733 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001734
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001735 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001736 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001737 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001738 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001739 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001740 }
1741
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001742 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001743
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001744 ypr_status(pctx, node->flags, node->exts, NULL);
1745 ypr_description(pctx, node->dsc, node->exts, NULL);
1746 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001747
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001748 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001749 struct lysc_node *child;
1750 struct lysc_node_action *action;
1751 struct lysc_node_notif *notif;
1752
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001753 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001754 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001755 }
Radek Krejci693262f2019-04-29 15:23:20 +02001756
Radek Krejci2a9fc652021-01-22 17:44:34 +01001757 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001758 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001759 }
Radek Krejci693262f2019-04-29 15:23:20 +02001760
Radek Krejci2a9fc652021-01-22 17:44:34 +01001761 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001762 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001763 }
Radek Krejci693262f2019-04-29 15:23:20 +02001764 }
1765
1766 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001767 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001768}
1769
1770static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001771yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001772{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001773 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001774 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001775
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001776 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777 LEVEL++;
1778
Michal Vaskob26d09d2022-08-22 09:52:19 +02001779 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001780 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781
1782 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001783 ypr_open(pctx->out, &flag);
1784 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001785 }
1786
1787 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001788 ypr_open(pctx->out, &flag);
1789 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790 }
1791
1792 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001793 ypr_open(pctx->out, &flag);
1794 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795 }
1796
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001797 ypr_config(pctx, refine->flags, refine->exts, &flag);
1798 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799
1800 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001801 ypr_open(pctx->out, &flag);
1802 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001803 }
1804 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001805 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001807 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001808 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001809 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810 }
1811 }
1812
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001813 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1814 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001815
1816 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001817 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001818}
1819
1820static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001821yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001824 struct lysp_node_action *action;
1825 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001827 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828 LEVEL++;
1829
Michal Vaskob26d09d2022-08-22 09:52:19 +02001830 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001831 yprp_when(pctx, aug->when, NULL);
1832 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1833 ypr_status(pctx, aug->flags, aug->exts, NULL);
1834 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1835 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001836
1837 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001838 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839 }
1840
Radek Krejci2a9fc652021-01-22 17:44:34 +01001841 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001842 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843 }
1844
Radek Krejci2a9fc652021-01-22 17:44:34 +01001845 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001846 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847 }
1848
1849 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001850 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851}
1852
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001854yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001856 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001857 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001859 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001861 yprp_node_common1(pctx, node, &flag);
1862 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863
1864 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001865 ypr_open(pctx->out, &flag);
1866 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001867 }
1868
Radek Krejci2a9fc652021-01-22 17:44:34 +01001869 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001870 ypr_open(pctx->out, &flag);
1871 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872 }
1873
1874 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001875 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001876}
1877
1878static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001879yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001881 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001882 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1884
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001885 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001886
1887 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001888 ypr_open(pctx->out, &flag);
1889 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890 }
1891
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001892 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893
1894 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001895 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001896}
1897
1898static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001899yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001901 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001902 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001903 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001905 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906
Radek Krejci693262f2019-04-29 15:23:20 +02001907 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001908 ypr_open(pctx->out, &flag);
1909 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910 }
1911
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001912 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001913
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001915 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916}
1917
1918static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001919yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920{
1921 switch (node->nodetype) {
1922 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001923 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001924 break;
1925 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001926 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 break;
1928 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001929 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930 break;
1931 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001932 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933 break;
1934 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001935 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 break;
1937 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001938 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 break;
1940 case LYS_ANYXML:
1941 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001942 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001943 break;
1944 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001945 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001946 break;
1947 default:
1948 break;
1949 }
1950}
1951
1952static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001953yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001954{
1955 switch (node->nodetype) {
1956 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001957 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001958 break;
1959 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001960 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001961 break;
1962 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001963 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001964 break;
1965 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001966 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001967 break;
1968 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001969 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001970 break;
1971 case LYS_ANYXML:
1972 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001973 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001974 break;
1975 default:
1976 break;
1977 }
1978}
1979
1980static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001981yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001983 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984 struct lysp_deviate_add *add;
1985 struct lysp_deviate_rpl *rpl;
1986 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001987 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001988
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001989 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 LEVEL++;
1991
Michal Vaskob26d09d2022-08-22 09:52:19 +02001992 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001993 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1994 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995
fredgan2b11ddb2019-10-21 11:03:39 +08001996 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001997 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001998 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1999 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002000 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 LEVEL++;
2002
Michal Vaskob26d09d2022-08-22 09:52:19 +02002003 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002005 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 continue;
2007 }
fredgan2b11ddb2019-10-21 11:03:39 +08002008 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002009 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002010 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002011 LEVEL++;
2012
Michal Vaskob26d09d2022-08-22 09:52:19 +02002013 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002014 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002015 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002016 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002018 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002019 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002021 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002022 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002024 ypr_config(pctx, add->flags, add->exts, NULL);
2025 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002027 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 }
2029 if (add->flags & LYS_SET_MAX) {
2030 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002031 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002033 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
2035 }
fredgan2b11ddb2019-10-21 11:03:39 +08002036 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002037 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002038 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 LEVEL++;
2040
Michal Vaskob26d09d2022-08-22 09:52:19 +02002041 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002042 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002043 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002045 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2046 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2047 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2048 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002050 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 }
2052 if (rpl->flags & LYS_SET_MAX) {
2053 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002054 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002056 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 }
2058 }
fredgan2b11ddb2019-10-21 11:03:39 +08002059 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002060 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002061 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 LEVEL++;
2063
Michal Vaskob26d09d2022-08-22 09:52:19 +02002064 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002065 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002066 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002067 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002069 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002070 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002071 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002072 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002073 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 }
2075 }
2076
2077 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002078 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 }
2080
2081 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002082 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002083}
2084
Michal Vasko7c8439f2020-08-05 13:25:19 +02002085static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002086yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002088 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089
Radek Krejcid3ca0632019-04-16 16:54:54 +02002090 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002091 if (modp->imports[u].flags & LYS_INTERNAL) {
2092 continue;
2093 }
2094
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002095 YPR_EXTRA_LINE_PRINT(pctx);
2096 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002098 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002099 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002101 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002103 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2104 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002105 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002106 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002107 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002108 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002109
Radek Krejcid3ca0632019-04-16 16:54:54 +02002110 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002111 if (modp->includes[u].injected) {
2112 /* do not print the includes injected from submodules */
2113 continue;
2114 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002115 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002116 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 +01002117 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002119 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002120 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002121 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002123 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2124 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002125 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002126 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002128 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002129 }
2130 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002131 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002132}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133
Michal Vasko7c8439f2020-08-05 13:25:19 +02002134static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002135yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002136{
2137 LY_ARRAY_COUNT_TYPE u;
2138 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002139 struct lysp_node_action *action;
2140 struct lysp_node_notif *notif;
2141 struct lysp_node_grp *grp;
2142 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143
Radek Krejcid3ca0632019-04-16 16:54:54 +02002144 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002145 YPR_EXTRA_LINE_PRINT(pctx);
2146 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002148
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002149 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002150
Radek Krejcid3ca0632019-04-16 16:54:54 +02002151 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002152 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002153 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002154 }
2155
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002156 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002157
Radek Krejcid3ca0632019-04-16 16:54:54 +02002158 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002159 YPR_EXTRA_LINE_PRINT(pctx);
2160 yprp_feature(pctx, &modp->features[u]);
2161 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002162 }
2163
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002164 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002165
Radek Krejcid3ca0632019-04-16 16:54:54 +02002166 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002167 YPR_EXTRA_LINE_PRINT(pctx);
2168 yprp_identity(pctx, &modp->identities[u]);
2169 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170 }
2171
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002172 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002173
Radek Krejcid3ca0632019-04-16 16:54:54 +02002174 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002175 YPR_EXTRA_LINE_PRINT(pctx);
2176 yprp_typedef(pctx, &modp->typedefs[u]);
2177 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002178 }
2179
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002180 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002181
Radek Krejci2a9fc652021-01-22 17:44:34 +01002182 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002183 YPR_EXTRA_LINE_PRINT(pctx);
2184 yprp_grouping(pctx, grp);
2185 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002186 }
2187
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002188 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002189
Radek Krejcid3ca0632019-04-16 16:54:54 +02002190 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002191 YPR_EXTRA_LINE_PRINT(pctx);
2192 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002193 }
2194
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002195 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002196
Radek Krejci2a9fc652021-01-22 17:44:34 +01002197 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002198 YPR_EXTRA_LINE_PRINT(pctx);
2199 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002200 }
2201
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002202 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002203
Radek Krejci2a9fc652021-01-22 17:44:34 +01002204 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002205 YPR_EXTRA_LINE_PRINT(pctx);
2206 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 }
2208
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002209 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002210
Radek Krejci2a9fc652021-01-22 17:44:34 +01002211 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002212 YPR_EXTRA_LINE_PRINT(pctx);
2213 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002214 }
2215
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002216 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002217
Radek Krejcid3ca0632019-04-16 16:54:54 +02002218 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002219 YPR_EXTRA_LINE_PRINT(pctx);
2220 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002221 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002222
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002223 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002224}
2225
2226LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002227yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002228{
2229 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002230 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002231 struct lys_ypr_ctx pctx_ = {
2232 .out = out,
2233 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002234 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002235 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002236 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002237 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002238
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002239 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002240 LEVEL++;
2241
2242 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002243 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002244 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 +02002245 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002246 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2247 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002248
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002249 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002250
Michal Vasko7c8439f2020-08-05 13:25:19 +02002251 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002252 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002253
2254 /* meta-stmts */
2255 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002256 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002257 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002258 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2259 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2260 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2261 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002262
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002263 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002264
Michal Vasko7c8439f2020-08-05 13:25:19 +02002265 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002266 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002267 YPR_EXTRA_LINE_PRINT(pctx);
2268 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002269 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002270
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002271 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002272
Michal Vasko7c8439f2020-08-05 13:25:19 +02002273 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002274 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002275
2276 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002277 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002278 ly_print_flush(out);
2279
2280 return LY_SUCCESS;
2281}
2282
2283static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002284yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002285{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002286 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002287 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002288 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002289 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002291 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002292}
2293
2294LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002295yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002296{
2297 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002298 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002299 .out = out,
2300 .level = 0,
2301 .options = options,
2302 .module = submodp->mod,
2303 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002304 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002305
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002306 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002307 LEVEL++;
2308
2309 /* submodule-header-stmts */
2310 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002311 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 +02002312 }
2313
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002314 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002315
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002316 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002317
Michal Vasko7c8439f2020-08-05 13:25:19 +02002318 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002319 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002320
2321 /* meta-stmts */
2322 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002323 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002324 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002325 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2326 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2327 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2328 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002329
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002330 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002331
Michal Vasko7c8439f2020-08-05 13:25:19 +02002332 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002333 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002334 YPR_EXTRA_LINE_PRINT(pctx);
2335 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002336 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002337
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002338 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002339
Michal Vasko7c8439f2020-08-05 13:25:19 +02002340 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002341 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002342
2343 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002344 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002345 ly_print_flush(out);
2346
2347 return LY_SUCCESS;
2348}
2349
2350LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002351yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002352{
Michal Vasko331303f2022-08-22 09:51:57 +02002353 struct lys_ypr_ctx pctx_ = {
2354 .out = out,
2355 .level = 0,
2356 .options = options,
2357 .module = node->module,
2358 .schema = LYS_YPR_COMPILED
2359 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002360
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002361 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002362
2363 ly_print_flush(out);
2364 return LY_SUCCESS;
2365}
2366
2367LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002368yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002369{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002370 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002371 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002372 struct lys_ypr_ctx pctx_ = {
2373 .out = out,
2374 .level = 0,
2375 .options = options,
2376 .module = module,
2377 .schema = LYS_YPR_COMPILED
2378 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002379
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002380 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002381 LEVEL++;
2382
Radek Krejci693262f2019-04-29 15:23:20 +02002383 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002384 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2385 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002386
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002387 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002388
Michal Vasko7c8439f2020-08-05 13:25:19 +02002389 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002390
2391 /* meta-stmts */
2392 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002393 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002394 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002395 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2396 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2397 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2398 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002399
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002400 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002401
Radek Krejci693262f2019-04-29 15:23:20 +02002402 /* revision-stmts */
2403 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002404 YPR_EXTRA_LINE_PRINT(pctx);
2405 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2406 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002407 }
2408
2409 /* body-stmts */
2410 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002411 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002412 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002413 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002414 }
2415
Radek Krejci80d281e2020-09-14 17:42:54 +02002416 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002417 YPR_EXTRA_LINE_PRINT(pctx);
2418 yprc_identity(pctx, &module->identities[u]);
2419 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002420 }
2421
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002422 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002423 struct lysc_node *data;
2424 struct lysc_node_action *rpc;
2425 struct lysc_node_notif *notif;
2426
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002427 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002428 YPR_EXTRA_LINE_PRINT(pctx);
2429 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002430 }
Radek Krejci693262f2019-04-29 15:23:20 +02002431
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002432 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002433
Radek Krejci2a9fc652021-01-22 17:44:34 +01002434 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002435 YPR_EXTRA_LINE_PRINT(pctx);
2436 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002437 }
Radek Krejci693262f2019-04-29 15:23:20 +02002438
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002439 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002440
Radek Krejci2a9fc652021-01-22 17:44:34 +01002441 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002442 YPR_EXTRA_LINE_PRINT(pctx);
2443 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002444 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002445
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002446 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002447 }
2448
2449 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002450 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002451 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002452
2453 return LY_SUCCESS;
2454}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002455
Michal Vaskocc28b152022-08-23 14:44:54 +02002456LIBYANG_API_DEF void
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002457lyplg_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 +01002458{
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002459 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002460 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002461 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002462
2463 LY_ARRAY_FOR(ext->substmts, u) {
2464 switch (ext->substmts[u].stmt) {
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002465 case LY_STMT_NOTIFICATION:
2466 case LY_STMT_INPUT:
2467 case LY_STMT_OUTPUT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002468 case LY_STMT_ACTION:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002469 case LY_STMT_RPC:
2470 case LY_STMT_ANYDATA:
2471 case LY_STMT_ANYXML:
2472 case LY_STMT_CASE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002473 case LY_STMT_CHOICE:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002474 case LY_STMT_CONTAINER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002475 case LY_STMT_LEAF:
2476 case LY_STMT_LEAF_LIST:
2477 case LY_STMT_LIST:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002478 case LY_STMT_USES: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002479 const struct lysc_node *node;
2480
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002481 if (data_printed) {
2482 break;
2483 }
2484
Radek Krejciadcf63d2021-02-09 10:21:18 +01002485 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002486 ypr_open(pctx->out, flag);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002487 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002488 yprc_notification(pctx, (struct lysc_node_notif *)node);
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002489 } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) {
2490 yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag);
2491 } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) {
2492 yprc_action(pctx, (struct lysc_node_action *)node);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002493 } else {
2494 yprc_node(pctx, node);
2495 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002496 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002497
2498 /* all data nodes are stored in a linked list so all were printed */
2499 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002500 break;
2501 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002502 case LY_STMT_ARGUMENT:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002503 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002504 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002505 case LY_STMT_ERROR_APP_TAG:
2506 case LY_STMT_ERROR_MESSAGE:
2507 case LY_STMT_KEY:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002508 case LY_STMT_MODIFIER:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002509 case LY_STMT_NAMESPACE:
2510 case LY_STMT_ORGANIZATION:
2511 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002512 case LY_STMT_REFERENCE:
2513 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002514 if (*(const char **)ext->substmts[u].storage) {
2515 ypr_open(pctx->out, flag);
2516 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002517 }
2518 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002519 case LY_STMT_BIT:
2520 case LY_STMT_ENUM: {
2521 const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage;
2522
2523 yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
2524 break;
2525 }
2526 case LY_STMT_CONFIG:
2527 ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2528 break;
2529 case LY_STMT_EXTENSION_INSTANCE:
2530 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0,
2531 *(struct lysc_ext_instance **)ext->substmts[u].storage, flag);
2532 break;
2533 case LY_STMT_FRACTION_DIGITS:
2534 if (*(uint8_t *)ext->substmts[u].storage) {
2535 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag);
2536 }
2537 break;
2538 case LY_STMT_IDENTITY: {
2539 const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage;
2540
2541 LY_ARRAY_FOR(idents, v) {
2542 yprc_identity(pctx, &idents[v]);
2543 }
2544 break;
2545 }
2546 case LY_STMT_LENGTH:
2547 if (*(struct lysc_range **)ext->substmts[u].storage) {
2548 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag);
2549 }
2550 break;
2551 case LY_STMT_MANDATORY:
2552 ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2553 break;
2554 case LY_STMT_MAX_ELEMENTS: {
2555 uint32_t max = *(uint32_t *)ext->substmts[u].storage;
2556
2557 if (max) {
2558 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
2559 } else {
2560 ypr_open(pctx->out, flag);
2561 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", ext->exts);
2562 }
2563 break;
2564 }
2565 case LY_STMT_MIN_ELEMENTS:
2566 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag);
2567 break;
2568 case LY_STMT_ORDERED_BY:
2569 ypr_open(pctx->out, flag);
2570 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
2571 (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", ext->exts);
2572 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002573 case LY_STMT_MUST: {
2574 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2575
2576 LY_ARRAY_FOR(musts, v) {
2577 yprc_must(pctx, &musts[v], flag);
2578 }
2579 break;
2580 }
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002581 case LY_STMT_PATTERN: {
2582 const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage;
2583
2584 LY_ARRAY_FOR(patterns, v) {
2585 yprc_pattern(pctx, &patterns[v], flag);
2586 }
2587 break;
2588 }
2589 case LY_STMT_POSITION:
2590 if (*(int64_t *)ext->substmts[u].storage) {
2591 ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2592 }
2593 break;
2594 case LY_STMT_VALUE:
2595 if (*(int64_t *)ext->substmts[u].storage) {
2596 ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
2597 }
2598 break;
2599 case LY_STMT_RANGE:
2600 if (*(struct lysc_range **)ext->substmts[u].storage) {
2601 yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag);
2602 }
2603 break;
2604 case LY_STMT_REQUIRE_INSTANCE:
2605 ypr_open(pctx->out, flag);
2606 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false",
2607 ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002608 break;
2609 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002610 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002611 break;
2612 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002613 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2614 ypr_open(pctx->out, flag);
2615 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002616 }
2617 break;
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002618 case LY_STMT_WHEN:
2619 yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag);
2620 break;
2621 case LY_STMT_AUGMENT:
2622 case LY_STMT_BASE:
2623 case LY_STMT_BELONGS_TO:
2624 case LY_STMT_DEFAULT:
2625 case LY_STMT_DEVIATE:
2626 case LY_STMT_DEVIATION:
2627 case LY_STMT_EXTENSION:
2628 case LY_STMT_FEATURE:
2629 case LY_STMT_GROUPING:
2630 case LY_STMT_IF_FEATURE:
2631 case LY_STMT_IMPORT:
2632 case LY_STMT_INCLUDE:
2633 case LY_STMT_MODULE:
2634 case LY_STMT_PATH:
2635 case LY_STMT_PREFIX:
2636 case LY_STMT_REFINE:
2637 case LY_STMT_REVISION:
2638 case LY_STMT_REVISION_DATE:
2639 case LY_STMT_SUBMODULE:
2640 case LY_STMT_TYPEDEF:
2641 case LY_STMT_UNIQUE:
2642 case LY_STMT_YANG_VERSION:
2643 case LY_STMT_YIN_ELEMENT:
2644 /* nothing to do */
2645 break;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002646 default:
Michal Vaskoa0ba01e2022-10-19 13:26:57 +02002647 LOGINT(pctx->module->ctx);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002648 break;
2649 }
2650 }
2651}