blob: 20899836a06381dc0725d80b8e79b9988a76afab [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief YANG printer
5 *
Michal Vaskob26d09d2022-08-22 09:52:19 +02006 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Radek Krejcid3ca0632019-04-16 16:54:54 +02007 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010022#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020023
Radek Krejci535ea9f2020-05-29 16:01:05 +020024#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020025#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010027#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020028#include "out_internal.h"
Radek Krejci77114102021-03-10 15:21:57 +010029#include "plugins_exts.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010030#include "plugins_exts_print.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
Radek Krejciaa14a0c2020-09-04 11:16:47 +020048#define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */
49
Michal Vasko61ad1ff2022-02-10 15:48:39 +010050#define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; }
51#define YPR_EXTRA_LINE_PRINT(PCTX) \
52 if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \
53 (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020054 if (DO_FORMAT) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +010055 ly_print_((PCTX)->out, "\n"); \
Radek Krejciaa14a0c2020-09-04 11:16:47 +020056 } \
57 }
58
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010059/**
60 * @brief Compiled YANG printer context
61 *
62 * Note that the YANG extensions API provides getter to the members for the extension plugins.
63 */
64struct lys_ypr_ctx {
65 union {
66 struct {
67 struct ly_out *out; /**< output specification */
68 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
Radek Krejciaa14a0c2020-09-04 11:16:47 +020069 uint16_t flags; /**< internal flags for use by printer */
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010070 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
71 const struct lys_module *module; /**< schema to print */
72 };
73 struct lyspr_ctx printer_ctx;
74 };
75
76 /* YANG printer specific members */
77 enum lys_ypr_schema_type schema; /**< type of the schema to print */
78};
79
80/**
Radek Krejcie7b95092019-05-15 11:03:07 +020081 * @brief Print the given text as content of a double quoted YANG string,
82 * including encoding characters that have special meanings. The quotation marks
83 * are not printed.
84 *
85 * Follows RFC 7950, section 6.1.3.
86 *
87 * @param[in] out Output specification.
88 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020089 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020090 * the @p text is printed completely as a NULL-terminated string.
91 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020092static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020093ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020094{
Radek Krejci1deb5be2020-08-26 16:43:36 +020095 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 const char *start;
97 char special = 0;
98
99 if (!len) {
100 return;
101 }
102
103 if (len < 0) {
104 len = strlen(text);
105 }
106
107 start = text;
108 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200109 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200110 switch (text[i]) {
111 case '\n':
112 case '\t':
113 case '\"':
114 case '\\':
115 special = text[i];
116 break;
117 default:
118 ++start_len;
119 break;
120 }
121
122 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200123 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200124 switch (special) {
125 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200126 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200127 break;
128 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200129 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130 break;
131 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200132 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200133 break;
134 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200135 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200136 break;
137 }
138
139 start += start_len + 1;
140 start_len = 0;
141
142 special = 0;
143 }
144 }
145
Michal Vasko5233e962020-08-14 14:26:20 +0200146 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200147}
148
149static void
Radek Krejci857189e2020-09-01 13:26:36 +0200150ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 if (flag && !*flag) {
153 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200154 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200155 }
156}
157
158static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100159ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200160{
161 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100162 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100164 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 }
166}
167
168static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100169ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200170{
171 const char *s, *t;
172
173 if (singleline) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100174 ly_print_(pctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200175 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100176 ly_print_(pctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 LEVEL++;
178
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100179 ly_print_(pctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 t = text;
182 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100183 ypr_encode(pctx->out, t, s - t);
184 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 t = s + 1;
186 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100187 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200188 }
189 }
190
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100191 ypr_encode(pctx->out, t, strlen(t));
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192 if (closed) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100193 ly_print_(pctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100195 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 if (!singleline) {
198 LEVEL--;
199 }
200}
201
202static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100203yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200204{
205 struct lysp_stmt *childstmt;
206 const char *s, *t;
207
208 if (stmt->arg) {
209 if (stmt->flags) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100210 ly_print_(pctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200211 LEVEL++;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100212 ly_print_(pctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213 t = stmt->arg;
214 while ((s = strchr(t, '\n'))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100215 ypr_encode(pctx->out, t, s - t);
216 ly_print_(pctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200217 t = s + 1;
218 if (*t != '\n') {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100219 ly_print_(pctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 }
221 }
222 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100223 ypr_encode(pctx->out, t, strlen(t));
224 ly_print_(pctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200225 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100226 ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 }
228 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100229 ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230 }
231
232 if (stmt->child) {
233 LEVEL++;
234 LY_LIST_FOR(stmt->child, childstmt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100235 yprp_stmt(pctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236 }
237 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200239 }
240}
241
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;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200248 struct lysp_ext *ext_def;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200249
Michal Vaskob26d09d2022-08-22 09:52:19 +0200250 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
251 return;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200252 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100253
Michal Vaskob26d09d2022-08-22 09:52:19 +0200254 lysp_ext_find_definition(pctx->module->ctx, ext, NULL, &ext_def);
255 if (!ext_def) {
256 return;
257 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200258
Michal Vaskob26d09d2022-08-22 09:52:19 +0200259 ypr_open(pctx->out, flag);
260
261 if (ext_def->argname) {
262 ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name);
263 lysp_ext_instance_resolve_argument(pctx->module->ctx, ext, ext_def);
264 ypr_encode(pctx->out, ext->argument, -1);
265 ly_print_(pctx->out, "\"");
266 } else {
267 ly_print_(pctx->out, "%*s%s", INDENT, ext->name);
268 }
269
270 child_presence = 0;
271 LEVEL++;
272 LY_LIST_FOR(ext->child, stmt) {
273 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200274 continue;
275 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200276 if (!child_presence) {
277 ly_print_(pctx->out, " {\n");
278 child_presence = 1;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200279 }
Michal Vaskob26d09d2022-08-22 09:52:19 +0200280 yprp_stmt(pctx, stmt);
281 }
282 LEVEL--;
283 if (child_presence) {
284 ly_print_(pctx->out, "%*s}\n", INDENT);
285 } else {
286 ly_print_(pctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287 }
288}
289
Radek Krejci693262f2019-04-29 15:23:20 +0200290static void
Michal Vaskob26d09d2022-08-22 09:52:19 +0200291yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
292 struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200293{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200294 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200295
296 LY_ARRAY_FOR(exts, u) {
297 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
298 }
299}
300
301static void
302yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
303 struct lysc_ext_instance *exts, ly_bool *flag)
304{
305 LY_ARRAY_COUNT_TYPE u;
306 ly_bool inner_flag;
307
308 LY_ARRAY_FOR(exts, u) {
309 if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) {
310 return;
311 }
312
313 ypr_open(pctx->out, flag);
314 if (exts[u].argument) {
315 ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name);
316 ypr_encode(pctx->out, exts[u].argument, -1);
317 ly_print_(pctx->out, "\"");
318 } else {
319 ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name);
320 }
321
322 LEVEL++;
323 inner_flag = 0;
324 yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag);
325
326 if (exts[u].def->plugin && exts[u].def->plugin->sprinter) {
327 exts[u].def->plugin->sprinter(&pctx->printer_ctx, &exts[u], &inner_flag);
328 }
329
330 LEVEL--;
331 ypr_close(pctx, inner_flag);
332 }
333}
334
335static void
336ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
337{
Radek Krejci857189e2020-09-01 13:26:36 +0200338 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200339
340 if (!text) {
341 /* nothing to print */
342 return;
343 }
344
Radek Krejcieccf6602021-02-05 19:42:54 +0100345 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100346 ly_print_(pctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200347 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100348 ypr_text(pctx, stmt_attr_info[substmt].name, text,
Radek Krejcieccf6602021-02-05 19:42:54 +0100349 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200350 }
351
352 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200353 if (pctx->schema == LYS_YPR_PARSED) {
354 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
355 } else {
356 yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200357 }
358 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100359 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200360}
361
362static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100363ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts,
364 unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200365{
366 char *str;
367
Radek Krejci1deb5be2020-08-26 16:43:36 +0200368 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100369 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200370 return;
371 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100372 ypr_open(pctx->out, flag);
373 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200374 free(str);
375}
376
377static void
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100378ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value,
379 ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380{
381 char *str;
382
Radek Krejci1deb5be2020-08-26 16:43:36 +0200383 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100384 LOGMEM(pctx->module->ctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200385 return;
386 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100387 ypr_open(pctx->out, flag);
388 ypr_substmt(pctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200389 free(str);
390}
391
392static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100393yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200394{
395 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100396 ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200397 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200398 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100399 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
400 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200401 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100402 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100404 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405 }
406}
407
408static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100409ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200410{
411 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100412 ypr_open(pctx->out, flag);
413 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200414 }
415}
416
417static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100418ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200419{
420 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100421 ypr_open(pctx->out, flag);
422 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200423 }
424}
425
426static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100427ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200428{
429 const char *status = NULL;
430
431 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100432 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 status = "current";
434 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100435 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200436 status = "deprecated";
437 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100438 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439 status = "obsolete";
440 }
Radek Krejci693262f2019-04-29 15:23:20 +0200441
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100442 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200443}
444
445static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100446ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447{
448 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100449 ypr_open(pctx->out, flag);
450 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200451 }
452}
453
454static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100455ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200456{
457 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100458 ypr_open(pctx->out, flag);
459 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200460 }
461}
462
463static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100464yprp_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 +0200465{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200466 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200467 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200468
Michal Vasko7f45cf22020-10-01 12:49:44 +0200469 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100470 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 extflag = 0;
472
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100473 ly_print_(pctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200474
475 /* extensions */
476 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200477 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100479 ypr_close(pctx, extflag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200480 }
481}
482
483static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100484yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200485{
Radek Krejci857189e2020-09-01 13:26:36 +0200486 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200487 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200488
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100489 ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200490 LEVEL++;
491
Michal Vaskob26d09d2022-08-22 09:52:19 +0200492 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200493
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100494 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100495 ypr_open(pctx->out, &flag);
496 ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200497 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200498 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200499 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100500 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 +0200501 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200502 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200503 }
504 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100505 (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 +0100506 ypr_open(pctx->out, &flag2);
507 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200509 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100510 ypr_close(pctx, flag2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200511 }
512
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100513 ypr_status(pctx, ext->flags, ext->exts, &flag);
514 ypr_description(pctx, ext->dsc, ext->exts, &flag);
515 ypr_reference(pctx, ext->ref, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200516
517 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100518 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200519}
520
521static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100522yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200523{
Radek Krejci857189e2020-09-01 13:26:36 +0200524 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200525
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100526 ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200527 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200528 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100529 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
530 ypr_status(pctx, feat->flags, feat->exts, &flag);
531 ypr_description(pctx, feat->dsc, feat->exts, &flag);
532 ypr_reference(pctx, feat->ref, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100534 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535}
536
537static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100538yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200539{
Radek Krejci857189e2020-09-01 13:26:36 +0200540 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200541 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200542
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100543 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200544 LEVEL++;
545
Michal Vaskob26d09d2022-08-22 09:52:19 +0200546 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100547 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200548
549 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100550 ypr_open(pctx->out, &flag);
551 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200552 }
553
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100554 ypr_status(pctx, ident->flags, ident->exts, &flag);
555 ypr_description(pctx, ident->dsc, ident->exts, &flag);
556 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200557
558 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100559 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200560}
561
562static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100563yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200564{
Radek Krejci857189e2020-09-01 13:26:36 +0200565 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200566 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200567
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100568 ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200569 LEVEL++;
570
Michal Vaskob26d09d2022-08-22 09:52:19 +0200571 yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200572
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100573 ypr_open(pctx->out, &flag);
aPiecekf4a0a192021-08-03 15:14:17 +0200574 if (lys_identity_iffeature_value(ident) == LY_ENOT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100575 ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name);
aPiecekf4a0a192021-08-03 15:14:17 +0200576 }
577
Radek Krejci693262f2019-04-29 15:23:20 +0200578 LY_ARRAY_FOR(ident->derived, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100579 if (pctx->module != ident->derived[u]->module) {
580 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 +0200581 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100582 ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200583 }
584 }
585
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100586 ypr_status(pctx, ident->flags, ident->exts, &flag);
587 ypr_description(pctx, ident->dsc, ident->exts, &flag);
588 ypr_reference(pctx, ident->ref, ident->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200589
590 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100591 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200592}
593
594static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100595yprp_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 +0200596{
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100597 ly_bool inner_flag = 0, singleline;
598 const char *text;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200599
600 if (!restr) {
601 return;
602 }
603
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100604 ypr_open(pctx->out, flag);
Michal Vasko9a9e4e72022-03-21 10:05:11 +0100605 text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ?
606 restr->arg.str : restr->arg.str + 1;
607 singleline = strchr(text, '\n') ? 0 : 1;
608 ypr_text(pctx, ly_stmt2str(stmt), text, singleline, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200609
610 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200611 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100612 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100614 ypr_open(pctx->out, &inner_flag);
615 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200616 }
617 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100618 ypr_open(pctx->out, &inner_flag);
619 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200620 }
621 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100622 ypr_open(pctx->out, &inner_flag);
623 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200624 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100625 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
626 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200627
Radek Krejcid3ca0632019-04-16 16:54:54 +0200628 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100629 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200630}
631
632static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100633yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200634{
Radek Krejci857189e2020-09-01 13:26:36 +0200635 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200636
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100637 ypr_open(pctx->out, flag);
638 ly_print_(pctx->out, "%*smust \"", INDENT);
639 ypr_encode(pctx->out, must->cond->expr, -1);
640 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200641
642 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200643 yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200644 if (must->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100645 ypr_open(pctx->out, &inner_flag);
646 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200647 }
648 if (must->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100649 ypr_open(pctx->out, &inner_flag);
650 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200651 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100652 ypr_description(pctx, must->dsc, must->exts, &inner_flag);
653 ypr_reference(pctx, must->ref, must->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200654
655 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200657}
658
659static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660yprc_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 +0200661{
Radek Krejci857189e2020-09-01 13:26:36 +0200662 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200663 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200664
Radek Krejci334ccc72019-06-12 13:49:29 +0200665 if (!range) {
666 return;
667 }
668
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100669 ypr_open(pctx->out, flag);
670 ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200671 LY_ARRAY_FOR(range->parts, u) {
672 if (u > 0) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100673 ly_print_(pctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200674 }
675 if (range->parts[u].max_64 == range->parts[u].min_64) {
676 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100677 ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200678 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100679 ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200680 }
681 } else {
682 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100683 ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200684 } else { /* signed values */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100685 ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200686 }
687 }
688 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100689 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200690
691 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200692 yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200693 if (range->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100694 ypr_open(pctx->out, &inner_flag);
695 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200696 }
697 if (range->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100698 ypr_open(pctx->out, &inner_flag);
699 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200700 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100701 ypr_description(pctx, range->dsc, range->exts, &inner_flag);
702 ypr_reference(pctx, range->ref, range->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200703
704 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100705 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200706}
707
708static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100709yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200710{
Radek Krejci857189e2020-09-01 13:26:36 +0200711 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200712
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100713 ypr_open(pctx->out, flag);
714 ly_print_(pctx->out, "%*spattern \"", INDENT);
715 ypr_encode(pctx->out, pattern->expr, -1);
716 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200717
718 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200719 yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200720 if (pattern->inverted) {
721 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100722 ypr_open(pctx->out, &inner_flag);
723 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200724 }
725 if (pattern->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100726 ypr_open(pctx->out, &inner_flag);
727 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200728 }
729 if (pattern->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100730 ypr_open(pctx->out, &inner_flag);
731 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200732 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100733 ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag);
734 ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200735
736 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100737 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200738}
739
740static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100741yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200742{
Radek Krejci857189e2020-09-01 13:26:36 +0200743 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200744
745 if (!when) {
746 return;
747 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100748 ypr_open(pctx->out, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200749
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100750 ly_print_(pctx->out, "%*swhen \"", INDENT);
751 ypr_encode(pctx->out, when->cond, -1);
752 ly_print_(pctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200753
754 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200755 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100756 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
757 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200758 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100759 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200760}
761
762static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100763yprc_when(struct lys_ypr_ctx *pctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200764{
Radek Krejci857189e2020-09-01 13:26:36 +0200765 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200766
767 if (!when) {
768 return;
769 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100770 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200771
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100772 ly_print_(pctx->out, "%*swhen \"", INDENT);
773 ypr_encode(pctx->out, when->cond->expr, -1);
774 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200775
776 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200777 yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
779 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200780 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100781 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200782}
783
784static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100785yprp_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 +0200786{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200787 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200788 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200789
790 LY_ARRAY_FOR(items, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100791 ypr_open(pctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200792 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100793 ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200794 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100795 ly_print_(pctx->out, "%*senum \"", INDENT);
796 ypr_encode(pctx->out, items[u].name, -1);
797 ly_print_(pctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200798 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200799 inner_flag = 0;
800 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200801 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100802 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200803 if (items[u].flags & LYS_SET_VALUE) {
804 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100805 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200806 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100807 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200808 }
809 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100810 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
811 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
812 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200813 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100814 ypr_close(pctx, inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200815 }
816}
817
818static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100819yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200820{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200821 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200822 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200823
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100824 ly_print_(pctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825 LEVEL++;
826
Michal Vaskob26d09d2022-08-22 09:52:19 +0200827 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200828
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100829 yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag);
830 yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200831 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100832 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200833 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100834 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
835 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200836
837 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100838 ypr_open(pctx->out, &flag);
839 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840 }
841 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100842 ypr_open(pctx->out, &flag);
843 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200844 }
845 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100846 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200847 }
848 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100849 ypr_open(pctx->out, &flag);
850 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200851 }
852 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100853 ypr_open(pctx->out, &flag);
854 yprp_type(pctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200855 }
856
857 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100858 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200859}
860
861static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100862yprc_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 +0200863 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200864{
Radek Krejci857189e2020-09-01 13:26:36 +0200865 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200866 const char *str;
867
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100868 str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
869 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200870 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200871 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200872 }
873}
874
875static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100876yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200877{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200878 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200879 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200880
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100881 ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200882 LEVEL++;
883
Michal Vaskob26d09d2022-08-22 09:52:19 +0200884 yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200885
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200886 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200887 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200888 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200889
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100890 yprc_range(pctx, bin->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200891 break;
892 }
893 case LY_TYPE_UINT8:
894 case LY_TYPE_UINT16:
895 case LY_TYPE_UINT32:
896 case LY_TYPE_UINT64:
897 case LY_TYPE_INT8:
898 case LY_TYPE_INT16:
899 case LY_TYPE_INT32:
900 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200901 struct lysc_type_num *num = (struct lysc_type_num *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200902
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100903 yprc_range(pctx, num->range, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200904 break;
905 }
906 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200907 struct lysc_type_str *str = (struct lysc_type_str *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200908
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100909 yprc_range(pctx, str->length, type->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200910 LY_ARRAY_FOR(str->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100911 yprc_pattern(pctx, str->patterns[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200912 }
913 break;
914 }
915 case LY_TYPE_BITS:
916 case LY_TYPE_ENUM: {
917 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200918 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200919
Radek Krejci693262f2019-04-29 15:23:20 +0200920 LY_ARRAY_FOR(bits->bits, u) {
921 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200922 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200923
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100924 ypr_open(pctx->out, &flag);
925 ly_print_(pctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
926 ypr_encode(pctx->out, item->name, -1);
927 ly_print_(pctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200928 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200929 if (type->basetype == LY_TYPE_BITS) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200930 yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100931 ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200932 } else { /* LY_TYPE_ENUM */
Michal Vaskob26d09d2022-08-22 09:52:19 +0200933 yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100934 ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200935 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100936 ypr_status(pctx, item->flags, item->exts, &inner_flag);
937 ypr_description(pctx, item->dsc, item->exts, &inner_flag);
938 ypr_reference(pctx, item->ref, item->exts, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200939 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100940 ypr_close(pctx, inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200941 }
942 break;
943 }
944 case LY_TYPE_BOOL:
945 case LY_TYPE_EMPTY:
946 /* nothing to do */
947 break;
948 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200949 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200950
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100951 ypr_open(pctx->out, &flag);
952 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
953 yprc_range(pctx, dec->range, dec->basetype, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200954 break;
955 }
956 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200957 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200958
Radek Krejci693262f2019-04-29 15:23:20 +0200959 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100960 ypr_open(pctx->out, &flag);
961 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200962 }
963 break;
964 }
965 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200966 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)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_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200970 break;
971 }
972 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200973 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200974
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100975 ypr_open(pctx->out, &flag);
976 ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
977 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
978 yprc_type(pctx, lr->realtype);
Radek Krejci693262f2019-04-29 15:23:20 +0200979 break;
980 }
981 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200982 struct lysc_type_union *un = (struct lysc_type_union *)type;
Michal Vasko26bbb272022-08-02 14:54:33 +0200983
Radek Krejci693262f2019-04-29 15:23:20 +0200984 LY_ARRAY_FOR(un->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100985 ypr_open(pctx->out, &flag);
986 yprc_type(pctx, un->types[u]);
Radek Krejci693262f2019-04-29 15:23:20 +0200987 }
988 break;
989 }
990 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100991 LOGINT(pctx->module->ctx);
Radek Krejci693262f2019-04-29 15:23:20 +0200992 }
993
994 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100995 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200996}
997
998static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100999yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001000{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001001 ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001002 LEVEL++;
1003
Michal Vaskob26d09d2022-08-22 09:52:19 +02001004 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001005
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001006 yprp_type(pctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001007
1008 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001009 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001010 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001011 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001012 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001013 }
1014
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001015 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
1016 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
1017 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001018
1019 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001020 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021}
1022
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001023static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
1024static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node);
1025static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
1026static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001027
1028static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001029yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001030{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001031 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001032 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001033 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001034 struct lysp_node_action *action;
1035 struct lysp_node_notif *notif;
1036 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001038 ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001039 LEVEL++;
1040
Michal Vaskob26d09d2022-08-22 09:52:19 +02001041 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001042 ypr_status(pctx, grp->flags, grp->exts, &flag);
1043 ypr_description(pctx, grp->dsc, grp->exts, &flag);
1044 ypr_reference(pctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001045
1046 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001047 ypr_open(pctx->out, &flag);
1048 yprp_typedef(pctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049 }
1050
Radek Krejci2a9fc652021-01-22 17:44:34 +01001051 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001052 ypr_open(pctx->out, &flag);
1053 yprp_grouping(pctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001054 }
1055
Radek Krejci01180ac2021-01-27 08:48:22 +01001056 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001057 ypr_open(pctx->out, &flag);
1058 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001059 }
1060
Radek Krejci2a9fc652021-01-22 17:44:34 +01001061 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001062 ypr_open(pctx->out, &flag);
1063 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001064 }
1065
1066 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001067 ypr_open(pctx->out, &flag);
1068 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001069 }
1070
1071 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001072 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073}
1074
1075static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001076yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001077{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001078 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001079 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001080 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081
Radek Krejci01180ac2021-01-27 08:48:22 +01001082 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001083 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084 return;
1085 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001086 ypr_open(pctx->out, flag);
1087 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001088
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001089 ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001090 LEVEL++;
1091
Michal Vaskob26d09d2022-08-22 09:52:19 +02001092 yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001093 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001094 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001095 }
1096 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001097 yprp_typedef(pctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001099 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001100 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001101 }
1102
Radek Krejci01180ac2021-01-27 08:48:22 +01001103 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001104 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001105 }
1106
1107 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001108 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001109}
1110
1111static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001112yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001113{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001114 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001115 struct lysc_node *data;
1116
Radek Krejci01180ac2021-01-27 08:48:22 +01001117 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001118 /* input/output is empty */
1119 return;
1120 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001121 ypr_open(pctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001122
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001123 ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001124 LEVEL++;
1125
Michal Vaskob26d09d2022-08-22 09:52:19 +02001126 yprc_extension_instances(pctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001127 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128 yprc_must(pctx, &inout->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001129 }
1130
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001131 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001132 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001133 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001134 }
Radek Krejci693262f2019-04-29 15:23:20 +02001135 }
1136
1137 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001138 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001139}
1140
1141static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001142yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001143{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001144 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001145 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001146 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001147 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001148
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001149 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001150
1151 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001152 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001153 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154
1155 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001156 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001157 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001158 ypr_status(pctx, notif->flags, notif->exts, &flag);
1159 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1160 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161
1162 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001163 ypr_open(pctx->out, &flag);
1164 yprp_typedef(pctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001165 }
1166
Radek Krejci2a9fc652021-01-22 17:44:34 +01001167 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001168 ypr_open(pctx->out, &flag);
1169 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001170 }
1171
Radek Krejci01180ac2021-01-27 08:48:22 +01001172 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001173 ypr_open(pctx->out, &flag);
1174 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001175 }
1176
1177 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001178 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001179}
1180
1181static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001182yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001183{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001184 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001185 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001186 struct lysc_node *data;
1187
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001188 ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001189
1190 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001191 yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001192
1193 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001194 yprc_must(pctx, &notif->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001195 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001196 ypr_status(pctx, notif->flags, notif->exts, &flag);
1197 ypr_description(pctx, notif->dsc, notif->exts, &flag);
1198 ypr_reference(pctx, notif->ref, notif->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001199
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001200 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001201 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001202 ypr_open(pctx->out, &flag);
1203 yprc_node(pctx, data);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001204 }
Radek Krejci693262f2019-04-29 15:23:20 +02001205 }
1206
1207 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001208 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001209}
1210
1211static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001212yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001213{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001214 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001215 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001216 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001217
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001218 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001219
1220 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001221 yprp_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001222 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
1223 ypr_status(pctx, action->flags, action->exts, &flag);
1224 ypr_description(pctx, action->dsc, action->exts, &flag);
1225 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001226
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001227 YPR_EXTRA_LINE(flag, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001228
Radek Krejcid3ca0632019-04-16 16:54:54 +02001229 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001230 ypr_open(pctx->out, &flag);
1231 YPR_EXTRA_LINE_PRINT(pctx);
1232 yprp_typedef(pctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001233 }
1234
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001235 YPR_EXTRA_LINE(action->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001236
Radek Krejci2a9fc652021-01-22 17:44:34 +01001237 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001238 ypr_open(pctx->out, &flag);
1239 YPR_EXTRA_LINE_PRINT(pctx);
1240 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001241 }
1242
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001243 YPR_EXTRA_LINE(action->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02001244
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001245 yprp_inout(pctx, &action->input, &flag);
1246 yprp_inout(pctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001247
1248 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001249 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001250}
1251
1252static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001253yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001254{
Radek Krejci857189e2020-09-01 13:26:36 +02001255 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001256
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001257 ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001258
1259 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001260 yprc_extension_instances(pctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001261 ypr_status(pctx, action->flags, action->exts, &flag);
1262 ypr_description(pctx, action->dsc, action->exts, &flag);
1263 ypr_reference(pctx, action->ref, action->exts, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001264
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001265 yprc_inout(pctx, &action->input, &flag);
1266 yprc_inout(pctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001267
1268 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001269 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001270}
1271
1272static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001273yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001274{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001275 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001276 LEVEL++;
1277
Michal Vaskob26d09d2022-08-22 09:52:19 +02001278 yprp_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001279 yprp_when(pctx, lysp_node_when(node), flag);
1280 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281}
1282
1283static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001284yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001285{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001286 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001287 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001289 ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001290 LEVEL++;
1291
Michal Vaskob26d09d2022-08-22 09:52:19 +02001292 yprc_extension_instances(pctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001293
1294 when = lysc_node_when(node);
1295 LY_ARRAY_FOR(when, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001296 yprc_when(pctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001297 }
Radek Krejci693262f2019-04-29 15:23:20 +02001298}
1299
Michal Vaskob26d09d2022-08-22 09:52:19 +02001300/* macro to unify the code */
Radek Krejci693262f2019-04-29 15:23:20 +02001301#define YPR_NODE_COMMON2 \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001302 ypr_config(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001303 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001304 ypr_mandatory(pctx, node->flags, node->exts, flag); \
Radek Krejci693262f2019-04-29 15:23:20 +02001305 } \
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001306 ypr_status(pctx, node->flags, node->exts, flag); \
1307 ypr_description(pctx, node->dsc, node->exts, flag); \
1308 ypr_reference(pctx, node->ref, node->exts, flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001309
1310static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001311yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001312{
1313 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001314}
1315
1316static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001317yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001318{
1319 YPR_NODE_COMMON2;
1320}
1321
1322#undef YPR_NODE_COMMON2
1323
1324static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001325yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001326{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001327 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001328 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001330 struct lysp_node_action *action;
1331 struct lysp_node_notif *notif;
1332 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001333 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1334
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001335 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001336
1337 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001338 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339 }
1340 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001341 ypr_open(pctx->out, &flag);
1342 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001343 }
1344
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001345 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001346
1347 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001348 ypr_open(pctx->out, &flag);
1349 yprp_typedef(pctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001350 }
1351
Radek Krejci2a9fc652021-01-22 17:44:34 +01001352 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001353 ypr_open(pctx->out, &flag);
1354 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001355 }
1356
1357 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001358 ypr_open(pctx->out, &flag);
1359 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001360 }
1361
Radek Krejci2a9fc652021-01-22 17:44:34 +01001362 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001363 ypr_open(pctx->out, &flag);
1364 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001365 }
1366
Radek Krejci2a9fc652021-01-22 17:44:34 +01001367 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001368 ypr_open(pctx->out, &flag);
1369 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001370 }
1371
1372 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001373 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001374}
1375
1376static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001377yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001378{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001379 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001380 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001381 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001382 struct lysc_node_action *action;
1383 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001384 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1385
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001386 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001387
1388 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001389 yprc_must(pctx, &cont->musts[u], &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001390 }
1391 if (cont->flags & LYS_PRESENCE) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001392 ypr_open(pctx->out, &flag);
1393 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001394 }
1395
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001396 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001397
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001398 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001399 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001400 ypr_open(pctx->out, &flag);
1401 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001402 }
Radek Krejci693262f2019-04-29 15:23:20 +02001403
Radek Krejci2a9fc652021-01-22 17:44:34 +01001404 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001405 ypr_open(pctx->out, &flag);
1406 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001407 }
Radek Krejci693262f2019-04-29 15:23:20 +02001408
Radek Krejci2a9fc652021-01-22 17:44:34 +01001409 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001410 ypr_open(pctx->out, &flag);
1411 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001412 }
Radek Krejci693262f2019-04-29 15:23:20 +02001413 }
1414
1415 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001416 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001417}
1418
1419static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001420yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001421{
Radek Krejci857189e2020-09-01 13:26:36 +02001422 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001423 struct lysp_node *child;
1424 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1425
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001426 yprp_node_common1(pctx, node, &flag);
1427 yprp_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001428
1429 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001430 ypr_open(pctx->out, &flag);
1431 yprp_node(pctx, child);
Radek Krejci693262f2019-04-29 15:23:20 +02001432 }
1433
1434 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001435 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001436}
1437
1438static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001439yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001440{
Radek Krejci857189e2020-09-01 13:26:36 +02001441 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001442 struct lysc_node *child;
1443
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001444 yprc_node_common1(pctx, &cs->node, &flag);
1445 yprc_node_common2(pctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001446
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001447 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001448 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001449 ypr_open(pctx->out, &flag);
1450 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001451 }
Radek Krejci693262f2019-04-29 15:23:20 +02001452 }
1453
1454 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001455 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001456}
1457
1458static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001459yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001460{
Radek Krejci857189e2020-09-01 13:26:36 +02001461 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001462 struct lysp_node *child;
1463 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1464
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001465 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001466
Michal Vasko7f45cf22020-10-01 12:49:44 +02001467 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001468 ypr_open(pctx->out, &flag);
1469 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470 }
1471
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001472 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473
1474 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001475 ypr_open(pctx->out, &flag);
1476 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001477 }
1478
1479 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001480 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001481}
1482
1483static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001484yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001485{
Radek Krejci857189e2020-09-01 13:26:36 +02001486 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001487 struct lysc_node_case *cs;
1488 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1489
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001490 yprc_node_common1(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001491
1492 if (choice->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001493 ypr_open(pctx->out, &flag);
1494 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001495 }
1496
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001497 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001498
Michal Vasko22df3f02020-08-24 13:29:22 +02001499 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001500 ypr_open(pctx->out, &flag);
1501 yprc_case(pctx, cs);
Radek Krejci693262f2019-04-29 15:23:20 +02001502 }
1503
1504 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001505 ypr_close(pctx, flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001506}
1507
1508static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001509yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001510{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001511 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001512 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1513
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001514 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001516 yprp_type(pctx, &leaf->type);
1517 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001519 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001521 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001522
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001523 yprp_node_common2(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001524
1525 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001526 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527}
1528
1529static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001530yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001531{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001532 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001533 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1534
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001535 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001536
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001537 yprc_type(pctx, leaf->type);
1538 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001539 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001540 yprc_must(pctx, &leaf->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001541 }
Radek Krejcia1911222019-07-22 17:24:50 +02001542
1543 if (leaf->dflt) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001544 yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001545 }
Radek Krejci693262f2019-04-29 15:23:20 +02001546
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001547 yprc_node_common2(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001548
1549 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001550 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001551}
1552
1553static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001554yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001555{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001556 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001557 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1558
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001559 yprp_node_common1(pctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001560
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001561 yprp_type(pctx, &llist->type);
1562 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001563 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001564 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565 }
1566 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001567 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001568 }
1569
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001570 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001571
1572 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001573 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001574 }
1575 if (llist->flags & LYS_SET_MAX) {
1576 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001577 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001578 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001579 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001580 }
1581 }
1582
1583 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001584 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585 }
1586
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001587 ypr_status(pctx, node->flags, node->exts, NULL);
1588 ypr_description(pctx, node->dsc, node->exts, NULL);
1589 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590
1591 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001592 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001593}
1594
1595static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001596yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001597{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001598 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001599 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1600
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001601 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001602
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001603 yprc_type(pctx, llist->type);
1604 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001605 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001606 yprc_must(pctx, &llist->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001607 }
1608 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001609 yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001610 }
1611
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001612 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001613
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001614 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001615 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001616 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001617 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001618 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001619 }
1620
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001621 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001622
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001623 ypr_status(pctx, node->flags, node->exts, NULL);
1624 ypr_description(pctx, node->dsc, node->exts, NULL);
1625 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001626
1627 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001628 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001629}
1630
1631static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001632yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001634 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001635 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001636 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001637 struct lysp_node_action *action;
1638 struct lysp_node_notif *notif;
1639 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001640 struct lysp_node_list *list = (struct lysp_node_list *)node;
1641
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001642 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001643
1644 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001645 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001646 }
1647 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001648 ypr_open(pctx->out, &flag);
1649 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001650 }
1651 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001652 ypr_open(pctx->out, &flag);
1653 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001656 ypr_config(pctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001657
1658 if (list->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001659 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001660 }
1661 if (list->flags & LYS_SET_MAX) {
1662 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001663 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001664 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001665 ypr_open(pctx->out, &flag);
1666 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001667 }
1668 }
1669
1670 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001671 ypr_open(pctx->out, &flag);
1672 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001673 }
1674
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001675 ypr_status(pctx, node->flags, node->exts, &flag);
1676 ypr_description(pctx, node->dsc, node->exts, &flag);
1677 ypr_reference(pctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001678
1679 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001680 ypr_open(pctx->out, &flag);
1681 yprp_typedef(pctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001682 }
1683
Radek Krejci2a9fc652021-01-22 17:44:34 +01001684 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001685 ypr_open(pctx->out, &flag);
1686 yprp_grouping(pctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001687 }
1688
1689 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001690 ypr_open(pctx->out, &flag);
1691 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001692 }
1693
Radek Krejci2a9fc652021-01-22 17:44:34 +01001694 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001695 ypr_open(pctx->out, &flag);
1696 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001697 }
1698
Radek Krejci2a9fc652021-01-22 17:44:34 +01001699 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001700 ypr_open(pctx->out, &flag);
1701 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001702 }
1703
1704 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001705 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001706}
1707
1708static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001709yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001710{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001711 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001712 struct lysc_node_list *list = (struct lysc_node_list *)node;
1713
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001714 yprc_node_common1(pctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001715
1716 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001717 yprc_must(pctx, &list->musts[u], NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001718 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001719 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001720 ly_print_(pctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001721 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 +01001722 ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001723 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001724 ly_print_(pctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001725 }
1726 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001727 ly_print_(pctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001728 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001729 ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001730 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001731 ypr_close(pctx, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001732 }
1733
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001734 ypr_config(pctx, node->flags, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001735
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001736 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001737 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001738 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001739 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001740 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001741 }
1742
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001743 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001744
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001745 ypr_status(pctx, node->flags, node->exts, NULL);
1746 ypr_description(pctx, node->dsc, node->exts, NULL);
1747 ypr_reference(pctx, node->ref, node->exts, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001748
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001749 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001750 struct lysc_node *child;
1751 struct lysc_node_action *action;
1752 struct lysc_node_notif *notif;
1753
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001754 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001755 yprc_node(pctx, child);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001756 }
Radek Krejci693262f2019-04-29 15:23:20 +02001757
Radek Krejci2a9fc652021-01-22 17:44:34 +01001758 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001759 yprc_action(pctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001760 }
Radek Krejci693262f2019-04-29 15:23:20 +02001761
Radek Krejci2a9fc652021-01-22 17:44:34 +01001762 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001763 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001764 }
Radek Krejci693262f2019-04-29 15:23:20 +02001765 }
1766
1767 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001768 ypr_close(pctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001769}
1770
1771static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001772yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001773{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001774 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001775 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001776
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001777 ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001778 LEVEL++;
1779
Michal Vaskob26d09d2022-08-22 09:52:19 +02001780 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001781 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001782
1783 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001784 ypr_open(pctx->out, &flag);
1785 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001786 }
1787
1788 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001789 ypr_open(pctx->out, &flag);
1790 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791 }
1792
1793 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001794 ypr_open(pctx->out, &flag);
1795 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796 }
1797
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001798 ypr_config(pctx, refine->flags, refine->exts, &flag);
1799 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001800
1801 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001802 ypr_open(pctx->out, &flag);
1803 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001804 }
1805 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001806 ypr_open(pctx->out, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001808 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001810 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001811 }
1812 }
1813
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001814 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1815 ypr_reference(pctx, refine->ref, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816
1817 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001818 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819}
1820
1821static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001822yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001824 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001825 struct lysp_node_action *action;
1826 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001828 ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001829 LEVEL++;
1830
Michal Vaskob26d09d2022-08-22 09:52:19 +02001831 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001832 yprp_when(pctx, aug->when, NULL);
1833 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1834 ypr_status(pctx, aug->flags, aug->exts, NULL);
1835 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1836 ypr_reference(pctx, aug->ref, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837
1838 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001839 yprp_node(pctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840 }
1841
Radek Krejci2a9fc652021-01-22 17:44:34 +01001842 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001843 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844 }
1845
Radek Krejci2a9fc652021-01-22 17:44:34 +01001846 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001847 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001848 }
1849
1850 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001851 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852}
1853
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001855yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001857 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001858 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001860 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001862 yprp_node_common1(pctx, node, &flag);
1863 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864
1865 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001866 ypr_open(pctx->out, &flag);
1867 yprp_refine(pctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868 }
1869
Radek Krejci2a9fc652021-01-22 17:44:34 +01001870 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001871 ypr_open(pctx->out, &flag);
1872 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873 }
1874
1875 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001876 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877}
1878
1879static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001880yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001881{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001882 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001883 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1885
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001886 yprp_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887
1888 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001889 ypr_open(pctx->out, &flag);
1890 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891 }
1892
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001893 yprp_node_common2(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894
1895 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001896 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897}
1898
1899static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001900yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001902 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001903 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001904 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001905
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001906 yprc_node_common1(pctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907
Radek Krejci693262f2019-04-29 15:23:20 +02001908 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001909 ypr_open(pctx->out, &flag);
1910 yprc_must(pctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001911 }
1912
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001913 yprc_node_common2(pctx, node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001914
Radek Krejcid3ca0632019-04-16 16:54:54 +02001915 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001916 ypr_close(pctx, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917}
1918
1919static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001920yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921{
1922 switch (node->nodetype) {
1923 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001924 yprp_container(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001925 break;
1926 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001927 yprp_choice(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928 break;
1929 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001930 yprp_leaf(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 break;
1932 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001933 yprp_leaflist(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001934 break;
1935 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001936 yprp_list(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937 break;
1938 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001939 yprp_uses(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940 break;
1941 case LYS_ANYXML:
1942 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001943 yprp_anydata(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001944 break;
1945 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001946 yprp_case(pctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001947 break;
1948 default:
1949 break;
1950 }
1951}
1952
1953static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001954yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001955{
1956 switch (node->nodetype) {
1957 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001958 yprc_container(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001959 break;
1960 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001961 yprc_choice(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001962 break;
1963 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001964 yprc_leaf(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001965 break;
1966 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001967 yprc_leaflist(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001968 break;
1969 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001970 yprc_list(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001971 break;
1972 case LYS_ANYXML:
1973 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001974 yprc_anydata(pctx, node);
Radek Krejci693262f2019-04-29 15:23:20 +02001975 break;
1976 default:
1977 break;
1978 }
1979}
1980
1981static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001982yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001983{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001984 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 struct lysp_deviate_add *add;
1986 struct lysp_deviate_rpl *rpl;
1987 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001988 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001990 ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001991 LEVEL++;
1992
Michal Vaskob26d09d2022-08-22 09:52:19 +02001993 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001994 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1995 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001996
fredgan2b11ddb2019-10-21 11:03:39 +08001997 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001998 ly_print_(pctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001999 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
2000 if (elem->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002001 ly_print_(pctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002002 LEVEL++;
2003
Michal Vaskob26d09d2022-08-22 09:52:19 +02002004 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002006 ly_print_(pctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 continue;
2008 }
fredgan2b11ddb2019-10-21 11:03:39 +08002009 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002010 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002011 ly_print_(pctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 LEVEL++;
2013
Michal Vaskob26d09d2022-08-22 09:52:19 +02002014 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002015 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002016 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002017 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002019 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002020 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002021 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002022 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002023 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002024 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002025 ypr_config(pctx, add->flags, add->exts, NULL);
2026 ypr_mandatory(pctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002027 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002028 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002029 }
2030 if (add->flags & LYS_SET_MAX) {
2031 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002032 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002034 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 }
2036 }
fredgan2b11ddb2019-10-21 11:03:39 +08002037 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002038 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002039 ly_print_(pctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 LEVEL++;
2041
Michal Vaskob26d09d2022-08-22 09:52:19 +02002042 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002044 yprp_type(pctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002046 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
2047 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
2048 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
2049 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002050 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002051 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 }
2053 if (rpl->flags & LYS_SET_MAX) {
2054 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002055 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002057 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058 }
2059 }
fredgan2b11ddb2019-10-21 11:03:39 +08002060 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002061 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002062 ly_print_(pctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 LEVEL++;
2064
Michal Vaskob26d09d2022-08-22 09:52:19 +02002065 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002066 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002067 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002068 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002069 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002070 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002071 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002073 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002074 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002075 }
2076 }
2077
2078 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002079 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002080 }
2081
2082 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002083 ypr_close(pctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084}
2085
Michal Vasko7c8439f2020-08-05 13:25:19 +02002086static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002087yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002088{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002089 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002090
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002092 if (modp->imports[u].flags & LYS_INTERNAL) {
2093 continue;
2094 }
2095
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002096 YPR_EXTRA_LINE_PRINT(pctx);
2097 ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002098 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002099 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002100 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002101 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002102 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002103 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002104 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2105 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002107 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002108 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002109 YPR_EXTRA_LINE(modp->imports, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002110
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002112 if (modp->includes[u].injected) {
2113 /* do not print the includes injected from submodules */
2114 continue;
2115 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002116 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 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 +01002118 ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002120 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002121 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002122 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002123 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002124 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2125 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002126 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002127 ly_print_(pctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002129 ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002130 }
2131 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002132 YPR_EXTRA_LINE(modp->includes, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002133}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002134
Michal Vasko7c8439f2020-08-05 13:25:19 +02002135static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002136yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002137{
2138 LY_ARRAY_COUNT_TYPE u;
2139 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002140 struct lysp_node_action *action;
2141 struct lysp_node_notif *notif;
2142 struct lysp_node_grp *grp;
2143 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002144
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002146 YPR_EXTRA_LINE_PRINT(pctx);
2147 yprp_extension(pctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002148 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002149
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002150 YPR_EXTRA_LINE(modp->extensions, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002151
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 if (modp->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002153 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002154 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 }
2156
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002157 YPR_EXTRA_LINE(modp->exts, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002158
Radek Krejcid3ca0632019-04-16 16:54:54 +02002159 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002160 YPR_EXTRA_LINE_PRINT(pctx);
2161 yprp_feature(pctx, &modp->features[u]);
2162 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002163 }
2164
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002165 YPR_EXTRA_LINE(modp->features, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002166
Radek Krejcid3ca0632019-04-16 16:54:54 +02002167 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002168 YPR_EXTRA_LINE_PRINT(pctx);
2169 yprp_identity(pctx, &modp->identities[u]);
2170 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002171 }
2172
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002173 YPR_EXTRA_LINE(modp->identities, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002174
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002176 YPR_EXTRA_LINE_PRINT(pctx);
2177 yprp_typedef(pctx, &modp->typedefs[u]);
2178 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002179 }
2180
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002181 YPR_EXTRA_LINE(modp->typedefs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002182
Radek Krejci2a9fc652021-01-22 17:44:34 +01002183 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002184 YPR_EXTRA_LINE_PRINT(pctx);
2185 yprp_grouping(pctx, grp);
2186 YPR_EXTRA_LINE(1, pctx);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 }
2188
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002189 YPR_EXTRA_LINE(modp->groupings, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002190
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002192 YPR_EXTRA_LINE_PRINT(pctx);
2193 yprp_node(pctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002194 }
2195
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002196 YPR_EXTRA_LINE(modp->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002197
Radek Krejci2a9fc652021-01-22 17:44:34 +01002198 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002199 YPR_EXTRA_LINE_PRINT(pctx);
2200 yprp_augment(pctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002201 }
2202
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002203 YPR_EXTRA_LINE(modp->augments, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002204
Radek Krejci2a9fc652021-01-22 17:44:34 +01002205 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002206 YPR_EXTRA_LINE_PRINT(pctx);
2207 yprp_action(pctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002208 }
2209
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002210 YPR_EXTRA_LINE(modp->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002211
Radek Krejci2a9fc652021-01-22 17:44:34 +01002212 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002213 YPR_EXTRA_LINE_PRINT(pctx);
2214 yprp_notification(pctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002215 }
2216
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002217 YPR_EXTRA_LINE(modp->notifs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002218
Radek Krejcid3ca0632019-04-16 16:54:54 +02002219 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002220 YPR_EXTRA_LINE_PRINT(pctx);
2221 yprp_deviation(pctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002222 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002223
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002224 YPR_EXTRA_LINE(modp->deviations, pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002225}
2226
2227LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002228yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002229{
2230 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002231 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002232 struct lys_ypr_ctx pctx_ = {
2233 .out = out,
2234 .level = 0,
Michal Vasko331303f2022-08-22 09:51:57 +02002235 .options = options,
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002236 .module = module,
Michal Vasko331303f2022-08-22 09:51:57 +02002237 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002238 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002239
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002240 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002241 LEVEL++;
2242
2243 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002244 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002245 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 +02002246 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002247 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2248 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002249
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002250 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002251
Michal Vasko7c8439f2020-08-05 13:25:19 +02002252 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002253 yang_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002254
2255 /* meta-stmts */
2256 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002257 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002258 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002259 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2260 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2261 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2262 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002263
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002264 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002265
Michal Vasko7c8439f2020-08-05 13:25:19 +02002266 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002267 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002268 YPR_EXTRA_LINE_PRINT(pctx);
2269 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002270 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002271
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002272 YPR_EXTRA_LINE(modp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002273
Michal Vasko7c8439f2020-08-05 13:25:19 +02002274 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002275 yang_print_parsed_body(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002276
2277 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002278 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002279 ly_print_flush(out);
2280
2281 return LY_SUCCESS;
2282}
2283
2284static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002285yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002286{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002287 ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002288 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02002289 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002290 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002291 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002292 ly_print_(pctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002293}
2294
2295LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002296yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002297{
2298 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002299 struct lys_ypr_ctx pctx_ = {
Michal Vasko331303f2022-08-22 09:51:57 +02002300 .out = out,
2301 .level = 0,
2302 .options = options,
2303 .module = submodp->mod,
2304 .schema = LYS_YPR_PARSED
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002305 }, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002306
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002307 ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002308 LEVEL++;
2309
2310 /* submodule-header-stmts */
2311 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002312 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 +02002313 }
2314
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002315 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002316
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002317 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002318
Michal Vasko7c8439f2020-08-05 13:25:19 +02002319 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002320 yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002321
2322 /* meta-stmts */
2323 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002324 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002325 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002326 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2327 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2328 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2329 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002330
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002331 YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002332
Michal Vasko7c8439f2020-08-05 13:25:19 +02002333 /* revision-stmts */
Michal Vasko7c8439f2020-08-05 13:25:19 +02002334 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002335 YPR_EXTRA_LINE_PRINT(pctx);
2336 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002337 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002338
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002339 YPR_EXTRA_LINE(submodp->revs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002340
Michal Vasko7c8439f2020-08-05 13:25:19 +02002341 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002342 yang_print_parsed_body(pctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002343
2344 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002345 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002346 ly_print_flush(out);
2347
2348 return LY_SUCCESS;
2349}
2350
2351LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002352yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002353{
Michal Vasko331303f2022-08-22 09:51:57 +02002354 struct lys_ypr_ctx pctx_ = {
2355 .out = out,
2356 .level = 0,
2357 .options = options,
2358 .module = node->module,
2359 .schema = LYS_YPR_COMPILED
2360 }, *pctx = &pctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002361
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002362 yprc_node(pctx, node);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002363
2364 ly_print_flush(out);
2365 return LY_SUCCESS;
2366}
2367
2368LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002369yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002370{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002371 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002372 struct lysc_module *modc = module->compiled;
Michal Vasko331303f2022-08-22 09:51:57 +02002373 struct lys_ypr_ctx pctx_ = {
2374 .out = out,
2375 .level = 0,
2376 .options = options,
2377 .module = module,
2378 .schema = LYS_YPR_COMPILED
2379 }, *pctx = &pctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002380
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002381 ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002382 LEVEL++;
2383
Radek Krejci693262f2019-04-29 15:23:20 +02002384 /* module-header-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002385 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2386 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002387
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002388 YPR_EXTRA_LINE(1, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002389
Michal Vasko7c8439f2020-08-05 13:25:19 +02002390 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002391
2392 /* meta-stmts */
2393 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002394 YPR_EXTRA_LINE_PRINT(pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002395 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002396 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2397 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2398 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2399 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002400
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002401 YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002402
Radek Krejci693262f2019-04-29 15:23:20 +02002403 /* revision-stmts */
2404 if (module->revision) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002405 YPR_EXTRA_LINE_PRINT(pctx);
2406 ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision);
2407 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002408 }
2409
2410 /* body-stmts */
2411 if (modc->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002412 YPR_EXTRA_LINE_PRINT(pctx);
Michal Vaskob26d09d2022-08-22 09:52:19 +02002413 yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002414 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002415 }
2416
Radek Krejci80d281e2020-09-14 17:42:54 +02002417 LY_ARRAY_FOR(module->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002418 YPR_EXTRA_LINE_PRINT(pctx);
2419 yprc_identity(pctx, &module->identities[u]);
2420 YPR_EXTRA_LINE(1, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002421 }
2422
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002423 if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002424 struct lysc_node *data;
2425 struct lysc_node_action *rpc;
2426 struct lysc_node_notif *notif;
2427
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002428 LY_LIST_FOR(modc->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002429 YPR_EXTRA_LINE_PRINT(pctx);
2430 yprc_node(pctx, data);
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->data, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002434
Radek Krejci2a9fc652021-01-22 17:44:34 +01002435 LY_LIST_FOR(modc->rpcs, rpc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002436 YPR_EXTRA_LINE_PRINT(pctx);
2437 yprc_action(pctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002438 }
Radek Krejci693262f2019-04-29 15:23:20 +02002439
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002440 YPR_EXTRA_LINE(modc->rpcs, pctx);
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002441
Radek Krejci2a9fc652021-01-22 17:44:34 +01002442 LY_LIST_FOR(modc->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002443 YPR_EXTRA_LINE_PRINT(pctx);
2444 yprc_notification(pctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002445 }
Radek Krejciaa14a0c2020-09-04 11:16:47 +02002446
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002447 YPR_EXTRA_LINE(modc->notifs, pctx);
Radek Krejci693262f2019-04-29 15:23:20 +02002448 }
2449
2450 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002451 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002452 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002453
2454 return LY_SUCCESS;
2455}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002456
Radek Krejciadcf63d2021-02-09 10:21:18 +01002457void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002458lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002459{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002460 struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002461 LY_ARRAY_COUNT_TYPE u, v;
2462
2463 LY_ARRAY_FOR(ext->substmts, u) {
2464 switch (ext->substmts[u].stmt) {
2465 case LY_STMT_CHOICE:
2466 case LY_STMT_CONTAINER: {
2467 const struct lysc_node *node;
2468
2469 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002470 ypr_open(pctx->out, flag);
2471 yprc_node(pctx, node);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002472 }
2473 break;
2474 }
2475 case LY_STMT_DESCRIPTION:
2476 case LY_STMT_REFERENCE:
2477 case LY_STMT_UNITS:
2478 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2479 if (*(const char **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002480 ypr_open(pctx->out, flag);
2481 ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002482 }
2483 } else {
2484 const char **strings = *(const char ***)ext->substmts[u].storage;
Michal Vasko26bbb272022-08-02 14:54:33 +02002485
Radek Krejciadcf63d2021-02-09 10:21:18 +01002486 LY_ARRAY_FOR(strings, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002487 ypr_open(pctx->out, flag);
2488 ypr_substmt(pctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002489 }
2490 }
2491 break;
2492 case LY_STMT_IF_FEATURE:
2493 /* nothing to do */
2494 break;
2495 case LY_STMT_STATUS:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002496 ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002497 break;
2498 case LY_STMT_TYPE:
2499 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2500 if (*(const struct lysc_type **)ext->substmts[u].storage) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002501 ypr_open(pctx->out, flag);
2502 yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002503 }
2504 } else {
2505 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
Michal Vasko26bbb272022-08-02 14:54:33 +02002506
Radek Krejciadcf63d2021-02-09 10:21:18 +01002507 LY_ARRAY_FOR(types, v) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002508 ypr_open(pctx->out, flag);
2509 yprc_type(pctx, types[v]);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002510 }
2511 }
2512 break;
2513 /* TODO support other substatements */
2514 default:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01002515 LOGWRN(pctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
Radek Krejciadcf63d2021-02-09 10:21:18 +01002516 ly_stmt2str(ext->substmts[u].stmt));
2517 break;
2518 }
2519 }
2520}