blob: 29df721f61c2e1915c465101377c07308bff8391 [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 Krejci77114102021-03-10 15:21:57 +010029#include "plugins_exts.h"
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010030#include "plugins_exts_print.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010041 * @brief Types of the YANG printers
42 */
43enum lys_ypr_schema_type {
44 LYS_YPR_PARSED, /**< YANG printer of the parsed schema */
45 LYS_YPR_COMPILED /**< YANG printer of the compiled schema */
46};
47
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 Krejci224d4b42021-04-23 13:54:59 +0200827yprc_dflt_value(struct lys_ypr_ctx *ctx, const struct ly_ctx *ly_ctx, const struct lyd_value *value,
828 struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200829{
Radek Krejci857189e2020-09-01 13:26:36 +0200830 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200831 const char *str;
832
Radek Krejci224d4b42021-04-23 13:54:59 +0200833 str = value->realtype->plugin->print(ly_ctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL);
Radek Krejcifc596f92021-02-26 22:40:26 +0100834 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200835 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200836 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200837 }
838}
839
840static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100841yprc_type(struct lys_ypr_ctx *ctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200842{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200843 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200844 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200845
Michal Vasko5233e962020-08-14 14:26:20 +0200846 ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200847 LEVEL++;
848
Radek Krejci39b7fc22021-02-26 23:29:18 +0100849 yprc_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200850
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200851 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200852 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200853 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200854 yprc_range(ctx, bin->length, type->basetype, &flag);
855 break;
856 }
857 case LY_TYPE_UINT8:
858 case LY_TYPE_UINT16:
859 case LY_TYPE_UINT32:
860 case LY_TYPE_UINT64:
861 case LY_TYPE_INT8:
862 case LY_TYPE_INT16:
863 case LY_TYPE_INT32:
864 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200865 struct lysc_type_num *num = (struct lysc_type_num *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200866 yprc_range(ctx, num->range, type->basetype, &flag);
867 break;
868 }
869 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200870 struct lysc_type_str *str = (struct lysc_type_str *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200871 yprc_range(ctx, str->length, type->basetype, &flag);
872 LY_ARRAY_FOR(str->patterns, u) {
873 yprc_pattern(ctx, str->patterns[u], &flag);
874 }
875 break;
876 }
877 case LY_TYPE_BITS:
878 case LY_TYPE_ENUM: {
879 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200880 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200881 LY_ARRAY_FOR(bits->bits, u) {
882 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200883 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200884
885 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200886 ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
Radek Krejci693262f2019-04-29 15:23:20 +0200887 ypr_encode(ctx->out, item->name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200888 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200889 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200890 if (type->basetype == LY_TYPE_BITS) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100891 yprc_extension_instances(ctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100892 ypr_unsigned(ctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200893 } else { /* LY_TYPE_ENUM */
Radek Krejci39b7fc22021-02-26 23:29:18 +0100894 yprc_extension_instances(ctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100895 ypr_signed(ctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200896 }
897 ypr_status(ctx, item->flags, item->exts, &inner_flag);
898 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
899 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
900 LEVEL--;
901 ypr_close(ctx, inner_flag);
902 }
903 break;
904 }
905 case LY_TYPE_BOOL:
906 case LY_TYPE_EMPTY:
907 /* nothing to do */
908 break;
909 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200910 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200911 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100912 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200913 yprc_range(ctx, dec->range, dec->basetype, &flag);
914 break;
915 }
916 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200917 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200918 LY_ARRAY_FOR(ident->bases, u) {
919 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100920 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200921 }
922 break;
923 }
924 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200925 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200926 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100927 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200928 break;
929 }
930 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200931 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200932 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100933 ypr_substmt(ctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
934 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200935 yprc_type(ctx, lr->realtype);
936 break;
937 }
938 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200939 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200940 LY_ARRAY_FOR(un->types, u) {
941 ypr_open(ctx->out, &flag);
942 yprc_type(ctx, un->types[u]);
943 }
944 break;
945 }
946 default:
947 LOGINT(ctx->module->ctx);
948 }
949
950 LEVEL--;
951 ypr_close(ctx, flag);
952}
953
954static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100955yprp_typedef(struct lys_ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200956{
Michal Vasko5233e962020-08-14 14:26:20 +0200957 ly_print_(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200958 LEVEL++;
959
Radek Krejci39b7fc22021-02-26 23:29:18 +0100960 yprp_extension_instances(ctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200961
Radek Krejci693262f2019-04-29 15:23:20 +0200962 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200963
964 if (tpdf->units) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100965 ypr_substmt(ctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200966 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200967 if (tpdf->dflt.str) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100968 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200969 }
970
Radek Krejci693262f2019-04-29 15:23:20 +0200971 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200972 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
973 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
974
975 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200976 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200977}
978
Radek Krejciadcf63d2021-02-09 10:21:18 +0100979static void yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node);
980static void yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node);
981static void yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action);
982static void yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200983
984static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100985yprp_grouping(struct lys_ypr_ctx *ctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200986{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200987 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200988 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200989 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100990 struct lysp_node_action *action;
991 struct lysp_node_notif *notif;
992 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993
Michal Vasko5233e962020-08-14 14:26:20 +0200994 ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200995 LEVEL++;
996
Radek Krejci39b7fc22021-02-26 23:29:18 +0100997 yprp_extension_instances(ctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200998 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +0200999 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1000 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001001
1002 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001003 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001004 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001005 }
1006
Radek Krejci2a9fc652021-01-22 17:44:34 +01001007 LY_LIST_FOR(grp->groupings, subgrp) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001008 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001009 yprp_grouping(ctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001010 }
1011
Radek Krejci01180ac2021-01-27 08:48:22 +01001012 LY_LIST_FOR(grp->child, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001013 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001014 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001015 }
1016
Radek Krejci2a9fc652021-01-22 17:44:34 +01001017 LY_LIST_FOR(grp->actions, action) {
1018 ypr_open(ctx->out, &flag);
1019 yprp_action(ctx, action);
1020 }
1021
1022 LY_LIST_FOR(grp->notifs, notif) {
1023 ypr_open(ctx->out, &flag);
1024 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001025 }
1026
1027 LEVEL--;
1028 ypr_close(ctx, flag);
1029}
1030
1031static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001032yprp_inout(struct lys_ypr_ctx *ctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001033{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001034 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001035 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001036 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037
Radek Krejci01180ac2021-01-27 08:48:22 +01001038 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001039 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001040 return;
1041 }
1042 ypr_open(ctx->out, flag);
1043
Michal Vasko544e58a2021-01-28 14:33:41 +01001044 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001045 LEVEL++;
1046
Radek Krejci39b7fc22021-02-26 23:29:18 +01001047 yprp_extension_instances(ctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001048 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001049 yprp_restr(ctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001050 }
1051 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001052 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001054 LY_LIST_FOR(inout->groupings, grp) {
1055 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001056 }
1057
Radek Krejci01180ac2021-01-27 08:48:22 +01001058 LY_LIST_FOR(inout->child, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001059 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001060 }
1061
1062 LEVEL--;
1063 ypr_close(ctx, 1);
1064}
1065
1066static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001067yprc_inout(struct lys_ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001068{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001069 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001070 struct lysc_node *data;
1071
Radek Krejci01180ac2021-01-27 08:48:22 +01001072 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001073 /* input/output is empty */
1074 return;
1075 }
1076 ypr_open(ctx->out, flag);
1077
Michal Vasko544e58a2021-01-28 14:33:41 +01001078 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001079 LEVEL++;
1080
Radek Krejci39b7fc22021-02-26 23:29:18 +01001081 yprc_extension_instances(ctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001082 LY_ARRAY_FOR(inout->musts, u) {
1083 yprc_must(ctx, &inout->musts[u], NULL);
1084 }
1085
Radek Krejci52f65552020-09-01 17:03:35 +02001086 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001087 LY_LIST_FOR(inout->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001088 yprc_node(ctx, data);
1089 }
Radek Krejci693262f2019-04-29 15:23:20 +02001090 }
1091
1092 LEVEL--;
1093 ypr_close(ctx, 1);
1094}
1095
1096static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001097yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001099 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001100 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001101 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001102 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001103
Michal Vasko5233e962020-08-14 14:26:20 +02001104 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001105
1106 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001107 yprp_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001108 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001109
1110 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001111 yprp_restr(ctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001112 }
Radek Krejci693262f2019-04-29 15:23:20 +02001113 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001114 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1115 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1116
1117 LY_ARRAY_FOR(notif->typedefs, u) {
1118 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001119 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120 }
1121
Radek Krejci2a9fc652021-01-22 17:44:34 +01001122 LY_LIST_FOR(notif->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001123 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001124 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001125 }
1126
Radek Krejci01180ac2021-01-27 08:48:22 +01001127 LY_LIST_FOR(notif->child, data) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001128 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001129 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001130 }
1131
1132 LEVEL--;
1133 ypr_close(ctx, flag);
1134}
1135
1136static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001137yprc_notification(struct lys_ypr_ctx *ctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001138{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001139 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001140 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001141 struct lysc_node *data;
1142
Michal Vasko5233e962020-08-14 14:26:20 +02001143 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001144
1145 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001146 yprc_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001147
1148 LY_ARRAY_FOR(notif->musts, u) {
1149 yprc_must(ctx, &notif->musts[u], &flag);
1150 }
1151 ypr_status(ctx, notif->flags, notif->exts, &flag);
1152 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1153 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1154
Radek Krejci52f65552020-09-01 17:03:35 +02001155 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001156 LY_LIST_FOR(notif->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001157 ypr_open(ctx->out, &flag);
1158 yprc_node(ctx, data);
1159 }
Radek Krejci693262f2019-04-29 15:23:20 +02001160 }
1161
1162 LEVEL--;
1163 ypr_close(ctx, flag);
1164}
1165
1166static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001167yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001168{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001169 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001170 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001171 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001172
Michal Vasko5233e962020-08-14 14:26:20 +02001173 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001174
1175 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001176 yprp_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001177 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1178 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001179 ypr_description(ctx, action->dsc, action->exts, &flag);
1180 ypr_reference(ctx, action->ref, action->exts, &flag);
1181
1182 LY_ARRAY_FOR(action->typedefs, u) {
1183 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001184 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001185 }
1186
Radek Krejci2a9fc652021-01-22 17:44:34 +01001187 LY_LIST_FOR(action->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001188 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001189 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001190 }
1191
Radek Krejci693262f2019-04-29 15:23:20 +02001192 yprp_inout(ctx, &action->input, &flag);
1193 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001194
1195 LEVEL--;
1196 ypr_close(ctx, flag);
1197}
1198
1199static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001200yprc_action(struct lys_ypr_ctx *ctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001201{
Radek Krejci857189e2020-09-01 13:26:36 +02001202 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001203
Michal Vasko5233e962020-08-14 14:26:20 +02001204 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001205
1206 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001207 yprc_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001208 ypr_status(ctx, action->flags, action->exts, &flag);
1209 ypr_description(ctx, action->dsc, action->exts, &flag);
1210 ypr_reference(ctx, action->ref, action->exts, &flag);
1211
Michal Vasko544e58a2021-01-28 14:33:41 +01001212 yprc_inout(ctx, &action->input, &flag);
1213 yprc_inout(ctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001214
1215 LEVEL--;
1216 ypr_close(ctx, flag);
1217}
1218
1219static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001220yprp_node_common1(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001221{
Michal Vasko5233e962020-08-14 14:26:20 +02001222 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001223 LEVEL++;
1224
Radek Krejci39b7fc22021-02-26 23:29:18 +01001225 yprp_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001226 yprp_when(ctx, lysp_node_when(node), flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001227 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001228}
1229
1230static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001231yprc_node_common1(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001232{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001233 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001234 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001235
Michal Vasko5233e962020-08-14 14:26:20 +02001236 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001237 LEVEL++;
1238
Radek Krejci39b7fc22021-02-26 23:29:18 +01001239 yprc_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001240
1241 when = lysc_node_when(node);
1242 LY_ARRAY_FOR(when, u) {
1243 yprc_when(ctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001244 }
Radek Krejci693262f2019-04-29 15:23:20 +02001245}
1246
1247/* macr oto unify the code */
1248#define YPR_NODE_COMMON2 \
1249 ypr_config(ctx, node->flags, node->exts, flag); \
1250 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1251 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1252 } \
1253 ypr_status(ctx, node->flags, node->exts, flag); \
1254 ypr_description(ctx, node->dsc, node->exts, flag); \
1255 ypr_reference(ctx, node->ref, node->exts, flag)
1256
1257static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001258yprp_node_common2(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001259{
1260 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261}
1262
1263static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001264yprc_node_common2(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001265{
1266 YPR_NODE_COMMON2;
1267}
1268
1269#undef YPR_NODE_COMMON2
1270
1271static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001272yprp_container(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001273{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001274 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001275 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001276 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001277 struct lysp_node_action *action;
1278 struct lysp_node_notif *notif;
1279 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001280 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1281
Radek Krejci693262f2019-04-29 15:23:20 +02001282 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001283
1284 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001285 yprp_restr(ctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286 }
1287 if (cont->presence) {
1288 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001289 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290 }
1291
Radek Krejci693262f2019-04-29 15:23:20 +02001292 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001293
1294 LY_ARRAY_FOR(cont->typedefs, u) {
1295 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001296 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001297 }
1298
Radek Krejci2a9fc652021-01-22 17:44:34 +01001299 LY_LIST_FOR(cont->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001300 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001301 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001302 }
1303
1304 LY_LIST_FOR(cont->child, child) {
1305 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001306 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001307 }
1308
Radek Krejci2a9fc652021-01-22 17:44:34 +01001309 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001310 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001311 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001312 }
1313
Radek Krejci2a9fc652021-01-22 17:44:34 +01001314 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001315 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001316 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001317 }
1318
1319 LEVEL--;
1320 ypr_close(ctx, flag);
1321}
1322
1323static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001324yprc_container(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001325{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001326 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001327 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001328 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001329 struct lysc_node_action *action;
1330 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001331 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1332
1333 yprc_node_common1(ctx, node, &flag);
1334
1335 LY_ARRAY_FOR(cont->musts, u) {
1336 yprc_must(ctx, &cont->musts[u], &flag);
1337 }
1338 if (cont->flags & LYS_PRESENCE) {
1339 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001340 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001341 }
1342
1343 yprc_node_common2(ctx, node, &flag);
1344
Radek Krejci52f65552020-09-01 17:03:35 +02001345 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001346 LY_LIST_FOR(cont->child, child) {
1347 ypr_open(ctx->out, &flag);
1348 yprc_node(ctx, child);
1349 }
Radek Krejci693262f2019-04-29 15:23:20 +02001350
Radek Krejci2a9fc652021-01-22 17:44:34 +01001351 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001352 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001353 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001354 }
Radek Krejci693262f2019-04-29 15:23:20 +02001355
Radek Krejci2a9fc652021-01-22 17:44:34 +01001356 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001357 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001358 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001359 }
Radek Krejci693262f2019-04-29 15:23:20 +02001360 }
1361
1362 LEVEL--;
1363 ypr_close(ctx, flag);
1364}
1365
1366static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001367yprp_case(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001368{
Radek Krejci857189e2020-09-01 13:26:36 +02001369 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001370 struct lysp_node *child;
1371 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1372
1373 yprp_node_common1(ctx, node, &flag);
1374 yprp_node_common2(ctx, node, &flag);
1375
1376 LY_LIST_FOR(cas->child, child) {
1377 ypr_open(ctx->out, &flag);
1378 yprp_node(ctx, child);
1379 }
1380
1381 LEVEL--;
1382 ypr_close(ctx, flag);
1383}
1384
1385static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001386yprc_case(struct lys_ypr_ctx *ctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001387{
Radek Krejci857189e2020-09-01 13:26:36 +02001388 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001389 struct lysc_node *child;
1390
Michal Vasko14ed9cd2021-01-28 14:16:25 +01001391 yprc_node_common1(ctx, &cs->node, &flag);
1392 yprc_node_common2(ctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001393
Radek Krejci52f65552020-09-01 17:03:35 +02001394 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001395 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001396 ypr_open(ctx->out, &flag);
1397 yprc_node(ctx, child);
1398 }
Radek Krejci693262f2019-04-29 15:23:20 +02001399 }
1400
1401 LEVEL--;
1402 ypr_close(ctx, flag);
1403}
1404
1405static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001406yprp_choice(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001407{
Radek Krejci857189e2020-09-01 13:26:36 +02001408 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001409 struct lysp_node *child;
1410 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1411
Radek Krejci693262f2019-04-29 15:23:20 +02001412 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001413
Michal Vasko7f45cf22020-10-01 12:49:44 +02001414 if (choice->dflt.str) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001415 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001416 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001417 }
1418
Radek Krejci693262f2019-04-29 15:23:20 +02001419 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001420
1421 LY_LIST_FOR(choice->child, child) {
1422 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001423 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001424 }
1425
1426 LEVEL--;
1427 ypr_close(ctx, flag);
1428}
1429
1430static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001431yprc_choice(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001432{
Radek Krejci857189e2020-09-01 13:26:36 +02001433 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001434 struct lysc_node_case *cs;
1435 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1436
1437 yprc_node_common1(ctx, node, &flag);
1438
1439 if (choice->dflt) {
1440 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001441 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001442 }
1443
1444 yprc_node_common2(ctx, node, &flag);
1445
Michal Vasko22df3f02020-08-24 13:29:22 +02001446 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Radek Krejci693262f2019-04-29 15:23:20 +02001447 ypr_open(ctx->out, &flag);
1448 yprc_case(ctx, cs);
1449 }
1450
1451 LEVEL--;
1452 ypr_close(ctx, flag);
1453}
1454
1455static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001456yprp_leaf(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001457{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001458 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001459 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1460
Radek Krejci693262f2019-04-29 15:23:20 +02001461 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001462
Radek Krejci693262f2019-04-29 15:23:20 +02001463 yprp_type(ctx, &leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001464 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001465 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001466 yprp_restr(ctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001467 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001468 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001469
Radek Krejci693262f2019-04-29 15:23:20 +02001470 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471
1472 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001473 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001474}
1475
1476static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001477yprc_leaf(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001478{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001479 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001480 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1481
1482 yprc_node_common1(ctx, node, NULL);
1483
1484 yprc_type(ctx, leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001485 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001486 LY_ARRAY_FOR(leaf->musts, u) {
1487 yprc_must(ctx, &leaf->musts[u], NULL);
1488 }
Radek Krejcia1911222019-07-22 17:24:50 +02001489
1490 if (leaf->dflt) {
Radek Krejci224d4b42021-04-23 13:54:59 +02001491 yprc_dflt_value(ctx, node->module->ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001492 }
Radek Krejci693262f2019-04-29 15:23:20 +02001493
1494 yprc_node_common2(ctx, node, NULL);
1495
1496 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001497 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001498}
1499
1500static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001501yprp_leaflist(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001502{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001503 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001504 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1505
Radek Krejci693262f2019-04-29 15:23:20 +02001506 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001507
Radek Krejci693262f2019-04-29 15:23:20 +02001508 yprp_type(ctx, &llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001509 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001510 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001511 yprp_restr(ctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001512 }
1513 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001514 ypr_substmt(ctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515 }
1516
Radek Krejci693262f2019-04-29 15:23:20 +02001517 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518
1519 if (llist->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001520 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001521 }
1522 if (llist->flags & LYS_SET_MAX) {
1523 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001524 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001525 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001526 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527 }
1528 }
1529
1530 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001531 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001532 }
1533
Radek Krejci693262f2019-04-29 15:23:20 +02001534 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001535 ypr_description(ctx, node->dsc, node->exts, NULL);
1536 ypr_reference(ctx, node->ref, node->exts, NULL);
1537
1538 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001539 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540}
1541
1542static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001543yprc_leaflist(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001544{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001545 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001546 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1547
1548 yprc_node_common1(ctx, node, NULL);
1549
1550 yprc_type(ctx, llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001551 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001552 LY_ARRAY_FOR(llist->musts, u) {
1553 yprc_must(ctx, &llist->musts[u], NULL);
1554 }
1555 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci224d4b42021-04-23 13:54:59 +02001556 yprc_dflt_value(ctx, node->module->ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001557 }
1558
1559 ypr_config(ctx, node->flags, node->exts, NULL);
1560
Radek Krejcifc596f92021-02-26 22:40:26 +01001561 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001562 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001563 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001564 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001565 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001566 }
1567
Radek Krejcifc596f92021-02-26 22:40:26 +01001568 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001569
1570 ypr_status(ctx, node->flags, node->exts, NULL);
1571 ypr_description(ctx, node->dsc, node->exts, NULL);
1572 ypr_reference(ctx, node->ref, node->exts, NULL);
1573
1574 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001575 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001576}
1577
1578static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001579yprp_list(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001580{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001581 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001582 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001584 struct lysp_node_action *action;
1585 struct lysp_node_notif *notif;
1586 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001587 struct lysp_node_list *list = (struct lysp_node_list *)node;
1588
Radek Krejci693262f2019-04-29 15:23:20 +02001589 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590
1591 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001592 yprp_restr(ctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001593 }
1594 if (list->key) {
1595 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001596 ypr_substmt(ctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597 }
1598 LY_ARRAY_FOR(list->uniques, u) {
1599 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001600 ypr_substmt(ctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001601 }
1602
Michal Vaskoacb8e742020-10-20 10:28:02 +02001603 ypr_config(ctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001604
1605 if (list->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001606 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001607 }
1608 if (list->flags & LYS_SET_MAX) {
1609 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001610 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001611 } else {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001612 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001613 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001614 }
1615 }
1616
1617 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001618 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001619 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001620 }
1621
Michal Vaskoacb8e742020-10-20 10:28:02 +02001622 ypr_status(ctx, node->flags, node->exts, &flag);
1623 ypr_description(ctx, node->dsc, node->exts, &flag);
1624 ypr_reference(ctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001625
1626 LY_ARRAY_FOR(list->typedefs, u) {
1627 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001628 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001629 }
1630
Radek Krejci2a9fc652021-01-22 17:44:34 +01001631 LY_LIST_FOR(list->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001632 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001633 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001634 }
1635
1636 LY_LIST_FOR(list->child, child) {
1637 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001638 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001639 }
1640
Radek Krejci2a9fc652021-01-22 17:44:34 +01001641 LY_LIST_FOR(list->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001643 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001644 }
1645
Radek Krejci2a9fc652021-01-22 17:44:34 +01001646 LY_LIST_FOR(list->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001648 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001649 }
1650
1651 LEVEL--;
1652 ypr_close(ctx, flag);
1653}
1654
1655static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001656yprc_list(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001657{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001658 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001659 struct lysc_node_list *list = (struct lysc_node_list *)node;
1660
Michal Vaskoacb8e742020-10-20 10:28:02 +02001661 yprc_node_common1(ctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001662
1663 LY_ARRAY_FOR(list->musts, u) {
1664 yprc_must(ctx, &list->musts[u], NULL);
1665 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001666 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko5233e962020-08-14 14:26:20 +02001667 ly_print_(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001668 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 +02001669 ly_print_(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001670 }
Michal Vasko5233e962020-08-14 14:26:20 +02001671 ly_print_(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001672 }
1673 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02001674 ly_print_(ctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001675 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko5233e962020-08-14 14:26:20 +02001676 ly_print_(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001677 }
1678 ypr_close(ctx, 0);
1679 }
1680
1681 ypr_config(ctx, node->flags, node->exts, NULL);
1682
Radek Krejcifc596f92021-02-26 22:40:26 +01001683 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001684 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001685 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001686 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001687 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001688 }
1689
Radek Krejcifc596f92021-02-26 22:40:26 +01001690 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001691
1692 ypr_status(ctx, node->flags, node->exts, NULL);
1693 ypr_description(ctx, node->dsc, node->exts, NULL);
1694 ypr_reference(ctx, node->ref, node->exts, NULL);
1695
Radek Krejci52f65552020-09-01 17:03:35 +02001696 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001697 struct lysc_node *child;
1698 struct lysc_node_action *action;
1699 struct lysc_node_notif *notif;
1700
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001701 LY_LIST_FOR(list->child, child) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001702 yprc_node(ctx, child);
1703 }
Radek Krejci693262f2019-04-29 15:23:20 +02001704
Radek Krejci2a9fc652021-01-22 17:44:34 +01001705 LY_LIST_FOR(list->actions, action) {
1706 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001707 }
Radek Krejci693262f2019-04-29 15:23:20 +02001708
Radek Krejci2a9fc652021-01-22 17:44:34 +01001709 LY_LIST_FOR(list->notifs, notif) {
1710 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001711 }
Radek Krejci693262f2019-04-29 15:23:20 +02001712 }
1713
1714 LEVEL--;
Michal Vaskoacb8e742020-10-20 10:28:02 +02001715 ypr_close(ctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001716}
1717
1718static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001719yprp_refine(struct lys_ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001720{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001721 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001722 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001723
Michal Vasko5233e962020-08-14 14:26:20 +02001724 ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001725 LEVEL++;
1726
Radek Krejci39b7fc22021-02-26 23:29:18 +01001727 yprp_extension_instances(ctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001728 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001729
1730 LY_ARRAY_FOR(refine->musts, u) {
1731 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001732 yprp_restr(ctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001733 }
1734
1735 if (refine->presence) {
1736 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001737 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001738 }
1739
1740 LY_ARRAY_FOR(refine->dflts, u) {
1741 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001742 ypr_substmt(ctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001743 }
1744
Radek Krejci693262f2019-04-29 15:23:20 +02001745 ypr_config(ctx, refine->flags, refine->exts, &flag);
1746 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001747
1748 if (refine->flags & LYS_SET_MIN) {
1749 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001750 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001751 }
1752 if (refine->flags & LYS_SET_MAX) {
1753 ypr_open(ctx->out, &flag);
1754 if (refine->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001755 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001757 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001758 }
1759 }
1760
1761 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1762 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1763
1764 LEVEL--;
1765 ypr_close(ctx, flag);
1766}
1767
1768static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001769yprp_augment(struct lys_ypr_ctx *ctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001770{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001771 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001772 struct lysp_node_action *action;
1773 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774
Michal Vasko5233e962020-08-14 14:26:20 +02001775 ly_print_(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001776 LEVEL++;
1777
Radek Krejci39b7fc22021-02-26 23:29:18 +01001778 yprp_extension_instances(ctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001779 yprp_when(ctx, aug->when, NULL);
1780 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1781 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001782 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1783 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1784
1785 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001786 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 }
1788
Radek Krejci2a9fc652021-01-22 17:44:34 +01001789 LY_LIST_FOR(aug->actions, action) {
1790 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791 }
1792
Radek Krejci2a9fc652021-01-22 17:44:34 +01001793 LY_LIST_FOR(aug->notifs, notif) {
1794 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795 }
1796
1797 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001798 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799}
1800
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001802yprp_uses(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001803{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001804 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001805 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001807 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001808
Radek Krejci693262f2019-04-29 15:23:20 +02001809 yprp_node_common1(ctx, node, &flag);
1810 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001811
1812 LY_ARRAY_FOR(uses->refines, u) {
1813 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001814 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001815 }
1816
Radek Krejci2a9fc652021-01-22 17:44:34 +01001817 LY_LIST_FOR(uses->augments, aug) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001818 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001819 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001820 }
1821
1822 LEVEL--;
1823 ypr_close(ctx, flag);
1824}
1825
1826static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001827yprp_anydata(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001829 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001830 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001831 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1832
Radek Krejci693262f2019-04-29 15:23:20 +02001833 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001834
1835 LY_ARRAY_FOR(any->musts, u) {
1836 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001837 yprp_restr(ctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838 }
1839
Radek Krejci693262f2019-04-29 15:23:20 +02001840 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841
1842 LEVEL--;
1843 ypr_close(ctx, flag);
1844}
1845
1846static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001847yprc_anydata(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001848{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001849 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001850 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001851 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001852
Radek Krejci693262f2019-04-29 15:23:20 +02001853 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854
Radek Krejci693262f2019-04-29 15:23:20 +02001855 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001857 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 }
1859
Radek Krejci693262f2019-04-29 15:23:20 +02001860 yprc_node_common2(ctx, node, &flag);
1861
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862 LEVEL--;
1863 ypr_close(ctx, flag);
1864}
1865
1866static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001867yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868{
1869 switch (node->nodetype) {
1870 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001871 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872 break;
1873 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001874 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001875 break;
1876 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001877 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001878 break;
1879 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001880 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001881 break;
1882 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001883 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 break;
1885 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001886 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887 break;
1888 case LYS_ANYXML:
1889 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001890 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891 break;
1892 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001893 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894 break;
1895 default:
1896 break;
1897 }
1898}
1899
1900static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001901yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001902{
1903 switch (node->nodetype) {
1904 case LYS_CONTAINER:
1905 yprc_container(ctx, node);
1906 break;
1907 case LYS_CHOICE:
1908 yprc_choice(ctx, node);
1909 break;
1910 case LYS_LEAF:
1911 yprc_leaf(ctx, node);
1912 break;
1913 case LYS_LEAFLIST:
1914 yprc_leaflist(ctx, node);
1915 break;
1916 case LYS_LIST:
1917 yprc_list(ctx, node);
1918 break;
1919 case LYS_ANYXML:
1920 case LYS_ANYDATA:
1921 yprc_anydata(ctx, node);
1922 break;
1923 default:
1924 break;
1925 }
1926}
1927
1928static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001929yprp_deviation(struct lys_ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001931 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932 struct lysp_deviate_add *add;
1933 struct lysp_deviate_rpl *rpl;
1934 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001935 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936
Michal Vasko5233e962020-08-14 14:26:20 +02001937 ly_print_(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001938 LEVEL++;
1939
Radek Krejci39b7fc22021-02-26 23:29:18 +01001940 yprp_extension_instances(ctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001941 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1942 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1943
fredgan2b11ddb2019-10-21 11:03:39 +08001944 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko5233e962020-08-14 14:26:20 +02001945 ly_print_(ctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001946 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1947 if (elem->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02001948 ly_print_(ctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001949 LEVEL++;
1950
Radek Krejci39b7fc22021-02-26 23:29:18 +01001951 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001952 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02001953 ly_print_(ctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001954 continue;
1955 }
fredgan2b11ddb2019-10-21 11:03:39 +08001956 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001957 add = (struct lysp_deviate_add *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001958 ly_print_(ctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001959 LEVEL++;
1960
Radek Krejci39b7fc22021-02-26 23:29:18 +01001961 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001962 ypr_substmt(ctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001963 LY_ARRAY_FOR(add->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001964 yprp_restr(ctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001965 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001966 LY_ARRAY_FOR(add->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001967 ypr_substmt(ctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001968 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001969 LY_ARRAY_FOR(add->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001970 ypr_substmt(ctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001971 }
Radek Krejci693262f2019-04-29 15:23:20 +02001972 ypr_config(ctx, add->flags, add->exts, NULL);
1973 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 if (add->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001975 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 }
1977 if (add->flags & LYS_SET_MAX) {
1978 if (add->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001979 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001980 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001981 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982 }
1983 }
fredgan2b11ddb2019-10-21 11:03:39 +08001984 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001985 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001986 ly_print_(ctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 LEVEL++;
1988
Radek Krejci39b7fc22021-02-26 23:29:18 +01001989 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001991 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001992 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001993 ypr_substmt(ctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
1994 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001995 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1996 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001997 if (rpl->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001998 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001999 }
2000 if (rpl->flags & LYS_SET_MAX) {
2001 if (rpl->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002002 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01002004 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 }
2006 }
fredgan2b11ddb2019-10-21 11:03:39 +08002007 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02002008 del = (struct lysp_deviate_del *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02002009 ly_print_(ctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 LEVEL++;
2011
Radek Krejci39b7fc22021-02-26 23:29:18 +01002012 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002013 ypr_substmt(ctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002014 LY_ARRAY_FOR(del->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01002015 yprp_restr(ctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002017 LY_ARRAY_FOR(del->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002018 ypr_substmt(ctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002019 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02002020 LY_ARRAY_FOR(del->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002021 ypr_substmt(ctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 }
2023 }
2024
2025 LEVEL--;
2026 ypr_close(ctx, 1);
2027 }
2028
2029 LEVEL--;
2030 ypr_close(ctx, 1);
2031}
2032
Michal Vasko7c8439f2020-08-05 13:25:19 +02002033static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002034yang_print_parsed_linkage(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002036 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002039 if (modp->imports[u].flags & LYS_INTERNAL) {
2040 continue;
2041 }
2042
Michal Vasko5233e962020-08-14 14:26:20 +02002043 ly_print_(ctx->out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002045 yprp_extension_instances(ctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002046 ypr_substmt(ctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 if (modp->imports[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002048 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002050 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2051 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002053 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002054 }
2055 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002056 if (modp->includes[u].injected) {
2057 /* do not print the includes injected from submodules */
2058 continue;
2059 }
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060 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 +02002061 ly_print_(ctx->out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002063 yprp_extension_instances(ctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064 if (modp->includes[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002065 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002066 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002067 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2068 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002069 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002070 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002071 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02002072 ly_print_(ctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002073 }
2074 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002075}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002076
Michal Vasko7c8439f2020-08-05 13:25:19 +02002077static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002078yang_print_parsed_body(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002079{
2080 LY_ARRAY_COUNT_TYPE u;
2081 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002082 struct lysp_node_action *action;
2083 struct lysp_node_notif *notif;
2084 struct lysp_node_grp *grp;
2085 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002086
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02002088 ly_print_(ctx->out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002089 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002090 }
2091 if (modp->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002092 ly_print_(ctx->out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002093 yprp_extension_instances(ctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 }
2095
2096 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002097 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002098 }
2099
2100 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002101 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 }
2103
2104 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002105 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106 }
2107
Radek Krejci2a9fc652021-01-22 17:44:34 +01002108 LY_LIST_FOR(modp->groupings, grp) {
2109 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002110 }
2111
2112 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002113 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002114 }
2115
Radek Krejci2a9fc652021-01-22 17:44:34 +01002116 LY_LIST_FOR(modp->augments, aug) {
2117 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118 }
2119
Radek Krejci2a9fc652021-01-22 17:44:34 +01002120 LY_LIST_FOR(modp->rpcs, action) {
2121 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 }
2123
Radek Krejci2a9fc652021-01-22 17:44:34 +01002124 LY_LIST_FOR(modp->notifs, notif) {
2125 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002126 }
2127
2128 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002129 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002130 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002131}
2132
2133LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002134yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002135{
2136 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002137 const struct lys_module *module = modp->mod;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002138 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 +02002139
Michal Vasko5233e962020-08-14 14:26:20 +02002140 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002141 LEVEL++;
2142
2143 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002144 if (modp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002145 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 +02002146 }
2147
Radek Krejcifc596f92021-02-26 22:40:26 +01002148 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2149 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002150
2151 /* linkage-stmts (import/include) */
2152 yang_print_parsed_linkage(ctx, modp);
2153
2154 /* meta-stmts */
2155 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002156 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002157 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002158 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2159 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2160 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2161 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002162
2163 /* revision-stmts */
2164 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002165 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002166 }
2167 LY_ARRAY_FOR(modp->revs, u) {
2168 yprp_revision(ctx, &modp->revs[u]);
2169 }
2170 /* body-stmts */
2171 yang_print_parsed_body(ctx, modp);
2172
2173 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002174 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002175 ly_print_flush(out);
2176
2177 return LY_SUCCESS;
2178}
2179
2180static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002181yprp_belongsto(struct lys_ypr_ctx *ctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002182{
Michal Vaskoc3781c32020-10-06 14:04:08 +02002183 ly_print_(ctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002184 LEVEL++;
Radek Krejcifc596f92021-02-26 22:40:26 +01002185 yprp_extension_instances(ctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2186 ypr_substmt(ctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002187 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002188 ly_print_(ctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002189}
2190
2191LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002192yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002193{
2194 LY_ARRAY_COUNT_TYPE u;
Radek Krejci07a55962021-03-02 20:16:43 +01002195 struct lys_ypr_ctx ctx_ = {
2196 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2197 .options = options
2198 }, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002199
Michal Vasko5233e962020-08-14 14:26:20 +02002200 ly_print_(ctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002201 LEVEL++;
2202
2203 /* submodule-header-stmts */
2204 if (submodp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002205 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 +02002206 }
2207
2208 yprp_belongsto(ctx, submodp);
2209
2210 /* linkage-stmts (import/include) */
2211 yang_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
2212
2213 /* meta-stmts */
2214 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002215 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002216 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002217 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2218 ypr_substmt(ctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2219 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2220 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002221
2222 /* revision-stmts */
2223 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002224 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002225 }
2226 LY_ARRAY_FOR(submodp->revs, u) {
2227 yprp_revision(ctx, &submodp->revs[u]);
2228 }
2229 /* body-stmts */
2230 yang_print_parsed_body(ctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002231
2232 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002233 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002234 ly_print_flush(out);
2235
2236 return LY_SUCCESS;
2237}
2238
2239LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002240yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002241{
Radek Krejciadcf63d2021-02-09 10:21:18 +01002242 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *ctx = &ctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002243
2244 yprc_node(ctx, node);
2245
2246 ly_print_flush(out);
2247 return LY_SUCCESS;
2248}
2249
2250LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002251yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002252{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002253 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002254 struct lysc_module *modc = module->compiled;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002255 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options}, *ctx = &ctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002256
Michal Vasko5233e962020-08-14 14:26:20 +02002257 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002258 LEVEL++;
2259
Radek Krejci693262f2019-04-29 15:23:20 +02002260 /* module-header-stmts */
Radek Krejcifc596f92021-02-26 22:40:26 +01002261 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2262 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002263
Michal Vasko7c8439f2020-08-05 13:25:19 +02002264 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002265
2266 /* meta-stmts */
2267 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002268 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002269 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002270 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2271 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2272 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2273 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002274
2275 /* revision-stmts */
2276 if (module->revision) {
Michal Vasko5233e962020-08-14 14:26:20 +02002277 ly_print_(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
Radek Krejci693262f2019-04-29 15:23:20 +02002278 }
2279
2280 /* body-stmts */
2281 if (modc->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002282 ly_print_(out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002283 yprc_extension_instances(ctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02002284 }
2285
Radek Krejci80d281e2020-09-14 17:42:54 +02002286 LY_ARRAY_FOR(module->identities, u) {
2287 yprc_identity(ctx, &module->identities[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02002288 }
2289
Radek Krejci52f65552020-09-01 17:03:35 +02002290 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002291 struct lysc_node *data;
2292 struct lysc_node_action *rpc;
2293 struct lysc_node_notif *notif;
2294
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002295 LY_LIST_FOR(modc->data, data) {
2296 yprc_node(ctx, data);
2297 }
Radek Krejci693262f2019-04-29 15:23:20 +02002298
Radek Krejci2a9fc652021-01-22 17:44:34 +01002299 LY_LIST_FOR(modc->rpcs, rpc) {
2300 yprc_action(ctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002301 }
Radek Krejci693262f2019-04-29 15:23:20 +02002302
Radek Krejci2a9fc652021-01-22 17:44:34 +01002303 LY_LIST_FOR(modc->notifs, notif) {
2304 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002305 }
Radek Krejci693262f2019-04-29 15:23:20 +02002306 }
2307
2308 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002309 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002310 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002311
2312 return LY_SUCCESS;
2313}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002314
2315/**
2316 * @param[in] count Number of extensions to print, 0 to print them all.
2317 */
2318static void
Radek Krejcifc596f92021-02-26 22:40:26 +01002319yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002320 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2321{
2322 LY_ARRAY_COUNT_TYPE u;
2323
2324 if (!count && ext) {
2325 count = LY_ARRAY_COUNT(ext);
2326 }
2327 LY_ARRAY_FOR(ext, u) {
2328 ly_bool inner_flag = 0;
2329
2330 if (!count) {
2331 break;
2332 }
2333
2334 count--;
Radek Krejciab430862021-03-02 20:13:40 +01002335 if ((ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
Radek Krejciadcf63d2021-02-09 10:21:18 +01002336 continue;
2337 }
2338
2339 ypr_open(ctx->out, flag);
2340 if (ext[u].argument) {
2341 ly_print_(ctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2342 ypr_encode(ctx->out, ext[u].argument, -1);
2343 ly_print_(ctx->out, "\"");
2344 } else {
2345 ly_print_(ctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
2346 }
2347
2348 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002349 yprc_extension_instances(ctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002350
Radek Krejci4a4d1e02021-04-09 14:04:40 +02002351 if (ext[u].def->plugin && ext[u].def->plugin->sprinter) {
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002352 ext[u].def->plugin->sprinter(&ctx->printer_ctx, &ext[u], &inner_flag);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002353 }
2354
2355 LEVEL--;
2356 ypr_close(ctx, inner_flag);
2357 }
2358}
2359
2360void
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002361lysc_print_extension_instance(struct lyspr_ctx *ctx_generic, const struct lysc_ext_instance *ext, ly_bool *flag)
Radek Krejciadcf63d2021-02-09 10:21:18 +01002362{
Radek Krejcif8d7f9a2021-03-10 14:32:36 +01002363 struct lys_ypr_ctx *ctx = (struct lys_ypr_ctx *)ctx_generic;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002364 LY_ARRAY_COUNT_TYPE u, v;
2365
2366 LY_ARRAY_FOR(ext->substmts, u) {
2367 switch (ext->substmts[u].stmt) {
2368 case LY_STMT_CHOICE:
2369 case LY_STMT_CONTAINER: {
2370 const struct lysc_node *node;
2371
2372 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
2373 ypr_open(ctx->out, flag);
2374 yprc_node(ctx, node);
2375 }
2376 break;
2377 }
2378 case LY_STMT_DESCRIPTION:
2379 case LY_STMT_REFERENCE:
2380 case LY_STMT_UNITS:
2381 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2382 if (*(const char **)ext->substmts[u].storage) {
2383 ypr_open(ctx->out, flag);
2384 ypr_substmt(ctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
2385 }
2386 } else {
2387 const char **strings = *(const char ***)ext->substmts[u].storage;
2388 LY_ARRAY_FOR(strings, v) {
2389 ypr_open(ctx->out, flag);
2390 ypr_substmt(ctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
2391 }
2392 }
2393 break;
2394 case LY_STMT_IF_FEATURE:
2395 /* nothing to do */
2396 break;
2397 case LY_STMT_STATUS:
2398 ypr_status(ctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2399 break;
2400 case LY_STMT_TYPE:
2401 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2402 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2403 ypr_open(ctx->out, flag);
2404 yprc_type(ctx, *(const struct lysc_type **)ext->substmts[u].storage);
2405 }
2406 } else {
2407 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2408 LY_ARRAY_FOR(types, v) {
2409 ypr_open(ctx->out, flag);
2410 yprc_type(ctx, types[v]);
2411 }
2412 }
2413 break;
2414 /* TODO support other substatements */
2415 default:
2416 LOGWRN(ctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
2417 ly_stmt2str(ext->substmts[u].stmt));
2418 break;
2419 }
2420 }
2421}