blob: c3a31a67b5aa6b9d403c9e7c472a32fe4c76bb34 [file] [log] [blame]
FredGand944bdc2019-11-05 21:57:07 +08001/**
2 * @file printer_yin.c
3 * @author Fred Gan <ganshaolong@vip.qq.com>
Michal Vaskob26d09d2022-08-22 09:52:19 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
FredGand944bdc2019-11-05 21:57:07 +08005 * @brief YIN printer
6 *
Michal Vaskob26d09d2022-08-22 09:52:19 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
FredGand944bdc2019-11-05 21:57:07 +08008 *
9 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
Radek Krejci535ea9f2020-05-29 16:01:05 +020016#define _GNU_SOURCE
FredGand944bdc2019-11-05 21:57:07 +080017
FredGand944bdc2019-11-05 21:57:07 +080018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
FredGand944bdc2019-11-05 21:57:07 +080021
Radek Krejciaa45bda2020-07-20 07:43:38 +020022#include "compat.h"
FredGand944bdc2019-11-05 21:57:07 +080023#include "log.h"
Michal Vasko8f702ee2024-02-20 15:44:24 +010024#include "ly_common.h"
Radek Krejci47fab892020-11-05 17:02:41 +010025#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020026#include "out_internal.h"
FredGand944bdc2019-11-05 21:57:07 +080027#include "printer_internal.h"
28#include "tree.h"
29#include "tree_schema.h"
30#include "tree_schema_internal.h"
FredGand944bdc2019-11-05 21:57:07 +080031#include "xml.h"
Michal Vasko004d3152020-06-11 19:59:22 +020032#include "xpath.h"
FredGand944bdc2019-11-05 21:57:07 +080033
34/**
35 * @brief YIN printer context.
36 */
Radek Krejciadcf63d2021-02-09 10:21:18 +010037struct lys_ypr_ctx {
Radek Krejcif8d7f9a2021-03-10 14:32:36 +010038 union {
39 struct {
40 struct ly_out *out; /**< output specification */
41 uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
42 uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */
43 const struct lys_module *module; /**< schema to print */
44 };
45 struct lyspr_ctx printer_ctx;
46 };
47
48 /* YIN printer specific members */
FredGand944bdc2019-11-05 21:57:07 +080049};
50
FredGand944bdc2019-11-05 21:57:07 +080051static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +010052ypr_open(struct lys_ypr_ctx *pctx, const char *elem_name, const char *attr_name, const char *attr_value, int8_t flag)
FredGand944bdc2019-11-05 21:57:07 +080053{
Michal Vasko61ad1ff2022-02-10 15:48:39 +010054 ly_print_(pctx->out, "%*s<%s", INDENT, elem_name);
FredGand944bdc2019-11-05 21:57:07 +080055
56 if (attr_name) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +010057 ly_print_(pctx->out, " %s=\"", attr_name);
58 lyxml_dump_text(pctx->out, attr_value, 1);
59 ly_print_(pctx->out, "\"%s", flag == -1 ? "/>\n" : flag == 1 ? ">\n" : "");
FredGand944bdc2019-11-05 21:57:07 +080060 } else if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +010061 ly_print_(pctx->out, flag == -1 ? "/>\n" : ">\n");
FredGand944bdc2019-11-05 21:57:07 +080062 }
63}
64
65static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +010066ypr_close(struct lys_ypr_ctx *pctx, const char *elem_name, int8_t flag)
FredGand944bdc2019-11-05 21:57:07 +080067{
68 if (flag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +010069 ly_print_(pctx->out, "%*s</%s>\n", INDENT, elem_name);
FredGand944bdc2019-11-05 21:57:07 +080070 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +010071 ly_print_(pctx->out, "/>\n");
FredGand944bdc2019-11-05 21:57:07 +080072 }
73}
74
75/*
76 * par_close_flag
77 * 0 - parent not yet closed, printing >\n, setting flag to 1
78 * 1 or NULL - parent already closed, do nothing
79 */
80static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +010081ypr_close_parent(struct lys_ypr_ctx *pctx, int8_t *par_close_flag)
FredGand944bdc2019-11-05 21:57:07 +080082{
83 if (par_close_flag && !(*par_close_flag)) {
84 (*par_close_flag) = 1;
Michal Vasko61ad1ff2022-02-10 15:48:39 +010085 ly_print_(pctx->out, ">\n");
FredGand944bdc2019-11-05 21:57:07 +080086 }
87}
88
89static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +010090ypr_yin_arg(struct lys_ypr_ctx *pctx, const char *arg, const char *text)
FredGand944bdc2019-11-05 21:57:07 +080091{
Michal Vasko61ad1ff2022-02-10 15:48:39 +010092 ly_print_(pctx->out, "%*s<%s>", INDENT, arg);
93 lyxml_dump_text(pctx->out, text, 0);
94 ly_print_(pctx->out, "</%s>\n", arg);
FredGand944bdc2019-11-05 21:57:07 +080095}
96
FredGand944bdc2019-11-05 21:57:07 +080097static void
Michal Vaskob26d09d2022-08-22 09:52:19 +020098yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt)
99{
100 struct lysp_stmt *childstmt;
101 int8_t flag = stmt->child ? 1 : -1;
102
Michal Vaskob872d0f2022-12-08 09:36:54 +0100103 if (lys_stmt_str(stmt->kw)) {
104 if (lys_stmt_flags(stmt->kw) & LY_STMT_FLAG_YIN) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200105 ypr_open(pctx, stmt->stmt, NULL, NULL, flag);
Michal Vaskob872d0f2022-12-08 09:36:54 +0100106 ypr_yin_arg(pctx, lys_stmt_arg(stmt->kw), stmt->arg);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200107 } else {
Michal Vaskob872d0f2022-12-08 09:36:54 +0100108 ypr_open(pctx, stmt->stmt, lys_stmt_arg(stmt->kw), stmt->arg, flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200109 }
zhangtaoga6c2b2c2024-02-21 15:26:15 +0800110 } else if (stmt->kw == LY_STMT_EXTENSION_INSTANCE) {
111 ypr_open(pctx, stmt->stmt, (stmt->arg && stmt->arg[0]) ? lys_stmt_arg(LY_STMT_VALUE) : NULL, stmt->arg, flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200112 }
113
114 if (stmt->child) {
115 LEVEL++;
116 LY_LIST_FOR(stmt->child, childstmt) {
117 yprp_stmt(pctx, childstmt);
118 }
119 LEVEL--;
120 ypr_close(pctx, stmt->stmt, flag);
121 }
122}
123
124static void
125yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
126 struct lysp_ext_instance *ext, int8_t *flag)
127{
128 struct lysp_stmt *stmt;
129 int8_t inner_flag;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200130
131 if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) {
132 return;
133 }
134
Michal Vaskob26d09d2022-08-22 09:52:19 +0200135 ypr_close_parent(pctx, flag);
136 inner_flag = 0;
137
Michal Vasko193dacd2022-10-13 08:43:05 +0200138 ypr_open(pctx, ext->name, (ext->def->flags & LYS_YINELEM_TRUE) ? NULL : ext->def->argname, ext->argument, inner_flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200139 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +0200140 if (ext->def->flags & LYS_YINELEM_TRUE) {
Michal Vaskob26d09d2022-08-22 09:52:19 +0200141 const char *prefix, *name, *id;
142 size_t prefix_len, name_len;
143
144 ypr_close_parent(pctx, &inner_flag);
145
146 /* we need to use the same namespace as for the extension instance element */
147 id = ext->name;
148 ly_parse_nodeid(&id, &prefix, &prefix_len, &name, &name_len);
Michal Vasko193dacd2022-10-13 08:43:05 +0200149 ly_print_(pctx->out, "%*s<%.*s:%s>", INDENT, (int)prefix_len, prefix, ext->def->argname);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200150 lyxml_dump_text(pctx->out, ext->argument, 0);
Michal Vasko193dacd2022-10-13 08:43:05 +0200151 ly_print_(pctx->out, "</%.*s:%s>\n", (int)prefix_len, prefix, ext->def->argname);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200152 }
153 LY_LIST_FOR(ext->child, stmt) {
154 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
155 continue;
156 }
157
158 ypr_close_parent(pctx, &inner_flag);
159 yprp_stmt(pctx, stmt);
160 }
161 LEVEL--;
162 ypr_close(pctx, ext->name, inner_flag);
163}
164
165static void
166yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index,
167 struct lysp_ext_instance *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800168{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200169 LY_ARRAY_COUNT_TYPE u;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200170
171 LY_ARRAY_FOR(exts, u) {
172 yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag);
173 }
174}
175
176static void
177ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts)
178{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200179 int8_t extflag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800180
181 if (!text) {
182 /* nothing to print */
183 return;
184 }
185
Michal Vaskob872d0f2022-12-08 09:36:54 +0100186 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) {
FredGand944bdc2019-11-05 21:57:07 +0800187 extflag = 1;
Michal Vaskob872d0f2022-12-08 09:36:54 +0100188 ypr_open(pctx, lys_stmt_str(substmt), NULL, NULL, extflag);
FredGand944bdc2019-11-05 21:57:07 +0800189 } else {
Michal Vaskob872d0f2022-12-08 09:36:54 +0100190 ypr_open(pctx, lys_stmt_str(substmt), lys_stmt_arg(substmt), text, extflag);
FredGand944bdc2019-11-05 21:57:07 +0800191 }
192
193 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200194 yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag);
FredGand944bdc2019-11-05 21:57:07 +0800195
196 /* argument as yin-element */
Michal Vaskob872d0f2022-12-08 09:36:54 +0100197 if (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) {
198 ypr_yin_arg(pctx, lys_stmt_arg(substmt), text);
FredGand944bdc2019-11-05 21:57:07 +0800199 }
200
201 LEVEL--;
Michal Vaskob872d0f2022-12-08 09:36:54 +0100202 ypr_close(pctx, lys_stmt_str(substmt), extflag);
FredGand944bdc2019-11-05 21:57:07 +0800203}
204
205static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100206ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, unsigned long attr_value)
FredGand944bdc2019-11-05 21:57:07 +0800207{
208 char *str;
Michal Vasko69730152020-10-09 16:30:07 +0200209
Radek Krejci1deb5be2020-08-26 16:43:36 +0200210 if (asprintf(&str, "%lu", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100211 LOGMEM(pctx->module->ctx);
FredGand944bdc2019-11-05 21:57:07 +0800212 return;
213 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100214 ypr_substmt(pctx, substmt, substmt_index, str, exts);
FredGand944bdc2019-11-05 21:57:07 +0800215 free(str);
216}
217
218static void
Michal Vasko2bf4af42023-01-04 12:08:38 +0100219ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value)
FredGand944bdc2019-11-05 21:57:07 +0800220{
221 char *str;
222
Radek Krejci1deb5be2020-08-26 16:43:36 +0200223 if (asprintf(&str, "%ld", attr_value) == -1) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100224 LOGMEM(pctx->module->ctx);
FredGand944bdc2019-11-05 21:57:07 +0800225 return;
226 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100227 ypr_substmt(pctx, substmt, substmt_index, str, exts);
FredGand944bdc2019-11-05 21:57:07 +0800228 free(str);
229}
230
231static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100232yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev)
FredGand944bdc2019-11-05 21:57:07 +0800233{
234 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100235 ypr_open(pctx, "revision", "date", rev->date, 1);
FredGand944bdc2019-11-05 21:57:07 +0800236 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200237 yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100238 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
239 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
FredGand944bdc2019-11-05 21:57:07 +0800240 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100241 ypr_close(pctx, "revision", 1);
FredGand944bdc2019-11-05 21:57:07 +0800242 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100243 ypr_open(pctx, "revision", "date", rev->date, -1);
FredGand944bdc2019-11-05 21:57:07 +0800244 }
245}
246
247static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100248ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800249{
250 if (flags & LYS_MAND_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100251 ypr_close_parent(pctx, flag);
252 ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
FredGand944bdc2019-11-05 21:57:07 +0800253 }
254}
255
256static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100257ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800258{
259 if (flags & LYS_CONFIG_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100260 ypr_close_parent(pctx, flag);
261 ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
FredGand944bdc2019-11-05 21:57:07 +0800262 }
263}
264
265static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100266ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800267{
268 const char *status = NULL;
269
270 if (flags & LYS_STATUS_CURR) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100271 ypr_close_parent(pctx, flag);
FredGand944bdc2019-11-05 21:57:07 +0800272 status = "current";
273 } else if (flags & LYS_STATUS_DEPRC) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100274 ypr_close_parent(pctx, flag);
FredGand944bdc2019-11-05 21:57:07 +0800275 status = "deprecated";
276 } else if (flags & LYS_STATUS_OBSLT) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100277 ypr_close_parent(pctx, flag);
FredGand944bdc2019-11-05 21:57:07 +0800278 status = "obsolete";
279 }
280
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100281 ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts);
FredGand944bdc2019-11-05 21:57:07 +0800282}
283
284static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100285ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800286{
287 if (dsc) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100288 ypr_close_parent(pctx, flag);
289 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
FredGand944bdc2019-11-05 21:57:07 +0800290 }
291}
292
293static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100294ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800295{
296 if (ref) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100297 ypr_close_parent(pctx, flag);
298 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts);
FredGand944bdc2019-11-05 21:57:07 +0800299 }
300}
301
302static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100303yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800304{
Michal Vaskob26d09d2022-08-22 09:52:19 +0200305 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200306 int8_t extflag;
FredGand944bdc2019-11-05 21:57:07 +0800307
Michal Vasko7f45cf22020-10-01 12:49:44 +0200308 LY_ARRAY_FOR(iffs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100309 ypr_close_parent(pctx, flag);
FredGand944bdc2019-11-05 21:57:07 +0800310 extflag = 0;
311
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100312 ly_print_(pctx->out, "%*s<if-feature name=\"%s", INDENT, iffs[u].str);
FredGand944bdc2019-11-05 21:57:07 +0800313
314 /* extensions */
315 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200316 yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag);
FredGand944bdc2019-11-05 21:57:07 +0800317 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100318 ly_print_(pctx->out, "\"/>\n");
FredGand944bdc2019-11-05 21:57:07 +0800319 }
320}
321
322static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100323yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext)
FredGand944bdc2019-11-05 21:57:07 +0800324{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200325 int8_t flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200326 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +0800327
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100328 ypr_open(pctx, "extension", "name", ext->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800329 LEVEL++;
330
331 if (ext->exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100332 ypr_close_parent(pctx, &flag);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200333 yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800334 }
335
Radek Krejci9f87b0c2021-03-05 14:45:26 +0100336 if (ext->argname) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100337 ypr_close_parent(pctx, &flag);
338 ypr_open(pctx, "argument", "name", ext->argname, flag2);
FredGand944bdc2019-11-05 21:57:07 +0800339
340 LEVEL++;
341 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200342 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100343 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100344 ypr_close_parent(pctx, &flag2);
Michal Vaskob26d09d2022-08-22 09:52:19 +0200345 yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2);
FredGand944bdc2019-11-05 21:57:07 +0800346 }
347 }
348 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100349 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100350 ypr_close_parent(pctx, &flag2);
351 ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
FredGand944bdc2019-11-05 21:57:07 +0800352 }
353 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100354 ypr_close(pctx, "argument", flag2);
FredGand944bdc2019-11-05 21:57:07 +0800355 }
356
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100357 ypr_status(pctx, ext->flags, ext->exts, &flag);
358 ypr_description(pctx, ext->dsc, ext->exts, &flag);
359 ypr_reference(pctx, ext->ref, ext->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800360
361 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100362 ypr_close(pctx, "extension", flag);
FredGand944bdc2019-11-05 21:57:07 +0800363}
364
365static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100366yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat)
FredGand944bdc2019-11-05 21:57:07 +0800367{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200368 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800369
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100370 ypr_open(pctx, "feature", "name", feat->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800371 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200372 yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100373 yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag);
374 ypr_status(pctx, feat->flags, feat->exts, &flag);
375 ypr_description(pctx, feat->dsc, feat->exts, &flag);
376 ypr_reference(pctx, feat->ref, feat->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800377 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100378 ypr_close(pctx, "feature", flag);
FredGand944bdc2019-11-05 21:57:07 +0800379}
380
381static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100382yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident)
FredGand944bdc2019-11-05 21:57:07 +0800383{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200384 int8_t flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200385 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +0800386
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100387 ypr_open(pctx, "identity", "name", ident->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800388 LEVEL++;
389
Michal Vaskob26d09d2022-08-22 09:52:19 +0200390 yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100391 yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800392
393 LY_ARRAY_FOR(ident->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100394 ypr_close_parent(pctx, &flag);
395 ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
FredGand944bdc2019-11-05 21:57:07 +0800396 }
397
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100398 ypr_status(pctx, ident->flags, ident->exts, &flag);
399 ypr_description(pctx, ident->dsc, ident->exts, &flag);
400 ypr_reference(pctx, ident->ref, ident->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800401
402 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100403 ypr_close(pctx, "identity", flag);
FredGand944bdc2019-11-05 21:57:07 +0800404}
405
406static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100407yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, const char *attr, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800408{
409 (void)flag;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200410 int8_t inner_flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800411
412 if (!restr) {
413 return;
414 }
415
Michal Vasko193dacd2022-10-13 08:43:05 +0200416 ly_print_(pctx->out, "%*s<%s %s=\"", INDENT, lyplg_ext_stmt2str(stmt), attr);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100417 lyxml_dump_text(pctx->out,
Radek Krejcif13b87b2020-12-01 22:02:17 +0100418 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
419 restr->arg.str : &restr->arg.str[1], 1);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100420 ly_print_(pctx->out, "\"");
FredGand944bdc2019-11-05 21:57:07 +0800421
422 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200423 yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100424 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100425 ypr_close_parent(pctx, &inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800426 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100427 ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
FredGand944bdc2019-11-05 21:57:07 +0800428 }
429 if (restr->emsg) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100430 ypr_close_parent(pctx, &inner_flag);
431 ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
FredGand944bdc2019-11-05 21:57:07 +0800432 }
433 if (restr->eapptag) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100434 ypr_close_parent(pctx, &inner_flag);
435 ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
FredGand944bdc2019-11-05 21:57:07 +0800436 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100437 ypr_description(pctx, restr->dsc, restr->exts, &inner_flag);
438 ypr_reference(pctx, restr->ref, restr->exts, &inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800439
440 LEVEL--;
Michal Vasko193dacd2022-10-13 08:43:05 +0200441 ypr_close(pctx, lyplg_ext_stmt2str(stmt), inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800442}
443
444static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100445yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800446{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200447 int8_t inner_flag = 0;
Michal Vasko69730152020-10-09 16:30:07 +0200448
FredGand944bdc2019-11-05 21:57:07 +0800449 if (!when) {
450 return;
451 }
452
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100453 ypr_close_parent(pctx, flag);
454 ly_print_(pctx->out, "%*s<when condition=\"", INDENT);
455 lyxml_dump_text(pctx->out, when->cond, 1);
456 ly_print_(pctx->out, "\"");
FredGand944bdc2019-11-05 21:57:07 +0800457
458 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200459 yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100460 ypr_description(pctx, when->dsc, when->exts, &inner_flag);
461 ypr_reference(pctx, when->ref, when->exts, &inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800462 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100463 ypr_close(pctx, "when", inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800464}
465
466static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100467yprp_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800468{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200469 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200470 int8_t inner_flag;
Michal Vasko69730152020-10-09 16:30:07 +0200471
FredGand944bdc2019-11-05 21:57:07 +0800472 (void)flag;
473
474 LY_ARRAY_FOR(items, u) {
475 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100476 ly_print_(pctx->out, "%*s<bit name=\"", INDENT);
477 lyxml_dump_text(pctx->out, items[u].name, 1);
478 ly_print_(pctx->out, "\"");
FredGand944bdc2019-11-05 21:57:07 +0800479 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100480 ly_print_(pctx->out, "%*s<enum name=\"", INDENT);
481 lyxml_dump_text(pctx->out, items[u].name, 1);
482 ly_print_(pctx->out, "\"");
FredGand944bdc2019-11-05 21:57:07 +0800483 }
484 inner_flag = 0;
485 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200486 yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100487 yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800488 if (items[u].flags & LYS_SET_VALUE) {
489 if (type == LY_TYPE_BITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100490 ypr_close_parent(pctx, &inner_flag);
491 ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value);
FredGand944bdc2019-11-05 21:57:07 +0800492 } else { /* LY_TYPE_ENUM */
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100493 ypr_close_parent(pctx, &inner_flag);
494 ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value);
FredGand944bdc2019-11-05 21:57:07 +0800495 }
496 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100497 ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag);
498 ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag);
499 ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800500 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100501 ypr_close(pctx, type == LY_TYPE_BITS ? "bit" : "enum", inner_flag);
FredGand944bdc2019-11-05 21:57:07 +0800502 }
503}
504
505static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100506yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type)
FredGand944bdc2019-11-05 21:57:07 +0800507{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200508 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200509 int8_t flag = 0;
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200510
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100511 if (!pctx || !type) {
FredGand944bdc2019-11-05 21:57:07 +0800512 return;
513 }
514
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100515 ypr_open(pctx, "type", "name", type->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800516 LEVEL++;
517
Michal Vaskob26d09d2022-08-22 09:52:19 +0200518 yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800519
520 if (type->range || type->length || type->patterns || type->bits || type->enums) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100521 ypr_close_parent(pctx, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800522 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100523 yprp_restr(pctx, type->range, LY_STMT_RANGE, "value", &flag);
524 yprp_restr(pctx, type->length, LY_STMT_LENGTH, "value", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800525 LY_ARRAY_FOR(type->patterns, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100526 yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, "value", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800527 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100528 yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag);
529 yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800530
531 if (type->path) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100532 ypr_close_parent(pctx, &flag);
533 ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
FredGand944bdc2019-11-05 21:57:07 +0800534 }
535 if (type->flags & LYS_SET_REQINST) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100536 ypr_close_parent(pctx, &flag);
537 ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
FredGand944bdc2019-11-05 21:57:07 +0800538 }
539 if (type->flags & LYS_SET_FRDIGITS) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100540 ypr_close_parent(pctx, &flag);
541 ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits);
FredGand944bdc2019-11-05 21:57:07 +0800542 }
543 LY_ARRAY_FOR(type->bases, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100544 ypr_close_parent(pctx, &flag);
545 ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts);
FredGand944bdc2019-11-05 21:57:07 +0800546 }
547 LY_ARRAY_FOR(type->types, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100548 ypr_close_parent(pctx, &flag);
549 yprp_type(pctx, &type->types[u]);
FredGand944bdc2019-11-05 21:57:07 +0800550 }
551
552 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100553 ypr_close(pctx, "type", flag);
FredGand944bdc2019-11-05 21:57:07 +0800554}
555
556static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100557yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf)
FredGand944bdc2019-11-05 21:57:07 +0800558{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100559 ypr_open(pctx, "typedef", "name", tpdf->name, 1);
FredGand944bdc2019-11-05 21:57:07 +0800560 LEVEL++;
561
Michal Vaskob26d09d2022-08-22 09:52:19 +0200562 yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +0800563
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100564 yprp_type(pctx, &tpdf->type);
FredGand944bdc2019-11-05 21:57:07 +0800565
566 if (tpdf->units) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100567 ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
FredGand944bdc2019-11-05 21:57:07 +0800568 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200569 if (tpdf->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100570 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
FredGand944bdc2019-11-05 21:57:07 +0800571 }
572
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100573 ypr_status(pctx, tpdf->flags, tpdf->exts, NULL);
574 ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL);
575 ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +0800576
577 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100578 ypr_close(pctx, "typedef", 1);
FredGand944bdc2019-11-05 21:57:07 +0800579}
580
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100581static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node);
582static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action);
583static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif);
FredGand944bdc2019-11-05 21:57:07 +0800584
585static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100586yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp)
FredGand944bdc2019-11-05 21:57:07 +0800587{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200588 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200589 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800590 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100591 struct lysp_node_action *action;
592 struct lysp_node_notif *notif;
593 struct lysp_node_grp *subgrp;
FredGand944bdc2019-11-05 21:57:07 +0800594
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100595 ypr_open(pctx, "grouping", "name", grp->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800596 LEVEL++;
597
Michal Vaskob26d09d2022-08-22 09:52:19 +0200598 yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100599 ypr_status(pctx, grp->flags, grp->exts, &flag);
600 ypr_description(pctx, grp->dsc, grp->exts, &flag);
601 ypr_reference(pctx, grp->ref, grp->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800602
603 LY_ARRAY_FOR(grp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100604 ypr_close_parent(pctx, &flag);
605 yprp_typedef(pctx, &grp->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800606 }
607
Radek Krejci2a9fc652021-01-22 17:44:34 +0100608 LY_LIST_FOR(grp->groupings, subgrp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100609 ypr_close_parent(pctx, &flag);
610 yprp_grouping(pctx, subgrp);
FredGand944bdc2019-11-05 21:57:07 +0800611 }
612
Radek Krejci01180ac2021-01-27 08:48:22 +0100613 LY_LIST_FOR(grp->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100614 ypr_close_parent(pctx, &flag);
615 yprp_node(pctx, data);
FredGand944bdc2019-11-05 21:57:07 +0800616 }
617
Radek Krejci2a9fc652021-01-22 17:44:34 +0100618 LY_LIST_FOR(grp->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100619 ypr_close_parent(pctx, &flag);
620 yprp_action(pctx, action);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100621 }
622
623 LY_LIST_FOR(grp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100624 ypr_close_parent(pctx, &flag);
625 yprp_notification(pctx, notif);
FredGand944bdc2019-11-05 21:57:07 +0800626 }
627
628 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100629 ypr_close(pctx, "grouping", flag);
FredGand944bdc2019-11-05 21:57:07 +0800630}
631
632static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100633yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800634{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200635 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +0800636 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100637 struct lysp_node_grp *grp;
FredGand944bdc2019-11-05 21:57:07 +0800638
Radek Krejci01180ac2021-01-27 08:48:22 +0100639 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +0200640 /* input/output is empty */
FredGand944bdc2019-11-05 21:57:07 +0800641 return;
642 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100643 ypr_close_parent(pctx, flag);
FredGand944bdc2019-11-05 21:57:07 +0800644
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100645 ypr_open(pctx, inout->name, NULL, NULL, *flag);
FredGand944bdc2019-11-05 21:57:07 +0800646 LEVEL++;
647
Michal Vasko193dacd2022-10-13 08:43:05 +0200648 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +0800649 LY_ARRAY_FOR(inout->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100650 yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, "condition", NULL);
FredGand944bdc2019-11-05 21:57:07 +0800651 }
652 LY_ARRAY_FOR(inout->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100653 yprp_typedef(pctx, &inout->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800654 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100655 LY_LIST_FOR(inout->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100656 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +0800657 }
658
Radek Krejci01180ac2021-01-27 08:48:22 +0100659 LY_LIST_FOR(inout->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100660 yprp_node(pctx, data);
FredGand944bdc2019-11-05 21:57:07 +0800661 }
662
663 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100664 ypr_close(pctx, inout->name, 1);
FredGand944bdc2019-11-05 21:57:07 +0800665}
666
667static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100668yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif)
FredGand944bdc2019-11-05 21:57:07 +0800669{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200670 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200671 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800672 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100673 struct lysp_node_grp *grp;
FredGand944bdc2019-11-05 21:57:07 +0800674
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100675 ypr_open(pctx, "notification", "name", notif->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800676
677 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +0200678 yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100679 yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800680
681 LY_ARRAY_FOR(notif->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100682 ypr_close_parent(pctx, &flag);
683 yprp_restr(pctx, &notif->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800684 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100685 ypr_status(pctx, notif->flags, notif->exts, &flag);
686 ypr_description(pctx, notif->dsc, notif->exts, &flag);
687 ypr_reference(pctx, notif->ref, notif->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800688
689 LY_ARRAY_FOR(notif->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100690 ypr_close_parent(pctx, &flag);
691 yprp_typedef(pctx, &notif->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800692 }
693
Radek Krejci2a9fc652021-01-22 17:44:34 +0100694 LY_LIST_FOR(notif->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100695 ypr_close_parent(pctx, &flag);
696 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +0800697 }
698
Radek Krejci01180ac2021-01-27 08:48:22 +0100699 LY_LIST_FOR(notif->child, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100700 ypr_close_parent(pctx, &flag);
701 yprp_node(pctx, data);
FredGand944bdc2019-11-05 21:57:07 +0800702 }
703
704 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100705 ypr_close(pctx, "notification", flag);
FredGand944bdc2019-11-05 21:57:07 +0800706}
707
708static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100709yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action)
FredGand944bdc2019-11-05 21:57:07 +0800710{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200711 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200712 int8_t flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100713 struct lysp_node_grp *grp;
FredGand944bdc2019-11-05 21:57:07 +0800714
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100715 ypr_open(pctx, action->parent ? "action" : "rpc", "name", action->name, flag);
FredGand944bdc2019-11-05 21:57:07 +0800716
717 LEVEL++;
Michal Vasko193dacd2022-10-13 08:43:05 +0200718 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100719 yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag);
720 ypr_status(pctx, action->flags, action->exts, &flag);
721 ypr_description(pctx, action->dsc, action->exts, &flag);
722 ypr_reference(pctx, action->ref, action->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800723
724 LY_ARRAY_FOR(action->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100725 ypr_close_parent(pctx, &flag);
726 yprp_typedef(pctx, &action->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800727 }
728
Radek Krejci2a9fc652021-01-22 17:44:34 +0100729 LY_LIST_FOR(action->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100730 ypr_close_parent(pctx, &flag);
731 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +0800732 }
733
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100734 yprp_inout(pctx, &action->input, &flag);
735 yprp_inout(pctx, &action->output, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800736
737 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100738 ypr_close(pctx, action->parent ? "action" : "rpc", flag);
FredGand944bdc2019-11-05 21:57:07 +0800739}
740
741static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100742yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800743{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100744 ypr_open(pctx, lys_nodetype2str(node->nodetype), "name", node->name, *flag);
FredGand944bdc2019-11-05 21:57:07 +0800745 LEVEL++;
746
Michal Vasko193dacd2022-10-13 08:43:05 +0200747 yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100748 yprp_when(pctx, lysp_node_when(node), flag);
749 yprp_iffeatures(pctx, node->iffeatures, node->exts, flag);
FredGand944bdc2019-11-05 21:57:07 +0800750}
751
752static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100753yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, int8_t *flag)
FredGand944bdc2019-11-05 21:57:07 +0800754{
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100755 ypr_config(pctx, node->flags, node->exts, flag);
FredGand944bdc2019-11-05 21:57:07 +0800756 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100757 ypr_mandatory(pctx, node->flags, node->exts, flag);
FredGand944bdc2019-11-05 21:57:07 +0800758 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100759 ypr_status(pctx, node->flags, node->exts, flag);
760 ypr_description(pctx, node->dsc, node->exts, flag);
761 ypr_reference(pctx, node->ref, node->exts, flag);
FredGand944bdc2019-11-05 21:57:07 +0800762}
763
764static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100765yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800766{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200767 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200768 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800769 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100770 struct lysp_node_action *action;
771 struct lysp_node_notif *notif;
772 struct lysp_node_grp *grp;
FredGand944bdc2019-11-05 21:57:07 +0800773 struct lysp_node_container *cont = (struct lysp_node_container *)node;
774
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100775 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800776
777 LY_ARRAY_FOR(cont->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100778 ypr_close_parent(pctx, &flag);
779 yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800780 }
781 if (cont->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100782 ypr_close_parent(pctx, &flag);
783 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
FredGand944bdc2019-11-05 21:57:07 +0800784 }
785
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100786 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800787
788 LY_ARRAY_FOR(cont->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100789 ypr_close_parent(pctx, &flag);
790 yprp_typedef(pctx, &cont->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800791 }
792
Radek Krejci2a9fc652021-01-22 17:44:34 +0100793 LY_LIST_FOR(cont->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100794 ypr_close_parent(pctx, &flag);
795 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +0800796 }
797
798 LY_LIST_FOR(cont->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100799 ypr_close_parent(pctx, &flag);
800 yprp_node(pctx, child);
FredGand944bdc2019-11-05 21:57:07 +0800801 }
802
Radek Krejci2a9fc652021-01-22 17:44:34 +0100803 LY_LIST_FOR(cont->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100804 ypr_close_parent(pctx, &flag);
805 yprp_action(pctx, action);
FredGand944bdc2019-11-05 21:57:07 +0800806 }
807
Radek Krejci2a9fc652021-01-22 17:44:34 +0100808 LY_LIST_FOR(cont->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100809 ypr_close_parent(pctx, &flag);
810 yprp_notification(pctx, notif);
FredGand944bdc2019-11-05 21:57:07 +0800811 }
812
813 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100814 ypr_close(pctx, "container", flag);
FredGand944bdc2019-11-05 21:57:07 +0800815}
816
817static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100818yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800819{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200820 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800821 struct lysp_node *child;
822 struct lysp_node_case *cas = (struct lysp_node_case *)node;
823
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100824 yprp_node_common1(pctx, node, &flag);
825 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800826
827 LY_LIST_FOR(cas->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100828 ypr_close_parent(pctx, &flag);
829 yprp_node(pctx, child);
FredGand944bdc2019-11-05 21:57:07 +0800830 }
831
832 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100833 ypr_close(pctx, "case", flag);
FredGand944bdc2019-11-05 21:57:07 +0800834}
835
836static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100837yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800838{
Radek Krejci1deb5be2020-08-26 16:43:36 +0200839 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800840 struct lysp_node *child;
841 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
842
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100843 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800844
Michal Vasko7f45cf22020-10-01 12:49:44 +0200845 if (choice->dflt.str) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100846 ypr_close_parent(pctx, &flag);
847 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
FredGand944bdc2019-11-05 21:57:07 +0800848 }
849
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100850 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800851
852 LY_LIST_FOR(choice->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100853 ypr_close_parent(pctx, &flag);
854 yprp_node(pctx, child);
FredGand944bdc2019-11-05 21:57:07 +0800855 }
856
857 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100858 ypr_close(pctx, "choice", flag);
FredGand944bdc2019-11-05 21:57:07 +0800859}
860
861static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100862yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800863{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200864 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +0800865 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
866
Radek Krejci1deb5be2020-08-26 16:43:36 +0200867 int8_t flag = 1;
Michal Vasko69730152020-10-09 16:30:07 +0200868
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100869 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800870
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100871 yprp_type(pctx, &leaf->type);
872 ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
FredGand944bdc2019-11-05 21:57:07 +0800873 LY_ARRAY_FOR(leaf->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100874 yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800875 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100876 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
FredGand944bdc2019-11-05 21:57:07 +0800877
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100878 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800879
880 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100881 ypr_close(pctx, "leaf", flag);
FredGand944bdc2019-11-05 21:57:07 +0800882}
883
884static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100885yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800886{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200887 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +0800888 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200889 int8_t flag = 1;
FredGand944bdc2019-11-05 21:57:07 +0800890
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100891 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800892
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100893 yprp_type(pctx, &llist->type);
894 ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
FredGand944bdc2019-11-05 21:57:07 +0800895 LY_ARRAY_FOR(llist->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100896 yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, "condition", NULL);
FredGand944bdc2019-11-05 21:57:07 +0800897 }
898 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100899 ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
FredGand944bdc2019-11-05 21:57:07 +0800900 }
901
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100902 ypr_config(pctx, node->flags, node->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +0800903
904 if (llist->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100905 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min);
FredGand944bdc2019-11-05 21:57:07 +0800906 }
907 if (llist->flags & LYS_SET_MAX) {
908 if (llist->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100909 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max);
FredGand944bdc2019-11-05 21:57:07 +0800910 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100911 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
FredGand944bdc2019-11-05 21:57:07 +0800912 }
913 }
914
915 if (llist->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100916 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
FredGand944bdc2019-11-05 21:57:07 +0800917 }
918
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100919 ypr_status(pctx, node->flags, node->exts, &flag);
920 ypr_description(pctx, node->dsc, node->exts, &flag);
921 ypr_reference(pctx, node->ref, node->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800922
923 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100924 ypr_close(pctx, "leaf-list", flag);
FredGand944bdc2019-11-05 21:57:07 +0800925}
926
927static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100928yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +0800929{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200930 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +0200931 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +0800932 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100933 struct lysp_node_action *action;
934 struct lysp_node_notif *notif;
935 struct lysp_node_grp *grp;
FredGand944bdc2019-11-05 21:57:07 +0800936 struct lysp_node_list *list = (struct lysp_node_list *)node;
937
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100938 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800939
940 LY_ARRAY_FOR(list->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100941 ypr_close_parent(pctx, &flag);
942 yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +0800943 }
944 if (list->key) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100945 ypr_close_parent(pctx, &flag);
946 ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts);
FredGand944bdc2019-11-05 21:57:07 +0800947 }
948 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100949 ypr_close_parent(pctx, &flag);
950 ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
FredGand944bdc2019-11-05 21:57:07 +0800951 }
952
Michal Vasko846e3ab2022-03-01 09:54:27 +0100953 ypr_config(pctx, node->flags, node->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800954
955 if (list->flags & LYS_SET_MIN) {
Michal Vasko07937f02022-11-29 08:24:05 +0100956 ypr_close_parent(pctx, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100957 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min);
FredGand944bdc2019-11-05 21:57:07 +0800958 }
959 if (list->flags & LYS_SET_MAX) {
Michal Vasko07937f02022-11-29 08:24:05 +0100960 ypr_close_parent(pctx, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800961 if (list->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100962 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max);
FredGand944bdc2019-11-05 21:57:07 +0800963 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100964 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
FredGand944bdc2019-11-05 21:57:07 +0800965 }
966 }
967
968 if (list->flags & LYS_ORDBY_MASK) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100969 ypr_close_parent(pctx, &flag);
970 ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
FredGand944bdc2019-11-05 21:57:07 +0800971 }
972
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100973 ypr_status(pctx, node->flags, node->exts, &flag);
974 ypr_description(pctx, node->dsc, node->exts, &flag);
975 ypr_reference(pctx, node->ref, node->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +0800976
977 LY_ARRAY_FOR(list->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100978 ypr_close_parent(pctx, &flag);
979 yprp_typedef(pctx, &list->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +0800980 }
981
Radek Krejci2a9fc652021-01-22 17:44:34 +0100982 LY_LIST_FOR(list->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100983 ypr_close_parent(pctx, &flag);
984 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +0800985 }
986
987 LY_LIST_FOR(list->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100988 ypr_close_parent(pctx, &flag);
989 yprp_node(pctx, child);
FredGand944bdc2019-11-05 21:57:07 +0800990 }
991
Radek Krejci2a9fc652021-01-22 17:44:34 +0100992 LY_LIST_FOR(list->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100993 ypr_close_parent(pctx, &flag);
994 yprp_action(pctx, action);
FredGand944bdc2019-11-05 21:57:07 +0800995 }
996
Radek Krejci2a9fc652021-01-22 17:44:34 +0100997 LY_LIST_FOR(list->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +0100998 ypr_close_parent(pctx, &flag);
999 yprp_notification(pctx, notif);
FredGand944bdc2019-11-05 21:57:07 +08001000 }
1001
1002 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001003 ypr_close(pctx, "list", flag);
FredGand944bdc2019-11-05 21:57:07 +08001004}
1005
1006static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001007yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine)
FredGand944bdc2019-11-05 21:57:07 +08001008{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001009 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +02001010 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +08001011
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001012 ypr_open(pctx, "refine", "target-node", refine->nodeid, flag);
FredGand944bdc2019-11-05 21:57:07 +08001013 LEVEL++;
1014
Michal Vaskob26d09d2022-08-22 09:52:19 +02001015 yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001016 yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001017
1018 LY_ARRAY_FOR(refine->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001019 ypr_close_parent(pctx, &flag);
1020 yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +08001021 }
1022
1023 if (refine->presence) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001024 ypr_close_parent(pctx, &flag);
1025 ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
FredGand944bdc2019-11-05 21:57:07 +08001026 }
1027
1028 LY_ARRAY_FOR(refine->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001029 ypr_close_parent(pctx, &flag);
1030 ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
FredGand944bdc2019-11-05 21:57:07 +08001031 }
1032
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001033 ypr_config(pctx, refine->flags, refine->exts, &flag);
1034 ypr_mandatory(pctx, refine->flags, refine->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001035
1036 if (refine->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001037 ypr_close_parent(pctx, &flag);
1038 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min);
FredGand944bdc2019-11-05 21:57:07 +08001039 }
1040 if (refine->flags & LYS_SET_MAX) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001041 ypr_close_parent(pctx, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001042 if (refine->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001043 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max);
FredGand944bdc2019-11-05 21:57:07 +08001044 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001045 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
FredGand944bdc2019-11-05 21:57:07 +08001046 }
1047 }
1048
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001049 ypr_description(pctx, refine->dsc, refine->exts, &flag);
1050 ypr_reference(pctx, refine->ref, refine->exts, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001051
1052 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001053 ypr_close(pctx, "refine", flag);
FredGand944bdc2019-11-05 21:57:07 +08001054}
1055
1056static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001057yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug)
FredGand944bdc2019-11-05 21:57:07 +08001058{
FredGand944bdc2019-11-05 21:57:07 +08001059 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001060 struct lysp_node_action *action;
1061 struct lysp_node_notif *notif;
FredGand944bdc2019-11-05 21:57:07 +08001062
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001063 ypr_open(pctx, "augment", "target-node", aug->nodeid, 1);
FredGand944bdc2019-11-05 21:57:07 +08001064 LEVEL++;
1065
Michal Vaskob26d09d2022-08-22 09:52:19 +02001066 yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001067 yprp_when(pctx, aug->when, NULL);
1068 yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL);
1069 ypr_status(pctx, aug->flags, aug->exts, NULL);
1070 ypr_description(pctx, aug->dsc, aug->exts, NULL);
1071 ypr_reference(pctx, aug->ref, aug->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001072
1073 LY_LIST_FOR(aug->child, child) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001074 yprp_node(pctx, child);
FredGand944bdc2019-11-05 21:57:07 +08001075 }
1076
Radek Krejci2a9fc652021-01-22 17:44:34 +01001077 LY_LIST_FOR(aug->actions, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001078 yprp_action(pctx, action);
FredGand944bdc2019-11-05 21:57:07 +08001079 }
1080
Radek Krejci2a9fc652021-01-22 17:44:34 +01001081 LY_LIST_FOR(aug->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001082 yprp_notification(pctx, notif);
FredGand944bdc2019-11-05 21:57:07 +08001083 }
1084
1085 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001086 ypr_close(pctx, "augment", 1);
FredGand944bdc2019-11-05 21:57:07 +08001087}
1088
FredGand944bdc2019-11-05 21:57:07 +08001089static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001090yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +08001091{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001092 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +02001093 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +08001094 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001095 struct lysp_node_augment *aug;
FredGand944bdc2019-11-05 21:57:07 +08001096
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001097 yprp_node_common1(pctx, node, &flag);
1098 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001099
1100 LY_ARRAY_FOR(uses->refines, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001101 ypr_close_parent(pctx, &flag);
1102 yprp_refine(pctx, &uses->refines[u]);
FredGand944bdc2019-11-05 21:57:07 +08001103 }
1104
Radek Krejci2a9fc652021-01-22 17:44:34 +01001105 LY_LIST_FOR(uses->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001106 ypr_close_parent(pctx, &flag);
1107 yprp_augment(pctx, aug);
FredGand944bdc2019-11-05 21:57:07 +08001108 }
1109
1110 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001111 ypr_close(pctx, "uses", flag);
FredGand944bdc2019-11-05 21:57:07 +08001112}
1113
1114static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001115yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +08001116{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001117 LY_ARRAY_COUNT_TYPE u;
Radek Krejci1deb5be2020-08-26 16:43:36 +02001118 int8_t flag = 0;
FredGand944bdc2019-11-05 21:57:07 +08001119 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1120
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001121 yprp_node_common1(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001122
1123 LY_ARRAY_FOR(any->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001124 ypr_close_parent(pctx, &flag);
1125 yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, "condition", &flag);
FredGand944bdc2019-11-05 21:57:07 +08001126 }
1127
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001128 yprp_node_common2(pctx, node, &flag);
FredGand944bdc2019-11-05 21:57:07 +08001129
1130 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001131 ypr_close(pctx, lys_nodetype2str(node->nodetype), flag);
FredGand944bdc2019-11-05 21:57:07 +08001132}
1133
1134static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001135yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node)
FredGand944bdc2019-11-05 21:57:07 +08001136{
FredGand944bdc2019-11-05 21:57:07 +08001137 switch (node->nodetype) {
1138 case LYS_CONTAINER:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001139 yprp_container(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001140 break;
1141 case LYS_CHOICE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001142 yprp_choice(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001143 break;
1144 case LYS_LEAF:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001145 yprp_leaf(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001146 break;
1147 case LYS_LEAFLIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001148 yprp_leaflist(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001149 break;
1150 case LYS_LIST:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001151 yprp_list(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001152 break;
1153 case LYS_USES:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001154 yprp_uses(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001155 break;
1156 case LYS_ANYXML:
1157 case LYS_ANYDATA:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001158 yprp_anydata(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001159 break;
1160 case LYS_CASE:
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001161 yprp_case(pctx, node);
FredGand944bdc2019-11-05 21:57:07 +08001162 break;
1163 default:
1164 break;
1165 }
1166}
1167
1168static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001169yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation)
FredGand944bdc2019-11-05 21:57:07 +08001170{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001171 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +08001172 struct lysp_deviate_add *add;
1173 struct lysp_deviate_rpl *rpl;
1174 struct lysp_deviate_del *del;
1175 struct lysp_deviate *elem;
1176
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001177 ypr_open(pctx, "deviation", "target-node", deviation->nodeid, 1);
FredGand944bdc2019-11-05 21:57:07 +08001178 LEVEL++;
1179
Michal Vaskob26d09d2022-08-22 09:52:19 +02001180 yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001181 ypr_description(pctx, deviation->dsc, deviation->exts, NULL);
1182 ypr_reference(pctx, deviation->ref, deviation->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001183
1184 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001185 ly_print_(pctx->out, "%*s<deviate value=\"", INDENT);
FredGand944bdc2019-11-05 21:57:07 +08001186 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1187 if (elem->exts) {
Michal Vasko12ef5362022-09-16 15:13:58 +02001188 ly_print_(pctx->out, "not-supported\">\n");
FredGand944bdc2019-11-05 21:57:07 +08001189 LEVEL++;
1190
Michal Vaskob26d09d2022-08-22 09:52:19 +02001191 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001192 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001193 ly_print_(pctx->out, "not-supported\"/>\n");
FredGand944bdc2019-11-05 21:57:07 +08001194 continue;
1195 }
1196 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001197 add = (struct lysp_deviate_add *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001198 ly_print_(pctx->out, "add\">\n");
FredGand944bdc2019-11-05 21:57:07 +08001199 LEVEL++;
1200
Michal Vaskob26d09d2022-08-22 09:52:19 +02001201 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001202 ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001203 LY_ARRAY_FOR(add->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001204 yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, "condition", NULL);
FredGand944bdc2019-11-05 21:57:07 +08001205 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001206 LY_ARRAY_FOR(add->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001207 ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
FredGand944bdc2019-11-05 21:57:07 +08001208 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001209 LY_ARRAY_FOR(add->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001210 ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
FredGand944bdc2019-11-05 21:57:07 +08001211 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001212 ypr_config(pctx, add->flags, add->exts, NULL);
1213 ypr_mandatory(pctx, add->flags, add->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001214 if (add->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001215 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min);
FredGand944bdc2019-11-05 21:57:07 +08001216 }
1217 if (add->flags & LYS_SET_MAX) {
1218 if (add->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001219 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max);
FredGand944bdc2019-11-05 21:57:07 +08001220 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001221 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
FredGand944bdc2019-11-05 21:57:07 +08001222 }
1223 }
1224 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001225 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001226 ly_print_(pctx->out, "replace\">\n");
FredGand944bdc2019-11-05 21:57:07 +08001227 LEVEL++;
1228
Michal Vaskob26d09d2022-08-22 09:52:19 +02001229 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001230 if (rpl->type) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001231 yprp_type(pctx, rpl->type);
FredGand944bdc2019-11-05 21:57:07 +08001232 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001233 ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
1234 ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
1235 ypr_config(pctx, rpl->flags, rpl->exts, NULL);
1236 ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001237 if (rpl->flags & LYS_SET_MIN) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001238 ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min);
FredGand944bdc2019-11-05 21:57:07 +08001239 }
1240 if (rpl->flags & LYS_SET_MAX) {
1241 if (rpl->max) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001242 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max);
FredGand944bdc2019-11-05 21:57:07 +08001243 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001244 ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
FredGand944bdc2019-11-05 21:57:07 +08001245 }
1246 }
1247 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001248 del = (struct lysp_deviate_del *)elem;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001249 ly_print_(pctx->out, "delete\">\n");
FredGand944bdc2019-11-05 21:57:07 +08001250 LEVEL++;
1251
Michal Vaskob26d09d2022-08-22 09:52:19 +02001252 yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001253 ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001254 LY_ARRAY_FOR(del->musts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001255 yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, "condition", NULL);
FredGand944bdc2019-11-05 21:57:07 +08001256 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001257 LY_ARRAY_FOR(del->uniques, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001258 ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
FredGand944bdc2019-11-05 21:57:07 +08001259 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001260 LY_ARRAY_FOR(del->dflts, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001261 ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
FredGand944bdc2019-11-05 21:57:07 +08001262 }
1263 }
1264
1265 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001266 ypr_close(pctx, "deviate", 1);
FredGand944bdc2019-11-05 21:57:07 +08001267 }
1268
1269 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001270 ypr_close(pctx, "deviation", 1);
FredGand944bdc2019-11-05 21:57:07 +08001271}
1272
FredGand944bdc2019-11-05 21:57:07 +08001273static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001274ypr_xmlns(struct lys_ypr_ctx *pctx, const struct lys_module *module, uint16_t indent)
FredGand944bdc2019-11-05 21:57:07 +08001275{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001276 ly_print_(pctx->out, "%*sxmlns=\"%s\"", indent + INDENT, YIN_NS_URI);
1277 ly_print_(pctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, module->prefix, module->ns);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001278}
FredGand944bdc2019-11-05 21:57:07 +08001279
Michal Vasko7c8439f2020-08-05 13:25:19 +02001280static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001281ypr_import_xmlns(struct lys_ypr_ctx *pctx, const struct lysp_module *modp, uint16_t indent)
Michal Vasko7c8439f2020-08-05 13:25:19 +02001282{
1283 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +08001284
1285 LY_ARRAY_FOR(modp->imports, u){
aPiecek6cf1d162023-11-08 16:07:00 +01001286 if (!(modp->imports[u].flags & LYS_INTERNAL)) {
1287 ly_print_(pctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, modp->imports[u].prefix, modp->imports[u].module->ns);
1288 }
FredGand944bdc2019-11-05 21:57:07 +08001289 }
1290}
1291
FredGand944bdc2019-11-05 21:57:07 +08001292static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001293yin_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
FredGand944bdc2019-11-05 21:57:07 +08001294{
Michal Vasko7c8439f2020-08-05 13:25:19 +02001295 LY_ARRAY_COUNT_TYPE u;
FredGand944bdc2019-11-05 21:57:07 +08001296
FredGand944bdc2019-11-05 21:57:07 +08001297 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01001298 if (modp->imports[u].flags & LYS_INTERNAL) {
1299 continue;
1300 }
1301
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001302 ypr_open(pctx, "import", "module", modp->imports[u].name, 1);
FredGand944bdc2019-11-05 21:57:07 +08001303 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001304 yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001305 ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
FredGand944bdc2019-11-05 21:57:07 +08001306 if (modp->imports[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001307 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
FredGand944bdc2019-11-05 21:57:07 +08001308 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001309 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
1310 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
FredGand944bdc2019-11-05 21:57:07 +08001311 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001312 ypr_close(pctx, "import", 1);
FredGand944bdc2019-11-05 21:57:07 +08001313 }
1314 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01001315 if (modp->includes[u].injected) {
1316 /* do not print the includes injected from submodules */
1317 continue;
1318 }
FredGand944bdc2019-11-05 21:57:07 +08001319 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001320 ypr_open(pctx, "include", "module", modp->includes[u].name, 1);
FredGand944bdc2019-11-05 21:57:07 +08001321 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001322 yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001323 if (modp->includes[u].rev[0]) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001324 ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
FredGand944bdc2019-11-05 21:57:07 +08001325 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001326 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
1327 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
FredGand944bdc2019-11-05 21:57:07 +08001328 LEVEL--;
NextLiteteb34bd8a2024-02-08 15:37:49 +08001329 ypr_close(pctx, "include", 1);
FredGand944bdc2019-11-05 21:57:07 +08001330 } else {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001331 ypr_open(pctx, "include", "module", modp->includes[u].name, -1);
FredGand944bdc2019-11-05 21:57:07 +08001332 }
1333 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02001334}
FredGand944bdc2019-11-05 21:57:07 +08001335
Michal Vasko7c8439f2020-08-05 13:25:19 +02001336static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001337yin_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02001338{
1339 LY_ARRAY_COUNT_TYPE u;
1340 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001341 struct lysp_node_action *action;
1342 struct lysp_node_notif *notif;
1343 struct lysp_node_grp *grp;
1344 struct lysp_node_augment *aug;
FredGand944bdc2019-11-05 21:57:07 +08001345
FredGand944bdc2019-11-05 21:57:07 +08001346 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001347 yprp_extension(pctx, &modp->extensions[u]);
FredGand944bdc2019-11-05 21:57:07 +08001348 }
1349 if (modp->exts) {
Michal Vaskob26d09d2022-08-22 09:52:19 +02001350 yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL);
FredGand944bdc2019-11-05 21:57:07 +08001351 }
1352
1353 LY_ARRAY_FOR(modp->features, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001354 yprp_feature(pctx, &modp->features[u]);
FredGand944bdc2019-11-05 21:57:07 +08001355 }
1356
1357 LY_ARRAY_FOR(modp->identities, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001358 yprp_identity(pctx, &modp->identities[u]);
FredGand944bdc2019-11-05 21:57:07 +08001359 }
1360
1361 LY_ARRAY_FOR(modp->typedefs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001362 yprp_typedef(pctx, &modp->typedefs[u]);
FredGand944bdc2019-11-05 21:57:07 +08001363 }
1364
Radek Krejci2a9fc652021-01-22 17:44:34 +01001365 LY_LIST_FOR(modp->groupings, grp) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001366 yprp_grouping(pctx, grp);
FredGand944bdc2019-11-05 21:57:07 +08001367 }
1368
1369 LY_LIST_FOR(modp->data, data) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001370 yprp_node(pctx, data);
FredGand944bdc2019-11-05 21:57:07 +08001371 }
1372
Radek Krejci2a9fc652021-01-22 17:44:34 +01001373 LY_LIST_FOR(modp->augments, aug) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001374 yprp_augment(pctx, aug);
FredGand944bdc2019-11-05 21:57:07 +08001375 }
1376
Radek Krejci2a9fc652021-01-22 17:44:34 +01001377 LY_LIST_FOR(modp->rpcs, action) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001378 yprp_action(pctx, action);
FredGand944bdc2019-11-05 21:57:07 +08001379 }
1380
Radek Krejci2a9fc652021-01-22 17:44:34 +01001381 LY_LIST_FOR(modp->notifs, notif) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001382 yprp_notification(pctx, notif);
FredGand944bdc2019-11-05 21:57:07 +08001383 }
1384
1385 LY_ARRAY_FOR(modp->deviations, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001386 yprp_deviation(pctx, &modp->deviations[u]);
FredGand944bdc2019-11-05 21:57:07 +08001387 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02001388}
1389
1390LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01001391yin_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02001392{
1393 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01001394 const struct lys_module *module = modp->mod;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001395 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = module, .options = options}, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02001396
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001397 ly_print_(pctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1398 ly_print_(pctx->out, "%*s<module name=\"%s\"\n", INDENT, module->name);
1399 ypr_xmlns(pctx, module, XML_NS_INDENT);
1400 ypr_import_xmlns(pctx, modp, XML_NS_INDENT);
1401 ly_print_(pctx->out, ">\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001402
1403 LEVEL++;
1404
1405 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02001406 if (modp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001407 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001408 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001409 ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
1410 ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001411
1412 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001413 yin_print_parsed_linkage(pctx, modp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001414
1415 /* meta-stmts */
1416 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02001417 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001418 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001419 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
1420 ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
1421 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
1422 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001423
1424 /* revision-stmts */
1425 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02001426 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001427 }
1428 LY_ARRAY_FOR(modp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001429 yprp_revision(pctx, &modp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001430 }
1431
1432 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001433 yin_print_parsed_body(pctx, modp);
FredGand944bdc2019-11-05 21:57:07 +08001434
1435 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001436 ly_print_(out, "%*s</module>\n", INDENT);
FredGand944bdc2019-11-05 21:57:07 +08001437 ly_print_flush(out);
1438
1439 return LY_SUCCESS;
1440}
1441
Michal Vasko7c8439f2020-08-05 13:25:19 +02001442static void
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001443yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02001444{
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001445 ypr_open(pctx, "belongs-to", "module", submodp->mod->name, 1);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001446 LEVEL++;
Michal Vaskob26d09d2022-08-22 09:52:19 +02001447 yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL);
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001448 ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001449 LEVEL--;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001450 ypr_close(pctx, "belongs-to", 1);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001451}
1452
1453LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01001454yin_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02001455{
1456 LY_ARRAY_COUNT_TYPE u;
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001457 struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = submodp->mod, .options = options}, *pctx = &pctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02001458
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001459 ly_print_(pctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1460 ly_print_(pctx->out, "%*s<submodule name=\"%s\"\n", INDENT, submodp->name);
1461 ypr_xmlns(pctx, submodp->mod, XML_NS_INDENT);
1462 ypr_import_xmlns(pctx, (struct lysp_module *)submodp, XML_NS_INDENT);
1463 ly_print_(pctx->out, ">\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001464
1465 LEVEL++;
1466
1467 /* submodule-header-stmts */
1468 if (submodp->version) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001469 ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001470 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001471 yprp_belongsto(pctx, submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001472
1473 /* linkage-stmts (import/include) */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001474 yin_print_parsed_linkage(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001475
1476 /* meta-stmts */
1477 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02001478 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001479 }
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001480 ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
1481 ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
1482 ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
1483 ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001484
1485 /* revision-stmts */
1486 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02001487 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02001488 }
1489 LY_ARRAY_FOR(submodp->revs, u) {
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001490 yprp_revision(pctx, &submodp->revs[u]);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001491 }
1492
1493 /* body-stmts */
Michal Vasko61ad1ff2022-02-10 15:48:39 +01001494 yin_print_parsed_body(pctx, (struct lysp_module *)submodp);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001495
1496 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001497 ly_print_(out, "%*s</submodule>\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02001498 ly_print_flush(out);
1499
1500 return LY_SUCCESS;
1501}