blob: e168396d2d90a8ca22ac6b96f2d990c5fc67b9ae [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_internal.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010030#include "plugins_exts_print.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
48/**
49 * @brief Compiled YANG printer context
50 *
51 * Note that the YANG extensions API provides getter to the members for the extension plugins.
52 */
53struct lys_ypr_ctx {
54 union {
55 struct {
56 struct ly_out *out; /**< output specification */
57 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
58 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
59 const struct lys_module *module; /**< schema to print */
60 };
61 struct lyspr_ctx printer_ctx;
62 };
63
64 /* YANG printer specific members */
65 enum lys_ypr_schema_type schema; /**< type of the schema to print */
66};
67
68/**
Radek Krejcie7b95092019-05-15 11:03:07 +020069 * @brief Print the given text as content of a double quoted YANG string,
70 * including encoding characters that have special meanings. The quotation marks
71 * are not printed.
72 *
73 * Follows RFC 7950, section 6.1.3.
74 *
75 * @param[in] out Output specification.
76 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020077 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020078 * the @p text is printed completely as a NULL-terminated string.
79 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020080static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020081ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020082{
Radek Krejci1deb5be2020-08-26 16:43:36 +020083 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020084 const char *start;
85 char special = 0;
86
87 if (!len) {
88 return;
89 }
90
91 if (len < 0) {
92 len = strlen(text);
93 }
94
95 start = text;
96 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +020097 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +020098 switch (text[i]) {
99 case '\n':
100 case '\t':
101 case '\"':
102 case '\\':
103 special = text[i];
104 break;
105 default:
106 ++start_len;
107 break;
108 }
109
110 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +0200111 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200112 switch (special) {
113 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +0200114 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200115 break;
116 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +0200117 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200118 break;
119 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +0200120 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200121 break;
122 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +0200123 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200124 break;
125 }
126
127 start += start_len + 1;
128 start_len = 0;
129
130 special = 0;
131 }
132 }
133
Michal Vasko5233e962020-08-14 14:26:20 +0200134 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135}
136
137static void
Radek Krejci857189e2020-09-01 13:26:36 +0200138ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200139{
140 if (flag && !*flag) {
141 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200142 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200143 }
144}
145
146static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100147ypr_close(struct lys_ypr_ctx *ctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200148{
149 if (flag) {
Michal Vasko5233e962020-08-14 14:26:20 +0200150 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200152 ly_print_(ctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200153 }
154}
155
156static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100157ypr_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 +0200158{
159 const char *s, *t;
160
161 if (singleline) {
Michal Vasko5233e962020-08-14 14:26:20 +0200162 ly_print_(ctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200163 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200164 ly_print_(ctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200165 LEVEL++;
166
Michal Vasko5233e962020-08-14 14:26:20 +0200167 ly_print_(ctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200168 }
169 t = text;
170 while ((s = strchr(t, '\n'))) {
171 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200172 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200173 t = s + 1;
174 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200175 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200176 }
177 }
178
179 ypr_encode(ctx->out, t, strlen(t));
180 if (closed) {
Michal Vasko5233e962020-08-14 14:26:20 +0200181 ly_print_(ctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200182 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200183 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200184 }
185 if (!singleline) {
186 LEVEL--;
187 }
188}
189
190static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100191yprp_stmt(struct lys_ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200192{
193 struct lysp_stmt *childstmt;
194 const char *s, *t;
195
196 if (stmt->arg) {
197 if (stmt->flags) {
Michal Vasko5233e962020-08-14 14:26:20 +0200198 ly_print_(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200199 LEVEL++;
Michal Vasko5233e962020-08-14 14:26:20 +0200200 ly_print_(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200201 t = stmt->arg;
202 while ((s = strchr(t, '\n'))) {
203 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200204 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200205 t = s + 1;
206 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200207 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200208 }
209 }
210 LEVEL--;
211 ypr_encode(ctx->out, t, strlen(t));
Michal Vasko5233e962020-08-14 14:26:20 +0200212 ly_print_(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200214 ly_print_(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200215 }
216 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200217 ly_print_(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200218 }
219
220 if (stmt->child) {
221 LEVEL++;
222 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200223 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200224 }
225 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200226 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200227 }
228}
229
230/**
231 * @param[in] count Number of extensions to print, 0 to print them all.
232 */
233static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100234yprp_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejci857189e2020-09-01 13:26:36 +0200235 struct lysp_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200236{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200237 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200238 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200239 ly_bool child_presence;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200240
241 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200242 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200243 }
244 LY_ARRAY_FOR(ext, u) {
Radek Krejci85ac8312021-03-03 20:21:33 +0100245 struct lysp_ext *ext_def = NULL;
246
Radek Krejcid3ca0632019-04-16 16:54:54 +0200247 if (!count) {
248 break;
249 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200250
Radek Krejcid3ca0632019-04-16 16:54:54 +0200251 count--;
Radek Krejciab430862021-03-02 20:13:40 +0100252 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200253 continue;
254 }
255
Radek Krejci85ac8312021-03-03 20:21:33 +0100256 lysp_ext_find_definition(ctx->module->ctx, &ext[u], NULL, &ext_def);
257 if (!ext_def) {
258 continue;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200259 }
Radek Krejci85ac8312021-03-03 20:21:33 +0100260
261 ypr_open(ctx->out, flag);
262
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100263 if (ext_def->argname) {
Michal Vasko5233e962020-08-14 14:26:20 +0200264 ly_print_(ctx->out, "%*s%s \"", INDENT, ext[u].name);
Radek Krejci85ac8312021-03-03 20:21:33 +0100265 lysp_ext_instance_resolve_argument(ctx->module->ctx, &ext[u], ext_def);
266 ypr_encode(ctx->out, ext[u].argument, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200267 ly_print_(ctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200268 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200269 ly_print_(ctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200270 }
271
272 child_presence = 0;
273 LEVEL++;
274 LY_LIST_FOR(ext[u].child, stmt) {
275 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
276 continue;
277 }
278 if (!child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200279 ly_print_(ctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200280 child_presence = 1;
281 }
282 yprp_stmt(ctx, stmt);
283 }
284 LEVEL--;
285 if (child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200286 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200287 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200288 ly_print_(ctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200289 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200290 }
291}
292
Radek Krejcifc596f92021-02-26 22:40:26 +0100293static void yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +0100294 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200295
296static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100297ypr_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 +0200298{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200299 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200300 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200301
302 if (!text) {
303 /* nothing to print */
304 return;
305 }
306
Radek Krejcieccf6602021-02-05 19:42:54 +0100307 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
308 ly_print_(ctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200309 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +0100310 ypr_text(ctx, stmt_attr_info[substmt].name, text,
311 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200312 }
313
314 LEVEL++;
315 LY_ARRAY_FOR(ext, u) {
Radek Krejciab430862021-03-02 20:13:40 +0100316 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 +0200317 continue;
318 }
Radek Krejciadcf63d2021-02-09 10:21:18 +0100319 if (ctx->schema == LYS_YPR_PARSED) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200320 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200321 } else {
Michal Vasko22df3f02020-08-24 13:29:22 +0200322 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200323 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 }
325 LEVEL--;
326 ypr_close(ctx, extflag);
327}
328
329static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100330ypr_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 +0200331{
332 char *str;
333
Radek Krejci1deb5be2020-08-26 16:43:36 +0200334 if (asprintf(&str, "%lu", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200335 LOGMEM(ctx->module->ctx);
336 return;
337 }
338 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200339 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 free(str);
341}
342
343static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100344ypr_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 +0200345{
346 char *str;
347
Radek Krejci1deb5be2020-08-26 16:43:36 +0200348 if (asprintf(&str, "%ld", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 LOGMEM(ctx->module->ctx);
350 return;
351 }
352 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200353 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200354 free(str);
355}
356
357static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100358yprp_revision(struct lys_ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200359{
360 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +0200361 ly_print_(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200362 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100363 yprp_extension_instances(ctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100364 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
365 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200366 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200367 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200368 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200369 ly_print_(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200370 }
371}
372
373static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100374ypr_mandatory(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200375{
376 if (flags & LYS_MAND_MASK) {
377 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100378 ypr_substmt(ctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200379 }
380}
381
382static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100383ypr_config(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384{
385 if (flags & LYS_CONFIG_MASK) {
386 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100387 ypr_substmt(ctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200388 }
389}
390
391static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100392ypr_status(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393{
394 const char *status = NULL;
395
396 if (flags & LYS_STATUS_CURR) {
397 ypr_open(ctx->out, flag);
398 status = "current";
399 } else if (flags & LYS_STATUS_DEPRC) {
400 ypr_open(ctx->out, flag);
401 status = "deprecated";
402 } else if (flags & LYS_STATUS_OBSLT) {
403 ypr_open(ctx->out, flag);
404 status = "obsolete";
405 }
Radek Krejci693262f2019-04-29 15:23:20 +0200406
Radek Krejcifc596f92021-02-26 22:40:26 +0100407 ypr_substmt(ctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200408}
409
410static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100411ypr_description(struct lys_ypr_ctx *ctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412{
413 if (dsc) {
414 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100415 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416 }
417}
418
419static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100420ypr_reference(struct lys_ypr_ctx *ctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200421{
422 if (ref) {
423 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100424 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200425 }
426}
427
428static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100429yprp_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 +0200430{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200431 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200432 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433
Michal Vasko7f45cf22020-10-01 12:49:44 +0200434 LY_ARRAY_FOR(iffs, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200435 ypr_open(ctx->out, flag);
436 extflag = 0;
437
Michal Vasko7f45cf22020-10-01 12:49:44 +0200438 ly_print_(ctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439
440 /* extensions */
441 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200442 LY_ARRAY_FOR(exts, v) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100443 yprp_extension_instances(ctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444 }
445 LEVEL--;
446 ypr_close(ctx, extflag);
447 }
448}
449
450static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100451yprp_extension(struct lys_ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200452{
Radek Krejci857189e2020-09-01 13:26:36 +0200453 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200454 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200455
Michal Vasko5233e962020-08-14 14:26:20 +0200456 ly_print_(ctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200457 LEVEL++;
458
459 if (ext->exts) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100460 yprp_extension_instances(ctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100463 if (ext->argname) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464 ypr_open(ctx->out, &flag);
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100465 ly_print_(ctx->out, "%*sargument %s", INDENT, ext->argname);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200466 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200467 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200468 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100469 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
470 yprp_extension_instances(ctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200471 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200472 }
473 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100474 (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 +0200475 ypr_open(ctx->out, &flag2);
Radek Krejcifc596f92021-02-26 22:40:26 +0100476 ypr_substmt(ctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200477 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200478 LEVEL--;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200479 ypr_close(ctx, flag2);
480 }
481
Radek Krejci693262f2019-04-29 15:23:20 +0200482 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 ypr_description(ctx, ext->dsc, ext->exts, &flag);
484 ypr_reference(ctx, ext->ref, ext->exts, &flag);
485
486 LEVEL--;
487 ypr_close(ctx, flag);
488}
489
490static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100491yprp_feature(struct lys_ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200492{
Radek Krejci857189e2020-09-01 13:26:36 +0200493 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494
Michal Vasko5233e962020-08-14 14:26:20 +0200495 ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200496 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100497 yprp_extension_instances(ctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200498 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
499 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200500 ypr_description(ctx, feat->dsc, feat->exts, &flag);
501 ypr_reference(ctx, feat->ref, feat->exts, &flag);
502 LEVEL--;
503 ypr_close(ctx, flag);
504}
505
506static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100507yprp_identity(struct lys_ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508{
Radek Krejci857189e2020-09-01 13:26:36 +0200509 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200510 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200511
Michal Vasko5233e962020-08-14 14:26:20 +0200512 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200513 LEVEL++;
514
Radek Krejci39b7fc22021-02-26 23:29:18 +0100515 yprp_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200516 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200517
518 LY_ARRAY_FOR(ident->bases, u) {
519 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100520 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200521 }
522
Radek Krejci693262f2019-04-29 15:23:20 +0200523 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200524 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 Krejciadcf63d2021-02-09 10:21:18 +0100532yprc_identity(struct lys_ypr_ctx *ctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200533{
Radek Krejci857189e2020-09-01 13:26:36 +0200534 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200535 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200536
Michal Vasko5233e962020-08-14 14:26:20 +0200537 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200538 LEVEL++;
539
Radek Krejci39b7fc22021-02-26 23:29:18 +0100540 yprc_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200541
542 LY_ARRAY_FOR(ident->derived, u) {
543 ypr_open(ctx->out, &flag);
544 if (ctx->module != ident->derived[u]->module) {
Michal Vasko5233e962020-08-14 14:26:20 +0200545 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 +0200546 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200547 ly_print_(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200548 }
549 }
550
551 ypr_status(ctx, ident->flags, ident->exts, &flag);
552 ypr_description(ctx, ident->dsc, ident->exts, &flag);
553 ypr_reference(ctx, ident->ref, ident->exts, &flag);
554
555 LEVEL--;
556 ypr_close(ctx, flag);
557}
558
559static void
Radek Krejci39b7fc22021-02-26 23:29:18 +0100560yprp_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 +0200561{
Radek Krejci857189e2020-09-01 13:26:36 +0200562 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563
564 if (!restr) {
565 return;
566 }
567
568 ypr_open(ctx->out, flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +0100569 ly_print_(ctx->out, "%*s%s \"", INDENT, ly_stmt2str(stmt));
Radek Krejcif13b87b2020-12-01 22:02:17 +0100570 ypr_encode(ctx->out,
571 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
572 restr->arg.str : &restr->arg.str[1], -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200573 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200574
575 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100576 yprp_extension_instances(ctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100577 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200578 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
579 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100580 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200581 }
582 if (restr->emsg) {
583 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100584 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200585 }
586 if (restr->eapptag) {
587 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100588 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200589 }
Radek Krejci693262f2019-04-29 15:23:20 +0200590 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
591 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
592
Radek Krejcid3ca0632019-04-16 16:54:54 +0200593 LEVEL--;
594 ypr_close(ctx, inner_flag);
595}
596
597static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100598yprc_must(struct lys_ypr_ctx *ctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200599{
Radek Krejci857189e2020-09-01 13:26:36 +0200600 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200601
602 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200603 ly_print_(ctx->out, "%*smust \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200604 ypr_encode(ctx->out, must->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200605 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200606
607 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100608 yprc_extension_instances(ctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200609 if (must->emsg) {
610 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100611 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200612 }
613 if (must->eapptag) {
614 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100615 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200616 }
617 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
618 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
619
620 LEVEL--;
621 ypr_close(ctx, inner_flag);
622}
623
624static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100625yprc_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 +0200626{
Radek Krejci857189e2020-09-01 13:26:36 +0200627 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200628 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200629
Radek Krejci334ccc72019-06-12 13:49:29 +0200630 if (!range) {
631 return;
632 }
633
Radek Krejci693262f2019-04-29 15:23:20 +0200634 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200635 ly_print_(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200636 LY_ARRAY_FOR(range->parts, u) {
637 if (u > 0) {
Michal Vasko5233e962020-08-14 14:26:20 +0200638 ly_print_(ctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200639 }
640 if (range->parts[u].max_64 == range->parts[u].min_64) {
641 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200642 ly_print_(ctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200643 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200644 ly_print_(ctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200645 }
646 } else {
647 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200648 ly_print_(ctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200649 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200650 ly_print_(ctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200651 }
652 }
653 }
Michal Vasko5233e962020-08-14 14:26:20 +0200654 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200655
656 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100657 yprc_extension_instances(ctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200658 if (range->emsg) {
659 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100660 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 }
662 if (range->eapptag) {
663 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100664 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200665 }
666 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
667 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
668
669 LEVEL--;
670 ypr_close(ctx, inner_flag);
671}
672
673static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100674yprc_pattern(struct lys_ypr_ctx *ctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200675{
Radek Krejci857189e2020-09-01 13:26:36 +0200676 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200677
678 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200679 ly_print_(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200680 ypr_encode(ctx->out, pattern->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200681 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200682
683 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100684 yprc_extension_instances(ctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200685 if (pattern->inverted) {
686 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
687 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100688 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200689 }
690 if (pattern->emsg) {
691 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100692 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200693 }
694 if (pattern->eapptag) {
695 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100696 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200697 }
698 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
699 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
700
701 LEVEL--;
702 ypr_close(ctx, inner_flag);
703}
704
705static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100706yprp_when(struct lys_ypr_ctx *ctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200707{
Radek Krejci857189e2020-09-01 13:26:36 +0200708 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200709
710 if (!when) {
711 return;
712 }
713 ypr_open(ctx->out, flag);
714
Michal Vasko5233e962020-08-14 14:26:20 +0200715 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200716 ypr_encode(ctx->out, when->cond, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200717 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200718
719 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100720 yprp_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200721 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
722 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
723 LEVEL--;
724 ypr_close(ctx, inner_flag);
725}
726
727static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100728yprc_when(struct lys_ypr_ctx *ctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200729{
Radek Krejci857189e2020-09-01 13:26:36 +0200730 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200731
732 if (!when) {
733 return;
734 }
735 ypr_open(ctx->out, flag);
736
Michal Vasko5233e962020-08-14 14:26:20 +0200737 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200738 ypr_encode(ctx->out, when->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200739 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200740
741 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100742 yprc_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200743 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
744 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
745 LEVEL--;
746 ypr_close(ctx, inner_flag);
747}
748
749static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100750yprp_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 +0200751{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200752 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200753 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200754
755 LY_ARRAY_FOR(items, u) {
756 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200757 if (type == LY_TYPE_BITS) {
Michal Vasko5233e962020-08-14 14:26:20 +0200758 ly_print_(ctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200759 } else { /* LY_TYPE_ENUM */
Michal Vasko5233e962020-08-14 14:26:20 +0200760 ly_print_(ctx->out, "%*senum \"", INDENT);
Radek Krejci7871ce52019-06-11 16:44:56 +0200761 ypr_encode(ctx->out, items[u].name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200762 ly_print_(ctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200763 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200764 inner_flag = 0;
765 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100766 yprp_extension_instances(ctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200767 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768 if (items[u].flags & LYS_SET_VALUE) {
769 if (type == LY_TYPE_BITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100770 ypr_unsigned(ctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200771 } else { /* LY_TYPE_ENUM */
Radek Krejcifc596f92021-02-26 22:40:26 +0100772 ypr_signed(ctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200773 }
774 }
Radek Krejci693262f2019-04-29 15:23:20 +0200775 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200776 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
777 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
778 LEVEL--;
779 ypr_close(ctx, inner_flag);
780 }
781}
782
783static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100784yprp_type(struct lys_ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200785{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200786 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200787 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200788
Michal Vasko5233e962020-08-14 14:26:20 +0200789 ly_print_(ctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790 LEVEL++;
791
Radek Krejci39b7fc22021-02-26 23:29:18 +0100792 yprp_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200793
Radek Krejci39b7fc22021-02-26 23:29:18 +0100794 yprp_restr(ctx, type->range, LY_STMT_RANGE, &flag);
795 yprp_restr(ctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100797 yprp_restr(ctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200798 }
Radek Krejci693262f2019-04-29 15:23:20 +0200799 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
800 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200801
802 if (type->path) {
803 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100804 ypr_substmt(ctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200805 }
806 if (type->flags & LYS_SET_REQINST) {
807 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100808 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809 }
810 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100811 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200812 }
813 LY_ARRAY_FOR(type->bases, u) {
814 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100815 ypr_substmt(ctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200816 }
817 LY_ARRAY_FOR(type->types, u) {
818 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200819 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200820 }
821
822 LEVEL--;
823 ypr_close(ctx, flag);
824}
825
826static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100827yprc_dflt_value(struct lys_ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200828{
Radek Krejci857189e2020-09-01 13:26:36 +0200829 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200830 const char *str;
831
Michal Vaskoba99a3e2020-08-18 15:50:05 +0200832 str = value->realtype->plugin->print(value, LY_PREF_JSON, NULL, &dynamic);
Radek Krejcifc596f92021-02-26 22:40:26 +0100833 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200834 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200835 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200836 }
837}
838
839static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100840yprc_type(struct lys_ypr_ctx *ctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200841{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200842 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200843 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200844
Michal Vasko5233e962020-08-14 14:26:20 +0200845 ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200846 LEVEL++;
847
Radek Krejci39b7fc22021-02-26 23:29:18 +0100848 yprc_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200849
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200850 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200851 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200852 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200853 yprc_range(ctx, bin->length, type->basetype, &flag);
854 break;
855 }
856 case LY_TYPE_UINT8:
857 case LY_TYPE_UINT16:
858 case LY_TYPE_UINT32:
859 case LY_TYPE_UINT64:
860 case LY_TYPE_INT8:
861 case LY_TYPE_INT16:
862 case LY_TYPE_INT32:
863 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200864 struct lysc_type_num *num = (struct lysc_type_num *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200865 yprc_range(ctx, num->range, type->basetype, &flag);
866 break;
867 }
868 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200869 struct lysc_type_str *str = (struct lysc_type_str *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200870 yprc_range(ctx, str->length, type->basetype, &flag);
871 LY_ARRAY_FOR(str->patterns, u) {
872 yprc_pattern(ctx, str->patterns[u], &flag);
873 }
874 break;
875 }
876 case LY_TYPE_BITS:
877 case LY_TYPE_ENUM: {
878 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200879 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200880 LY_ARRAY_FOR(bits->bits, u) {
881 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200882 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200883
884 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200885 ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
Radek Krejci693262f2019-04-29 15:23:20 +0200886 ypr_encode(ctx->out, item->name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200887 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200888 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200889 if (type->basetype == LY_TYPE_BITS) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100890 yprc_extension_instances(ctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100891 ypr_unsigned(ctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200892 } else { /* LY_TYPE_ENUM */
Radek Krejci39b7fc22021-02-26 23:29:18 +0100893 yprc_extension_instances(ctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100894 ypr_signed(ctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200895 }
896 ypr_status(ctx, item->flags, item->exts, &inner_flag);
897 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
898 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
899 LEVEL--;
900 ypr_close(ctx, inner_flag);
901 }
902 break;
903 }
904 case LY_TYPE_BOOL:
905 case LY_TYPE_EMPTY:
906 /* nothing to do */
907 break;
908 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200909 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200910 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100911 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200912 yprc_range(ctx, dec->range, dec->basetype, &flag);
913 break;
914 }
915 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200916 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200917 LY_ARRAY_FOR(ident->bases, u) {
918 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100919 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200920 }
921 break;
922 }
923 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200924 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200925 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100926 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200927 break;
928 }
929 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200930 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200931 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100932 ypr_substmt(ctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
933 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200934 yprc_type(ctx, lr->realtype);
935 break;
936 }
937 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200938 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200939 LY_ARRAY_FOR(un->types, u) {
940 ypr_open(ctx->out, &flag);
941 yprc_type(ctx, un->types[u]);
942 }
943 break;
944 }
945 default:
946 LOGINT(ctx->module->ctx);
947 }
948
949 LEVEL--;
950 ypr_close(ctx, flag);
951}
952
953static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100954yprp_typedef(struct lys_ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200955{
Michal Vasko5233e962020-08-14 14:26:20 +0200956 ly_print_(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200957 LEVEL++;
958
Radek Krejci39b7fc22021-02-26 23:29:18 +0100959 yprp_extension_instances(ctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200960
Radek Krejci693262f2019-04-29 15:23:20 +0200961 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200962
963 if (tpdf->units) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100964 ypr_substmt(ctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200965 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200966 if (tpdf->dflt.str) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100967 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200968 }
969
Radek Krejci693262f2019-04-29 15:23:20 +0200970 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200971 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
972 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
973
974 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200975 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200976}
977
Radek Krejciadcf63d2021-02-09 10:21:18 +0100978static void yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node);
979static void yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node);
980static void yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action);
981static void yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200982
983static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100984yprp_grouping(struct lys_ypr_ctx *ctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200985{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200986 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200987 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200988 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100989 struct lysp_node_action *action;
990 struct lysp_node_notif *notif;
991 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200992
Michal Vasko5233e962020-08-14 14:26:20 +0200993 ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200994 LEVEL++;
995
Radek Krejci39b7fc22021-02-26 23:29:18 +0100996 yprp_extension_instances(ctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200997 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +0200998 ypr_description(ctx, grp->dsc, grp->exts, &flag);
999 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001000
1001 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001002 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001003 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004 }
1005
Radek Krejci2a9fc652021-01-22 17:44:34 +01001006 LY_LIST_FOR(grp->groupings, subgrp) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001007 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001008 yprp_grouping(ctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001009 }
1010
Radek Krejci01180ac2021-01-27 08:48:22 +01001011 LY_LIST_FOR(grp->child, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001012 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001013 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001014 }
1015
Radek Krejci2a9fc652021-01-22 17:44:34 +01001016 LY_LIST_FOR(grp->actions, action) {
1017 ypr_open(ctx->out, &flag);
1018 yprp_action(ctx, action);
1019 }
1020
1021 LY_LIST_FOR(grp->notifs, notif) {
1022 ypr_open(ctx->out, &flag);
1023 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024 }
1025
1026 LEVEL--;
1027 ypr_close(ctx, flag);
1028}
1029
1030static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001031yprp_inout(struct lys_ypr_ctx *ctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001033 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001034 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001035 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001036
Radek Krejci01180ac2021-01-27 08:48:22 +01001037 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001038 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001039 return;
1040 }
1041 ypr_open(ctx->out, flag);
1042
Michal Vasko544e58a2021-01-28 14:33:41 +01001043 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044 LEVEL++;
1045
Radek Krejci39b7fc22021-02-26 23:29:18 +01001046 yprp_extension_instances(ctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001048 yprp_restr(ctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049 }
1050 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001051 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001053 LY_LIST_FOR(inout->groupings, grp) {
1054 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055 }
1056
Radek Krejci01180ac2021-01-27 08:48:22 +01001057 LY_LIST_FOR(inout->child, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001058 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001059 }
1060
1061 LEVEL--;
1062 ypr_close(ctx, 1);
1063}
1064
1065static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001066yprc_inout(struct lys_ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001067{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001068 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001069 struct lysc_node *data;
1070
Radek Krejci01180ac2021-01-27 08:48:22 +01001071 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001072 /* input/output is empty */
1073 return;
1074 }
1075 ypr_open(ctx->out, flag);
1076
Michal Vasko544e58a2021-01-28 14:33:41 +01001077 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001078 LEVEL++;
1079
Radek Krejci39b7fc22021-02-26 23:29:18 +01001080 yprc_extension_instances(ctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001081 LY_ARRAY_FOR(inout->musts, u) {
1082 yprc_must(ctx, &inout->musts[u], NULL);
1083 }
1084
Radek Krejci52f65552020-09-01 17:03:35 +02001085 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001086 LY_LIST_FOR(inout->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001087 yprc_node(ctx, data);
1088 }
Radek Krejci693262f2019-04-29 15:23:20 +02001089 }
1090
1091 LEVEL--;
1092 ypr_close(ctx, 1);
1093}
1094
1095static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001096yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001097{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001098 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001099 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001101 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001102
Michal Vasko5233e962020-08-14 14:26:20 +02001103 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001104
1105 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001106 yprp_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001107 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001108
1109 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001110 yprp_restr(ctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001111 }
Radek Krejci693262f2019-04-29 15:23:20 +02001112 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001113 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1114 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1115
1116 LY_ARRAY_FOR(notif->typedefs, u) {
1117 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001118 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001119 }
1120
Radek Krejci2a9fc652021-01-22 17:44:34 +01001121 LY_LIST_FOR(notif->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001123 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001124 }
1125
Radek Krejci01180ac2021-01-27 08:48:22 +01001126 LY_LIST_FOR(notif->child, data) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001127 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001128 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001129 }
1130
1131 LEVEL--;
1132 ypr_close(ctx, flag);
1133}
1134
1135static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001136yprc_notification(struct lys_ypr_ctx *ctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001137{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001138 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001139 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001140 struct lysc_node *data;
1141
Michal Vasko5233e962020-08-14 14:26:20 +02001142 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001143
1144 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001145 yprc_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001146
1147 LY_ARRAY_FOR(notif->musts, u) {
1148 yprc_must(ctx, &notif->musts[u], &flag);
1149 }
1150 ypr_status(ctx, notif->flags, notif->exts, &flag);
1151 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1152 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1153
Radek Krejci52f65552020-09-01 17:03:35 +02001154 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001155 LY_LIST_FOR(notif->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001156 ypr_open(ctx->out, &flag);
1157 yprc_node(ctx, data);
1158 }
Radek Krejci693262f2019-04-29 15:23:20 +02001159 }
1160
1161 LEVEL--;
1162 ypr_close(ctx, flag);
1163}
1164
1165static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001166yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001167{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001168 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001169 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001170 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001171
Michal Vasko5233e962020-08-14 14:26:20 +02001172 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001173
1174 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001175 yprp_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001176 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1177 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001178 ypr_description(ctx, action->dsc, action->exts, &flag);
1179 ypr_reference(ctx, action->ref, action->exts, &flag);
1180
1181 LY_ARRAY_FOR(action->typedefs, u) {
1182 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001183 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001184 }
1185
Radek Krejci2a9fc652021-01-22 17:44:34 +01001186 LY_LIST_FOR(action->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001187 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001188 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001189 }
1190
Radek Krejci693262f2019-04-29 15:23:20 +02001191 yprp_inout(ctx, &action->input, &flag);
1192 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001193
1194 LEVEL--;
1195 ypr_close(ctx, flag);
1196}
1197
1198static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001199yprc_action(struct lys_ypr_ctx *ctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001200{
Radek Krejci857189e2020-09-01 13:26:36 +02001201 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001202
Michal Vasko5233e962020-08-14 14:26:20 +02001203 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001204
1205 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001206 yprc_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001207 ypr_status(ctx, action->flags, action->exts, &flag);
1208 ypr_description(ctx, action->dsc, action->exts, &flag);
1209 ypr_reference(ctx, action->ref, action->exts, &flag);
1210
Michal Vasko544e58a2021-01-28 14:33:41 +01001211 yprc_inout(ctx, &action->input, &flag);
1212 yprc_inout(ctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001213
1214 LEVEL--;
1215 ypr_close(ctx, flag);
1216}
1217
1218static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001219yprp_node_common1(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001220{
Michal Vasko5233e962020-08-14 14:26:20 +02001221 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001222 LEVEL++;
1223
Radek Krejci39b7fc22021-02-26 23:29:18 +01001224 yprp_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001225 yprp_when(ctx, lysp_node_when(node), flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001226 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001227}
1228
1229static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001230yprc_node_common1(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001231{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001232 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001233 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234
Michal Vasko5233e962020-08-14 14:26:20 +02001235 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001236 LEVEL++;
1237
Radek Krejci39b7fc22021-02-26 23:29:18 +01001238 yprc_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001239
1240 when = lysc_node_when(node);
1241 LY_ARRAY_FOR(when, u) {
1242 yprc_when(ctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001243 }
Radek Krejci693262f2019-04-29 15:23:20 +02001244}
1245
1246/* macr oto unify the code */
1247#define YPR_NODE_COMMON2 \
1248 ypr_config(ctx, node->flags, node->exts, flag); \
1249 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1250 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1251 } \
1252 ypr_status(ctx, node->flags, node->exts, flag); \
1253 ypr_description(ctx, node->dsc, node->exts, flag); \
1254 ypr_reference(ctx, node->ref, node->exts, flag)
1255
1256static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001257yprp_node_common2(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001258{
1259 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001260}
1261
1262static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001263yprc_node_common2(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001264{
1265 YPR_NODE_COMMON2;
1266}
1267
1268#undef YPR_NODE_COMMON2
1269
1270static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001271yprp_container(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001272{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001273 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001274 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001276 struct lysp_node_action *action;
1277 struct lysp_node_notif *notif;
1278 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001279 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1280
Radek Krejci693262f2019-04-29 15:23:20 +02001281 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001282
1283 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001284 yprp_restr(ctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001285 }
1286 if (cont->presence) {
1287 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001288 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001289 }
1290
Radek Krejci693262f2019-04-29 15:23:20 +02001291 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292
1293 LY_ARRAY_FOR(cont->typedefs, u) {
1294 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001295 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001296 }
1297
Radek Krejci2a9fc652021-01-22 17:44:34 +01001298 LY_LIST_FOR(cont->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001299 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001300 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001301 }
1302
1303 LY_LIST_FOR(cont->child, child) {
1304 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001305 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001306 }
1307
Radek Krejci2a9fc652021-01-22 17:44:34 +01001308 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001309 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001310 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001311 }
1312
Radek Krejci2a9fc652021-01-22 17:44:34 +01001313 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001314 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001315 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001316 }
1317
1318 LEVEL--;
1319 ypr_close(ctx, flag);
1320}
1321
1322static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001323yprc_container(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001324{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001325 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001326 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001327 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001328 struct lysc_node_action *action;
1329 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001330 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1331
1332 yprc_node_common1(ctx, node, &flag);
1333
1334 LY_ARRAY_FOR(cont->musts, u) {
1335 yprc_must(ctx, &cont->musts[u], &flag);
1336 }
1337 if (cont->flags & LYS_PRESENCE) {
1338 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001339 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001340 }
1341
1342 yprc_node_common2(ctx, node, &flag);
1343
Radek Krejci52f65552020-09-01 17:03:35 +02001344 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001345 LY_LIST_FOR(cont->child, child) {
1346 ypr_open(ctx->out, &flag);
1347 yprc_node(ctx, child);
1348 }
Radek Krejci693262f2019-04-29 15:23:20 +02001349
Radek Krejci2a9fc652021-01-22 17:44:34 +01001350 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001351 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001352 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001353 }
Radek Krejci693262f2019-04-29 15:23:20 +02001354
Radek Krejci2a9fc652021-01-22 17:44:34 +01001355 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001356 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001357 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001358 }
Radek Krejci693262f2019-04-29 15:23:20 +02001359 }
1360
1361 LEVEL--;
1362 ypr_close(ctx, flag);
1363}
1364
1365static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001366yprp_case(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001367{
Radek Krejci857189e2020-09-01 13:26:36 +02001368 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001369 struct lysp_node *child;
1370 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1371
1372 yprp_node_common1(ctx, node, &flag);
1373 yprp_node_common2(ctx, node, &flag);
1374
1375 LY_LIST_FOR(cas->child, child) {
1376 ypr_open(ctx->out, &flag);
1377 yprp_node(ctx, child);
1378 }
1379
1380 LEVEL--;
1381 ypr_close(ctx, flag);
1382}
1383
1384static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001385yprc_case(struct lys_ypr_ctx *ctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001386{
Radek Krejci857189e2020-09-01 13:26:36 +02001387 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001388 struct lysc_node *child;
1389
Michal Vasko14ed9cd2021-01-28 14:16:25 +01001390 yprc_node_common1(ctx, &cs->node, &flag);
1391 yprc_node_common2(ctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001392
Radek Krejci52f65552020-09-01 17:03:35 +02001393 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001394 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001395 ypr_open(ctx->out, &flag);
1396 yprc_node(ctx, child);
1397 }
Radek Krejci693262f2019-04-29 15:23:20 +02001398 }
1399
1400 LEVEL--;
1401 ypr_close(ctx, flag);
1402}
1403
1404static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001405yprp_choice(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001406{
Radek Krejci857189e2020-09-01 13:26:36 +02001407 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001408 struct lysp_node *child;
1409 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1410
Radek Krejci693262f2019-04-29 15:23:20 +02001411 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001412
Michal Vasko7f45cf22020-10-01 12:49:44 +02001413 if (choice->dflt.str) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001414 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001415 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001416 }
1417
Radek Krejci693262f2019-04-29 15:23:20 +02001418 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001419
1420 LY_LIST_FOR(choice->child, child) {
1421 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001422 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001423 }
1424
1425 LEVEL--;
1426 ypr_close(ctx, flag);
1427}
1428
1429static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001430yprc_choice(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001431{
Radek Krejci857189e2020-09-01 13:26:36 +02001432 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001433 struct lysc_node_case *cs;
1434 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1435
1436 yprc_node_common1(ctx, node, &flag);
1437
1438 if (choice->dflt) {
1439 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001440 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001441 }
1442
1443 yprc_node_common2(ctx, node, &flag);
1444
Michal Vasko22df3f02020-08-24 13:29:22 +02001445 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Radek Krejci693262f2019-04-29 15:23:20 +02001446 ypr_open(ctx->out, &flag);
1447 yprc_case(ctx, cs);
1448 }
1449
1450 LEVEL--;
1451 ypr_close(ctx, flag);
1452}
1453
1454static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001455yprp_leaf(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001456{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001457 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001458 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1459
Radek Krejci693262f2019-04-29 15:23:20 +02001460 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001461
Radek Krejci693262f2019-04-29 15:23:20 +02001462 yprp_type(ctx, &leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001463 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001464 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001465 yprp_restr(ctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001466 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001467 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001468
Radek Krejci693262f2019-04-29 15:23:20 +02001469 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470
1471 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001472 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473}
1474
1475static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001476yprc_leaf(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001477{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001478 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001479 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1480
1481 yprc_node_common1(ctx, node, NULL);
1482
1483 yprc_type(ctx, leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001484 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001485 LY_ARRAY_FOR(leaf->musts, u) {
1486 yprc_must(ctx, &leaf->musts[u], NULL);
1487 }
Radek Krejcia1911222019-07-22 17:24:50 +02001488
1489 if (leaf->dflt) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001490 yprc_dflt_value(ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001491 }
Radek Krejci693262f2019-04-29 15:23:20 +02001492
1493 yprc_node_common2(ctx, node, NULL);
1494
1495 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001496 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001497}
1498
1499static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001500yprp_leaflist(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001501{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001502 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1504
Radek Krejci693262f2019-04-29 15:23:20 +02001505 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001506
Radek Krejci693262f2019-04-29 15:23:20 +02001507 yprp_type(ctx, &llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001508 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001509 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001510 yprp_restr(ctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511 }
1512 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001513 ypr_substmt(ctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514 }
1515
Radek Krejci693262f2019-04-29 15:23:20 +02001516 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517
1518 if (llist->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001519 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520 }
1521 if (llist->flags & LYS_SET_MAX) {
1522 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001523 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001524 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001525 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001526 }
1527 }
1528
1529 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001530 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001531 }
1532
Radek Krejci693262f2019-04-29 15:23:20 +02001533 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534 ypr_description(ctx, node->dsc, node->exts, NULL);
1535 ypr_reference(ctx, node->ref, node->exts, NULL);
1536
1537 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001538 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001539}
1540
1541static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001542yprc_leaflist(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001543{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001544 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001545 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1546
1547 yprc_node_common1(ctx, node, NULL);
1548
1549 yprc_type(ctx, llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001550 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001551 LY_ARRAY_FOR(llist->musts, u) {
1552 yprc_must(ctx, &llist->musts[u], NULL);
1553 }
1554 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001555 yprc_dflt_value(ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001556 }
1557
1558 ypr_config(ctx, node->flags, node->exts, NULL);
1559
Radek Krejcifc596f92021-02-26 22:40:26 +01001560 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001561 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001562 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001563 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001564 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001565 }
1566
Radek Krejcifc596f92021-02-26 22:40:26 +01001567 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001568
1569 ypr_status(ctx, node->flags, node->exts, NULL);
1570 ypr_description(ctx, node->dsc, node->exts, NULL);
1571 ypr_reference(ctx, node->ref, node->exts, NULL);
1572
1573 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001574 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001575}
1576
1577static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001578yprp_list(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001580 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001581 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001582 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001583 struct lysp_node_action *action;
1584 struct lysp_node_notif *notif;
1585 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001586 struct lysp_node_list *list = (struct lysp_node_list *)node;
1587
Radek Krejci693262f2019-04-29 15:23:20 +02001588 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001589
1590 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001591 yprp_restr(ctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001592 }
1593 if (list->key) {
1594 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001595 ypr_substmt(ctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001596 }
1597 LY_ARRAY_FOR(list->uniques, u) {
1598 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001599 ypr_substmt(ctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600 }
1601
Michal Vaskoacb8e742020-10-20 10:28:02 +02001602 ypr_config(ctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001603
1604 if (list->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001605 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001606 }
1607 if (list->flags & LYS_SET_MAX) {
1608 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001609 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001610 } else {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001611 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001612 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001613 }
1614 }
1615
1616 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001617 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001618 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001619 }
1620
Michal Vaskoacb8e742020-10-20 10:28:02 +02001621 ypr_status(ctx, node->flags, node->exts, &flag);
1622 ypr_description(ctx, node->dsc, node->exts, &flag);
1623 ypr_reference(ctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001624
1625 LY_ARRAY_FOR(list->typedefs, u) {
1626 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001627 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001628 }
1629
Radek Krejci2a9fc652021-01-22 17:44:34 +01001630 LY_LIST_FOR(list->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001631 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001632 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633 }
1634
1635 LY_LIST_FOR(list->child, child) {
1636 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001637 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 }
1639
Radek Krejci2a9fc652021-01-22 17:44:34 +01001640 LY_LIST_FOR(list->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001641 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001642 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001643 }
1644
Radek Krejci2a9fc652021-01-22 17:44:34 +01001645 LY_LIST_FOR(list->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001646 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001647 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648 }
1649
1650 LEVEL--;
1651 ypr_close(ctx, flag);
1652}
1653
1654static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001655yprc_list(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001656{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001657 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001658 struct lysc_node_list *list = (struct lysc_node_list *)node;
1659
Michal Vaskoacb8e742020-10-20 10:28:02 +02001660 yprc_node_common1(ctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001661
1662 LY_ARRAY_FOR(list->musts, u) {
1663 yprc_must(ctx, &list->musts[u], NULL);
1664 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001665 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko5233e962020-08-14 14:26:20 +02001666 ly_print_(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001667 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 +02001668 ly_print_(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001669 }
Michal Vasko5233e962020-08-14 14:26:20 +02001670 ly_print_(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001671 }
1672 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02001673 ly_print_(ctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001674 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko5233e962020-08-14 14:26:20 +02001675 ly_print_(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001676 }
1677 ypr_close(ctx, 0);
1678 }
1679
1680 ypr_config(ctx, node->flags, node->exts, NULL);
1681
Radek Krejcifc596f92021-02-26 22:40:26 +01001682 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001683 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001684 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001685 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001686 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001687 }
1688
Radek Krejcifc596f92021-02-26 22:40:26 +01001689 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001690
1691 ypr_status(ctx, node->flags, node->exts, NULL);
1692 ypr_description(ctx, node->dsc, node->exts, NULL);
1693 ypr_reference(ctx, node->ref, node->exts, NULL);
1694
Radek Krejci52f65552020-09-01 17:03:35 +02001695 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001696 struct lysc_node *child;
1697 struct lysc_node_action *action;
1698 struct lysc_node_notif *notif;
1699
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001700 LY_LIST_FOR(list->child, child) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001701 yprc_node(ctx, child);
1702 }
Radek Krejci693262f2019-04-29 15:23:20 +02001703
Radek Krejci2a9fc652021-01-22 17:44:34 +01001704 LY_LIST_FOR(list->actions, action) {
1705 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001706 }
Radek Krejci693262f2019-04-29 15:23:20 +02001707
Radek Krejci2a9fc652021-01-22 17:44:34 +01001708 LY_LIST_FOR(list->notifs, notif) {
1709 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001710 }
Radek Krejci693262f2019-04-29 15:23:20 +02001711 }
1712
1713 LEVEL--;
Michal Vaskoacb8e742020-10-20 10:28:02 +02001714 ypr_close(ctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001715}
1716
1717static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001718yprp_refine(struct lys_ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001719{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001720 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001721 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001722
Michal Vasko5233e962020-08-14 14:26:20 +02001723 ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001724 LEVEL++;
1725
Radek Krejci39b7fc22021-02-26 23:29:18 +01001726 yprp_extension_instances(ctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001727 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001728
1729 LY_ARRAY_FOR(refine->musts, u) {
1730 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001731 yprp_restr(ctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001732 }
1733
1734 if (refine->presence) {
1735 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001736 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001737 }
1738
1739 LY_ARRAY_FOR(refine->dflts, u) {
1740 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001741 ypr_substmt(ctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001742 }
1743
Radek Krejci693262f2019-04-29 15:23:20 +02001744 ypr_config(ctx, refine->flags, refine->exts, &flag);
1745 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001746
1747 if (refine->flags & LYS_SET_MIN) {
1748 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001749 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750 }
1751 if (refine->flags & LYS_SET_MAX) {
1752 ypr_open(ctx->out, &flag);
1753 if (refine->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001754 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001755 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001756 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001757 }
1758 }
1759
1760 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1761 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1762
1763 LEVEL--;
1764 ypr_close(ctx, flag);
1765}
1766
1767static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001768yprp_augment(struct lys_ypr_ctx *ctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001770 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001771 struct lysp_node_action *action;
1772 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001773
Michal Vasko5233e962020-08-14 14:26:20 +02001774 ly_print_(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001775 LEVEL++;
1776
Radek Krejci39b7fc22021-02-26 23:29:18 +01001777 yprp_extension_instances(ctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001778 yprp_when(ctx, aug->when, NULL);
1779 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1780 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1782 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1783
1784 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001785 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001786 }
1787
Radek Krejci2a9fc652021-01-22 17:44:34 +01001788 LY_LIST_FOR(aug->actions, action) {
1789 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790 }
1791
Radek Krejci2a9fc652021-01-22 17:44:34 +01001792 LY_LIST_FOR(aug->notifs, notif) {
1793 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001794 }
1795
1796 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001797 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001798}
1799
Radek Krejcid3ca0632019-04-16 16:54:54 +02001800static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001801yprp_uses(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001803 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001804 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001805 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001806 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807
Radek Krejci693262f2019-04-29 15:23:20 +02001808 yprp_node_common1(ctx, node, &flag);
1809 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810
1811 LY_ARRAY_FOR(uses->refines, u) {
1812 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001813 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814 }
1815
Radek Krejci2a9fc652021-01-22 17:44:34 +01001816 LY_LIST_FOR(uses->augments, aug) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001818 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819 }
1820
1821 LEVEL--;
1822 ypr_close(ctx, flag);
1823}
1824
1825static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001826yprp_anydata(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001828 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001829 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1831
Radek Krejci693262f2019-04-29 15:23:20 +02001832 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833
1834 LY_ARRAY_FOR(any->musts, u) {
1835 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001836 yprp_restr(ctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837 }
1838
Radek Krejci693262f2019-04-29 15:23:20 +02001839 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840
1841 LEVEL--;
1842 ypr_close(ctx, flag);
1843}
1844
1845static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001846yprc_anydata(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001848 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001849 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001850 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851
Radek Krejci693262f2019-04-29 15:23:20 +02001852 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853
Radek Krejci693262f2019-04-29 15:23:20 +02001854 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001856 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857 }
1858
Radek Krejci693262f2019-04-29 15:23:20 +02001859 yprc_node_common2(ctx, node, &flag);
1860
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861 LEVEL--;
1862 ypr_close(ctx, flag);
1863}
1864
1865static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001866yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001867{
1868 switch (node->nodetype) {
1869 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001870 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001871 break;
1872 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001873 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001874 break;
1875 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001876 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877 break;
1878 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001879 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880 break;
1881 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001882 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883 break;
1884 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001885 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001886 break;
1887 case LYS_ANYXML:
1888 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001889 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890 break;
1891 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001892 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893 break;
1894 default:
1895 break;
1896 }
1897}
1898
1899static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001900yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001901{
1902 switch (node->nodetype) {
1903 case LYS_CONTAINER:
1904 yprc_container(ctx, node);
1905 break;
1906 case LYS_CHOICE:
1907 yprc_choice(ctx, node);
1908 break;
1909 case LYS_LEAF:
1910 yprc_leaf(ctx, node);
1911 break;
1912 case LYS_LEAFLIST:
1913 yprc_leaflist(ctx, node);
1914 break;
1915 case LYS_LIST:
1916 yprc_list(ctx, node);
1917 break;
1918 case LYS_ANYXML:
1919 case LYS_ANYDATA:
1920 yprc_anydata(ctx, node);
1921 break;
1922 default:
1923 break;
1924 }
1925}
1926
1927static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001928yprp_deviation(struct lys_ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001929{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001930 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 struct lysp_deviate_add *add;
1932 struct lysp_deviate_rpl *rpl;
1933 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001934 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001935
Michal Vasko5233e962020-08-14 14:26:20 +02001936 ly_print_(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937 LEVEL++;
1938
Radek Krejci39b7fc22021-02-26 23:29:18 +01001939 yprp_extension_instances(ctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1941 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1942
fredgan2b11ddb2019-10-21 11:03:39 +08001943 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko5233e962020-08-14 14:26:20 +02001944 ly_print_(ctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001945 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1946 if (elem->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02001947 ly_print_(ctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001948 LEVEL++;
1949
Radek Krejci39b7fc22021-02-26 23:29:18 +01001950 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001951 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02001952 ly_print_(ctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953 continue;
1954 }
fredgan2b11ddb2019-10-21 11:03:39 +08001955 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001956 add = (struct lysp_deviate_add *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001957 ly_print_(ctx->out, "add {\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, add->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001961 ypr_substmt(ctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001962 LY_ARRAY_FOR(add->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001963 yprp_restr(ctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001964 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001965 LY_ARRAY_FOR(add->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001966 ypr_substmt(ctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001967 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001968 LY_ARRAY_FOR(add->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001969 ypr_substmt(ctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970 }
Radek Krejci693262f2019-04-29 15:23:20 +02001971 ypr_config(ctx, add->flags, add->exts, NULL);
1972 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001973 if (add->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001974 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001975 }
1976 if (add->flags & LYS_SET_MAX) {
1977 if (add->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001978 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001980 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001981 }
1982 }
fredgan2b11ddb2019-10-21 11:03:39 +08001983 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001984 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001985 ly_print_(ctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001986 LEVEL++;
1987
Radek Krejci39b7fc22021-02-26 23:29:18 +01001988 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001990 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001991 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001992 ypr_substmt(ctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
1993 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001994 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1995 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001996 if (rpl->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001997 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001998 }
1999 if (rpl->flags & LYS_SET_MAX) {
2000 if (rpl->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002001 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002002 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01002003 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 }
2005 }
fredgan2b11ddb2019-10-21 11:03:39 +08002006 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002007 del = (struct lysp_deviate_del *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02002008 ly_print_(ctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 LEVEL++;
2010
Radek Krejci39b7fc22021-02-26 23:29:18 +01002011 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002012 ypr_substmt(ctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002013 LY_ARRAY_FOR(del->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01002014 yprp_restr(ctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002015 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002016 LY_ARRAY_FOR(del->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002017 ypr_substmt(ctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002019 LY_ARRAY_FOR(del->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002020 ypr_substmt(ctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002021 }
2022 }
2023
2024 LEVEL--;
2025 ypr_close(ctx, 1);
2026 }
2027
2028 LEVEL--;
2029 ypr_close(ctx, 1);
2030}
2031
Michal Vasko7c8439f2020-08-05 13:25:19 +02002032static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002033yang_print_parsed_linkage(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002035 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002038 if (modp->imports[u].flags & LYS_INTERNAL) {
2039 continue;
2040 }
2041
Michal Vasko5233e962020-08-14 14:26:20 +02002042 ly_print_(ctx->out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002044 yprp_extension_instances(ctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002045 ypr_substmt(ctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002046 if (modp->imports[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002047 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002048 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002049 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2050 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002052 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002053 }
2054 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002055 if (modp->includes[u].injected) {
2056 /* do not print the includes injected from submodules */
2057 continue;
2058 }
Radek Krejcid3ca0632019-04-16 16:54:54 +02002059 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 +02002060 ly_print_(ctx->out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002062 yprp_extension_instances(ctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 if (modp->includes[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002064 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002066 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2067 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002069 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02002071 ly_print_(ctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072 }
2073 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002074}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002075
Michal Vasko7c8439f2020-08-05 13:25:19 +02002076static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002077yang_print_parsed_body(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002078{
2079 LY_ARRAY_COUNT_TYPE u;
2080 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002081 struct lysp_node_action *action;
2082 struct lysp_node_notif *notif;
2083 struct lysp_node_grp *grp;
2084 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085
Radek Krejcid3ca0632019-04-16 16:54:54 +02002086 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02002087 ly_print_(ctx->out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002088 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089 }
2090 if (modp->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002091 ly_print_(ctx->out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002092 yprp_extension_instances(ctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093 }
2094
2095 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002096 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 }
2098
2099 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002100 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002101 }
2102
2103 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002104 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002105 }
2106
Radek Krejci2a9fc652021-01-22 17:44:34 +01002107 LY_LIST_FOR(modp->groupings, grp) {
2108 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002109 }
2110
2111 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002112 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002113 }
2114
Radek Krejci2a9fc652021-01-22 17:44:34 +01002115 LY_LIST_FOR(modp->augments, aug) {
2116 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 }
2118
Radek Krejci2a9fc652021-01-22 17:44:34 +01002119 LY_LIST_FOR(modp->rpcs, action) {
2120 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002121 }
2122
Radek Krejci2a9fc652021-01-22 17:44:34 +01002123 LY_LIST_FOR(modp->notifs, notif) {
2124 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002125 }
2126
2127 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002128 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002129 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002130}
2131
2132LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002133yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002134{
2135 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002136 const struct lys_module *module = modp->mod;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002137 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 +02002138
Michal Vasko5233e962020-08-14 14:26:20 +02002139 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002140 LEVEL++;
2141
2142 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002143 if (modp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002144 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 +02002145 }
2146
Radek Krejcifc596f92021-02-26 22:40:26 +01002147 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2148 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002149
2150 /* linkage-stmts (import/include) */
2151 yang_print_parsed_linkage(ctx, modp);
2152
2153 /* meta-stmts */
2154 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002155 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002156 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002157 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2158 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2159 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2160 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002161
2162 /* revision-stmts */
2163 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002164 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002165 }
2166 LY_ARRAY_FOR(modp->revs, u) {
2167 yprp_revision(ctx, &modp->revs[u]);
2168 }
2169 /* body-stmts */
2170 yang_print_parsed_body(ctx, modp);
2171
2172 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002173 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002174 ly_print_flush(out);
2175
2176 return LY_SUCCESS;
2177}
2178
2179static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002180yprp_belongsto(struct lys_ypr_ctx *ctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002181{
Michal Vaskoc3781c32020-10-06 14:04:08 +02002182 ly_print_(ctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002183 LEVEL++;
Radek Krejcifc596f92021-02-26 22:40:26 +01002184 yprp_extension_instances(ctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2185 ypr_substmt(ctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002186 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002187 ly_print_(ctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002188}
2189
2190LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002191yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002192{
2193 LY_ARRAY_COUNT_TYPE u;
Radek Krejci07a55962021-03-02 20:16:43 +01002194 struct lys_ypr_ctx ctx_ = {
2195 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2196 .options = options
2197 }, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002198
Michal Vasko5233e962020-08-14 14:26:20 +02002199 ly_print_(ctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002200 LEVEL++;
2201
2202 /* submodule-header-stmts */
2203 if (submodp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002204 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 +02002205 }
2206
2207 yprp_belongsto(ctx, submodp);
2208
2209 /* linkage-stmts (import/include) */
2210 yang_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
2211
2212 /* meta-stmts */
2213 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002214 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002215 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002216 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2217 ypr_substmt(ctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2218 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2219 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002220
2221 /* revision-stmts */
2222 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002223 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002224 }
2225 LY_ARRAY_FOR(submodp->revs, u) {
2226 yprp_revision(ctx, &submodp->revs[u]);
2227 }
2228 /* body-stmts */
2229 yang_print_parsed_body(ctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002230
2231 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002232 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002233 ly_print_flush(out);
2234
2235 return LY_SUCCESS;
2236}
2237
2238LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002239yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002240{
Radek Krejciadcf63d2021-02-09 10:21:18 +01002241 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *ctx = &ctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002242
2243 yprc_node(ctx, node);
2244
2245 ly_print_flush(out);
2246 return LY_SUCCESS;
2247}
2248
2249LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002250yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002251{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002252 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002253 struct lysc_module *modc = module->compiled;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002254 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options}, *ctx = &ctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002255
Michal Vasko5233e962020-08-14 14:26:20 +02002256 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002257 LEVEL++;
2258
Radek Krejci693262f2019-04-29 15:23:20 +02002259 /* module-header-stmts */
Radek Krejcifc596f92021-02-26 22:40:26 +01002260 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2261 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002262
Michal Vasko7c8439f2020-08-05 13:25:19 +02002263 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002264
2265 /* meta-stmts */
2266 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002267 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002268 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002269 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2270 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2271 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2272 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002273
2274 /* revision-stmts */
2275 if (module->revision) {
Michal Vasko5233e962020-08-14 14:26:20 +02002276 ly_print_(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
Radek Krejci693262f2019-04-29 15:23:20 +02002277 }
2278
2279 /* body-stmts */
2280 if (modc->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002281 ly_print_(out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002282 yprc_extension_instances(ctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02002283 }
2284
Radek Krejci80d281e2020-09-14 17:42:54 +02002285 LY_ARRAY_FOR(module->identities, u) {
2286 yprc_identity(ctx, &module->identities[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02002287 }
2288
Radek Krejci52f65552020-09-01 17:03:35 +02002289 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002290 struct lysc_node *data;
2291 struct lysc_node_action *rpc;
2292 struct lysc_node_notif *notif;
2293
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002294 LY_LIST_FOR(modc->data, data) {
2295 yprc_node(ctx, data);
2296 }
Radek Krejci693262f2019-04-29 15:23:20 +02002297
Radek Krejci2a9fc652021-01-22 17:44:34 +01002298 LY_LIST_FOR(modc->rpcs, rpc) {
2299 yprc_action(ctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002300 }
Radek Krejci693262f2019-04-29 15:23:20 +02002301
Radek Krejci2a9fc652021-01-22 17:44:34 +01002302 LY_LIST_FOR(modc->notifs, notif) {
2303 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002304 }
Radek Krejci693262f2019-04-29 15:23:20 +02002305 }
2306
2307 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002308 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002309 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002310
2311 return LY_SUCCESS;
2312}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002313
2314/**
2315 * @param[in] count Number of extensions to print, 0 to print them all.
2316 */
2317static void
Radek Krejcifc596f92021-02-26 22:40:26 +01002318yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002319 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2320{
2321 LY_ARRAY_COUNT_TYPE u;
2322
2323 if (!count && ext) {
2324 count = LY_ARRAY_COUNT(ext);
2325 }
2326 LY_ARRAY_FOR(ext, u) {
2327 ly_bool inner_flag = 0;
2328
2329 if (!count) {
2330 break;
2331 }
2332
2333 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002334 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002335 continue;
2336 }
2337
2338 ypr_open(ctx->out, flag);
2339 if (ext[u].argument) {
2340 ly_print_(ctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2341 ypr_encode(ctx->out, ext[u].argument, -1);
2342 ly_print_(ctx->out, "\"");
2343 } else {
2344 ly_print_(ctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
2345 }
2346
2347 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002348 yprc_extension_instances(ctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002349
2350 if (ext[u].def->plugin->sprinter) {
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002351 ext[u].def->plugin->sprinter(&ctx->printer_ctx, &ext[u], &inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002352 }
2353
2354 LEVEL--;
2355 ypr_close(ctx, inner_flag);
2356 }
2357}
2358
2359void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002360lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002361{
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002362 struct lys_ypr_ctx *ctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002363 LY_ARRAY_COUNT_TYPE u, v;
2364
2365 LY_ARRAY_FOR(ext->substmts, u) {
2366 switch (ext->substmts[u].stmt) {
2367 case LY_STMT_CHOICE:
2368 case LY_STMT_CONTAINER: {
2369 const struct lysc_node *node;
2370
2371 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
2372 ypr_open(ctx->out, flag);
2373 yprc_node(ctx, node);
2374 }
2375 break;
2376 }
2377 case LY_STMT_DESCRIPTION:
2378 case LY_STMT_REFERENCE:
2379 case LY_STMT_UNITS:
2380 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2381 if (*(const char **)ext->substmts[u].storage) {
2382 ypr_open(ctx->out, flag);
2383 ypr_substmt(ctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
2384 }
2385 } else {
2386 const char **strings = *(const char ***)ext->substmts[u].storage;
2387 LY_ARRAY_FOR(strings, v) {
2388 ypr_open(ctx->out, flag);
2389 ypr_substmt(ctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
2390 }
2391 }
2392 break;
2393 case LY_STMT_IF_FEATURE:
2394 /* nothing to do */
2395 break;
2396 case LY_STMT_STATUS:
2397 ypr_status(ctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2398 break;
2399 case LY_STMT_TYPE:
2400 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2401 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2402 ypr_open(ctx->out, flag);
2403 yprc_type(ctx, *(const struct lysc_type **)ext->substmts[u].storage);
2404 }
2405 } else {
2406 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2407 LY_ARRAY_FOR(types, v) {
2408 ypr_open(ctx->out, flag);
2409 yprc_type(ctx, types[v]);
2410 }
2411 }
2412 break;
2413 /* TODO support other substatements */
2414 default:
2415 LOGWRN(ctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
2416 ly_stmt2str(ext->substmts[u].stmt));
2417 break;
2418 }
2419 }
2420}