blob: c5700b451f000530490770676e89a83d4312b1bc [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 Krejcifc596f92021-02-26 22:40:26 +0100206yprp_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt 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 Krejcid3ca0632019-04-16 16:54:54 +0200212
213 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200214 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200215 }
216 LY_ARRAY_FOR(ext, u) {
Radek Krejci85ac8312021-03-03 20:21:33 +0100217 struct lysp_ext *ext_def = NULL;
218
Radek Krejcid3ca0632019-04-16 16:54:54 +0200219 if (!count) {
220 break;
221 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200222
Radek Krejcid3ca0632019-04-16 16:54:54 +0200223 count--;
Radek Krejciab430862021-03-02 20:13:40 +0100224 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200225 continue;
226 }
227
Radek Krejci85ac8312021-03-03 20:21:33 +0100228 lysp_ext_find_definition(ctx->module->ctx, &ext[u], NULL, &ext_def);
229 if (!ext_def) {
230 continue;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200231 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100232
233 ypr_open(ctx->out, flag);
234
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100235 if (ext_def->argname) {
Michal Vasko5233e962020-08-14 14:26:20 +0200236 ly_print_(ctx->out, "%*s%s \"", INDENT, ext[u].name);
Radek Krejci85ac8312021-03-03 20:21:33 +0100237 lysp_ext_instance_resolve_argument(ctx->module->ctx, &ext[u], ext_def);
238 ypr_encode(ctx->out, ext[u].argument, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200239 ly_print_(ctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200240 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200241 ly_print_(ctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200242 }
243
244 child_presence = 0;
245 LEVEL++;
246 LY_LIST_FOR(ext[u].child, stmt) {
247 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
248 continue;
249 }
250 if (!child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200251 ly_print_(ctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200252 child_presence = 1;
253 }
254 yprp_stmt(ctx, stmt);
255 }
256 LEVEL--;
257 if (child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200258 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200259 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200260 ly_print_(ctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200261 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200262 }
263}
264
Radek Krejcifc596f92021-02-26 22:40:26 +0100265static void yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +0100266 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200267
268static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100269ypr_substmt(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200270{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200271 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200272 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200273
274 if (!text) {
275 /* nothing to print */
276 return;
277 }
278
Radek Krejcieccf6602021-02-05 19:42:54 +0100279 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
280 ly_print_(ctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +0100282 ypr_text(ctx, stmt_attr_info[substmt].name, text,
283 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200284 }
285
286 LEVEL++;
287 LY_ARRAY_FOR(ext, u) {
Radek Krejciab430862021-03-02 20:13:40 +0100288 if ((((struct lysp_ext_instance *)ext)[u].parent_stmt != substmt) || (((struct lysp_ext_instance *)ext)[u].parent_stmt_index != substmt_index)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200289 continue;
290 }
Radek Krejciadcf63d2021-02-09 10:21:18 +0100291 if (ctx->schema == LYS_YPR_PARSED) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200292 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200293 } else {
Michal Vasko22df3f02020-08-24 13:29:22 +0200294 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200295 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200296 }
297 LEVEL--;
298 ypr_close(ctx, extflag);
299}
300
301static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100302ypr_unsigned(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200303{
304 char *str;
305
Radek Krejci1deb5be2020-08-26 16:43:36 +0200306 if (asprintf(&str, "%lu", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200307 LOGMEM(ctx->module->ctx);
308 return;
309 }
310 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200311 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200312 free(str);
313}
314
315static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100316ypr_signed(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200317{
318 char *str;
319
Radek Krejci1deb5be2020-08-26 16:43:36 +0200320 if (asprintf(&str, "%ld", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200321 LOGMEM(ctx->module->ctx);
322 return;
323 }
324 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200325 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200326 free(str);
327}
328
329static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100330yprp_revision(struct lys_ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200331{
332 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +0200333 ly_print_(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200334 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100335 yprp_extension_instances(ctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100336 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
337 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200338 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200339 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200341 ly_print_(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200342 }
343}
344
345static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100346ypr_mandatory(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200347{
348 if (flags & LYS_MAND_MASK) {
349 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100350 ypr_substmt(ctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200351 }
352}
353
354static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100355ypr_config(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200356{
357 if (flags & LYS_CONFIG_MASK) {
358 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100359 ypr_substmt(ctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200360 }
361}
362
363static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100364ypr_status(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200365{
366 const char *status = NULL;
367
368 if (flags & LYS_STATUS_CURR) {
369 ypr_open(ctx->out, flag);
370 status = "current";
371 } else if (flags & LYS_STATUS_DEPRC) {
372 ypr_open(ctx->out, flag);
373 status = "deprecated";
374 } else if (flags & LYS_STATUS_OBSLT) {
375 ypr_open(ctx->out, flag);
376 status = "obsolete";
377 }
Radek Krejci693262f2019-04-29 15:23:20 +0200378
Radek Krejcifc596f92021-02-26 22:40:26 +0100379 ypr_substmt(ctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380}
381
382static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100383ypr_description(struct lys_ypr_ctx *ctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384{
385 if (dsc) {
386 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100387 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200388 }
389}
390
391static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100392ypr_reference(struct lys_ypr_ctx *ctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393{
394 if (ref) {
395 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100396 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200397 }
398}
399
400static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100401yprp_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 +0200402{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200403 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200404 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405
Michal Vasko7f45cf22020-10-01 12:49:44 +0200406 LY_ARRAY_FOR(iffs, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407 ypr_open(ctx->out, flag);
408 extflag = 0;
409
Michal Vasko7f45cf22020-10-01 12:49:44 +0200410 ly_print_(ctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200411
412 /* extensions */
413 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200414 LY_ARRAY_FOR(exts, v) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100415 yprp_extension_instances(ctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 }
417 LEVEL--;
418 ypr_close(ctx, extflag);
419 }
420}
421
422static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100423yprp_extension(struct lys_ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200424{
Radek Krejci857189e2020-09-01 13:26:36 +0200425 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200426 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200427
Michal Vasko5233e962020-08-14 14:26:20 +0200428 ly_print_(ctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200429 LEVEL++;
430
431 if (ext->exts) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100432 yprp_extension_instances(ctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 }
434
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100435 if (ext->argname) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200436 ypr_open(ctx->out, &flag);
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100437 ly_print_(ctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200438 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200440 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100441 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
442 yprp_extension_instances(ctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200443 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 }
445 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100446 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447 ypr_open(ctx->out, &flag2);
Radek Krejcifc596f92021-02-26 22:40:26 +0100448 ypr_substmt(ctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200450 LEVEL--;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200451 ypr_close(ctx, flag2);
452 }
453
Radek Krejci693262f2019-04-29 15:23:20 +0200454 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200455 ypr_description(ctx, ext->dsc, ext->exts, &flag);
456 ypr_reference(ctx, ext->ref, ext->exts, &flag);
457
458 LEVEL--;
459 ypr_close(ctx, flag);
460}
461
462static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100463yprp_feature(struct lys_ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464{
Radek Krejci857189e2020-09-01 13:26:36 +0200465 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466
Michal Vasko5233e962020-08-14 14:26:20 +0200467 ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200468 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100469 yprp_extension_instances(ctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200470 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
471 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200472 ypr_description(ctx, feat->dsc, feat->exts, &flag);
473 ypr_reference(ctx, feat->ref, feat->exts, &flag);
474 LEVEL--;
475 ypr_close(ctx, flag);
476}
477
478static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100479yprp_identity(struct lys_ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200480{
Radek Krejci857189e2020-09-01 13:26:36 +0200481 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200482 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483
Michal Vasko5233e962020-08-14 14:26:20 +0200484 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200485 LEVEL++;
486
Radek Krejci39b7fc22021-02-26 23:29:18 +0100487 yprp_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200488 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200489
490 LY_ARRAY_FOR(ident->bases, u) {
491 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100492 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200493 }
494
Radek Krejci693262f2019-04-29 15:23:20 +0200495 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200496 ypr_description(ctx, ident->dsc, ident->exts, &flag);
497 ypr_reference(ctx, ident->ref, ident->exts, &flag);
498
499 LEVEL--;
500 ypr_close(ctx, flag);
501}
502
503static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100504yprc_identity(struct lys_ypr_ctx *ctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200505{
Radek Krejci857189e2020-09-01 13:26:36 +0200506 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200507 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200508
Michal Vasko5233e962020-08-14 14:26:20 +0200509 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200510 LEVEL++;
511
Radek Krejci39b7fc22021-02-26 23:29:18 +0100512 yprc_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200513
514 LY_ARRAY_FOR(ident->derived, u) {
515 ypr_open(ctx->out, &flag);
516 if (ctx->module != ident->derived[u]->module) {
Michal Vasko5233e962020-08-14 14:26:20 +0200517 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 +0200518 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200519 ly_print_(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200520 }
521 }
522
523 ypr_status(ctx, ident->flags, ident->exts, &flag);
524 ypr_description(ctx, ident->dsc, ident->exts, &flag);
525 ypr_reference(ctx, ident->ref, ident->exts, &flag);
526
527 LEVEL--;
528 ypr_close(ctx, flag);
529}
530
531static void
Radek Krejci39b7fc22021-02-26 23:29:18 +0100532yprp_restr(struct lys_ypr_ctx *ctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533{
Radek Krejci857189e2020-09-01 13:26:36 +0200534 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200535
536 if (!restr) {
537 return;
538 }
539
540 ypr_open(ctx->out, flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +0100541 ly_print_(ctx->out, "%*s%s \"", INDENT, ly_stmt2str(stmt));
Radek Krejcif13b87b2020-12-01 22:02:17 +0100542 ypr_encode(ctx->out,
543 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
544 restr->arg.str : &restr->arg.str[1], -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200545 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200546
547 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100548 yprp_extension_instances(ctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100549 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200550 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
551 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100552 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553 }
554 if (restr->emsg) {
555 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100556 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200557 }
558 if (restr->eapptag) {
559 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100560 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200561 }
Radek Krejci693262f2019-04-29 15:23:20 +0200562 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
563 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
564
Radek Krejcid3ca0632019-04-16 16:54:54 +0200565 LEVEL--;
566 ypr_close(ctx, inner_flag);
567}
568
569static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100570yprc_must(struct lys_ypr_ctx *ctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200571{
Radek Krejci857189e2020-09-01 13:26:36 +0200572 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200573
574 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200575 ly_print_(ctx->out, "%*smust \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200576 ypr_encode(ctx->out, must->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200577 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200578
579 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100580 yprc_extension_instances(ctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200581 if (must->emsg) {
582 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100583 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200584 }
585 if (must->eapptag) {
586 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100587 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200588 }
589 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
590 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
591
592 LEVEL--;
593 ypr_close(ctx, inner_flag);
594}
595
596static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100597yprc_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 +0200598{
Radek Krejci857189e2020-09-01 13:26:36 +0200599 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200600 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200601
Radek Krejci334ccc72019-06-12 13:49:29 +0200602 if (!range) {
603 return;
604 }
605
Radek Krejci693262f2019-04-29 15:23:20 +0200606 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200607 ly_print_(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200608 LY_ARRAY_FOR(range->parts, u) {
609 if (u > 0) {
Michal Vasko5233e962020-08-14 14:26:20 +0200610 ly_print_(ctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200611 }
612 if (range->parts[u].max_64 == range->parts[u].min_64) {
613 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200614 ly_print_(ctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200615 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200616 ly_print_(ctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200617 }
618 } else {
619 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200620 ly_print_(ctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200621 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200622 ly_print_(ctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200623 }
624 }
625 }
Michal Vasko5233e962020-08-14 14:26:20 +0200626 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200627
628 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100629 yprc_extension_instances(ctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200630 if (range->emsg) {
631 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100632 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200633 }
634 if (range->eapptag) {
635 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100636 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200637 }
638 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
639 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
640
641 LEVEL--;
642 ypr_close(ctx, inner_flag);
643}
644
645static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100646yprc_pattern(struct lys_ypr_ctx *ctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200647{
Radek Krejci857189e2020-09-01 13:26:36 +0200648 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200649
650 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200651 ly_print_(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200652 ypr_encode(ctx->out, pattern->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200653 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200654
655 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100656 yprc_extension_instances(ctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200657 if (pattern->inverted) {
658 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
659 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100660 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 }
662 if (pattern->emsg) {
663 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100664 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200665 }
666 if (pattern->eapptag) {
667 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100668 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200669 }
670 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
671 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
672
673 LEVEL--;
674 ypr_close(ctx, inner_flag);
675}
676
677static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100678yprp_when(struct lys_ypr_ctx *ctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200679{
Radek Krejci857189e2020-09-01 13:26:36 +0200680 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200681
682 if (!when) {
683 return;
684 }
685 ypr_open(ctx->out, flag);
686
Michal Vasko5233e962020-08-14 14:26:20 +0200687 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200688 ypr_encode(ctx->out, when->cond, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200689 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200690
691 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100692 yprp_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200693 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
694 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
695 LEVEL--;
696 ypr_close(ctx, inner_flag);
697}
698
699static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100700yprc_when(struct lys_ypr_ctx *ctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200701{
Radek Krejci857189e2020-09-01 13:26:36 +0200702 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200703
704 if (!when) {
705 return;
706 }
707 ypr_open(ctx->out, flag);
708
Michal Vasko5233e962020-08-14 14:26:20 +0200709 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200710 ypr_encode(ctx->out, when->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200711 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200712
713 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100714 yprc_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200715 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
716 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
717 LEVEL--;
718 ypr_close(ctx, inner_flag);
719}
720
721static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100722yprp_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 +0200723{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200724 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200725 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200726
727 LY_ARRAY_FOR(items, u) {
728 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200729 if (type == LY_TYPE_BITS) {
Michal Vasko5233e962020-08-14 14:26:20 +0200730 ly_print_(ctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200731 } else { /* LY_TYPE_ENUM */
Michal Vasko5233e962020-08-14 14:26:20 +0200732 ly_print_(ctx->out, "%*senum \"", INDENT);
Radek Krejci7871ce52019-06-11 16:44:56 +0200733 ypr_encode(ctx->out, items[u].name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200734 ly_print_(ctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200735 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200736 inner_flag = 0;
737 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100738 yprp_extension_instances(ctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200739 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200740 if (items[u].flags & LYS_SET_VALUE) {
741 if (type == LY_TYPE_BITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100742 ypr_unsigned(ctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743 } else { /* LY_TYPE_ENUM */
Radek Krejcifc596f92021-02-26 22:40:26 +0100744 ypr_signed(ctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200745 }
746 }
Radek Krejci693262f2019-04-29 15:23:20 +0200747 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200748 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
749 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
750 LEVEL--;
751 ypr_close(ctx, inner_flag);
752 }
753}
754
755static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100756yprp_type(struct lys_ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200757{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200758 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200759 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200760
Michal Vasko5233e962020-08-14 14:26:20 +0200761 ly_print_(ctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200762 LEVEL++;
763
Radek Krejci39b7fc22021-02-26 23:29:18 +0100764 yprp_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200765
Radek Krejci39b7fc22021-02-26 23:29:18 +0100766 yprp_restr(ctx, type->range, LY_STMT_RANGE, &flag);
767 yprp_restr(ctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100769 yprp_restr(ctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200770 }
Radek Krejci693262f2019-04-29 15:23:20 +0200771 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
772 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773
774 if (type->path) {
775 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100776 ypr_substmt(ctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200777 }
778 if (type->flags & LYS_SET_REQINST) {
779 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100780 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200781 }
782 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100783 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200784 }
785 LY_ARRAY_FOR(type->bases, u) {
786 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100787 ypr_substmt(ctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200788 }
789 LY_ARRAY_FOR(type->types, u) {
790 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200791 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200792 }
793
794 LEVEL--;
795 ypr_close(ctx, flag);
796}
797
798static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100799yprc_dflt_value(struct lys_ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200800{
Radek Krejci857189e2020-09-01 13:26:36 +0200801 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200802 const char *str;
803
Michal Vaskoba99a3e2020-08-18 15:50:05 +0200804 str = value->realtype->plugin->print(value, LY_PREF_JSON, NULL, &dynamic);
Radek Krejcifc596f92021-02-26 22:40:26 +0100805 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200806 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200807 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200808 }
809}
810
811static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100812yprc_type(struct lys_ypr_ctx *ctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200813{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200814 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200815 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200816
Michal Vasko5233e962020-08-14 14:26:20 +0200817 ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200818 LEVEL++;
819
Radek Krejci39b7fc22021-02-26 23:29:18 +0100820 yprc_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200821
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200822 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200823 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200824 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200825 yprc_range(ctx, bin->length, type->basetype, &flag);
826 break;
827 }
828 case LY_TYPE_UINT8:
829 case LY_TYPE_UINT16:
830 case LY_TYPE_UINT32:
831 case LY_TYPE_UINT64:
832 case LY_TYPE_INT8:
833 case LY_TYPE_INT16:
834 case LY_TYPE_INT32:
835 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200836 struct lysc_type_num *num = (struct lysc_type_num *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200837 yprc_range(ctx, num->range, type->basetype, &flag);
838 break;
839 }
840 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200841 struct lysc_type_str *str = (struct lysc_type_str *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200842 yprc_range(ctx, str->length, type->basetype, &flag);
843 LY_ARRAY_FOR(str->patterns, u) {
844 yprc_pattern(ctx, str->patterns[u], &flag);
845 }
846 break;
847 }
848 case LY_TYPE_BITS:
849 case LY_TYPE_ENUM: {
850 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200851 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200852 LY_ARRAY_FOR(bits->bits, u) {
853 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200854 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200855
856 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200857 ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
Radek Krejci693262f2019-04-29 15:23:20 +0200858 ypr_encode(ctx->out, item->name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200859 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200860 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200861 if (type->basetype == LY_TYPE_BITS) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100862 yprc_extension_instances(ctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100863 ypr_unsigned(ctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200864 } else { /* LY_TYPE_ENUM */
Radek Krejci39b7fc22021-02-26 23:29:18 +0100865 yprc_extension_instances(ctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100866 ypr_signed(ctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200867 }
868 ypr_status(ctx, item->flags, item->exts, &inner_flag);
869 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
870 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
871 LEVEL--;
872 ypr_close(ctx, inner_flag);
873 }
874 break;
875 }
876 case LY_TYPE_BOOL:
877 case LY_TYPE_EMPTY:
878 /* nothing to do */
879 break;
880 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200881 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200882 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100883 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200884 yprc_range(ctx, dec->range, dec->basetype, &flag);
885 break;
886 }
887 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200888 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200889 LY_ARRAY_FOR(ident->bases, u) {
890 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100891 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200892 }
893 break;
894 }
895 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200896 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200897 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100898 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200899 break;
900 }
901 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200902 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200903 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100904 ypr_substmt(ctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
905 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200906 yprc_type(ctx, lr->realtype);
907 break;
908 }
909 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200910 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200911 LY_ARRAY_FOR(un->types, u) {
912 ypr_open(ctx->out, &flag);
913 yprc_type(ctx, un->types[u]);
914 }
915 break;
916 }
917 default:
918 LOGINT(ctx->module->ctx);
919 }
920
921 LEVEL--;
922 ypr_close(ctx, flag);
923}
924
925static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100926yprp_typedef(struct lys_ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200927{
Michal Vasko5233e962020-08-14 14:26:20 +0200928 ly_print_(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200929 LEVEL++;
930
Radek Krejci39b7fc22021-02-26 23:29:18 +0100931 yprp_extension_instances(ctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200932
Radek Krejci693262f2019-04-29 15:23:20 +0200933 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200934
935 if (tpdf->units) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100936 ypr_substmt(ctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200937 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200938 if (tpdf->dflt.str) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100939 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200940 }
941
Radek Krejci693262f2019-04-29 15:23:20 +0200942 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200943 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
944 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
945
946 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200947 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200948}
949
Radek Krejciadcf63d2021-02-09 10:21:18 +0100950static void yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node);
951static void yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node);
952static void yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action);
953static void yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200954
955static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100956yprp_grouping(struct lys_ypr_ctx *ctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200957{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200958 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200959 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200960 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100961 struct lysp_node_action *action;
962 struct lysp_node_notif *notif;
963 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200964
Michal Vasko5233e962020-08-14 14:26:20 +0200965 ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200966 LEVEL++;
967
Radek Krejci39b7fc22021-02-26 23:29:18 +0100968 yprp_extension_instances(ctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200969 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +0200970 ypr_description(ctx, grp->dsc, grp->exts, &flag);
971 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200972
973 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200974 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200975 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200976 }
977
Radek Krejci2a9fc652021-01-22 17:44:34 +0100978 LY_LIST_FOR(grp->groupings, subgrp) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200979 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100980 yprp_grouping(ctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200981 }
982
Radek Krejci01180ac2021-01-27 08:48:22 +0100983 LY_LIST_FOR(grp->child, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +0200984 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200985 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200986 }
987
Radek Krejci2a9fc652021-01-22 17:44:34 +0100988 LY_LIST_FOR(grp->actions, action) {
989 ypr_open(ctx->out, &flag);
990 yprp_action(ctx, action);
991 }
992
993 LY_LIST_FOR(grp->notifs, notif) {
994 ypr_open(ctx->out, &flag);
995 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200996 }
997
998 LEVEL--;
999 ypr_close(ctx, flag);
1000}
1001
1002static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001003yprp_inout(struct lys_ypr_ctx *ctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001005 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001007 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001008
Radek Krejci01180ac2021-01-27 08:48:22 +01001009 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001010 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001011 return;
1012 }
1013 ypr_open(ctx->out, flag);
1014
Michal Vasko544e58a2021-01-28 14:33:41 +01001015 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016 LEVEL++;
1017
Radek Krejci39b7fc22021-02-26 23:29:18 +01001018 yprp_extension_instances(ctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001019 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001020 yprp_restr(ctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021 }
1022 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001023 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001025 LY_LIST_FOR(inout->groupings, grp) {
1026 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001027 }
1028
Radek Krejci01180ac2021-01-27 08:48:22 +01001029 LY_LIST_FOR(inout->child, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001030 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001031 }
1032
1033 LEVEL--;
1034 ypr_close(ctx, 1);
1035}
1036
1037static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001038yprc_inout(struct lys_ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001039{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001040 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001041 struct lysc_node *data;
1042
Radek Krejci01180ac2021-01-27 08:48:22 +01001043 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001044 /* input/output is empty */
1045 return;
1046 }
1047 ypr_open(ctx->out, flag);
1048
Michal Vasko544e58a2021-01-28 14:33:41 +01001049 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001050 LEVEL++;
1051
Radek Krejci39b7fc22021-02-26 23:29:18 +01001052 yprc_extension_instances(ctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001053 LY_ARRAY_FOR(inout->musts, u) {
1054 yprc_must(ctx, &inout->musts[u], NULL);
1055 }
1056
Radek Krejci52f65552020-09-01 17:03:35 +02001057 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001058 LY_LIST_FOR(inout->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001059 yprc_node(ctx, data);
1060 }
Radek Krejci693262f2019-04-29 15:23:20 +02001061 }
1062
1063 LEVEL--;
1064 ypr_close(ctx, 1);
1065}
1066
1067static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001068yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001069{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001070 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001071 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001073 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074
Michal Vasko5233e962020-08-14 14:26:20 +02001075 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076
1077 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001078 yprp_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001079 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080
1081 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001082 yprp_restr(ctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 }
Radek Krejci693262f2019-04-29 15:23:20 +02001084 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001085 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1086 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1087
1088 LY_ARRAY_FOR(notif->typedefs, u) {
1089 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001090 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 }
1092
Radek Krejci2a9fc652021-01-22 17:44:34 +01001093 LY_LIST_FOR(notif->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001095 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001096 }
1097
Radek Krejci01180ac2021-01-27 08:48:22 +01001098 LY_LIST_FOR(notif->child, data) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001099 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001100 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001101 }
1102
1103 LEVEL--;
1104 ypr_close(ctx, flag);
1105}
1106
1107static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001108yprc_notification(struct lys_ypr_ctx *ctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001109{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001110 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001111 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001112 struct lysc_node *data;
1113
Michal Vasko5233e962020-08-14 14:26:20 +02001114 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001115
1116 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001117 yprc_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001118
1119 LY_ARRAY_FOR(notif->musts, u) {
1120 yprc_must(ctx, &notif->musts[u], &flag);
1121 }
1122 ypr_status(ctx, notif->flags, notif->exts, &flag);
1123 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1124 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1125
Radek Krejci52f65552020-09-01 17:03:35 +02001126 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001127 LY_LIST_FOR(notif->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001128 ypr_open(ctx->out, &flag);
1129 yprc_node(ctx, data);
1130 }
Radek Krejci693262f2019-04-29 15:23:20 +02001131 }
1132
1133 LEVEL--;
1134 ypr_close(ctx, flag);
1135}
1136
1137static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001138yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001139{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001140 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001141 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001142 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001143
Michal Vasko5233e962020-08-14 14:26:20 +02001144 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001145
1146 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001147 yprp_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001148 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1149 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001150 ypr_description(ctx, action->dsc, action->exts, &flag);
1151 ypr_reference(ctx, action->ref, action->exts, &flag);
1152
1153 LY_ARRAY_FOR(action->typedefs, u) {
1154 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001155 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001156 }
1157
Radek Krejci2a9fc652021-01-22 17:44:34 +01001158 LY_LIST_FOR(action->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001159 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001160 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161 }
1162
Radek Krejci693262f2019-04-29 15:23:20 +02001163 yprp_inout(ctx, &action->input, &flag);
1164 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001165
1166 LEVEL--;
1167 ypr_close(ctx, flag);
1168}
1169
1170static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001171yprc_action(struct lys_ypr_ctx *ctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001172{
Radek Krejci857189e2020-09-01 13:26:36 +02001173 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001174
Michal Vasko5233e962020-08-14 14:26:20 +02001175 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001176
1177 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001178 yprc_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001179 ypr_status(ctx, action->flags, action->exts, &flag);
1180 ypr_description(ctx, action->dsc, action->exts, &flag);
1181 ypr_reference(ctx, action->ref, action->exts, &flag);
1182
Michal Vasko544e58a2021-01-28 14:33:41 +01001183 yprc_inout(ctx, &action->input, &flag);
1184 yprc_inout(ctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001185
1186 LEVEL--;
1187 ypr_close(ctx, flag);
1188}
1189
1190static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001191yprp_node_common1(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001192{
Michal Vasko5233e962020-08-14 14:26:20 +02001193 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001194 LEVEL++;
1195
Radek Krejci39b7fc22021-02-26 23:29:18 +01001196 yprp_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001197 yprp_when(ctx, lysp_node_when(node), flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001198 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001199}
1200
1201static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001202yprc_node_common1(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001204 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001205 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001206
Michal Vasko5233e962020-08-14 14:26:20 +02001207 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001208 LEVEL++;
1209
Radek Krejci39b7fc22021-02-26 23:29:18 +01001210 yprc_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001211
1212 when = lysc_node_when(node);
1213 LY_ARRAY_FOR(when, u) {
1214 yprc_when(ctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001215 }
Radek Krejci693262f2019-04-29 15:23:20 +02001216}
1217
1218/* macr oto unify the code */
1219#define YPR_NODE_COMMON2 \
1220 ypr_config(ctx, node->flags, node->exts, flag); \
1221 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1222 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1223 } \
1224 ypr_status(ctx, node->flags, node->exts, flag); \
1225 ypr_description(ctx, node->dsc, node->exts, flag); \
1226 ypr_reference(ctx, node->ref, node->exts, flag)
1227
1228static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001229yprp_node_common2(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001230{
1231 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001232}
1233
1234static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001235yprc_node_common2(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001236{
1237 YPR_NODE_COMMON2;
1238}
1239
1240#undef YPR_NODE_COMMON2
1241
1242static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001243yprp_container(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001244{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001245 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001246 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001247 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001248 struct lysp_node_action *action;
1249 struct lysp_node_notif *notif;
1250 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001251 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1252
Radek Krejci693262f2019-04-29 15:23:20 +02001253 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001254
1255 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001256 yprp_restr(ctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001257 }
1258 if (cont->presence) {
1259 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001260 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261 }
1262
Radek Krejci693262f2019-04-29 15:23:20 +02001263 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001264
1265 LY_ARRAY_FOR(cont->typedefs, u) {
1266 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001267 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001268 }
1269
Radek Krejci2a9fc652021-01-22 17:44:34 +01001270 LY_LIST_FOR(cont->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001271 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001272 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001273 }
1274
1275 LY_LIST_FOR(cont->child, child) {
1276 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001277 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001278 }
1279
Radek Krejci2a9fc652021-01-22 17:44:34 +01001280 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001282 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001283 }
1284
Radek Krejci2a9fc652021-01-22 17:44:34 +01001285 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001287 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288 }
1289
1290 LEVEL--;
1291 ypr_close(ctx, flag);
1292}
1293
1294static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001295yprc_container(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001296{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001297 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001298 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001299 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001300 struct lysc_node_action *action;
1301 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001302 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1303
1304 yprc_node_common1(ctx, node, &flag);
1305
1306 LY_ARRAY_FOR(cont->musts, u) {
1307 yprc_must(ctx, &cont->musts[u], &flag);
1308 }
1309 if (cont->flags & LYS_PRESENCE) {
1310 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001311 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001312 }
1313
1314 yprc_node_common2(ctx, node, &flag);
1315
Radek Krejci52f65552020-09-01 17:03:35 +02001316 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001317 LY_LIST_FOR(cont->child, child) {
1318 ypr_open(ctx->out, &flag);
1319 yprc_node(ctx, child);
1320 }
Radek Krejci693262f2019-04-29 15:23:20 +02001321
Radek Krejci2a9fc652021-01-22 17:44:34 +01001322 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001323 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001324 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001325 }
Radek Krejci693262f2019-04-29 15:23:20 +02001326
Radek Krejci2a9fc652021-01-22 17:44:34 +01001327 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001328 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001329 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001330 }
Radek Krejci693262f2019-04-29 15:23:20 +02001331 }
1332
1333 LEVEL--;
1334 ypr_close(ctx, flag);
1335}
1336
1337static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001338yprp_case(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001339{
Radek Krejci857189e2020-09-01 13:26:36 +02001340 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001341 struct lysp_node *child;
1342 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1343
1344 yprp_node_common1(ctx, node, &flag);
1345 yprp_node_common2(ctx, node, &flag);
1346
1347 LY_LIST_FOR(cas->child, child) {
1348 ypr_open(ctx->out, &flag);
1349 yprp_node(ctx, child);
1350 }
1351
1352 LEVEL--;
1353 ypr_close(ctx, flag);
1354}
1355
1356static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001357yprc_case(struct lys_ypr_ctx *ctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001358{
Radek Krejci857189e2020-09-01 13:26:36 +02001359 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001360 struct lysc_node *child;
1361
Michal Vasko14ed9cd2021-01-28 14:16:25 +01001362 yprc_node_common1(ctx, &cs->node, &flag);
1363 yprc_node_common2(ctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001364
Radek Krejci52f65552020-09-01 17:03:35 +02001365 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001366 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001367 ypr_open(ctx->out, &flag);
1368 yprc_node(ctx, child);
1369 }
Radek Krejci693262f2019-04-29 15:23:20 +02001370 }
1371
1372 LEVEL--;
1373 ypr_close(ctx, flag);
1374}
1375
1376static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001377yprp_choice(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001378{
Radek Krejci857189e2020-09-01 13:26:36 +02001379 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001380 struct lysp_node *child;
1381 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1382
Radek Krejci693262f2019-04-29 15:23:20 +02001383 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001384
Michal Vasko7f45cf22020-10-01 12:49:44 +02001385 if (choice->dflt.str) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001386 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001387 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001388 }
1389
Radek Krejci693262f2019-04-29 15:23:20 +02001390 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001391
1392 LY_LIST_FOR(choice->child, child) {
1393 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001394 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001395 }
1396
1397 LEVEL--;
1398 ypr_close(ctx, flag);
1399}
1400
1401static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001402yprc_choice(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001403{
Radek Krejci857189e2020-09-01 13:26:36 +02001404 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001405 struct lysc_node_case *cs;
1406 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1407
1408 yprc_node_common1(ctx, node, &flag);
1409
1410 if (choice->dflt) {
1411 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001412 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001413 }
1414
1415 yprc_node_common2(ctx, node, &flag);
1416
Michal Vasko22df3f02020-08-24 13:29:22 +02001417 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Radek Krejci693262f2019-04-29 15:23:20 +02001418 ypr_open(ctx->out, &flag);
1419 yprc_case(ctx, cs);
1420 }
1421
1422 LEVEL--;
1423 ypr_close(ctx, flag);
1424}
1425
1426static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001427yprp_leaf(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001428{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001429 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001430 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1431
Radek Krejci693262f2019-04-29 15:23:20 +02001432 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001433
Radek Krejci693262f2019-04-29 15:23:20 +02001434 yprp_type(ctx, &leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001435 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001436 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001437 yprp_restr(ctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001438 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001439 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001440
Radek Krejci693262f2019-04-29 15:23:20 +02001441 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001442
1443 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001444 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001445}
1446
1447static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001448yprc_leaf(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001449{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001450 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001451 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1452
1453 yprc_node_common1(ctx, node, NULL);
1454
1455 yprc_type(ctx, leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001456 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001457 LY_ARRAY_FOR(leaf->musts, u) {
1458 yprc_must(ctx, &leaf->musts[u], NULL);
1459 }
Radek Krejcia1911222019-07-22 17:24:50 +02001460
1461 if (leaf->dflt) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001462 yprc_dflt_value(ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001463 }
Radek Krejci693262f2019-04-29 15:23:20 +02001464
1465 yprc_node_common2(ctx, node, NULL);
1466
1467 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001468 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001469}
1470
1471static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001472yprp_leaflist(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001474 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001475 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1476
Radek Krejci693262f2019-04-29 15:23:20 +02001477 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478
Radek Krejci693262f2019-04-29 15:23:20 +02001479 yprp_type(ctx, &llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001480 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001481 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001482 yprp_restr(ctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001483 }
1484 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001485 ypr_substmt(ctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001486 }
1487
Radek Krejci693262f2019-04-29 15:23:20 +02001488 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489
1490 if (llist->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001491 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001492 }
1493 if (llist->flags & LYS_SET_MAX) {
1494 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001495 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001496 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001497 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001498 }
1499 }
1500
1501 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001502 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503 }
1504
Radek Krejci693262f2019-04-29 15:23:20 +02001505 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001506 ypr_description(ctx, node->dsc, node->exts, NULL);
1507 ypr_reference(ctx, node->ref, node->exts, NULL);
1508
1509 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001510 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511}
1512
1513static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001514yprc_leaflist(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001515{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001516 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001517 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1518
1519 yprc_node_common1(ctx, node, NULL);
1520
1521 yprc_type(ctx, llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001522 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001523 LY_ARRAY_FOR(llist->musts, u) {
1524 yprc_must(ctx, &llist->musts[u], NULL);
1525 }
1526 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001527 yprc_dflt_value(ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001528 }
1529
1530 ypr_config(ctx, node->flags, node->exts, NULL);
1531
Radek Krejcifc596f92021-02-26 22:40:26 +01001532 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001533 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001534 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001535 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001536 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001537 }
1538
Radek Krejcifc596f92021-02-26 22:40:26 +01001539 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001540
1541 ypr_status(ctx, node->flags, node->exts, NULL);
1542 ypr_description(ctx, node->dsc, node->exts, NULL);
1543 ypr_reference(ctx, node->ref, node->exts, NULL);
1544
1545 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001546 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001547}
1548
1549static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001550yprp_list(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001551{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001552 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001553 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001555 struct lysp_node_action *action;
1556 struct lysp_node_notif *notif;
1557 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558 struct lysp_node_list *list = (struct lysp_node_list *)node;
1559
Radek Krejci693262f2019-04-29 15:23:20 +02001560 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561
1562 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001563 yprp_restr(ctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001564 }
1565 if (list->key) {
1566 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001567 ypr_substmt(ctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001568 }
1569 LY_ARRAY_FOR(list->uniques, u) {
1570 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001571 ypr_substmt(ctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001572 }
1573
Michal Vaskoacb8e742020-10-20 10:28:02 +02001574 ypr_config(ctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575
1576 if (list->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001577 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001578 }
1579 if (list->flags & LYS_SET_MAX) {
1580 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001581 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001582 } else {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001583 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001584 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585 }
1586 }
1587
1588 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001589 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001590 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001591 }
1592
Michal Vaskoacb8e742020-10-20 10:28:02 +02001593 ypr_status(ctx, node->flags, node->exts, &flag);
1594 ypr_description(ctx, node->dsc, node->exts, &flag);
1595 ypr_reference(ctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001596
1597 LY_ARRAY_FOR(list->typedefs, u) {
1598 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001599 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600 }
1601
Radek Krejci2a9fc652021-01-22 17:44:34 +01001602 LY_LIST_FOR(list->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001603 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001604 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001605 }
1606
1607 LY_LIST_FOR(list->child, child) {
1608 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001609 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001610 }
1611
Radek Krejci2a9fc652021-01-22 17:44:34 +01001612 LY_LIST_FOR(list->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001613 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001614 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001615 }
1616
Radek Krejci2a9fc652021-01-22 17:44:34 +01001617 LY_LIST_FOR(list->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001618 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001619 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001620 }
1621
1622 LEVEL--;
1623 ypr_close(ctx, flag);
1624}
1625
1626static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001627yprc_list(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001628{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001629 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001630 struct lysc_node_list *list = (struct lysc_node_list *)node;
1631
Michal Vaskoacb8e742020-10-20 10:28:02 +02001632 yprc_node_common1(ctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001633
1634 LY_ARRAY_FOR(list->musts, u) {
1635 yprc_must(ctx, &list->musts[u], NULL);
1636 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001637 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko5233e962020-08-14 14:26:20 +02001638 ly_print_(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001639 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 +02001640 ly_print_(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001641 }
Michal Vasko5233e962020-08-14 14:26:20 +02001642 ly_print_(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001643 }
1644 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02001645 ly_print_(ctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001646 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko5233e962020-08-14 14:26:20 +02001647 ly_print_(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001648 }
1649 ypr_close(ctx, 0);
1650 }
1651
1652 ypr_config(ctx, node->flags, node->exts, NULL);
1653
Radek Krejcifc596f92021-02-26 22:40:26 +01001654 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001655 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001656 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001657 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001658 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001659 }
1660
Radek Krejcifc596f92021-02-26 22:40:26 +01001661 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001662
1663 ypr_status(ctx, node->flags, node->exts, NULL);
1664 ypr_description(ctx, node->dsc, node->exts, NULL);
1665 ypr_reference(ctx, node->ref, node->exts, NULL);
1666
Radek Krejci52f65552020-09-01 17:03:35 +02001667 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001668 struct lysc_node *child;
1669 struct lysc_node_action *action;
1670 struct lysc_node_notif *notif;
1671
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001672 LY_LIST_FOR(list->child, child) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001673 yprc_node(ctx, child);
1674 }
Radek Krejci693262f2019-04-29 15:23:20 +02001675
Radek Krejci2a9fc652021-01-22 17:44:34 +01001676 LY_LIST_FOR(list->actions, action) {
1677 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001678 }
Radek Krejci693262f2019-04-29 15:23:20 +02001679
Radek Krejci2a9fc652021-01-22 17:44:34 +01001680 LY_LIST_FOR(list->notifs, notif) {
1681 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001682 }
Radek Krejci693262f2019-04-29 15:23:20 +02001683 }
1684
1685 LEVEL--;
Michal Vaskoacb8e742020-10-20 10:28:02 +02001686 ypr_close(ctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001687}
1688
1689static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001690yprp_refine(struct lys_ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001691{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001692 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001693 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001694
Michal Vasko5233e962020-08-14 14:26:20 +02001695 ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001696 LEVEL++;
1697
Radek Krejci39b7fc22021-02-26 23:29:18 +01001698 yprp_extension_instances(ctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001699 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001700
1701 LY_ARRAY_FOR(refine->musts, u) {
1702 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001703 yprp_restr(ctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001704 }
1705
1706 if (refine->presence) {
1707 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001708 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001709 }
1710
1711 LY_ARRAY_FOR(refine->dflts, u) {
1712 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001713 ypr_substmt(ctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001714 }
1715
Radek Krejci693262f2019-04-29 15:23:20 +02001716 ypr_config(ctx, refine->flags, refine->exts, &flag);
1717 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001718
1719 if (refine->flags & LYS_SET_MIN) {
1720 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001721 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001722 }
1723 if (refine->flags & LYS_SET_MAX) {
1724 ypr_open(ctx->out, &flag);
1725 if (refine->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001726 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001727 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001728 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001729 }
1730 }
1731
1732 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1733 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1734
1735 LEVEL--;
1736 ypr_close(ctx, flag);
1737}
1738
1739static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001740yprp_augment(struct lys_ypr_ctx *ctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001741{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001742 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001743 struct lysp_node_action *action;
1744 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001745
Michal Vasko5233e962020-08-14 14:26:20 +02001746 ly_print_(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001747 LEVEL++;
1748
Radek Krejci39b7fc22021-02-26 23:29:18 +01001749 yprp_extension_instances(ctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001750 yprp_when(ctx, aug->when, NULL);
1751 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1752 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001753 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1754 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1755
1756 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001757 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001758 }
1759
Radek Krejci2a9fc652021-01-22 17:44:34 +01001760 LY_LIST_FOR(aug->actions, action) {
1761 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001762 }
1763
Radek Krejci2a9fc652021-01-22 17:44:34 +01001764 LY_LIST_FOR(aug->notifs, notif) {
1765 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001766 }
1767
1768 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001769 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001770}
1771
Radek Krejcid3ca0632019-04-16 16:54:54 +02001772static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001773yprp_uses(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001775 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001776 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001778 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779
Radek Krejci693262f2019-04-29 15:23:20 +02001780 yprp_node_common1(ctx, node, &flag);
1781 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001782
1783 LY_ARRAY_FOR(uses->refines, u) {
1784 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001785 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001786 }
1787
Radek Krejci2a9fc652021-01-22 17:44:34 +01001788 LY_LIST_FOR(uses->augments, aug) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001789 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001790 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791 }
1792
1793 LEVEL--;
1794 ypr_close(ctx, flag);
1795}
1796
1797static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001798yprp_anydata(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001800 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001801 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1803
Radek Krejci693262f2019-04-29 15:23:20 +02001804 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001805
1806 LY_ARRAY_FOR(any->musts, u) {
1807 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001808 yprp_restr(ctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809 }
1810
Radek Krejci693262f2019-04-29 15:23:20 +02001811 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812
1813 LEVEL--;
1814 ypr_close(ctx, flag);
1815}
1816
1817static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001818yprc_anydata(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001820 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001821 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001822 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823
Radek Krejci693262f2019-04-29 15:23:20 +02001824 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825
Radek Krejci693262f2019-04-29 15:23:20 +02001826 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001828 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001829 }
1830
Radek Krejci693262f2019-04-29 15:23:20 +02001831 yprc_node_common2(ctx, node, &flag);
1832
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833 LEVEL--;
1834 ypr_close(ctx, flag);
1835}
1836
1837static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001838yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839{
1840 switch (node->nodetype) {
1841 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001842 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843 break;
1844 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001845 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001846 break;
1847 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 break;
1850 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001851 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852 break;
1853 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001854 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855 break;
1856 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001857 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 break;
1859 case LYS_ANYXML:
1860 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001861 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862 break;
1863 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001864 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001865 break;
1866 default:
1867 break;
1868 }
1869}
1870
1871static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001872yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001873{
1874 switch (node->nodetype) {
1875 case LYS_CONTAINER:
1876 yprc_container(ctx, node);
1877 break;
1878 case LYS_CHOICE:
1879 yprc_choice(ctx, node);
1880 break;
1881 case LYS_LEAF:
1882 yprc_leaf(ctx, node);
1883 break;
1884 case LYS_LEAFLIST:
1885 yprc_leaflist(ctx, node);
1886 break;
1887 case LYS_LIST:
1888 yprc_list(ctx, node);
1889 break;
1890 case LYS_ANYXML:
1891 case LYS_ANYDATA:
1892 yprc_anydata(ctx, node);
1893 break;
1894 default:
1895 break;
1896 }
1897}
1898
1899static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001900yprp_deviation(struct lys_ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001902 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903 struct lysp_deviate_add *add;
1904 struct lysp_deviate_rpl *rpl;
1905 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001906 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907
Michal Vasko5233e962020-08-14 14:26:20 +02001908 ly_print_(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909 LEVEL++;
1910
Radek Krejci39b7fc22021-02-26 23:29:18 +01001911 yprp_extension_instances(ctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1913 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1914
fredgan2b11ddb2019-10-21 11:03:39 +08001915 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko5233e962020-08-14 14:26:20 +02001916 ly_print_(ctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001917 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1918 if (elem->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02001919 ly_print_(ctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 LEVEL++;
1921
Radek Krejci39b7fc22021-02-26 23:29:18 +01001922 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02001924 ly_print_(ctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001925 continue;
1926 }
fredgan2b11ddb2019-10-21 11:03:39 +08001927 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001928 add = (struct lysp_deviate_add *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001929 ly_print_(ctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930 LEVEL++;
1931
Radek Krejci39b7fc22021-02-26 23:29:18 +01001932 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001933 ypr_substmt(ctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001934 LY_ARRAY_FOR(add->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001935 yprp_restr(ctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001937 LY_ARRAY_FOR(add->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001938 ypr_substmt(ctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001940 LY_ARRAY_FOR(add->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001941 ypr_substmt(ctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942 }
Radek Krejci693262f2019-04-29 15:23:20 +02001943 ypr_config(ctx, add->flags, add->exts, NULL);
1944 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 if (add->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001946 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001947 }
1948 if (add->flags & LYS_SET_MAX) {
1949 if (add->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001950 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001951 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001952 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953 }
1954 }
fredgan2b11ddb2019-10-21 11:03:39 +08001955 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001956 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001957 ly_print_(ctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001958 LEVEL++;
1959
Radek Krejci39b7fc22021-02-26 23:29:18 +01001960 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001961 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001962 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001964 ypr_substmt(ctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
1965 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001966 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1967 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001968 if (rpl->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001969 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970 }
1971 if (rpl->flags & LYS_SET_MAX) {
1972 if (rpl->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001973 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001975 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 }
1977 }
fredgan2b11ddb2019-10-21 11:03:39 +08001978 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001979 del = (struct lysp_deviate_del *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001980 ly_print_(ctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001981 LEVEL++;
1982
Radek Krejci39b7fc22021-02-26 23:29:18 +01001983 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001984 ypr_substmt(ctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001985 LY_ARRAY_FOR(del->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001986 yprp_restr(ctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001988 LY_ARRAY_FOR(del->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001989 ypr_substmt(ctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001991 LY_ARRAY_FOR(del->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001992 ypr_substmt(ctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993 }
1994 }
1995
1996 LEVEL--;
1997 ypr_close(ctx, 1);
1998 }
1999
2000 LEVEL--;
2001 ypr_close(ctx, 1);
2002}
2003
Michal Vasko7c8439f2020-08-05 13:25:19 +02002004static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002005yang_print_parsed_linkage(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002007 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002008
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002010 if (modp->imports[u].flags & LYS_INTERNAL) {
2011 continue;
2012 }
2013
Michal Vasko5233e962020-08-14 14:26:20 +02002014 ly_print_(ctx->out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002015 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002016 yprp_extension_instances(ctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002017 ypr_substmt(ctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 if (modp->imports[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002019 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002021 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2022 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002024 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002025 }
2026 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002027 if (modp->includes[u].injected) {
2028 /* do not print the includes injected from submodules */
2029 continue;
2030 }
Radek Krejcid3ca0632019-04-16 16:54:54 +02002031 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 +02002032 ly_print_(ctx->out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002034 yprp_extension_instances(ctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 if (modp->includes[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002036 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002038 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2039 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002041 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002042 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02002043 ly_print_(ctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 }
2045 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002046}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047
Michal Vasko7c8439f2020-08-05 13:25:19 +02002048static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002049yang_print_parsed_body(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002050{
2051 LY_ARRAY_COUNT_TYPE u;
2052 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002053 struct lysp_node_action *action;
2054 struct lysp_node_notif *notif;
2055 struct lysp_node_grp *grp;
2056 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02002059 ly_print_(ctx->out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002060 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 }
2062 if (modp->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002063 ly_print_(ctx->out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002064 yprp_extension_instances(ctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065 }
2066
2067 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002068 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002069 }
2070
2071 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002072 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073 }
2074
2075 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002076 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002077 }
2078
Radek Krejci2a9fc652021-01-22 17:44:34 +01002079 LY_LIST_FOR(modp->groupings, grp) {
2080 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081 }
2082
2083 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002084 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085 }
2086
Radek Krejci2a9fc652021-01-22 17:44:34 +01002087 LY_LIST_FOR(modp->augments, aug) {
2088 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089 }
2090
Radek Krejci2a9fc652021-01-22 17:44:34 +01002091 LY_LIST_FOR(modp->rpcs, action) {
2092 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093 }
2094
Radek Krejci2a9fc652021-01-22 17:44:34 +01002095 LY_LIST_FOR(modp->notifs, notif) {
2096 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 }
2098
2099 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002100 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002101 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002102}
2103
2104LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002105yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002106{
2107 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002108 const struct lys_module *module = modp->mod;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002109 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 +02002110
Michal Vasko5233e962020-08-14 14:26:20 +02002111 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002112 LEVEL++;
2113
2114 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002115 if (modp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002116 ypr_substmt(ctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002117 }
2118
Radek Krejcifc596f92021-02-26 22:40:26 +01002119 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2120 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002121
2122 /* linkage-stmts (import/include) */
2123 yang_print_parsed_linkage(ctx, modp);
2124
2125 /* meta-stmts */
2126 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002127 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002128 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002129 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2130 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2131 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2132 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002133
2134 /* revision-stmts */
2135 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002136 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002137 }
2138 LY_ARRAY_FOR(modp->revs, u) {
2139 yprp_revision(ctx, &modp->revs[u]);
2140 }
2141 /* body-stmts */
2142 yang_print_parsed_body(ctx, modp);
2143
2144 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002145 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002146 ly_print_flush(out);
2147
2148 return LY_SUCCESS;
2149}
2150
2151static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002152yprp_belongsto(struct lys_ypr_ctx *ctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002153{
Michal Vaskoc3781c32020-10-06 14:04:08 +02002154 ly_print_(ctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002155 LEVEL++;
Radek Krejcifc596f92021-02-26 22:40:26 +01002156 yprp_extension_instances(ctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2157 ypr_substmt(ctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002158 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002159 ly_print_(ctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002160}
2161
2162LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002163yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002164{
2165 LY_ARRAY_COUNT_TYPE u;
Radek Krejci07a55962021-03-02 20:16:43 +01002166 struct lys_ypr_ctx ctx_ = {
2167 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2168 .options = options
2169 }, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002170
Michal Vasko5233e962020-08-14 14:26:20 +02002171 ly_print_(ctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002172 LEVEL++;
2173
2174 /* submodule-header-stmts */
2175 if (submodp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002176 ypr_substmt(ctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002177 }
2178
2179 yprp_belongsto(ctx, submodp);
2180
2181 /* linkage-stmts (import/include) */
2182 yang_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
2183
2184 /* meta-stmts */
2185 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002186 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002187 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002188 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2189 ypr_substmt(ctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2190 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2191 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002192
2193 /* revision-stmts */
2194 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002195 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002196 }
2197 LY_ARRAY_FOR(submodp->revs, u) {
2198 yprp_revision(ctx, &submodp->revs[u]);
2199 }
2200 /* body-stmts */
2201 yang_print_parsed_body(ctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202
2203 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002204 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002205 ly_print_flush(out);
2206
2207 return LY_SUCCESS;
2208}
2209
2210LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002211yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002212{
Radek Krejciadcf63d2021-02-09 10:21:18 +01002213 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *ctx = &ctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002214
2215 yprc_node(ctx, node);
2216
2217 ly_print_flush(out);
2218 return LY_SUCCESS;
2219}
2220
2221LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002222yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002223{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002224 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002225 struct lysc_module *modc = module->compiled;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002226 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options}, *ctx = &ctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002227
Michal Vasko5233e962020-08-14 14:26:20 +02002228 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002229 LEVEL++;
2230
Radek Krejci693262f2019-04-29 15:23:20 +02002231 /* module-header-stmts */
Radek Krejcifc596f92021-02-26 22:40:26 +01002232 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2233 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002234
Michal Vasko7c8439f2020-08-05 13:25:19 +02002235 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002236
2237 /* meta-stmts */
2238 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002239 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002240 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002241 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2242 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2243 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2244 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002245
2246 /* revision-stmts */
2247 if (module->revision) {
Michal Vasko5233e962020-08-14 14:26:20 +02002248 ly_print_(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
Radek Krejci693262f2019-04-29 15:23:20 +02002249 }
2250
2251 /* body-stmts */
2252 if (modc->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002253 ly_print_(out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002254 yprc_extension_instances(ctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02002255 }
2256
Radek Krejci80d281e2020-09-14 17:42:54 +02002257 LY_ARRAY_FOR(module->identities, u) {
2258 yprc_identity(ctx, &module->identities[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02002259 }
2260
Radek Krejci52f65552020-09-01 17:03:35 +02002261 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002262 struct lysc_node *data;
2263 struct lysc_node_action *rpc;
2264 struct lysc_node_notif *notif;
2265
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002266 LY_LIST_FOR(modc->data, data) {
2267 yprc_node(ctx, data);
2268 }
Radek Krejci693262f2019-04-29 15:23:20 +02002269
Radek Krejci2a9fc652021-01-22 17:44:34 +01002270 LY_LIST_FOR(modc->rpcs, rpc) {
2271 yprc_action(ctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002272 }
Radek Krejci693262f2019-04-29 15:23:20 +02002273
Radek Krejci2a9fc652021-01-22 17:44:34 +01002274 LY_LIST_FOR(modc->notifs, notif) {
2275 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002276 }
Radek Krejci693262f2019-04-29 15:23:20 +02002277 }
2278
2279 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002280 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002281 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002282
2283 return LY_SUCCESS;
2284}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002285
2286/**
2287 * @param[in] count Number of extensions to print, 0 to print them all.
2288 */
2289static void
Radek Krejcifc596f92021-02-26 22:40:26 +01002290yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002291 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2292{
2293 LY_ARRAY_COUNT_TYPE u;
2294
2295 if (!count && ext) {
2296 count = LY_ARRAY_COUNT(ext);
2297 }
2298 LY_ARRAY_FOR(ext, u) {
2299 ly_bool inner_flag = 0;
2300
2301 if (!count) {
2302 break;
2303 }
2304
2305 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002306 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002307 continue;
2308 }
2309
2310 ypr_open(ctx->out, flag);
2311 if (ext[u].argument) {
2312 ly_print_(ctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2313 ypr_encode(ctx->out, ext[u].argument, -1);
2314 ly_print_(ctx->out, "\"");
2315 } else {
2316 ly_print_(ctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
2317 }
2318
2319 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002320 yprc_extension_instances(ctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002321
2322 if (ext[u].def->plugin->sprinter) {
2323 ext[u].def->plugin->sprinter(ctx, &ext[u], &inner_flag);
2324 }
2325
2326 LEVEL--;
2327 ypr_close(ctx, inner_flag);
2328 }
2329}
2330
2331void
2332lysc_print_extension_instance(struct lys_ypr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag)
2333{
2334 LY_ARRAY_COUNT_TYPE u, v;
2335
2336 LY_ARRAY_FOR(ext->substmts, u) {
2337 switch (ext->substmts[u].stmt) {
2338 case LY_STMT_CHOICE:
2339 case LY_STMT_CONTAINER: {
2340 const struct lysc_node *node;
2341
2342 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
2343 ypr_open(ctx->out, flag);
2344 yprc_node(ctx, node);
2345 }
2346 break;
2347 }
2348 case LY_STMT_DESCRIPTION:
2349 case LY_STMT_REFERENCE:
2350 case LY_STMT_UNITS:
2351 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2352 if (*(const char **)ext->substmts[u].storage) {
2353 ypr_open(ctx->out, flag);
2354 ypr_substmt(ctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
2355 }
2356 } else {
2357 const char **strings = *(const char ***)ext->substmts[u].storage;
2358 LY_ARRAY_FOR(strings, v) {
2359 ypr_open(ctx->out, flag);
2360 ypr_substmt(ctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
2361 }
2362 }
2363 break;
2364 case LY_STMT_IF_FEATURE:
2365 /* nothing to do */
2366 break;
2367 case LY_STMT_STATUS:
2368 ypr_status(ctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2369 break;
2370 case LY_STMT_TYPE:
2371 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2372 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2373 ypr_open(ctx->out, flag);
2374 yprc_type(ctx, *(const struct lysc_type **)ext->substmts[u].storage);
2375 }
2376 } else {
2377 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2378 LY_ARRAY_FOR(types, v) {
2379 ypr_open(ctx->out, flag);
2380 yprc_type(ctx, types[v]);
2381 }
2382 }
2383 break;
2384 /* TODO support other substatements */
2385 default:
2386 LOGWRN(ctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
2387 ly_stmt2str(ext->substmts[u].stmt));
2388 break;
2389 }
2390 }
2391}