blob: 0bca5eebf31a176e68320c15295c5f268cadaf28 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief YANG printer
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010022#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020023
Radek Krejci535ea9f2020-05-29 16:01:05 +020024#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020025#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010027#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020028#include "out_internal.h"
Radek Krejciadcf63d2021-02-09 10:21:18 +010029#include "plugins_exts.h"
30#include "plugins_exts_internal.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 Krejcie7b95092019-05-15 11:03:07 +020041 * @brief Print the given text as content of a double quoted YANG string,
42 * including encoding characters that have special meanings. The quotation marks
43 * are not printed.
44 *
45 * Follows RFC 7950, section 6.1.3.
46 *
47 * @param[in] out Output specification.
48 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020049 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020050 * the @p text is printed completely as a NULL-terminated string.
51 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020052static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020053ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020054{
Radek Krejci1deb5be2020-08-26 16:43:36 +020055 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020056 const char *start;
57 char special = 0;
58
59 if (!len) {
60 return;
61 }
62
63 if (len < 0) {
64 len = strlen(text);
65 }
66
67 start = text;
68 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +020069 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +020070 switch (text[i]) {
71 case '\n':
72 case '\t':
73 case '\"':
74 case '\\':
75 special = text[i];
76 break;
77 default:
78 ++start_len;
79 break;
80 }
81
82 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +020083 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +020084 switch (special) {
85 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +020086 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020087 break;
88 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +020089 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020090 break;
91 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +020092 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020093 break;
94 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +020095 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 break;
97 }
98
99 start += start_len + 1;
100 start_len = 0;
101
102 special = 0;
103 }
104 }
105
Michal Vasko5233e962020-08-14 14:26:20 +0200106 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200107}
108
109static void
Radek Krejci857189e2020-09-01 13:26:36 +0200110ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200111{
112 if (flag && !*flag) {
113 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200114 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200115 }
116}
117
118static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100119ypr_close(struct lys_ypr_ctx *ctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200120{
121 if (flag) {
Michal Vasko5233e962020-08-14 14:26:20 +0200122 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200123 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200124 ly_print_(ctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200125 }
126}
127
128static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100129ypr_text(struct lys_ypr_ctx *ctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130{
131 const char *s, *t;
132
133 if (singleline) {
Michal Vasko5233e962020-08-14 14:26:20 +0200134 ly_print_(ctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200136 ly_print_(ctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200137 LEVEL++;
138
Michal Vasko5233e962020-08-14 14:26:20 +0200139 ly_print_(ctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200140 }
141 t = text;
142 while ((s = strchr(t, '\n'))) {
143 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200144 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200145 t = s + 1;
146 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200147 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200148 }
149 }
150
151 ypr_encode(ctx->out, t, strlen(t));
152 if (closed) {
Michal Vasko5233e962020-08-14 14:26:20 +0200153 ly_print_(ctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200154 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200155 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200156 }
157 if (!singleline) {
158 LEVEL--;
159 }
160}
161
162static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100163yprp_stmt(struct lys_ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200164{
165 struct lysp_stmt *childstmt;
166 const char *s, *t;
167
168 if (stmt->arg) {
169 if (stmt->flags) {
Michal Vasko5233e962020-08-14 14:26:20 +0200170 ly_print_(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200171 LEVEL++;
Michal Vasko5233e962020-08-14 14:26:20 +0200172 ly_print_(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200173 t = stmt->arg;
174 while ((s = strchr(t, '\n'))) {
175 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200176 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 t = s + 1;
178 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200179 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 }
182 LEVEL--;
183 ypr_encode(ctx->out, t, strlen(t));
Michal Vasko5233e962020-08-14 14:26:20 +0200184 ly_print_(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200186 ly_print_(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200187 }
188 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200189 ly_print_(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200190 }
191
192 if (stmt->child) {
193 LEVEL++;
194 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200195 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200198 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200199 }
200}
201
202/**
203 * @param[in] count Number of extensions to print, 0 to print them all.
204 */
205static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100206yprp_extension_instances(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejci857189e2020-09-01 13:26:36 +0200207 struct lysp_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200208{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200209 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200210 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200211 ly_bool child_presence;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200212 const char *argument;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213
214 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200215 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200216 }
217 LY_ARRAY_FOR(ext, u) {
218 if (!count) {
219 break;
220 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200221
Radek Krejcid3ca0632019-04-16 16:54:54 +0200222 count--;
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100223 if ((ext->flags & LYS_INTERNAL) || (ext->insubstmt != substmt) || (ext->insubstmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200224 continue;
225 }
226
Radek Krejcif56e2a42019-09-09 14:15:25 +0200227 ypr_open(ctx->out, flag);
228 argument = NULL;
229 if (ext[u].compiled) {
230 argument = ext[u].compiled->argument;
231 } else {
232 argument = ext[u].argument;
233 }
234 if (argument) {
Michal Vasko5233e962020-08-14 14:26:20 +0200235 ly_print_(ctx->out, "%*s%s \"", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200236 ypr_encode(ctx->out, argument, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200237 ly_print_(ctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200238 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200239 ly_print_(ctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200240 }
241
242 child_presence = 0;
243 LEVEL++;
244 LY_LIST_FOR(ext[u].child, stmt) {
245 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
246 continue;
247 }
248 if (!child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200249 ly_print_(ctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200250 child_presence = 1;
251 }
252 yprp_stmt(ctx, stmt);
253 }
254 LEVEL--;
255 if (child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200256 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200257 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200258 ly_print_(ctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200259 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200260 }
261}
262
Radek Krejciadcf63d2021-02-09 10:21:18 +0100263static void yprc_extension_instances(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
264 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200265
266static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100267ypr_substmt(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200268{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200269 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200270 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200271
272 if (!text) {
273 /* nothing to print */
274 return;
275 }
276
Radek Krejcieccf6602021-02-05 19:42:54 +0100277 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
278 ly_print_(ctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200279 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +0100280 ypr_text(ctx, stmt_attr_info[substmt].name, text,
281 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200282 }
283
284 LEVEL++;
285 LY_ARRAY_FOR(ext, u) {
Michal Vasko69730152020-10-09 16:30:07 +0200286 if ((((struct lysp_ext_instance *)ext)[u].insubstmt != substmt) || (((struct lysp_ext_instance *)ext)[u].insubstmt_index != substmt_index)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287 continue;
288 }
Radek Krejciadcf63d2021-02-09 10:21:18 +0100289 if (ctx->schema == LYS_YPR_PARSED) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200290 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200291 } else {
Michal Vasko22df3f02020-08-24 13:29:22 +0200292 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200293 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200294 }
295 LEVEL--;
296 ypr_close(ctx, extflag);
297}
298
299static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100300ypr_unsigned(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200301{
302 char *str;
303
Radek Krejci1deb5be2020-08-26 16:43:36 +0200304 if (asprintf(&str, "%lu", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200305 LOGMEM(ctx->module->ctx);
306 return;
307 }
308 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200309 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200310 free(str);
311}
312
313static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100314ypr_signed(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200315{
316 char *str;
317
Radek Krejci1deb5be2020-08-26 16:43:36 +0200318 if (asprintf(&str, "%ld", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200319 LOGMEM(ctx->module->ctx);
320 return;
321 }
322 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200323 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 free(str);
325}
326
327static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100328yprp_revision(struct lys_ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200329{
330 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +0200331 ly_print_(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200332 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200333 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
334 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
335 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200337 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200338 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200339 ly_print_(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 }
341}
342
343static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100344ypr_mandatory(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200345{
346 if (flags & LYS_MAND_MASK) {
347 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200348 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 }
350}
351
352static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100353ypr_config(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200354{
355 if (flags & LYS_CONFIG_MASK) {
356 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200357 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358 }
359}
360
361static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100362ypr_status(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200363{
364 const char *status = NULL;
365
366 if (flags & LYS_STATUS_CURR) {
367 ypr_open(ctx->out, flag);
368 status = "current";
369 } else if (flags & LYS_STATUS_DEPRC) {
370 ypr_open(ctx->out, flag);
371 status = "deprecated";
372 } else if (flags & LYS_STATUS_OBSLT) {
373 ypr_open(ctx->out, flag);
374 status = "obsolete";
375 }
Radek Krejci693262f2019-04-29 15:23:20 +0200376
377 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378}
379
380static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100381ypr_description(struct lys_ypr_ctx *ctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382{
383 if (dsc) {
384 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200385 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200386 }
387}
388
389static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100390ypr_reference(struct lys_ypr_ctx *ctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200391{
392 if (ref) {
393 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200394 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200395 }
396}
397
398static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100399yprp_iffeatures(struct lys_ypr_ctx *ctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200400{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200401 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200402 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403
Michal Vasko7f45cf22020-10-01 12:49:44 +0200404 LY_ARRAY_FOR(iffs, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405 ypr_open(ctx->out, flag);
406 extflag = 0;
407
Michal Vasko7f45cf22020-10-01 12:49:44 +0200408 ly_print_(ctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200409
410 /* extensions */
411 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200412 LY_ARRAY_FOR(exts, v) {
Radek Krejcieccf6602021-02-05 19:42:54 +0100413 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200414 }
415 LEVEL--;
416 ypr_close(ctx, extflag);
417 }
418}
419
420static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100421yprp_extension(struct lys_ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422{
Radek Krejci857189e2020-09-01 13:26:36 +0200423 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200424 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200425
Michal Vasko5233e962020-08-14 14:26:20 +0200426 ly_print_(ctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200427 LEVEL++;
428
429 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200430 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200431 }
432
433 if (ext->argument) {
434 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200435 ly_print_(ctx->out, "%*sargument %s", INDENT, ext->argument);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200436 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200437 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200438 u = -1;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200439 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200440 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200441 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200442 }
443 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcieccf6602021-02-05 19:42:54 +0100444 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200445 ypr_open(ctx->out, &flag2);
Radek Krejcieccf6602021-02-05 19:42:54 +0100446 ypr_substmt(ctx, LYEXT_SUBSTMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200448 LEVEL--;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449 ypr_close(ctx, flag2);
450 }
451
Radek Krejci693262f2019-04-29 15:23:20 +0200452 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453 ypr_description(ctx, ext->dsc, ext->exts, &flag);
454 ypr_reference(ctx, ext->ref, ext->exts, &flag);
455
456 LEVEL--;
457 ypr_close(ctx, flag);
458}
459
460static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100461yprp_feature(struct lys_ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200462{
Radek Krejci857189e2020-09-01 13:26:36 +0200463 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464
Michal Vasko5233e962020-08-14 14:26:20 +0200465 ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200467 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
468 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
469 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200470 ypr_description(ctx, feat->dsc, feat->exts, &flag);
471 ypr_reference(ctx, feat->ref, feat->exts, &flag);
472 LEVEL--;
473 ypr_close(ctx, flag);
474}
475
476static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100477yprp_identity(struct lys_ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478{
Radek Krejci857189e2020-09-01 13:26:36 +0200479 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200480 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481
Michal Vasko5233e962020-08-14 14:26:20 +0200482 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 LEVEL++;
484
Radek Krejci693262f2019-04-29 15:23:20 +0200485 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
486 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200487
488 LY_ARRAY_FOR(ident->bases, u) {
489 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200490 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 }
492
Radek Krejci693262f2019-04-29 15:23:20 +0200493 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494 ypr_description(ctx, ident->dsc, ident->exts, &flag);
495 ypr_reference(ctx, ident->ref, ident->exts, &flag);
496
497 LEVEL--;
498 ypr_close(ctx, flag);
499}
500
501static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100502yprc_identity(struct lys_ypr_ctx *ctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200503{
Radek Krejci857189e2020-09-01 13:26:36 +0200504 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200505 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200506
Michal Vasko5233e962020-08-14 14:26:20 +0200507 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200508 LEVEL++;
509
510 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200511
512 LY_ARRAY_FOR(ident->derived, u) {
513 ypr_open(ctx->out, &flag);
514 if (ctx->module != ident->derived[u]->module) {
Michal Vasko5233e962020-08-14 14:26:20 +0200515 ly_print_(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200516 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200517 ly_print_(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200518 }
519 }
520
521 ypr_status(ctx, ident->flags, ident->exts, &flag);
522 ypr_description(ctx, ident->dsc, ident->exts, &flag);
523 ypr_reference(ctx, ident->ref, ident->exts, &flag);
524
525 LEVEL--;
526 ypr_close(ctx, flag);
527}
528
529static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100530yprp_restr(struct lys_ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531{
Radek Krejci857189e2020-09-01 13:26:36 +0200532 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533
534 if (!restr) {
535 return;
536 }
537
538 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200539 ly_print_(ctx->out, "%*s%s \"", INDENT, name);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100540 ypr_encode(ctx->out,
541 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
542 restr->arg.str : &restr->arg.str[1], -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200543 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200544
545 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200546 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100547 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200548 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
549 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200550 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200551 }
552 if (restr->emsg) {
553 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100554 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200555 }
556 if (restr->eapptag) {
557 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100558 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200559 }
Radek Krejci693262f2019-04-29 15:23:20 +0200560 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
561 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
562
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563 LEVEL--;
564 ypr_close(ctx, inner_flag);
565}
566
567static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100568yprc_must(struct lys_ypr_ctx *ctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200569{
Radek Krejci857189e2020-09-01 13:26:36 +0200570 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200571
572 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200573 ly_print_(ctx->out, "%*smust \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200574 ypr_encode(ctx->out, must->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200575 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200576
577 LEVEL++;
578 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
579 if (must->emsg) {
580 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100581 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200582 }
583 if (must->eapptag) {
584 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100585 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200586 }
587 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
588 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
589
590 LEVEL--;
591 ypr_close(ctx, inner_flag);
592}
593
594static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100595yprc_range(struct lys_ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200596{
Radek Krejci857189e2020-09-01 13:26:36 +0200597 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200598 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200599
Radek Krejci334ccc72019-06-12 13:49:29 +0200600 if (!range) {
601 return;
602 }
603
Radek Krejci693262f2019-04-29 15:23:20 +0200604 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200605 ly_print_(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200606 LY_ARRAY_FOR(range->parts, u) {
607 if (u > 0) {
Michal Vasko5233e962020-08-14 14:26:20 +0200608 ly_print_(ctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200609 }
610 if (range->parts[u].max_64 == range->parts[u].min_64) {
611 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200612 ly_print_(ctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200613 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200614 ly_print_(ctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200615 }
616 } else {
617 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200618 ly_print_(ctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200619 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200620 ly_print_(ctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200621 }
622 }
623 }
Michal Vasko5233e962020-08-14 14:26:20 +0200624 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200625
626 LEVEL++;
627 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
628 if (range->emsg) {
629 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100630 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200631 }
632 if (range->eapptag) {
633 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100634 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200635 }
636 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
637 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
638
639 LEVEL--;
640 ypr_close(ctx, inner_flag);
641}
642
643static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100644yprc_pattern(struct lys_ypr_ctx *ctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200645{
Radek Krejci857189e2020-09-01 13:26:36 +0200646 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200647
648 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200649 ly_print_(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200650 ypr_encode(ctx->out, pattern->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200651 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200652
653 LEVEL++;
654 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
655 if (pattern->inverted) {
656 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
657 ypr_open(ctx->out, &inner_flag);
658 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
659 }
660 if (pattern->emsg) {
661 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100662 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200663 }
664 if (pattern->eapptag) {
665 ypr_open(ctx->out, &inner_flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100666 ypr_substmt(ctx, LYEXT_SUBSTMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200667 }
668 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
669 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
670
671 LEVEL--;
672 ypr_close(ctx, inner_flag);
673}
674
675static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100676yprp_when(struct lys_ypr_ctx *ctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200677{
Radek Krejci857189e2020-09-01 13:26:36 +0200678 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200679
680 if (!when) {
681 return;
682 }
683 ypr_open(ctx->out, flag);
684
Michal Vasko5233e962020-08-14 14:26:20 +0200685 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200686 ypr_encode(ctx->out, when->cond, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200687 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200688
689 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200690 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200691 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
692 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
693 LEVEL--;
694 ypr_close(ctx, inner_flag);
695}
696
697static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100698yprc_when(struct lys_ypr_ctx *ctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200699{
Radek Krejci857189e2020-09-01 13:26:36 +0200700 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200701
702 if (!when) {
703 return;
704 }
705 ypr_open(ctx->out, flag);
706
Michal Vasko5233e962020-08-14 14:26:20 +0200707 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200708 ypr_encode(ctx->out, when->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200709 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200710
711 LEVEL++;
712 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
713 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
714 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
715 LEVEL--;
716 ypr_close(ctx, inner_flag);
717}
718
719static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100720yprp_enum(struct lys_ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200721{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200722 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200723 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200724
725 LY_ARRAY_FOR(items, u) {
726 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200727 if (type == LY_TYPE_BITS) {
Michal Vasko5233e962020-08-14 14:26:20 +0200728 ly_print_(ctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200729 } else { /* LY_TYPE_ENUM */
Michal Vasko5233e962020-08-14 14:26:20 +0200730 ly_print_(ctx->out, "%*senum \"", INDENT);
Radek Krejci7871ce52019-06-11 16:44:56 +0200731 ypr_encode(ctx->out, items[u].name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200732 ly_print_(ctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200733 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200734 inner_flag = 0;
735 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200736 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
737 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200738 if (items[u].flags & LYS_SET_VALUE) {
739 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200740 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200742 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743 }
744 }
Radek Krejci693262f2019-04-29 15:23:20 +0200745 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200746 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
747 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
748 LEVEL--;
749 ypr_close(ctx, inner_flag);
750 }
751}
752
753static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100754yprp_type(struct lys_ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200755{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200756 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200757 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200758
Michal Vasko5233e962020-08-14 14:26:20 +0200759 ly_print_(ctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200760 LEVEL++;
761
Radek Krejci693262f2019-04-29 15:23:20 +0200762 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200763
Radek Krejci693262f2019-04-29 15:23:20 +0200764 yprp_restr(ctx, type->range, "range", &flag);
765 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200766 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200767 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768 }
Radek Krejci693262f2019-04-29 15:23:20 +0200769 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
770 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200771
772 if (type->path) {
773 ypr_open(ctx->out, &flag);
Michal Vasko004d3152020-06-11 19:59:22 +0200774 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200775 }
776 if (type->flags & LYS_SET_REQINST) {
777 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100778 ypr_substmt(ctx, LYEXT_SUBSTMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200779 }
780 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejcieccf6602021-02-05 19:42:54 +0100781 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782 }
783 LY_ARRAY_FOR(type->bases, u) {
784 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200785 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200786 }
787 LY_ARRAY_FOR(type->types, u) {
788 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200789 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790 }
791
792 LEVEL--;
793 ypr_close(ctx, flag);
794}
795
796static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100797yprc_dflt_value(struct lys_ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200798{
Radek Krejci857189e2020-09-01 13:26:36 +0200799 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200800 const char *str;
801
Michal Vaskoba99a3e2020-08-18 15:50:05 +0200802 str = value->realtype->plugin->print(value, LY_PREF_JSON, NULL, &dynamic);
Radek Krejcia1911222019-07-22 17:24:50 +0200803 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, str, exts);
804 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200805 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200806 }
807}
808
809static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100810yprc_type(struct lys_ypr_ctx *ctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200811{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200812 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200813 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200814
Michal Vasko5233e962020-08-14 14:26:20 +0200815 ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200816 LEVEL++;
817
818 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200819
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200820 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200821 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200822 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200823 yprc_range(ctx, bin->length, type->basetype, &flag);
824 break;
825 }
826 case LY_TYPE_UINT8:
827 case LY_TYPE_UINT16:
828 case LY_TYPE_UINT32:
829 case LY_TYPE_UINT64:
830 case LY_TYPE_INT8:
831 case LY_TYPE_INT16:
832 case LY_TYPE_INT32:
833 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200834 struct lysc_type_num *num = (struct lysc_type_num *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200835 yprc_range(ctx, num->range, type->basetype, &flag);
836 break;
837 }
838 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200839 struct lysc_type_str *str = (struct lysc_type_str *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200840 yprc_range(ctx, str->length, type->basetype, &flag);
841 LY_ARRAY_FOR(str->patterns, u) {
842 yprc_pattern(ctx, str->patterns[u], &flag);
843 }
844 break;
845 }
846 case LY_TYPE_BITS:
847 case LY_TYPE_ENUM: {
848 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200849 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200850 LY_ARRAY_FOR(bits->bits, u) {
851 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200852 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200853
854 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200855 ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
Radek Krejci693262f2019-04-29 15:23:20 +0200856 ypr_encode(ctx->out, item->name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200857 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200858 LEVEL++;
859 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200860 if (type->basetype == LY_TYPE_BITS) {
861 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
862 } else { /* LY_TYPE_ENUM */
863 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
864 }
865 ypr_status(ctx, item->flags, item->exts, &inner_flag);
866 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
867 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
868 LEVEL--;
869 ypr_close(ctx, inner_flag);
870 }
871 break;
872 }
873 case LY_TYPE_BOOL:
874 case LY_TYPE_EMPTY:
875 /* nothing to do */
876 break;
877 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200878 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200879 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100880 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200881 yprc_range(ctx, dec->range, dec->basetype, &flag);
882 break;
883 }
884 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200885 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200886 LY_ARRAY_FOR(ident->bases, u) {
887 ypr_open(ctx->out, &flag);
888 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
889 }
890 break;
891 }
892 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200893 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200894 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +0100895 ypr_substmt(ctx, LYEXT_SUBSTMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200896 break;
897 }
898 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200899 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200900 ypr_open(ctx->out, &flag);
Michal Vasko004d3152020-06-11 19:59:22 +0200901 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path->expr, lr->exts);
Radek Krejcieccf6602021-02-05 19:42:54 +0100902 ypr_substmt(ctx, LYEXT_SUBSTMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200903 yprc_type(ctx, lr->realtype);
904 break;
905 }
906 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200907 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200908 LY_ARRAY_FOR(un->types, u) {
909 ypr_open(ctx->out, &flag);
910 yprc_type(ctx, un->types[u]);
911 }
912 break;
913 }
914 default:
915 LOGINT(ctx->module->ctx);
916 }
917
918 LEVEL--;
919 ypr_close(ctx, flag);
920}
921
922static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100923yprp_typedef(struct lys_ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200924{
Michal Vasko5233e962020-08-14 14:26:20 +0200925 ly_print_(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200926 LEVEL++;
927
Radek Krejci693262f2019-04-29 15:23:20 +0200928 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200929
Radek Krejci693262f2019-04-29 15:23:20 +0200930 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200931
932 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +0200933 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200934 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200935 if (tpdf->dflt.str) {
936 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200937 }
938
Radek Krejci693262f2019-04-29 15:23:20 +0200939 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200940 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
941 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
942
943 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200944 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200945}
946
Radek Krejciadcf63d2021-02-09 10:21:18 +0100947static void yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node);
948static void yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node);
949static void yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action);
950static void yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200951
952static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100953yprp_grouping(struct lys_ypr_ctx *ctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200954{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200955 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200956 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200957 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100958 struct lysp_node_action *action;
959 struct lysp_node_notif *notif;
960 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200961
Michal Vasko5233e962020-08-14 14:26:20 +0200962 ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200963 LEVEL++;
964
Radek Krejci693262f2019-04-29 15:23:20 +0200965 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
966 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +0200967 ypr_description(ctx, grp->dsc, grp->exts, &flag);
968 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200969
970 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200971 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200972 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200973 }
974
Radek Krejci2a9fc652021-01-22 17:44:34 +0100975 LY_LIST_FOR(grp->groupings, subgrp) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200976 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100977 yprp_grouping(ctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200978 }
979
Radek Krejci01180ac2021-01-27 08:48:22 +0100980 LY_LIST_FOR(grp->child, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +0200981 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200982 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200983 }
984
Radek Krejci2a9fc652021-01-22 17:44:34 +0100985 LY_LIST_FOR(grp->actions, action) {
986 ypr_open(ctx->out, &flag);
987 yprp_action(ctx, action);
988 }
989
990 LY_LIST_FOR(grp->notifs, notif) {
991 ypr_open(ctx->out, &flag);
992 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993 }
994
995 LEVEL--;
996 ypr_close(ctx, flag);
997}
998
999static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001000yprp_inout(struct lys_ypr_ctx *ctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001002 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001003 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001004 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001005
Radek Krejci01180ac2021-01-27 08:48:22 +01001006 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001007 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001008 return;
1009 }
1010 ypr_open(ctx->out, flag);
1011
Michal Vasko544e58a2021-01-28 14:33:41 +01001012 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001013 LEVEL++;
1014
Radek Krejci693262f2019-04-29 15:23:20 +02001015 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001017 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001018 }
1019 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001020 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001022 LY_LIST_FOR(inout->groupings, grp) {
1023 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024 }
1025
Radek Krejci01180ac2021-01-27 08:48:22 +01001026 LY_LIST_FOR(inout->child, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001027 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028 }
1029
1030 LEVEL--;
1031 ypr_close(ctx, 1);
1032}
1033
1034static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001035yprc_inout(struct lys_ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001036{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001037 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001038 struct lysc_node *data;
1039
Radek Krejci01180ac2021-01-27 08:48:22 +01001040 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001041 /* input/output is empty */
1042 return;
1043 }
1044 ypr_open(ctx->out, flag);
1045
Michal Vasko544e58a2021-01-28 14:33:41 +01001046 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001047 LEVEL++;
1048
Michal Vasko544e58a2021-01-28 14:33:41 +01001049 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001050 LY_ARRAY_FOR(inout->musts, u) {
1051 yprc_must(ctx, &inout->musts[u], NULL);
1052 }
1053
Radek Krejci52f65552020-09-01 17:03:35 +02001054 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001055 LY_LIST_FOR(inout->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001056 yprc_node(ctx, data);
1057 }
Radek Krejci693262f2019-04-29 15:23:20 +02001058 }
1059
1060 LEVEL--;
1061 ypr_close(ctx, 1);
1062}
1063
1064static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001065yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001066{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001067 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001068 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001069 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001070 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001071
Michal Vasko5233e962020-08-14 14:26:20 +02001072 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073
1074 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001075 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1076 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001077
1078 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001079 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080 }
Radek Krejci693262f2019-04-29 15:23:20 +02001081 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1083 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1084
1085 LY_ARRAY_FOR(notif->typedefs, u) {
1086 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001087 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001088 }
1089
Radek Krejci2a9fc652021-01-22 17:44:34 +01001090 LY_LIST_FOR(notif->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001092 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001093 }
1094
Radek Krejci01180ac2021-01-27 08:48:22 +01001095 LY_LIST_FOR(notif->child, data) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001096 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001097 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 }
1099
1100 LEVEL--;
1101 ypr_close(ctx, flag);
1102}
1103
1104static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001105yprc_notification(struct lys_ypr_ctx *ctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001106{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001107 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001108 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001109 struct lysc_node *data;
1110
Michal Vasko5233e962020-08-14 14:26:20 +02001111 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001112
1113 LEVEL++;
1114 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001115
1116 LY_ARRAY_FOR(notif->musts, u) {
1117 yprc_must(ctx, &notif->musts[u], &flag);
1118 }
1119 ypr_status(ctx, notif->flags, notif->exts, &flag);
1120 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1121 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1122
Radek Krejci52f65552020-09-01 17:03:35 +02001123 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001124 LY_LIST_FOR(notif->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001125 ypr_open(ctx->out, &flag);
1126 yprc_node(ctx, data);
1127 }
Radek Krejci693262f2019-04-29 15:23:20 +02001128 }
1129
1130 LEVEL--;
1131 ypr_close(ctx, flag);
1132}
1133
1134static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001135yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001136{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001137 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001138 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001139 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001140
Michal Vasko5233e962020-08-14 14:26:20 +02001141 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001142
1143 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001144 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1145 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1146 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147 ypr_description(ctx, action->dsc, action->exts, &flag);
1148 ypr_reference(ctx, action->ref, action->exts, &flag);
1149
1150 LY_ARRAY_FOR(action->typedefs, u) {
1151 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001152 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153 }
1154
Radek Krejci2a9fc652021-01-22 17:44:34 +01001155 LY_LIST_FOR(action->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001156 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001157 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001158 }
1159
Radek Krejci693262f2019-04-29 15:23:20 +02001160 yprp_inout(ctx, &action->input, &flag);
1161 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162
1163 LEVEL--;
1164 ypr_close(ctx, flag);
1165}
1166
1167static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001168yprc_action(struct lys_ypr_ctx *ctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001169{
Radek Krejci857189e2020-09-01 13:26:36 +02001170 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001171
Michal Vasko5233e962020-08-14 14:26:20 +02001172 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001173
1174 LEVEL++;
1175 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001176 ypr_status(ctx, action->flags, action->exts, &flag);
1177 ypr_description(ctx, action->dsc, action->exts, &flag);
1178 ypr_reference(ctx, action->ref, action->exts, &flag);
1179
Michal Vasko544e58a2021-01-28 14:33:41 +01001180 yprc_inout(ctx, &action->input, &flag);
1181 yprc_inout(ctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001182
1183 LEVEL--;
1184 ypr_close(ctx, flag);
1185}
1186
1187static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001188yprp_node_common1(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001189{
Michal Vasko5233e962020-08-14 14:26:20 +02001190 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191 LEVEL++;
1192
Radek Krejci693262f2019-04-29 15:23:20 +02001193 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001194 yprp_when(ctx, lysp_node_when(node), flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001195 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001196}
1197
1198static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001199yprc_node_common1(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001200{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001201 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001202 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203
Michal Vasko5233e962020-08-14 14:26:20 +02001204 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001205 LEVEL++;
1206
1207 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001208
1209 when = lysc_node_when(node);
1210 LY_ARRAY_FOR(when, u) {
1211 yprc_when(ctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001212 }
Radek Krejci693262f2019-04-29 15:23:20 +02001213}
1214
1215/* macr oto unify the code */
1216#define YPR_NODE_COMMON2 \
1217 ypr_config(ctx, node->flags, node->exts, flag); \
1218 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1219 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1220 } \
1221 ypr_status(ctx, node->flags, node->exts, flag); \
1222 ypr_description(ctx, node->dsc, node->exts, flag); \
1223 ypr_reference(ctx, node->ref, node->exts, flag)
1224
1225static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001226yprp_node_common2(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001227{
1228 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001229}
1230
1231static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001232yprc_node_common2(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001233{
1234 YPR_NODE_COMMON2;
1235}
1236
1237#undef YPR_NODE_COMMON2
1238
1239static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001240yprp_container(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001241{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001242 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001243 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001244 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001245 struct lysp_node_action *action;
1246 struct lysp_node_notif *notif;
1247 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1249
Radek Krejci693262f2019-04-29 15:23:20 +02001250 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001251
1252 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001253 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001254 }
1255 if (cont->presence) {
1256 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001257 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001258 }
1259
Radek Krejci693262f2019-04-29 15:23:20 +02001260 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261
1262 LY_ARRAY_FOR(cont->typedefs, u) {
1263 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001264 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001265 }
1266
Radek Krejci2a9fc652021-01-22 17:44:34 +01001267 LY_LIST_FOR(cont->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001268 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001269 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001270 }
1271
1272 LY_LIST_FOR(cont->child, child) {
1273 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001274 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275 }
1276
Radek Krejci2a9fc652021-01-22 17:44:34 +01001277 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001278 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001279 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001280 }
1281
Radek Krejci2a9fc652021-01-22 17:44:34 +01001282 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001283 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001284 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001285 }
1286
1287 LEVEL--;
1288 ypr_close(ctx, flag);
1289}
1290
1291static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001292yprc_container(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001293{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001294 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001295 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001296 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001297 struct lysc_node_action *action;
1298 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001299 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1300
1301 yprc_node_common1(ctx, node, &flag);
1302
1303 LY_ARRAY_FOR(cont->musts, u) {
1304 yprc_must(ctx, &cont->musts[u], &flag);
1305 }
1306 if (cont->flags & LYS_PRESENCE) {
1307 ypr_open(ctx->out, &flag);
1308 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1309 }
1310
1311 yprc_node_common2(ctx, node, &flag);
1312
Radek Krejci52f65552020-09-01 17:03:35 +02001313 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001314 LY_LIST_FOR(cont->child, child) {
1315 ypr_open(ctx->out, &flag);
1316 yprc_node(ctx, child);
1317 }
Radek Krejci693262f2019-04-29 15:23:20 +02001318
Radek Krejci2a9fc652021-01-22 17:44:34 +01001319 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001320 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001321 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001322 }
Radek Krejci693262f2019-04-29 15:23:20 +02001323
Radek Krejci2a9fc652021-01-22 17:44:34 +01001324 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001325 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001326 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001327 }
Radek Krejci693262f2019-04-29 15:23:20 +02001328 }
1329
1330 LEVEL--;
1331 ypr_close(ctx, flag);
1332}
1333
1334static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001335yprp_case(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001336{
Radek Krejci857189e2020-09-01 13:26:36 +02001337 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001338 struct lysp_node *child;
1339 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1340
1341 yprp_node_common1(ctx, node, &flag);
1342 yprp_node_common2(ctx, node, &flag);
1343
1344 LY_LIST_FOR(cas->child, child) {
1345 ypr_open(ctx->out, &flag);
1346 yprp_node(ctx, child);
1347 }
1348
1349 LEVEL--;
1350 ypr_close(ctx, flag);
1351}
1352
1353static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001354yprc_case(struct lys_ypr_ctx *ctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001355{
Radek Krejci857189e2020-09-01 13:26:36 +02001356 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001357 struct lysc_node *child;
1358
Michal Vasko14ed9cd2021-01-28 14:16:25 +01001359 yprc_node_common1(ctx, &cs->node, &flag);
1360 yprc_node_common2(ctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001361
Radek Krejci52f65552020-09-01 17:03:35 +02001362 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001363 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001364 ypr_open(ctx->out, &flag);
1365 yprc_node(ctx, child);
1366 }
Radek Krejci693262f2019-04-29 15:23:20 +02001367 }
1368
1369 LEVEL--;
1370 ypr_close(ctx, flag);
1371}
1372
1373static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001374yprp_choice(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001375{
Radek Krejci857189e2020-09-01 13:26:36 +02001376 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001377 struct lysp_node *child;
1378 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1379
Radek Krejci693262f2019-04-29 15:23:20 +02001380 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001381
Michal Vasko7f45cf22020-10-01 12:49:44 +02001382 if (choice->dflt.str) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001383 ypr_open(ctx->out, &flag);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001384 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001385 }
1386
Radek Krejci693262f2019-04-29 15:23:20 +02001387 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001388
1389 LY_LIST_FOR(choice->child, child) {
1390 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001391 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001392 }
1393
1394 LEVEL--;
1395 ypr_close(ctx, flag);
1396}
1397
1398static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001399yprc_choice(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001400{
Radek Krejci857189e2020-09-01 13:26:36 +02001401 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001402 struct lysc_node_case *cs;
1403 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1404
1405 yprc_node_common1(ctx, node, &flag);
1406
1407 if (choice->dflt) {
1408 ypr_open(ctx->out, &flag);
1409 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1410 }
1411
1412 yprc_node_common2(ctx, node, &flag);
1413
Michal Vasko22df3f02020-08-24 13:29:22 +02001414 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Radek Krejci693262f2019-04-29 15:23:20 +02001415 ypr_open(ctx->out, &flag);
1416 yprc_case(ctx, cs);
1417 }
1418
1419 LEVEL--;
1420 ypr_close(ctx, flag);
1421}
1422
1423static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001424yprp_leaf(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001425{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001426 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001427 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1428
Radek Krejci693262f2019-04-29 15:23:20 +02001429 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001430
Radek Krejci693262f2019-04-29 15:23:20 +02001431 yprp_type(ctx, &leaf->type);
1432 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001433 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001434 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001435 }
Michal Vasko7f45cf22020-10-01 12:49:44 +02001436 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001437
Radek Krejci693262f2019-04-29 15:23:20 +02001438 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001439
1440 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001441 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001442}
1443
1444static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001445yprc_leaf(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001446{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001447 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001448 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1449
1450 yprc_node_common1(ctx, node, NULL);
1451
1452 yprc_type(ctx, leaf->type);
1453 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1454 LY_ARRAY_FOR(leaf->musts, u) {
1455 yprc_must(ctx, &leaf->musts[u], NULL);
1456 }
Radek Krejcia1911222019-07-22 17:24:50 +02001457
1458 if (leaf->dflt) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001459 yprc_dflt_value(ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001460 }
Radek Krejci693262f2019-04-29 15:23:20 +02001461
1462 yprc_node_common2(ctx, node, NULL);
1463
1464 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001465 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001466}
1467
1468static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001469yprp_leaflist(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001471 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001472 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1473
Radek Krejci693262f2019-04-29 15:23:20 +02001474 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001475
Radek Krejci693262f2019-04-29 15:23:20 +02001476 yprp_type(ctx, &llist->type);
1477 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001479 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001480 }
1481 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001482 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001483 }
1484
Radek Krejci693262f2019-04-29 15:23:20 +02001485 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001486
1487 if (llist->flags & LYS_SET_MIN) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001488 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489 }
1490 if (llist->flags & LYS_SET_MAX) {
1491 if (llist->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001492 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001493 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001494 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001495 }
1496 }
1497
1498 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001499 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001500 }
1501
Radek Krejci693262f2019-04-29 15:23:20 +02001502 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503 ypr_description(ctx, node->dsc, node->exts, NULL);
1504 ypr_reference(ctx, node->ref, node->exts, NULL);
1505
1506 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001507 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508}
1509
1510static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001511yprc_leaflist(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001512{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001513 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001514 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1515
1516 yprc_node_common1(ctx, node, NULL);
1517
1518 yprc_type(ctx, llist->type);
1519 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1520 LY_ARRAY_FOR(llist->musts, u) {
1521 yprc_must(ctx, &llist->musts[u], NULL);
1522 }
1523 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001524 yprc_dflt_value(ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001525 }
1526
1527 ypr_config(ctx, node->flags, node->exts, NULL);
1528
Radek Krejcieccf6602021-02-05 19:42:54 +01001529 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001530 if (llist->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001531 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001532 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001533 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001534 }
1535
Radek Krejcieccf6602021-02-05 19:42:54 +01001536 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001537
1538 ypr_status(ctx, node->flags, node->exts, NULL);
1539 ypr_description(ctx, node->dsc, node->exts, NULL);
1540 ypr_reference(ctx, node->ref, node->exts, NULL);
1541
1542 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001543 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001544}
1545
1546static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001547yprp_list(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001548{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001549 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001550 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001551 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001552 struct lysp_node_action *action;
1553 struct lysp_node_notif *notif;
1554 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001555 struct lysp_node_list *list = (struct lysp_node_list *)node;
1556
Radek Krejci693262f2019-04-29 15:23:20 +02001557 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558
1559 LY_ARRAY_FOR(list->musts, u) {
Michal Vaskoabf81a02021-02-03 11:30:41 +01001560 yprp_restr(ctx, &list->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561 }
1562 if (list->key) {
1563 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001564 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565 }
1566 LY_ARRAY_FOR(list->uniques, u) {
1567 ypr_open(ctx->out, &flag);
Michal Vasko7f45cf22020-10-01 12:49:44 +02001568 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569 }
1570
Michal Vaskoacb8e742020-10-20 10:28:02 +02001571 ypr_config(ctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001572
1573 if (list->flags & LYS_SET_MIN) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001574 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 }
1576 if (list->flags & LYS_SET_MAX) {
1577 if (list->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001578 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 } else {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001580 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +01001581 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001582 }
1583 }
1584
1585 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001586 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +01001587 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001588 }
1589
Michal Vaskoacb8e742020-10-20 10:28:02 +02001590 ypr_status(ctx, node->flags, node->exts, &flag);
1591 ypr_description(ctx, node->dsc, node->exts, &flag);
1592 ypr_reference(ctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001593
1594 LY_ARRAY_FOR(list->typedefs, u) {
1595 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001596 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597 }
1598
Radek Krejci2a9fc652021-01-22 17:44:34 +01001599 LY_LIST_FOR(list->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001601 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001602 }
1603
1604 LY_LIST_FOR(list->child, child) {
1605 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001606 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001607 }
1608
Radek Krejci2a9fc652021-01-22 17:44:34 +01001609 LY_LIST_FOR(list->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001610 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001611 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001612 }
1613
Radek Krejci2a9fc652021-01-22 17:44:34 +01001614 LY_LIST_FOR(list->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001615 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001616 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001617 }
1618
1619 LEVEL--;
1620 ypr_close(ctx, flag);
1621}
1622
1623static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001624yprc_list(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001625{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001626 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001627 struct lysc_node_list *list = (struct lysc_node_list *)node;
1628
Michal Vaskoacb8e742020-10-20 10:28:02 +02001629 yprc_node_common1(ctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001630
1631 LY_ARRAY_FOR(list->musts, u) {
1632 yprc_must(ctx, &list->musts[u], NULL);
1633 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001634 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko5233e962020-08-14 14:26:20 +02001635 ly_print_(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001636 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
Michal Vasko5233e962020-08-14 14:26:20 +02001637 ly_print_(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001638 }
Michal Vasko5233e962020-08-14 14:26:20 +02001639 ly_print_(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001640 }
1641 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02001642 ly_print_(ctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001643 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko5233e962020-08-14 14:26:20 +02001644 ly_print_(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001645 }
1646 ypr_close(ctx, 0);
1647 }
1648
1649 ypr_config(ctx, node->flags, node->exts, NULL);
1650
Radek Krejcieccf6602021-02-05 19:42:54 +01001651 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001652 if (list->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001653 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001654 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001655 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001656 }
1657
Radek Krejcieccf6602021-02-05 19:42:54 +01001658 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001659
1660 ypr_status(ctx, node->flags, node->exts, NULL);
1661 ypr_description(ctx, node->dsc, node->exts, NULL);
1662 ypr_reference(ctx, node->ref, node->exts, NULL);
1663
Radek Krejci52f65552020-09-01 17:03:35 +02001664 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001665 struct lysc_node *child;
1666 struct lysc_node_action *action;
1667 struct lysc_node_notif *notif;
1668
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001669 LY_LIST_FOR(list->child, child) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001670 yprc_node(ctx, child);
1671 }
Radek Krejci693262f2019-04-29 15:23:20 +02001672
Radek Krejci2a9fc652021-01-22 17:44:34 +01001673 LY_LIST_FOR(list->actions, action) {
1674 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001675 }
Radek Krejci693262f2019-04-29 15:23:20 +02001676
Radek Krejci2a9fc652021-01-22 17:44:34 +01001677 LY_LIST_FOR(list->notifs, notif) {
1678 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001679 }
Radek Krejci693262f2019-04-29 15:23:20 +02001680 }
1681
1682 LEVEL--;
Michal Vaskoacb8e742020-10-20 10:28:02 +02001683 ypr_close(ctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001684}
1685
1686static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001687yprp_refine(struct lys_ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001688{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001689 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001690 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001691
Michal Vasko5233e962020-08-14 14:26:20 +02001692 ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001693 LEVEL++;
1694
Radek Krejci693262f2019-04-29 15:23:20 +02001695 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1696 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001697
1698 LY_ARRAY_FOR(refine->musts, u) {
1699 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001700 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001701 }
1702
1703 if (refine->presence) {
1704 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001705 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001706 }
1707
1708 LY_ARRAY_FOR(refine->dflts, u) {
1709 ypr_open(ctx->out, &flag);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001710 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001711 }
1712
Radek Krejci693262f2019-04-29 15:23:20 +02001713 ypr_config(ctx, refine->flags, refine->exts, &flag);
1714 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001715
1716 if (refine->flags & LYS_SET_MIN) {
1717 ypr_open(ctx->out, &flag);
Radek Krejcieccf6602021-02-05 19:42:54 +01001718 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001719 }
1720 if (refine->flags & LYS_SET_MAX) {
1721 ypr_open(ctx->out, &flag);
1722 if (refine->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001723 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001724 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001725 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001726 }
1727 }
1728
1729 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1730 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1731
1732 LEVEL--;
1733 ypr_close(ctx, flag);
1734}
1735
1736static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001737yprp_augment(struct lys_ypr_ctx *ctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001738{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001739 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001740 struct lysp_node_action *action;
1741 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001742
Michal Vasko5233e962020-08-14 14:26:20 +02001743 ly_print_(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001744 LEVEL++;
1745
Radek Krejci693262f2019-04-29 15:23:20 +02001746 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1747 yprp_when(ctx, aug->when, NULL);
1748 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1749 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1751 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1752
1753 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001754 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001755 }
1756
Radek Krejci2a9fc652021-01-22 17:44:34 +01001757 LY_LIST_FOR(aug->actions, action) {
1758 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001759 }
1760
Radek Krejci2a9fc652021-01-22 17:44:34 +01001761 LY_LIST_FOR(aug->notifs, notif) {
1762 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001763 }
1764
1765 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001766 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001767}
1768
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001770yprp_uses(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001771{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001772 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001773 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001775 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001776
Radek Krejci693262f2019-04-29 15:23:20 +02001777 yprp_node_common1(ctx, node, &flag);
1778 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779
1780 LY_ARRAY_FOR(uses->refines, u) {
1781 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001782 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783 }
1784
Radek Krejci2a9fc652021-01-22 17:44:34 +01001785 LY_LIST_FOR(uses->augments, aug) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001786 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001787 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001788 }
1789
1790 LEVEL--;
1791 ypr_close(ctx, flag);
1792}
1793
1794static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001795yprp_anydata(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001797 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001798 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1800
Radek Krejci693262f2019-04-29 15:23:20 +02001801 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802
1803 LY_ARRAY_FOR(any->musts, u) {
1804 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001805 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806 }
1807
Radek Krejci693262f2019-04-29 15:23:20 +02001808 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809
1810 LEVEL--;
1811 ypr_close(ctx, flag);
1812}
1813
1814static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001815yprc_anydata(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001817 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001818 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001819 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820
Radek Krejci693262f2019-04-29 15:23:20 +02001821 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822
Radek Krejci693262f2019-04-29 15:23:20 +02001823 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001824 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001825 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826 }
1827
Radek Krejci693262f2019-04-29 15:23:20 +02001828 yprc_node_common2(ctx, node, &flag);
1829
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 LEVEL--;
1831 ypr_close(ctx, flag);
1832}
1833
1834static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001835yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001836{
1837 switch (node->nodetype) {
1838 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001839 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840 break;
1841 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001842 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843 break;
1844 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001845 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001846 break;
1847 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 break;
1850 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001851 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852 break;
1853 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001854 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855 break;
1856 case LYS_ANYXML:
1857 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001858 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859 break;
1860 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001861 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862 break;
1863 default:
1864 break;
1865 }
1866}
1867
1868static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001869yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001870{
1871 switch (node->nodetype) {
1872 case LYS_CONTAINER:
1873 yprc_container(ctx, node);
1874 break;
1875 case LYS_CHOICE:
1876 yprc_choice(ctx, node);
1877 break;
1878 case LYS_LEAF:
1879 yprc_leaf(ctx, node);
1880 break;
1881 case LYS_LEAFLIST:
1882 yprc_leaflist(ctx, node);
1883 break;
1884 case LYS_LIST:
1885 yprc_list(ctx, node);
1886 break;
1887 case LYS_ANYXML:
1888 case LYS_ANYDATA:
1889 yprc_anydata(ctx, node);
1890 break;
1891 default:
1892 break;
1893 }
1894}
1895
1896static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001897yprp_deviation(struct lys_ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001898{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001899 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900 struct lysp_deviate_add *add;
1901 struct lysp_deviate_rpl *rpl;
1902 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001903 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904
Michal Vasko5233e962020-08-14 14:26:20 +02001905 ly_print_(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906 LEVEL++;
1907
Radek Krejci693262f2019-04-29 15:23:20 +02001908 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1910 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1911
fredgan2b11ddb2019-10-21 11:03:39 +08001912 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko5233e962020-08-14 14:26:20 +02001913 ly_print_(ctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001914 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1915 if (elem->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02001916 ly_print_(ctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917 LEVEL++;
1918
fredgan2b11ddb2019-10-21 11:03:39 +08001919 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02001921 ly_print_(ctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922 continue;
1923 }
fredgan2b11ddb2019-10-21 11:03:39 +08001924 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001925 add = (struct lysp_deviate_add *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001926 ly_print_(ctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 LEVEL++;
1928
Radek Krejci693262f2019-04-29 15:23:20 +02001929 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
1930 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001931 LY_ARRAY_FOR(add->musts, u) {
1932 yprp_restr(ctx, &add->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001934 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001935 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001937 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001938 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 }
Radek Krejci693262f2019-04-29 15:23:20 +02001940 ypr_config(ctx, add->flags, add->exts, NULL);
1941 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942 if (add->flags & LYS_SET_MIN) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001943 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001944 }
1945 if (add->flags & LYS_SET_MAX) {
1946 if (add->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001947 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001948 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001949 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001950 }
1951 }
fredgan2b11ddb2019-10-21 11:03:39 +08001952 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001953 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001954 ly_print_(ctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001955 LEVEL++;
1956
Radek Krejci693262f2019-04-29 15:23:20 +02001957 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001958 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001959 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001960 }
Radek Krejci693262f2019-04-29 15:23:20 +02001961 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001962 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001963 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1964 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001965 if (rpl->flags & LYS_SET_MIN) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001966 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001967 }
1968 if (rpl->flags & LYS_SET_MAX) {
1969 if (rpl->max) {
Radek Krejcieccf6602021-02-05 19:42:54 +01001970 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001971 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +01001972 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001973 }
1974 }
fredgan2b11ddb2019-10-21 11:03:39 +08001975 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001976 del = (struct lysp_deviate_del *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001977 ly_print_(ctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001978 LEVEL++;
1979
Radek Krejci693262f2019-04-29 15:23:20 +02001980 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
1981 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001982 LY_ARRAY_FOR(del->musts, u) {
1983 yprp_restr(ctx, &del->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001985 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001986 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001988 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001989 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 }
1991 }
1992
1993 LEVEL--;
1994 ypr_close(ctx, 1);
1995 }
1996
1997 LEVEL--;
1998 ypr_close(ctx, 1);
1999}
2000
Michal Vasko7c8439f2020-08-05 13:25:19 +02002001static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002002yang_print_parsed_linkage(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002004 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002007 if (modp->imports[u].flags & LYS_INTERNAL) {
2008 continue;
2009 }
2010
Michal Vasko5233e962020-08-14 14:26:20 +02002011 ly_print_(ctx->out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002013 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2014 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002015 if (modp->imports[u].rev[0]) {
Radek Krejcieccf6602021-02-05 19:42:54 +01002016 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 }
Radek Krejci693262f2019-04-29 15:23:20 +02002018 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2019 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002021 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 }
2023 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002024 if (modp->includes[u].injected) {
2025 /* do not print the includes injected from submodules */
2026 continue;
2027 }
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002029 ly_print_(ctx->out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002031 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 if (modp->includes[u].rev[0]) {
Radek Krejcieccf6602021-02-05 19:42:54 +01002033 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
Radek Krejci693262f2019-04-29 15:23:20 +02002035 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2036 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002038 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02002040 ly_print_(ctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 }
2042 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002043}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044
Michal Vasko7c8439f2020-08-05 13:25:19 +02002045static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002046yang_print_parsed_body(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002047{
2048 LY_ARRAY_COUNT_TYPE u;
2049 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002050 struct lysp_node_action *action;
2051 struct lysp_node_notif *notif;
2052 struct lysp_node_grp *grp;
2053 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002054
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02002056 ly_print_(ctx->out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002057 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058 }
2059 if (modp->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002060 ly_print_(ctx->out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002061 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 }
2063
2064 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002065 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002066 }
2067
2068 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002069 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 }
2071
2072 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002073 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 }
2075
Radek Krejci2a9fc652021-01-22 17:44:34 +01002076 LY_LIST_FOR(modp->groupings, grp) {
2077 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002078 }
2079
2080 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002081 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002082 }
2083
Radek Krejci2a9fc652021-01-22 17:44:34 +01002084 LY_LIST_FOR(modp->augments, aug) {
2085 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002086 }
2087
Radek Krejci2a9fc652021-01-22 17:44:34 +01002088 LY_LIST_FOR(modp->rpcs, action) {
2089 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002090 }
2091
Radek Krejci2a9fc652021-01-22 17:44:34 +01002092 LY_LIST_FOR(modp->notifs, notif) {
2093 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 }
2095
2096 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002097 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002098 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002099}
2100
2101LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002102yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002103{
2104 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002105 const struct lys_module *module = modp->mod;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002106 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = LYS_YPR_PARSED, .options = options}, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002107
Michal Vasko5233e962020-08-14 14:26:20 +02002108 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002109 LEVEL++;
2110
2111 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002112 if (modp->version) {
Radek Krejcieccf6602021-02-05 19:42:54 +01002113 ypr_substmt(ctx, LYEXT_SUBSTMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002114 }
2115
2116 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2117 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
2118
2119 /* linkage-stmts (import/include) */
2120 yang_print_parsed_linkage(ctx, modp);
2121
2122 /* meta-stmts */
2123 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002124 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002125 }
2126 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2127 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2128 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2129 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
2130
2131 /* revision-stmts */
2132 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002133 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002134 }
2135 LY_ARRAY_FOR(modp->revs, u) {
2136 yprp_revision(ctx, &modp->revs[u]);
2137 }
2138 /* body-stmts */
2139 yang_print_parsed_body(ctx, modp);
2140
2141 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002142 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002143 ly_print_flush(out);
2144
2145 return LY_SUCCESS;
2146}
2147
2148static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002149yprp_belongsto(struct lys_ypr_ctx *ctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002150{
Michal Vaskoc3781c32020-10-06 14:04:08 +02002151 ly_print_(ctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002152 LEVEL++;
Radek Krejcieccf6602021-02-05 19:42:54 +01002153 yprp_extension_instances(ctx, LYEXT_SUBSTMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002154 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, submodp->prefix, submodp->exts);
2155 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002156 ly_print_(ctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002157}
2158
2159LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002160yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002161{
2162 LY_ARRAY_COUNT_TYPE u;
Radek Krejci07a55962021-03-02 20:16:43 +01002163 struct lys_ypr_ctx ctx_ = {
2164 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2165 .options = options
2166 }, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002167
Michal Vasko5233e962020-08-14 14:26:20 +02002168 ly_print_(ctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002169 LEVEL++;
2170
2171 /* submodule-header-stmts */
2172 if (submodp->version) {
Radek Krejcieccf6602021-02-05 19:42:54 +01002173 ypr_substmt(ctx, LYEXT_SUBSTMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002174 }
2175
2176 yprp_belongsto(ctx, submodp);
2177
2178 /* linkage-stmts (import/include) */
2179 yang_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
2180
2181 /* meta-stmts */
2182 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002183 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002184 }
2185 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2186 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, submodp->contact, submodp->exts);
2187 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2188 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, submodp->ref, submodp->exts);
2189
2190 /* revision-stmts */
2191 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002192 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002193 }
2194 LY_ARRAY_FOR(submodp->revs, u) {
2195 yprp_revision(ctx, &submodp->revs[u]);
2196 }
2197 /* body-stmts */
2198 yang_print_parsed_body(ctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199
2200 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002201 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202 ly_print_flush(out);
2203
2204 return LY_SUCCESS;
2205}
2206
2207LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002208yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002209{
Radek Krejciadcf63d2021-02-09 10:21:18 +01002210 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *ctx = &ctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002211
2212 yprc_node(ctx, node);
2213
2214 ly_print_flush(out);
2215 return LY_SUCCESS;
2216}
2217
2218LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002219yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002220{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002221 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002222 struct lysc_module *modc = module->compiled;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002223 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options}, *ctx = &ctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002224
Michal Vasko5233e962020-08-14 14:26:20 +02002225 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002226 LEVEL++;
2227
Radek Krejci693262f2019-04-29 15:23:20 +02002228 /* module-header-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002229 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2230 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2231
Michal Vasko7c8439f2020-08-05 13:25:19 +02002232 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002233
2234 /* meta-stmts */
2235 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002236 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002237 }
2238 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2239 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2240 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2241 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2242
2243 /* revision-stmts */
2244 if (module->revision) {
Michal Vasko5233e962020-08-14 14:26:20 +02002245 ly_print_(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
Radek Krejci693262f2019-04-29 15:23:20 +02002246 }
2247
2248 /* body-stmts */
2249 if (modc->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002250 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002251 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2252 }
2253
Radek Krejci80d281e2020-09-14 17:42:54 +02002254 LY_ARRAY_FOR(module->identities, u) {
2255 yprc_identity(ctx, &module->identities[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02002256 }
2257
Radek Krejci52f65552020-09-01 17:03:35 +02002258 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002259 struct lysc_node *data;
2260 struct lysc_node_action *rpc;
2261 struct lysc_node_notif *notif;
2262
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002263 LY_LIST_FOR(modc->data, data) {
2264 yprc_node(ctx, data);
2265 }
Radek Krejci693262f2019-04-29 15:23:20 +02002266
Radek Krejci2a9fc652021-01-22 17:44:34 +01002267 LY_LIST_FOR(modc->rpcs, rpc) {
2268 yprc_action(ctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002269 }
Radek Krejci693262f2019-04-29 15:23:20 +02002270
Radek Krejci2a9fc652021-01-22 17:44:34 +01002271 LY_LIST_FOR(modc->notifs, notif) {
2272 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002273 }
Radek Krejci693262f2019-04-29 15:23:20 +02002274 }
2275
2276 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002277 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002278 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002279
2280 return LY_SUCCESS;
2281}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002282
2283/**
2284 * @param[in] count Number of extensions to print, 0 to print them all.
2285 */
2286static void
2287yprc_extension_instances(struct lys_ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
2288 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2289{
2290 LY_ARRAY_COUNT_TYPE u;
2291
2292 if (!count && ext) {
2293 count = LY_ARRAY_COUNT(ext);
2294 }
2295 LY_ARRAY_FOR(ext, u) {
2296 ly_bool inner_flag = 0;
2297
2298 if (!count) {
2299 break;
2300 }
2301
2302 count--;
2303 if ((ext->insubstmt != substmt) || (ext->insubstmt_index != substmt_index)) {
2304 continue;
2305 }
2306
2307 ypr_open(ctx->out, flag);
2308 if (ext[u].argument) {
2309 ly_print_(ctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2310 ypr_encode(ctx->out, ext[u].argument, -1);
2311 ly_print_(ctx->out, "\"");
2312 } else {
2313 ly_print_(ctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
2314 }
2315
2316 LEVEL++;
2317 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext[u].exts, &inner_flag, 0);
2318
2319 if (ext[u].def->plugin->sprinter) {
2320 ext[u].def->plugin->sprinter(ctx, &ext[u], &inner_flag);
2321 }
2322
2323 LEVEL--;
2324 ypr_close(ctx, inner_flag);
2325 }
2326}
2327
2328void
2329lysc_print_extension_instance(struct lys_ypr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag)
2330{
2331 LY_ARRAY_COUNT_TYPE u, v;
2332
2333 LY_ARRAY_FOR(ext->substmts, u) {
2334 switch (ext->substmts[u].stmt) {
2335 case LY_STMT_CHOICE:
2336 case LY_STMT_CONTAINER: {
2337 const struct lysc_node *node;
2338
2339 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
2340 ypr_open(ctx->out, flag);
2341 yprc_node(ctx, node);
2342 }
2343 break;
2344 }
2345 case LY_STMT_DESCRIPTION:
2346 case LY_STMT_REFERENCE:
2347 case LY_STMT_UNITS:
2348 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2349 if (*(const char **)ext->substmts[u].storage) {
2350 ypr_open(ctx->out, flag);
2351 ypr_substmt(ctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
2352 }
2353 } else {
2354 const char **strings = *(const char ***)ext->substmts[u].storage;
2355 LY_ARRAY_FOR(strings, v) {
2356 ypr_open(ctx->out, flag);
2357 ypr_substmt(ctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
2358 }
2359 }
2360 break;
2361 case LY_STMT_IF_FEATURE:
2362 /* nothing to do */
2363 break;
2364 case LY_STMT_STATUS:
2365 ypr_status(ctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2366 break;
2367 case LY_STMT_TYPE:
2368 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2369 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2370 ypr_open(ctx->out, flag);
2371 yprc_type(ctx, *(const struct lysc_type **)ext->substmts[u].storage);
2372 }
2373 } else {
2374 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2375 LY_ARRAY_FOR(types, v) {
2376 ypr_open(ctx->out, flag);
2377 yprc_type(ctx, types[v]);
2378 }
2379 }
2380 break;
2381 /* TODO support other substatements */
2382 default:
2383 LOGWRN(ctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
2384 ly_stmt2str(ext->substmts[u].stmt));
2385 break;
2386 }
2387 }
2388}