blob: fd2853ee2da20cd637b928c34995df0315425206 [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
Radek Krejci693262f2019-04-29 15:23:20 +020018#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include <stdint.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010023#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020024
Radek Krejci535ea9f2020-05-29 16:01:05 +020025#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020026#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020027#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010028#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020029#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010030#include "plugins_exts.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
Radek Krejciaa14a0c2020-09-04 11:16:47 +020048#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
49
Michal Vasko61ad1ff2022-02-10 15:48:39 +010050#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
51#define YPR_EXTRA_LINE_PRINT(PCTX) \
52 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
53 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020054 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010055 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020056 } \
57 }
58
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010059/**
60 * @brief Compiled YANG printer context
61 *
62 * Note that the YANG extensions API provides getter to the members for the extension plugins.
63 */
64struct lys_ypr_ctx {
65 union {
66 struct {
67 struct ly_out *out; /**< output specification */
68 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020069 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010070 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
71 const struct lys_module *module; /**< schema to print */
72 };
73 struct lyspr_ctx printer_ctx;
74 };
75
76 /* YANG printer specific members */
77 enum lys_ypr_schema_type schema; /**< type of the schema to print */
78};
79
80/**
Radek Krejcie7b95092019-05-15 11:03:07 +020081 * @brief Print the given text as content of a double quoted YANG string,
82 * including encoding characters that have special meanings. The quotation marks
83 * are not printed.
84 *
85 * Follows RFC 7950, section 6.1.3.
86 *
87 * @param[in] out Output specification.
88 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020089 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020090 * the @p text is printed completely as a NULL-terminated string.
91 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020092static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020093ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020094{
Radek Krejci1deb5be2020-08-26 16:43:36 +020095 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 const char *start;
97 char special = 0;
98
99 if (!len) {
100 return;
101 }
102
103 if (len < 0) {
104 len = strlen(text);
105 }
106
107 start = text;
108 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200109 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200110 switch (text[i]) {
111 case '\n':
112 case '\t':
113 case '\"':
114 case '\\':
115 special = text[i];
116 break;
117 default:
118 ++start_len;
119 break;
120 }
121
122 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200123 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200124 switch (special) {
125 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200126 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200127 break;
128 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200129 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130 break;
131 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200132 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200133 break;
134 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200135 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200136 break;
137 }
138
139 start += start_len + 1;
140 start_len = 0;
141
142 special = 0;
143 }
144 }
145
Michal Vasko5233e962020-08-14 14:26:20 +0200146 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200147}
148
149static void
Radek Krejci857189e2020-09-01 13:26:36 +0200150ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 if (flag && !*flag) {
153 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200154 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155 }
156}
157
158static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100159ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200160{
161 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100162 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100164 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 }
166}
167
168static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100169ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200170{
171 const char *s, *t;
172
173 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100174 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200175 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100176 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 LEVEL++;
178
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100179 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 t = text;
182 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100183 ypr_encode(pctx->out, t, s - t);
184 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 t = s + 1;
186 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100187 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200188 }
189 }
190
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100191 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100193 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100195 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 if (!singleline) {
198 LEVEL--;
199 }
200}
201
202static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100203yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200204{
205 struct lysp_stmt *childstmt;
206 const char *s, *t;
207
208 if (stmt->arg) {
209 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100210 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200211 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100212 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213 t = stmt->arg;
214 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100215 ypr_encode(pctx->out, t, s - t);
216 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200217 t = s + 1;
218 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100219 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 }
221 }
222 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100223 ypr_encode(pctx->out, t, strlen(t));
224 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100226 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 }
228 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100229 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230 }
231
232 if (stmt->child) {
233 LEVEL++;
234 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100235 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 }
237 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200239 }
240}
241
Radek Krejcid3ca0632019-04-16 16:54:54 +0200242static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200243yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
244 struct lysp_ext_instance *ext, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200245{
Radek Krejcid3ca0632019-04-16 16:54:54 +0200246 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200247 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200248
Michal Vaskob26d09d2022-08-22 09:52:19 +0200249 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
250 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200251 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100252
Michal Vaskob26d09d2022-08-22 09:52:19 +0200253 ypr_open(pctx->out, flag);
254
Michal Vasko193dacd2022-10-13 08:43:05 +0200255 if (ext->def->argname) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200256 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200257 ypr_encode(pctx->out, ext->argument, -1);
258 ly_print_(pctx->out, "\"");
259 } else {
260 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
261 }
262
263 child_presence = 0;
264 LEVEL++;
265 LY_LIST_FOR(ext->child, stmt) {
266 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200267 continue;
268 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200269 if (!child_presence) {
270 ly_print_(pctx->out, " {\n");
271 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200272 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200273 yprp_stmt(pctx, stmt);
274 }
275 LEVEL--;
276 if (child_presence) {
277 ly_print_(pctx->out, "%*s}\n", INDENT);
278 } else {
279 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200280 }
281}
282
Radek Krejci693262f2019-04-29 15:23:20 +0200283static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200284yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
285 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200286{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200287 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200288
289 LY_ARRAY_FOR(exts, u) {
290 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
291 }
292}
293
294static void
295yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
296 struct lysc_ext_instance *exts, ly_bool *flag)
297{
298 LY_ARRAY_COUNT_TYPE u;
299 ly_bool inner_flag;
300
301 LY_ARRAY_FOR(exts, u) {
302 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
303 return;
304 }
305
306 ypr_open(pctx->out, flag);
307 if (exts[u].argument) {
308 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
309 ypr_encode(pctx->out, exts[u].argument, -1);
310 ly_print_(pctx->out, "\"");
311 } else {
312 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
313 }
314
315 LEVEL++;
316 inner_flag = 0;
317 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
318
Michal Vasko941e0562022-10-18 10:35:00 +0200319 if (exts[u].def->plugin && exts[u].def->plugin->printer_info) {
320 exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200321 }
322
323 LEVEL--;
324 ypr_close(pctx, inner_flag);
325 }
326}
327
328static void
329ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
330{
Radek Krejci857189e2020-09-01 13:26:36 +0200331 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200332
333 if (!text) {
334 /* nothing to print */
335 return;
336 }
337
Radek Krejcieccf6602021-02-05 19:42:54 +0100338 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100339 ly_print_(pctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100341 ypr_text(pctx, stmt_attr_info[substmt].name, text,
Radek Krejcieccf6602021-02-05 19:42:54 +0100342 (stmt_attr_info[substmt].flags & 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,
357 unsigned long int 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 Vasko9a9e4e72022-03-21 10:05:11 +0100371ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value,
372 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373{
374 char *str;
375
Radek Krejci1deb5be2020-08-26 16:43:36 +0200376 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100377 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378 return;
379 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100380 ypr_open(pctx->out, flag);
381 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 free(str);
383}
384
385static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100386yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200387{
388 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100389 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200390 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200391 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100392 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
393 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200394 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100395 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200396 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100397 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398 }
399}
400
401static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100402ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403{
404 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100405 ypr_open(pctx->out, flag);
406 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407 }
408}
409
410static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100411ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412{
413 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100414 ypr_open(pctx->out, flag);
415 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 }
417}
418
419static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100420ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200421{
422 const char *status = NULL;
423
424 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200426 status = "current";
427 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100428 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429 status = "deprecated";
430 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100431 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200432 status = "obsolete";
433 }
Radek Krejci693262f2019-04-29 15:23:20 +0200434
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100435 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200436}
437
438static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100439ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200440{
441 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100442 ypr_open(pctx->out, flag);
443 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 }
445}
446
447static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100448ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449{
450 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100451 ypr_open(pctx->out, flag);
452 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453 }
454}
455
456static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100457yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200458{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200459 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200460 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461
Michal Vasko7f45cf22020-10-01 12:49:44 +0200462 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464 extflag = 0;
465
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100466 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467
468 /* extensions */
469 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200470 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100472 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200473 }
474}
475
476static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100477yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478{
Radek Krejci857189e2020-09-01 13:26:36 +0200479 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200480 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100482 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 LEVEL++;
484
Michal Vaskob26d09d2022-08-22 09:52:19 +0200485 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100487 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100488 ypr_open(pctx->out, &flag);
489 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200490 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200492 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100493 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200494 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200496 }
497 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100498 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100499 ypr_open(pctx->out, &flag2);
500 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200501 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200502 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100503 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200504 }
505
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100506 ypr_status(pctx, ext->flags, ext->exts, &flag);
507 ypr_description(pctx, ext->dsc, ext->exts, &flag);
508 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200509
510 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512}
513
514static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100515yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516{
Radek Krejci857189e2020-09-01 13:26:36 +0200517 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200518
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100519 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200521 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100522 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
523 ypr_status(pctx, feat->flags, feat->exts, &flag);
524 ypr_description(pctx, feat->dsc, feat->exts, &flag);
525 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200526 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100527 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200528}
529
530static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100531yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200532{
Radek Krejci857189e2020-09-01 13:26:36 +0200533 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200534 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100536 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200537 LEVEL++;
538
Michal Vaskob26d09d2022-08-22 09:52:19 +0200539 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100540 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541
542 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100543 ypr_open(pctx->out, &flag);
544 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200545 }
546
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100547 ypr_status(pctx, ident->flags, ident->exts, &flag);
548 ypr_description(pctx, ident->dsc, ident->exts, &flag);
549 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200550
551 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100552 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553}
554
555static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100556yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200557{
Radek Krejci857189e2020-09-01 13:26:36 +0200558 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200559 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200560
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100561 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200562 LEVEL++;
563
Michal Vaskob26d09d2022-08-22 09:52:19 +0200564 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200565
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100566 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200567 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100568 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200569 }
570
Radek Krejci693262f2019-04-29 15:23:20 +0200571 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100572 if (pctx->module != ident->derived[u]->module) {
573 ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200574 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100575 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200576 }
577 }
578
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100579 ypr_status(pctx, ident->flags, ident->exts, &flag);
580 ypr_description(pctx, ident->dsc, ident->exts, &flag);
581 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200582
583 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100584 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200585}
586
587static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100588yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200589{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100590 ly_bool inner_flag = 0, singleline;
591 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200592
593 if (!restr) {
594 return;
595 }
596
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100597 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100598 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
599 restr->arg.str : restr->arg.str + 1;
600 singleline = strchr(text, '\n') ? 0 : 1;
Michal Vasko193dacd2022-10-13 08:43:05 +0200601 ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200602
603 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200604 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100605 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200606 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100607 ypr_open(pctx->out, &inner_flag);
608 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609 }
610 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100611 ypr_open(pctx->out, &inner_flag);
612 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613 }
614 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100615 ypr_open(pctx->out, &inner_flag);
616 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200617 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100618 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
619 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200620
Radek Krejcid3ca0632019-04-16 16:54:54 +0200621 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100622 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200623}
624
625static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100626yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200627{
Radek Krejci857189e2020-09-01 13:26:36 +0200628 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200629
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100630 ypr_open(pctx->out, flag);
631 ly_print_(pctx->out, "%*smust \"", INDENT);
632 ypr_encode(pctx->out, must->cond->expr, -1);
633 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200634
635 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200636 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100638 ypr_open(pctx->out, &inner_flag);
639 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200640 }
641 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100642 ypr_open(pctx->out, &inner_flag);
643 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200644 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100645 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
646 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200647
648 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100649 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200650}
651
652static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100653yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200654{
Radek Krejci857189e2020-09-01 13:26:36 +0200655 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200656 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200657
Radek Krejci334ccc72019-06-12 13:49:29 +0200658 if (!range) {
659 return;
660 }
661
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100662 ypr_open(pctx->out, flag);
663 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200664 LY_ARRAY_FOR(range->parts, u) {
665 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100666 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200667 }
668 if (range->parts[u].max_64 == range->parts[u].min_64) {
669 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100670 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200671 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100672 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200673 }
674 } else {
675 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100676 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200677 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100678 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200679 }
680 }
681 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100682 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200683
684 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200685 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200686 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100687 ypr_open(pctx->out, &inner_flag);
688 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200689 }
690 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100691 ypr_open(pctx->out, &inner_flag);
692 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200693 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100694 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
695 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200696
697 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100698 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200699}
700
701static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100702yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200703{
Radek Krejci857189e2020-09-01 13:26:36 +0200704 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200705
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100706 ypr_open(pctx->out, flag);
707 ly_print_(pctx->out, "%*spattern \"", INDENT);
708 ypr_encode(pctx->out, pattern->expr, -1);
709 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200710
711 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200712 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200713 if (pattern->inverted) {
714 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100715 ypr_open(pctx->out, &inner_flag);
716 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200717 }
718 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100719 ypr_open(pctx->out, &inner_flag);
720 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200721 }
722 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100723 ypr_open(pctx->out, &inner_flag);
724 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200725 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100726 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
727 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200728
729 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100730 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200731}
732
733static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100734yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200735{
Radek Krejci857189e2020-09-01 13:26:36 +0200736 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200737
738 if (!when) {
739 return;
740 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100741 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200742
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100743 ly_print_(pctx->out, "%*swhen \"", INDENT);
744 ypr_encode(pctx->out, when->cond, -1);
745 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200746
747 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200748 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100749 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
750 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200751 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100752 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200753}
754
755static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100756yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200757{
Radek Krejci857189e2020-09-01 13:26:36 +0200758 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200759
760 if (!when) {
761 return;
762 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100763 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200764
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100765 ly_print_(pctx->out, "%*swhen \"", INDENT);
766 ypr_encode(pctx->out, when->cond->expr, -1);
767 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200768
769 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200770 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100771 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
772 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200773 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100774 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200775}
776
777static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778yprp_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 +0200779{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200780 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200781 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782
783 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100784 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200785 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100786 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200787 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100788 ly_print_(pctx->out, "%*senum \"", INDENT);
789 ypr_encode(pctx->out, items[u].name, -1);
790 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200791 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200792 inner_flag = 0;
793 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200794 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100795 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 if (items[u].flags & LYS_SET_VALUE) {
797 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100798 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200799 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100800 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200801 }
802 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100803 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
804 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
805 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200806 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100807 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200808 }
809}
810
811static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100812yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200813{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200814 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200815 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100817 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200818 LEVEL++;
819
Michal Vaskob26d09d2022-08-22 09:52:19 +0200820 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200821
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100822 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
823 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200824 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100825 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100827 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
828 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200829
830 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100831 ypr_open(pctx->out, &flag);
832 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200833 }
834 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100835 ypr_open(pctx->out, &flag);
836 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200837 }
838 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100839 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840 }
841 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100842 ypr_open(pctx->out, &flag);
843 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200844 }
845 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100846 ypr_open(pctx->out, &flag);
847 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200848 }
849
850 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100851 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200852}
853
854static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100855yprc_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 +0200856 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200857{
Radek Krejci857189e2020-09-01 13:26:36 +0200858 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200859 const char *str;
860
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100861 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
862 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200863 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200864 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200865 }
866}
867
868static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100869yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200870{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200871 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200872 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200873
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100874 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200875 LEVEL++;
876
Michal Vaskob26d09d2022-08-22 09:52:19 +0200877 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200878
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200879 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200880 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200881 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200882
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100883 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200884 break;
885 }
886 case LY_TYPE_UINT8:
887 case LY_TYPE_UINT16:
888 case LY_TYPE_UINT32:
889 case LY_TYPE_UINT64:
890 case LY_TYPE_INT8:
891 case LY_TYPE_INT16:
892 case LY_TYPE_INT32:
893 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200894 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200895
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100896 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200897 break;
898 }
899 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200900 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200901
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100902 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200903 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100904 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200905 }
906 break;
907 }
908 case LY_TYPE_BITS:
909 case LY_TYPE_ENUM: {
910 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200911 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200912
Radek Krejci693262f2019-04-29 15:23:20 +0200913 LY_ARRAY_FOR(bits->bits, u) {
914 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200915 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200916
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100917 ypr_open(pctx->out, &flag);
918 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
919 ypr_encode(pctx->out, item->name, -1);
920 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200921 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200922 if (type->basetype == LY_TYPE_BITS) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200923 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100924 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200925 } else { /* LY_TYPE_ENUM */
Michal Vaskob26d09d2022-08-22 09:52:19 +0200926 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100927 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200928 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100929 ypr_status(pctx, item->flags, item->exts, &inner_flag);
930 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
931 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200932 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100933 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200934 }
935 break;
936 }
937 case LY_TYPE_BOOL:
938 case LY_TYPE_EMPTY:
939 /* nothing to do */
940 break;
941 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200942 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200943
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100944 ypr_open(pctx->out, &flag);
945 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
946 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200947 break;
948 }
949 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200950 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200951
Radek Krejci693262f2019-04-29 15:23:20 +0200952 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100953 ypr_open(pctx->out, &flag);
954 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200955 }
956 break;
957 }
958 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200959 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200960
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100961 ypr_open(pctx->out, &flag);
962 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200963 break;
964 }
965 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200966 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200967
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100968 ypr_open(pctx->out, &flag);
969 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
970 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
971 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200972 break;
973 }
974 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200975 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200976
Radek Krejci693262f2019-04-29 15:23:20 +0200977 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100978 ypr_open(pctx->out, &flag);
979 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200980 }
981 break;
982 }
983 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100984 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200985 }
986
987 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100988 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200989}
990
991static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100992yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100994 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200995 LEVEL++;
996
Michal Vaskob26d09d2022-08-22 09:52:19 +0200997 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200998
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100999 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001000
1001 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001002 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001003 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001004 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001005 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006 }
1007
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001008 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1009 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1010 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001011
1012 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001013 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001014}
1015
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001016static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1017static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1018static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1019static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001020
1021static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001022yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001023{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001024 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001025 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001027 struct lysp_node_action *action;
1028 struct lysp_node_notif *notif;
1029 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001030
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001031 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032 LEVEL++;
1033
Michal Vaskob26d09d2022-08-22 09:52:19 +02001034 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001035 ypr_status(pctx, grp->flags, grp->exts, &flag);
1036 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1037 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038
1039 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001040 ypr_open(pctx->out, &flag);
1041 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042 }
1043
Radek Krejci2a9fc652021-01-22 17:44:34 +01001044 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001045 ypr_open(pctx->out, &flag);
1046 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047 }
1048
Radek Krejci01180ac2021-01-27 08:48:22 +01001049 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001050 ypr_open(pctx->out, &flag);
1051 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052 }
1053
Radek Krejci2a9fc652021-01-22 17:44:34 +01001054 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001055 ypr_open(pctx->out, &flag);
1056 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001057 }
1058
1059 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001060 ypr_open(pctx->out, &flag);
1061 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062 }
1063
1064 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001065 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001066}
1067
1068static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001069yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001071 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001073 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074
Radek Krejci01180ac2021-01-27 08:48:22 +01001075 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001076 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001077 return;
1078 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001079 ypr_open(pctx->out, flag);
1080 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001082 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 LEVEL++;
1084
Michal Vaskob26d09d2022-08-22 09:52:19 +02001085 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001086 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001087 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001088 }
1089 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001090 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001092 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001093 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 }
1095
Radek Krejci01180ac2021-01-27 08:48:22 +01001096 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001097 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 }
1099
1100 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001101 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001102}
1103
1104static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001105yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001106{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001107 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001108 struct lysc_node *data;
1109
Radek Krejci01180ac2021-01-27 08:48:22 +01001110 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001111 /* input/output is empty */
1112 return;
1113 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001114 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001115
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001116 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001117 LEVEL++;
1118
Michal Vasko193dacd2022-10-13 08:43:05 +02001119 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001120 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001121 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001122 }
1123
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001124 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001125 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001126 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001127 }
Radek Krejci693262f2019-04-29 15:23:20 +02001128 }
1129
1130 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001131 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001132}
1133
1134static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001135yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001136{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001137 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001138 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001139 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001140 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001141
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001142 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001143
1144 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001145 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001146 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147
1148 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001149 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001150 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001151 ypr_status(pctx, notif->flags, notif->exts, &flag);
1152 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1153 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154
1155 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001156 ypr_open(pctx->out, &flag);
1157 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001158 }
1159
Radek Krejci2a9fc652021-01-22 17:44:34 +01001160 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001161 ypr_open(pctx->out, &flag);
1162 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001163 }
1164
Radek Krejci01180ac2021-01-27 08:48:22 +01001165 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001166 ypr_open(pctx->out, &flag);
1167 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001168 }
1169
1170 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001171 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001172}
1173
1174static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001175yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001176{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001177 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001178 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001179 struct lysc_node *data;
1180
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001181 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001182
1183 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001184 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001185
1186 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001187 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001188 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001189 ypr_status(pctx, notif->flags, notif->exts, &flag);
1190 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1191 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001192
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001193 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001194 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001195 ypr_open(pctx->out, &flag);
1196 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001197 }
Radek Krejci693262f2019-04-29 15:23:20 +02001198 }
1199
1200 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001201 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001202}
1203
1204static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001205yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001206{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001207 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001208 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001209 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001210
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001211 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001212
1213 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001214 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001215 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1216 ypr_status(pctx, action->flags, action->exts, &flag);
1217 ypr_description(pctx, action->dsc, action->exts, &flag);
1218 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001219
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001220 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001221
Radek Krejcid3ca0632019-04-16 16:54:54 +02001222 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001223 ypr_open(pctx->out, &flag);
1224 YPR_EXTRA_LINE_PRINT(pctx);
1225 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001226 }
1227
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001228 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001229
Radek Krejci2a9fc652021-01-22 17:44:34 +01001230 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001231 ypr_open(pctx->out, &flag);
1232 YPR_EXTRA_LINE_PRINT(pctx);
1233 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234 }
1235
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001236 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001237
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001238 yprp_inout(pctx, &action->input, &flag);
1239 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001240
1241 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001242 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001243}
1244
1245static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001246yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001247{
Radek Krejci857189e2020-09-01 13:26:36 +02001248 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001249
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001250 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001251
1252 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +02001253 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001254 ypr_status(pctx, action->flags, action->exts, &flag);
1255 ypr_description(pctx, action->dsc, action->exts, &flag);
1256 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001257
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258 yprc_inout(pctx, &action->input, &flag);
1259 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001260
1261 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001262 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001263}
1264
1265static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001266yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001267{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001268 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001269 LEVEL++;
1270
Michal Vasko193dacd2022-10-13 08:43:05 +02001271 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001272 yprp_when(pctx, lysp_node_when(node), flag);
1273 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001274}
1275
1276static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001277yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001278{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001279 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001280 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001282 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001283 LEVEL++;
1284
Michal Vasko193dacd2022-10-13 08:43:05 +02001285 yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001286
1287 when = lysc_node_when(node);
1288 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001289 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001290 }
Radek Krejci693262f2019-04-29 15:23:20 +02001291}
1292
Michal Vaskob26d09d2022-08-22 09:52:19 +02001293/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001294#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001295 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001296 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001297 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001298 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001299 ypr_status(pctx, node->flags, node->exts, flag); \
1300 ypr_description(pctx, node->dsc, node->exts, flag); \
1301 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001302
1303static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001304yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001305{
1306 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001307}
1308
1309static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001310yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001311{
1312 YPR_NODE_COMMON2;
1313}
1314
1315#undef YPR_NODE_COMMON2
1316
1317static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001318yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001319{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001320 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001321 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001322 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001323 struct lysp_node_action *action;
1324 struct lysp_node_notif *notif;
1325 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001326 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1327
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001328 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329
1330 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001331 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001332 }
1333 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001334 ypr_open(pctx->out, &flag);
1335 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001336 }
1337
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001338 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339
1340 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001341 ypr_open(pctx->out, &flag);
1342 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001343 }
1344
Radek Krejci2a9fc652021-01-22 17:44:34 +01001345 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001346 ypr_open(pctx->out, &flag);
1347 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001348 }
1349
1350 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001351 ypr_open(pctx->out, &flag);
1352 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001353 }
1354
Radek Krejci2a9fc652021-01-22 17:44:34 +01001355 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001356 ypr_open(pctx->out, &flag);
1357 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001358 }
1359
Radek Krejci2a9fc652021-01-22 17:44:34 +01001360 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001361 ypr_open(pctx->out, &flag);
1362 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001363 }
1364
1365 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001366 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001367}
1368
1369static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001370yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001371{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001372 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001373 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001374 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001375 struct lysc_node_action *action;
1376 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001377 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1378
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001379 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001380
1381 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001382 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001383 }
1384 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001385 ypr_open(pctx->out, &flag);
1386 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001387 }
1388
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001389 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001390
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001391 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001392 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001393 ypr_open(pctx->out, &flag);
1394 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001395 }
Radek Krejci693262f2019-04-29 15:23:20 +02001396
Radek Krejci2a9fc652021-01-22 17:44:34 +01001397 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001398 ypr_open(pctx->out, &flag);
1399 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001400 }
Radek Krejci693262f2019-04-29 15:23:20 +02001401
Radek Krejci2a9fc652021-01-22 17:44:34 +01001402 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001403 ypr_open(pctx->out, &flag);
1404 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001405 }
Radek Krejci693262f2019-04-29 15:23:20 +02001406 }
1407
1408 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001409 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001410}
1411
1412static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001413yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001414{
Radek Krejci857189e2020-09-01 13:26:36 +02001415 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001416 struct lysp_node *child;
1417 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1418
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001419 yprp_node_common1(pctx, node, &flag);
1420 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001421
1422 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001423 ypr_open(pctx->out, &flag);
1424 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001425 }
1426
1427 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001428 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001429}
1430
1431static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001432yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001433{
Radek Krejci857189e2020-09-01 13:26:36 +02001434 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001435 struct lysc_node *child;
1436
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001437 yprc_node_common1(pctx, &cs->node, &flag);
1438 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001439
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001440 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001441 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001442 ypr_open(pctx->out, &flag);
1443 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001444 }
Radek Krejci693262f2019-04-29 15:23:20 +02001445 }
1446
1447 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001448 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001449}
1450
1451static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001452yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001453{
Radek Krejci857189e2020-09-01 13:26:36 +02001454 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001455 struct lysp_node *child;
1456 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1457
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001458 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001459
Michal Vasko7f45cf22020-10-01 12:49:44 +02001460 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001461 ypr_open(pctx->out, &flag);
1462 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001463 }
1464
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001465 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001466
1467 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001468 ypr_open(pctx->out, &flag);
1469 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470 }
1471
1472 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001473 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001474}
1475
1476static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001477yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001478{
Radek Krejci857189e2020-09-01 13:26:36 +02001479 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001480 struct lysc_node_case *cs;
1481 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1482
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001483 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001484
1485 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001486 ypr_open(pctx->out, &flag);
1487 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001488 }
1489
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001490 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001491
Michal Vasko22df3f02020-08-24 13:29:22 +02001492 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001493 ypr_open(pctx->out, &flag);
1494 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001495 }
1496
1497 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001498 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001499}
1500
1501static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001502yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001504 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001505 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1506
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001507 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001509 yprp_type(pctx, &leaf->type);
1510 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001512 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001513 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001514 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001516 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517
1518 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001519 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520}
1521
1522static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001523yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001524{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001525 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001526 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1527
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001528 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001529
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001530 yprc_type(pctx, leaf->type);
1531 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001532 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001533 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001534 }
Radek Krejcia1911222019-07-22 17:24:50 +02001535
1536 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001537 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001538 }
Radek Krejci693262f2019-04-29 15:23:20 +02001539
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001540 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001541
1542 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001543 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001544}
1545
1546static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001547yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001548{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001549 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1551
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001552 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001553
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001554 yprp_type(pctx, &llist->type);
1555 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001557 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558 }
1559 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001560 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561 }
1562
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001563 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001564
1565 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001566 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001567 }
1568 if (llist->flags & LYS_SET_MAX) {
1569 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001571 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001572 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573 }
1574 }
1575
1576 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001577 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001578 }
1579
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001580 ypr_status(pctx, node->flags, node->exts, NULL);
1581 ypr_description(pctx, node->dsc, node->exts, NULL);
1582 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583
1584 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001585 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001586}
1587
1588static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001589yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001590{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001591 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001592 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1593
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001594 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001595
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001596 yprc_type(pctx, llist->type);
1597 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001598 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001599 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001600 }
1601 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001602 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001603 }
1604
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001605 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001606
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001607 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001608 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001609 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001610 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001611 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001612 }
1613
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001614 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001615
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001616 ypr_status(pctx, node->flags, node->exts, NULL);
1617 ypr_description(pctx, node->dsc, node->exts, NULL);
1618 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001619
1620 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001621 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001622}
1623
1624static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001625yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001626{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001627 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001628 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001629 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001630 struct lysp_node_action *action;
1631 struct lysp_node_notif *notif;
1632 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633 struct lysp_node_list *list = (struct lysp_node_list *)node;
1634
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001635 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001636
1637 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001638 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001639 }
1640 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001641 ypr_open(pctx->out, &flag);
1642 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001643 }
1644 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001645 ypr_open(pctx->out, &flag);
1646 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 }
1648
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001649 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001650
1651 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001652 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001653 }
1654 if (list->flags & LYS_SET_MAX) {
1655 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001656 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001657 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001658 ypr_open(pctx->out, &flag);
1659 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001660 }
1661 }
1662
1663 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001664 ypr_open(pctx->out, &flag);
1665 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666 }
1667
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001668 ypr_status(pctx, node->flags, node->exts, &flag);
1669 ypr_description(pctx, node->dsc, node->exts, &flag);
1670 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001671
1672 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001673 ypr_open(pctx->out, &flag);
1674 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001675 }
1676
Radek Krejci2a9fc652021-01-22 17:44:34 +01001677 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001678 ypr_open(pctx->out, &flag);
1679 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001680 }
1681
1682 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001683 ypr_open(pctx->out, &flag);
1684 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001685 }
1686
Radek Krejci2a9fc652021-01-22 17:44:34 +01001687 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001688 ypr_open(pctx->out, &flag);
1689 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001690 }
1691
Radek Krejci2a9fc652021-01-22 17:44:34 +01001692 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001693 ypr_open(pctx->out, &flag);
1694 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001695 }
1696
1697 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001698 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001699}
1700
1701static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001702yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001703{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001704 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001705 struct lysc_node_list *list = (struct lysc_node_list *)node;
1706
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001707 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001708
1709 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001710 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001711 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001712 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001713 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001714 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 +01001715 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001716 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001717 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001718 }
1719 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001720 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001721 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001722 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001723 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001724 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001725 }
1726
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001727 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001728
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001729 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001730 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001731 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001732 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001733 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001734 }
1735
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001736 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001737
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001738 ypr_status(pctx, node->flags, node->exts, NULL);
1739 ypr_description(pctx, node->dsc, node->exts, NULL);
1740 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001741
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001742 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001743 struct lysc_node *child;
1744 struct lysc_node_action *action;
1745 struct lysc_node_notif *notif;
1746
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001747 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001748 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001749 }
Radek Krejci693262f2019-04-29 15:23:20 +02001750
Radek Krejci2a9fc652021-01-22 17:44:34 +01001751 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001752 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001753 }
Radek Krejci693262f2019-04-29 15:23:20 +02001754
Radek Krejci2a9fc652021-01-22 17:44:34 +01001755 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001756 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001757 }
Radek Krejci693262f2019-04-29 15:23:20 +02001758 }
1759
1760 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001761 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001762}
1763
1764static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001765yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001766{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001767 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001768 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001770 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001771 LEVEL++;
1772
Michal Vaskob26d09d2022-08-22 09:52:19 +02001773 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001774 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001775
1776 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001777 ypr_open(pctx->out, &flag);
1778 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 }
1780
1781 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001782 ypr_open(pctx->out, &flag);
1783 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001784 }
1785
1786 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001787 ypr_open(pctx->out, &flag);
1788 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001789 }
1790
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001791 ypr_config(pctx, refine->flags, refine->exts, &flag);
1792 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001793
1794 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001795 ypr_open(pctx->out, &flag);
1796 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797 }
1798 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001799 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001800 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001801 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001803 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001804 }
1805 }
1806
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001807 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1808 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809
1810 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001811 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812}
1813
1814static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001815yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001818 struct lysp_node_action *action;
1819 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001821 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822 LEVEL++;
1823
Michal Vaskob26d09d2022-08-22 09:52:19 +02001824 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001825 yprp_when(pctx, aug->when, NULL);
1826 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1827 ypr_status(pctx, aug->flags, aug->exts, NULL);
1828 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1829 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830
1831 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001832 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833 }
1834
Radek Krejci2a9fc652021-01-22 17:44:34 +01001835 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001836 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837 }
1838
Radek Krejci2a9fc652021-01-22 17:44:34 +01001839 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001840 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 }
1842
1843 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001844 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845}
1846
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001848yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001850 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001851 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001853 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001855 yprp_node_common1(pctx, node, &flag);
1856 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857
1858 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001859 ypr_open(pctx->out, &flag);
1860 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861 }
1862
Radek Krejci2a9fc652021-01-22 17:44:34 +01001863 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001864 ypr_open(pctx->out, &flag);
1865 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866 }
1867
1868 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001869 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001870}
1871
1872static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001873yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001874{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001875 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001876 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1878
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001879 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880
1881 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001882 ypr_open(pctx->out, &flag);
1883 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 }
1885
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001886 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887
1888 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001889 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890}
1891
1892static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001893yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001895 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001896 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001897 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001898
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001899 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900
Radek Krejci693262f2019-04-29 15:23:20 +02001901 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001902 ypr_open(pctx->out, &flag);
1903 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904 }
1905
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001906 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001907
Radek Krejcid3ca0632019-04-16 16:54:54 +02001908 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001909 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910}
1911
1912static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001913yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914{
1915 switch (node->nodetype) {
1916 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001917 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 break;
1919 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001920 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921 break;
1922 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001923 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001924 break;
1925 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001926 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 break;
1928 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001929 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930 break;
1931 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001932 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933 break;
1934 case LYS_ANYXML:
1935 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001936 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937 break;
1938 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001939 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940 break;
1941 default:
1942 break;
1943 }
1944}
1945
1946static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001947yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001948{
1949 switch (node->nodetype) {
1950 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001951 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001952 break;
1953 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001954 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001955 break;
1956 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001957 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001958 break;
1959 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001960 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001961 break;
1962 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001963 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001964 break;
1965 case LYS_ANYXML:
1966 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001967 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001968 break;
1969 default:
1970 break;
1971 }
1972}
1973
1974static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001975yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001977 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001978 struct lysp_deviate_add *add;
1979 struct lysp_deviate_rpl *rpl;
1980 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001981 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001983 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984 LEVEL++;
1985
Michal Vaskob26d09d2022-08-22 09:52:19 +02001986 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001987 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1988 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989
fredgan2b11ddb2019-10-21 11:03:39 +08001990 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001991 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001992 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1993 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001994 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995 LEVEL++;
1996
Michal Vaskob26d09d2022-08-22 09:52:19 +02001997 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001998 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001999 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002000 continue;
2001 }
fredgan2b11ddb2019-10-21 11:03:39 +08002002 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002003 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002004 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 LEVEL++;
2006
Michal Vaskob26d09d2022-08-22 09:52:19 +02002007 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002008 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002009 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002010 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002011 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002012 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002013 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002014 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002015 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002016 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002018 ypr_config(pctx, add->flags, add->exts, NULL);
2019 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002021 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 }
2023 if (add->flags & LYS_SET_MAX) {
2024 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002025 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002027 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 }
2029 }
fredgan2b11ddb2019-10-21 11:03:39 +08002030 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002031 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002032 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 LEVEL++;
2034
Michal Vaskob26d09d2022-08-22 09:52:19 +02002035 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002037 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2040 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2041 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2042 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002044 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 }
2046 if (rpl->flags & LYS_SET_MAX) {
2047 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002048 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002050 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 }
2052 }
fredgan2b11ddb2019-10-21 11:03:39 +08002053 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002054 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002055 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056 LEVEL++;
2057
Michal Vaskob26d09d2022-08-22 09:52:19 +02002058 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002059 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002060 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002061 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002063 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002064 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002066 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002067 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
2069 }
2070
2071 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002072 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073 }
2074
2075 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002076 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002077}
2078
Michal Vasko7c8439f2020-08-05 13:25:19 +02002079static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002080yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002082 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002083
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002085 if (modp->imports[u].flags & LYS_INTERNAL) {
2086 continue;
2087 }
2088
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002089 YPR_EXTRA_LINE_PRINT(pctx);
2090 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002092 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002093 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002095 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002096 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002097 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2098 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002099 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002100 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002101 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002102 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002103
Radek Krejcid3ca0632019-04-16 16:54:54 +02002104 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002105 if (modp->includes[u].injected) {
2106 /* do not print the includes injected from submodules */
2107 continue;
2108 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002109 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002110 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 +01002111 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002112 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002113 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002114 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002115 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002116 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002117 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2118 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002120 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002121 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002122 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002123 }
2124 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002125 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002126}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127
Michal Vasko7c8439f2020-08-05 13:25:19 +02002128static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002129yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002130{
2131 LY_ARRAY_COUNT_TYPE u;
2132 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002133 struct lysp_node_action *action;
2134 struct lysp_node_notif *notif;
2135 struct lysp_node_grp *grp;
2136 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002137
Radek Krejcid3ca0632019-04-16 16:54:54 +02002138 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002139 YPR_EXTRA_LINE_PRINT(pctx);
2140 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002141 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002142
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002143 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002144
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002146 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002147 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002148 }
2149
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002150 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002151
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002153 YPR_EXTRA_LINE_PRINT(pctx);
2154 yprp_feature(pctx, &modp->features[u]);
2155 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002156 }
2157
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002158 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002159
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002161 YPR_EXTRA_LINE_PRINT(pctx);
2162 yprp_identity(pctx, &modp->identities[u]);
2163 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 }
2165
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002166 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002167
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002169 YPR_EXTRA_LINE_PRINT(pctx);
2170 yprp_typedef(pctx, &modp->typedefs[u]);
2171 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 }
2173
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002174 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002175
Radek Krejci2a9fc652021-01-22 17:44:34 +01002176 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002177 YPR_EXTRA_LINE_PRINT(pctx);
2178 yprp_grouping(pctx, grp);
2179 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 }
2181
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002182 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002183
Radek Krejcid3ca0632019-04-16 16:54:54 +02002184 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002185 YPR_EXTRA_LINE_PRINT(pctx);
2186 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 }
2188
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002190
Radek Krejci2a9fc652021-01-22 17:44:34 +01002191 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002192 YPR_EXTRA_LINE_PRINT(pctx);
2193 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002194 }
2195
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002196 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002197
Radek Krejci2a9fc652021-01-22 17:44:34 +01002198 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002199 YPR_EXTRA_LINE_PRINT(pctx);
2200 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002201 }
2202
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002203 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002204
Radek Krejci2a9fc652021-01-22 17:44:34 +01002205 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002206 YPR_EXTRA_LINE_PRINT(pctx);
2207 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002208 }
2209
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002210 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002211
Radek Krejcid3ca0632019-04-16 16:54:54 +02002212 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002213 YPR_EXTRA_LINE_PRINT(pctx);
2214 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002215 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002216
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002217 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002218}
2219
2220LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002221yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002222{
2223 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002224 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002225 struct lys_ypr_ctx pctx_ = {
2226 .out = out,
2227 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002228 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002229 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002230 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002231 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002232
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002233 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002234 LEVEL++;
2235
2236 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002237 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002238 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 +02002239 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002240 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2241 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002242
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002243 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002244
Michal Vasko7c8439f2020-08-05 13:25:19 +02002245 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002246 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002247
2248 /* meta-stmts */
2249 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002250 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002251 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002252 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2253 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2254 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2255 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002256
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002257 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002258
Michal Vasko7c8439f2020-08-05 13:25:19 +02002259 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002260 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002261 YPR_EXTRA_LINE_PRINT(pctx);
2262 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002263 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002264
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002265 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002266
Michal Vasko7c8439f2020-08-05 13:25:19 +02002267 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002268 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002269
2270 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002271 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002272 ly_print_flush(out);
2273
2274 return LY_SUCCESS;
2275}
2276
2277static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002278yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002279{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002280 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002281 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002282 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002283 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002284 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002285 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002286}
2287
2288LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002289yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002290{
2291 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002292 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002293 .out = out,
2294 .level = 0,
2295 .options = options,
2296 .module = submodp->mod,
2297 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002298 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002299
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002300 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002301 LEVEL++;
2302
2303 /* submodule-header-stmts */
2304 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002305 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 +02002306 }
2307
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002308 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002309
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002310 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002311
Michal Vasko7c8439f2020-08-05 13:25:19 +02002312 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002313 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002314
2315 /* meta-stmts */
2316 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002317 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002318 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002319 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2320 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2321 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2322 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002323
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002324 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002325
Michal Vasko7c8439f2020-08-05 13:25:19 +02002326 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002327 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002328 YPR_EXTRA_LINE_PRINT(pctx);
2329 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002330 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002331
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002332 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002333
Michal Vasko7c8439f2020-08-05 13:25:19 +02002334 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002335 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002336
2337 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002338 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002339 ly_print_flush(out);
2340
2341 return LY_SUCCESS;
2342}
2343
2344LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002345yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002346{
Michal Vasko331303f2022-08-22 09:51:57 +02002347 struct lys_ypr_ctx pctx_ = {
2348 .out = out,
2349 .level = 0,
2350 .options = options,
2351 .module = node->module,
2352 .schema = LYS_YPR_COMPILED
2353 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002354
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002355 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002356
2357 ly_print_flush(out);
2358 return LY_SUCCESS;
2359}
2360
2361LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002362yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002363{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002364 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002365 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002366 struct lys_ypr_ctx pctx_ = {
2367 .out = out,
2368 .level = 0,
2369 .options = options,
2370 .module = module,
2371 .schema = LYS_YPR_COMPILED
2372 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002373
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002374 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002375 LEVEL++;
2376
Radek Krejci693262f2019-04-29 15:23:20 +02002377 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002378 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2379 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002380
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002381 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002382
Michal Vasko7c8439f2020-08-05 13:25:19 +02002383 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002384
2385 /* meta-stmts */
2386 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002387 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002388 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002389 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2390 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2391 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2392 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002393
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002394 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002395
Radek Krejci693262f2019-04-29 15:23:20 +02002396 /* revision-stmts */
2397 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002398 YPR_EXTRA_LINE_PRINT(pctx);
2399 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2400 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002401 }
2402
2403 /* body-stmts */
2404 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002405 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002406 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002407 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002408 }
2409
Radek Krejci80d281e2020-09-14 17:42:54 +02002410 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002411 YPR_EXTRA_LINE_PRINT(pctx);
2412 yprc_identity(pctx, &module->identities[u]);
2413 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002414 }
2415
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002416 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002417 struct lysc_node *data;
2418 struct lysc_node_action *rpc;
2419 struct lysc_node_notif *notif;
2420
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002421 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002422 YPR_EXTRA_LINE_PRINT(pctx);
2423 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002424 }
Radek Krejci693262f2019-04-29 15:23:20 +02002425
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002426 YPR_EXTRA_LINE(modc->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002427
Radek Krejci2a9fc652021-01-22 17:44:34 +01002428 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002429 YPR_EXTRA_LINE_PRINT(pctx);
2430 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002431 }
Radek Krejci693262f2019-04-29 15:23:20 +02002432
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002433 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002434
Radek Krejci2a9fc652021-01-22 17:44:34 +01002435 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002436 YPR_EXTRA_LINE_PRINT(pctx);
2437 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002438 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002439
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002440 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002441 }
2442
2443 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002444 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002445 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002446
2447 return LY_SUCCESS;
2448}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002449
Michal Vaskocc28b152022-08-23 14:44:54 +02002450LIBYANG_API_DEF void
Michal Vasko941e0562022-10-18 10:35:00 +02002451lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002452{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002453 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002454 LY_ARRAY_COUNT_TYPE u, v;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002455 ly_bool data_printed = 0;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002456
2457 LY_ARRAY_FOR(ext->substmts, u) {
2458 switch (ext->substmts[u].stmt) {
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002459 case LY_STMT_ACTION:
2460 case LY_STMT_CONTAINER:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002461 case LY_STMT_CHOICE:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002462 case LY_STMT_LEAF:
2463 case LY_STMT_LEAF_LIST:
2464 case LY_STMT_LIST:
2465 case LY_STMT_NOTIFICATION:
2466 case LY_STMT_RPC:
2467 case LY_STMT_ANYXML:
2468 case LY_STMT_ANYDATA: {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002469 const struct lysc_node *node;
2470
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002471 if (data_printed) {
2472 break;
2473 }
2474
Radek Krejciadcf63d2021-02-09 10:21:18 +01002475 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002476 ypr_open(pctx->out, flag);
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002477 if ((ext->substmts[u].stmt == LY_STMT_ACTION) || (ext->substmts[u].stmt == LY_STMT_RPC)) {
2478 yprc_action(pctx, (struct lysc_node_action *)node);
2479 } else if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
2480 yprc_notification(pctx, (struct lysc_node_notif *)node);
2481 } else {
2482 yprc_node(pctx, node);
2483 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002484 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002485
2486 /* all data nodes are stored in a linked list so all were printed */
2487 data_printed = 1;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002488 break;
2489 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002490 case LY_STMT_CONTACT:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002491 case LY_STMT_DESCRIPTION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002492 case LY_STMT_ERROR_APP_TAG:
2493 case LY_STMT_ERROR_MESSAGE:
2494 case LY_STMT_KEY:
2495 case LY_STMT_NAMESPACE:
2496 case LY_STMT_ORGANIZATION:
2497 case LY_STMT_PRESENCE:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002498 case LY_STMT_REFERENCE:
2499 case LY_STMT_UNITS:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002500 if (*(const char **)ext->substmts[u].storage) {
2501 ypr_open(pctx->out, flag);
2502 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002503 }
2504 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002505 case LY_STMT_MUST: {
2506 const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
2507
2508 LY_ARRAY_FOR(musts, v) {
2509 yprc_must(pctx, &musts[v], flag);
2510 }
2511 break;
2512 }
Radek Krejciadcf63d2021-02-09 10:21:18 +01002513 case LY_STMT_IF_FEATURE:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02002514 case LY_STMT_USES:
2515 case LY_STMT_GROUPING:
2516 case LY_STMT_TYPEDEF:
Radek Krejciadcf63d2021-02-09 10:21:18 +01002517 /* nothing to do */
2518 break;
2519 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002520 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002521 break;
2522 case LY_STMT_TYPE:
Michal Vasko9c3556a2022-10-06 16:08:47 +02002523 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2524 ypr_open(pctx->out, flag);
2525 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002526 }
2527 break;
2528 /* TODO support other substatements */
2529 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002530 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Michal Vasko193dacd2022-10-13 08:43:05 +02002531 lyplg_ext_stmt2str(ext->substmts[u].stmt));
Radek Krejciadcf63d2021-02-09 10:21:18 +01002532 break;
2533 }
2534 }
2535}