blob: 515693585970ac6628f899072d4d1f38557829c2 [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
15#include "common.h"
16
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 Krejci693262f2019-04-29 15:23:20 +020022
Radek Krejcie7b95092019-05-15 11:03:07 +020023#include "extensions.h"
24#include "log.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020025#include "printer_internal.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "tree.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020027#include "tree_schema.h"
28#include "tree_schema_internal.h"
Radek Krejcia1911222019-07-22 17:24:50 +020029#include "plugins_types.h"
Radek Krejci693262f2019-04-29 15:23:20 +020030#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020031
Radek Krejcie7b95092019-05-15 11:03:07 +020032/**
33 * @brief Types of the YANG printers
34 */
Radek Krejci693262f2019-04-29 15:23:20 +020035enum schema_type {
Radek Krejcie7b95092019-05-15 11:03:07 +020036 YPR_PARSED, /**< YANG printer of the parsed schema */
37 YPR_COMPILED /**< YANG printer of the compiled schema */
Radek Krejci693262f2019-04-29 15:23:20 +020038};
39
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
41 * @brief YANG printer context.
42 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020043struct ypr_ctx {
Radek Krejcie7b95092019-05-15 11:03:07 +020044 struct lyout *out; /**< output specification */
45 unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
46 const struct lys_module *module; /**< schema to print */
47 enum schema_type schema; /**< type of the schema to print */
Radek Krejcid3ca0632019-04-16 16:54:54 +020048};
49
Radek Krejcie7b95092019-05-15 11:03:07 +020050#define LEVEL ctx->level /**< current level */
51#define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */
52
53/**
54 * @brief Print the given text as content of a double quoted YANG string,
55 * including encoding characters that have special meanings. The quotation marks
56 * are not printed.
57 *
58 * Follows RFC 7950, section 6.1.3.
59 *
60 * @param[in] out Output specification.
61 * @param[in] text String to be printed.
62 * @param[in] len Length of the string from @p text to be printed. In case of 0,
63 * the @p text is printed completely as a NULL-terminated string.
64 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020065static void
66ypr_encode(struct lyout *out, const char *text, int len)
67{
68 int i, start_len;
69 const char *start;
70 char special = 0;
71
72 if (!len) {
73 return;
74 }
75
76 if (len < 0) {
77 len = strlen(text);
78 }
79
80 start = text;
81 start_len = 0;
82 for (i = 0; i < len; ++i) {
83 switch (text[i]) {
84 case '\n':
85 case '\t':
86 case '\"':
87 case '\\':
88 special = text[i];
89 break;
90 default:
91 ++start_len;
92 break;
93 }
94
95 if (special) {
96 ly_write(out, start, start_len);
97 switch (special) {
98 case '\n':
99 ly_write(out, "\\n", 2);
100 break;
101 case '\t':
102 ly_write(out, "\\t", 2);
103 break;
104 case '\"':
105 ly_write(out, "\\\"", 2);
106 break;
107 case '\\':
108 ly_write(out, "\\\\", 2);
109 break;
110 }
111
112 start += start_len + 1;
113 start_len = 0;
114
115 special = 0;
116 }
117 }
118
119 ly_write(out, start, start_len);
120}
121
122static void
123ypr_open(struct lyout *out, int *flag)
124{
125 if (flag && !*flag) {
126 *flag = 1;
127 ly_print(out, " {\n");
128 }
129}
130
131static void
132ypr_close(struct ypr_ctx *ctx, int flag)
133{
134 if (flag) {
135 ly_print(ctx->out, "%*s}\n", INDENT);
136 } else {
137 ly_print(ctx->out, ";\n");
138 }
139}
140
141static void
142ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
143{
144 const char *s, *t;
145
146 if (singleline) {
147 ly_print(ctx->out, "%*s%s \"", INDENT, name);
148 } else {
149 ly_print(ctx->out, "%*s%s\n", INDENT, name);
150 LEVEL++;
151
152 ly_print(ctx->out, "%*s\"", INDENT);
153 }
154 t = text;
155 while ((s = strchr(t, '\n'))) {
156 ypr_encode(ctx->out, t, s - t);
157 ly_print(ctx->out, "\n");
158 t = s + 1;
159 if (*t != '\n') {
160 ly_print(ctx->out, "%*s ", INDENT);
161 }
162 }
163
164 ypr_encode(ctx->out, t, strlen(t));
165 if (closed) {
166 ly_print(ctx->out, "\";\n");
167 } else {
168 ly_print(ctx->out, "\"");
169 }
170 if (!singleline) {
171 LEVEL--;
172 }
173}
174
175static void
Radek Krejci693262f2019-04-29 15:23:20 +0200176yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177{
178 struct lysp_stmt *childstmt;
179 const char *s, *t;
180
181 if (stmt->arg) {
182 if (stmt->flags) {
183 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
184 LEVEL++;
185 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
186 t = stmt->arg;
187 while ((s = strchr(t, '\n'))) {
188 ypr_encode(ctx->out, t, s - t);
189 ly_print(ctx->out, "\n");
190 t = s + 1;
191 if (*t != '\n') {
192 ly_print(ctx->out, "%*s ", INDENT);
193 }
194 }
195 LEVEL--;
196 ypr_encode(ctx->out, t, strlen(t));
197 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
198 } else {
199 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
200 }
201 } else {
202 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
203 }
204
205 if (stmt->child) {
206 LEVEL++;
207 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200208 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200209 }
210 LEVEL--;
211 ly_print(ctx->out, "%*s}\n", INDENT);
212 }
213}
214
215/**
216 * @param[in] count Number of extensions to print, 0 to print them all.
217 */
218static void
Radek Krejci693262f2019-04-29 15:23:20 +0200219yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 struct lysp_ext_instance *ext, int *flag, unsigned int count)
221{
222 unsigned int u;
223 struct lysp_stmt *stmt;
224
225 if (!count && ext) {
226 count = LY_ARRAY_SIZE(ext);
227 }
228 LY_ARRAY_FOR(ext, u) {
229 if (!count) {
230 break;
231 }
David Sedlákbbd06ca2019-06-27 14:15:38 +0200232 if (ext->yin) {
233 ly_print(ctx->out, "%*s%s Model comes from different input format, extensions must be resolved first.", INDENT, ext[u].name);
234 } else if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200235 ypr_open(ctx->out, flag);
236 if (ext[u].argument) {
237 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
238 } else {
239 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
240 }
241
242 if (ext[u].child) {
243 LEVEL++;
244 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200245 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200246 }
247 LEVEL--;
248 ly_print(ctx->out, "%*s}\n", INDENT);
249 }
250 }
251 count--;
252 }
253}
254
Radek Krejci693262f2019-04-29 15:23:20 +0200255/**
256 * @param[in] count Number of extensions to print, 0 to print them all.
257 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200258static void
Radek Krejci693262f2019-04-29 15:23:20 +0200259yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
260 struct lysc_ext_instance *ext, int *flag, unsigned int count)
261{
262 unsigned int u;
263
264 if (!count && ext) {
265 count = LY_ARRAY_SIZE(ext);
266 }
267 LY_ARRAY_FOR(ext, u) {
268 if (!count) {
269 break;
270 }
271 /* TODO compiled extensions */
272 (void) ctx;
273 (void) substmt;
274 (void) substmt_index;
275 (void) flag;
276
277 count--;
278 }
279}
280
281static void
282ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200283{
284 unsigned int u;
285 int extflag = 0;
286
287 if (!text) {
288 /* nothing to print */
289 return;
290 }
291
292 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
293 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
294 } else {
295 ypr_text(ctx, ext_substmt_info[substmt].name, text,
296 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
297 }
298
299 LEVEL++;
300 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200301 if (((struct lysp_ext_instance*)ext)[u].insubstmt != substmt || ((struct lysp_ext_instance*)ext)[u].insubstmt_index != substmt_index) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200302 continue;
303 }
Radek Krejci693262f2019-04-29 15:23:20 +0200304 if (ctx->schema == YPR_PARSED) {
305 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
306 } else {
307 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
308 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200309 }
310 LEVEL--;
311 ypr_close(ctx, extflag);
312}
313
314static void
Radek Krejci693262f2019-04-29 15:23:20 +0200315ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200316{
317 char *str;
318
319 if (asprintf(&str, "%u", attr_value) == -1) {
320 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200321 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200322 return;
323 }
324 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200325 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200326 free(str);
327}
328
329static void
Radek Krejci693262f2019-04-29 15:23:20 +0200330ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200331{
332 char *str;
333
334 if (asprintf(&str, "%d", attr_value) == -1) {
335 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200336 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200337 return;
338 }
339 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200340 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200341 free(str);
342}
343
344static void
Radek Krejci693262f2019-04-29 15:23:20 +0200345yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200346{
347 if (rev->dsc || rev->ref || rev->exts) {
348 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
349 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200350 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
351 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
352 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353 LEVEL--;
354 ly_print(ctx->out, "%*s}\n", INDENT);
355 } else {
356 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
357 }
358}
359
360static void
Radek Krejci693262f2019-04-29 15:23:20 +0200361ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200362{
363 if (flags & LYS_MAND_MASK) {
364 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200365 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200366 }
367}
368
369static void
Radek Krejci693262f2019-04-29 15:23:20 +0200370ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200371{
372 if (flags & LYS_CONFIG_MASK) {
373 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200374 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200375 }
376}
377
378static void
Radek Krejci693262f2019-04-29 15:23:20 +0200379ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380{
381 const char *status = NULL;
382
383 if (flags & LYS_STATUS_CURR) {
384 ypr_open(ctx->out, flag);
385 status = "current";
386 } else if (flags & LYS_STATUS_DEPRC) {
387 ypr_open(ctx->out, flag);
388 status = "deprecated";
389 } else if (flags & LYS_STATUS_OBSLT) {
390 ypr_open(ctx->out, flag);
391 status = "obsolete";
392 }
Radek Krejci693262f2019-04-29 15:23:20 +0200393
394 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200395}
396
397static void
Radek Krejci693262f2019-04-29 15:23:20 +0200398ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200399{
400 if (dsc) {
401 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200402 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403 }
404}
405
406static void
Radek Krejci693262f2019-04-29 15:23:20 +0200407ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200408{
409 if (ref) {
410 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200411 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200412 }
413}
414
415static void
Radek Krejci693262f2019-04-29 15:23:20 +0200416yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200417{
418 unsigned int u;
419 int extflag;
420
421 LY_ARRAY_FOR(iff, u) {
422 ypr_open(ctx->out, flag);
423 extflag = 0;
424
425 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
426
427 /* extensions */
428 LEVEL++;
429 LY_ARRAY_FOR(exts, u) {
430 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
431 continue;
432 }
Radek Krejci693262f2019-04-29 15:23:20 +0200433 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200434 }
435 LEVEL--;
436 ypr_close(ctx, extflag);
437 }
438}
439
440static void
Radek Krejci693262f2019-04-29 15:23:20 +0200441yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
442{
443 int brackets_flag = *index_e;
444 uint8_t op;
445
446 op = lysc_iff_getop(feat->expr, *index_e);
447 (*index_e)++;
448
449 switch (op) {
450 case LYS_IFF_F:
451 if (ctx->module == feat->features[*index_f]->module) {
452 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
453 } else {
454 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
455 }
456 (*index_f)++;
457 break;
458 case LYS_IFF_NOT:
459 ly_print(ctx->out, "not ");
460 yprc_iffeature(ctx, feat, index_e, index_f);
461 break;
462 case LYS_IFF_AND:
463 if (brackets_flag) {
464 /* AND need brackets only if previous op was not */
465 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
466 brackets_flag = 0;
467 }
468 }
469 /* falls through */
470 case LYS_IFF_OR:
471 if (brackets_flag) {
472 ly_print(ctx->out, "(");
473 }
474 yprc_iffeature(ctx, feat, index_e, index_f);
475 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
476 yprc_iffeature(ctx, feat, index_e, index_f);
477 if (brackets_flag) {
478 ly_print(ctx->out, ")");
479 }
480 }
481}
482
483static void
484yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
485{
Radek Krejci334ccc72019-06-12 13:49:29 +0200486 unsigned int u, v;
Radek Krejci693262f2019-04-29 15:23:20 +0200487 int extflag;
488
489 LY_ARRAY_FOR(iff, u) {
490 int index_e = 0, index_f = 0;
491
492 ypr_open(ctx->out, flag);
493 extflag = 0;
494
Radek Krejci989e53b2019-04-30 09:51:09 +0200495 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200496 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200497 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200498
499 /* extensions */
500 LEVEL++;
Radek Krejci334ccc72019-06-12 13:49:29 +0200501 LY_ARRAY_FOR(exts, v) {
502 if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200503 continue;
504 }
Radek Krejci334ccc72019-06-12 13:49:29 +0200505 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200506 }
507 LEVEL--;
508 ypr_close(ctx, extflag);
509 }
510}
511
512static void
513yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200514{
515 int flag = 0, flag2 = 0;
516 unsigned int i;
517
518 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
519 LEVEL++;
520
521 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200522 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200523 }
524
525 if (ext->argument) {
526 ypr_open(ctx->out, &flag);
527 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
528 if (ext->exts) {
529 LEVEL++;
530 i = -1;
531 while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
Radek Krejci693262f2019-04-29 15:23:20 +0200532 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533 }
534 LEVEL--;
535 }
536 if ((ext->flags & LYS_YINELEM_MASK) ||
537 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
538 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200539 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200540 }
541 ypr_close(ctx, flag2);
542 }
543
Radek Krejci693262f2019-04-29 15:23:20 +0200544 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200545 ypr_description(ctx, ext->dsc, ext->exts, &flag);
546 ypr_reference(ctx, ext->ref, ext->exts, &flag);
547
548 LEVEL--;
549 ypr_close(ctx, flag);
550}
551
552static void
Radek Krejci693262f2019-04-29 15:23:20 +0200553yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200554{
555 int flag = 0;
556
557 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
558 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200559 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
560 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
561 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200562 ypr_description(ctx, feat->dsc, feat->exts, &flag);
563 ypr_reference(ctx, feat->ref, feat->exts, &flag);
564 LEVEL--;
565 ypr_close(ctx, flag);
566}
567
568static void
Radek Krejci693262f2019-04-29 15:23:20 +0200569yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
570{
571 int flag = 0;
572
573 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
574 LEVEL++;
575 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
576 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
577 ypr_status(ctx, feat->flags, feat->exts, &flag);
578 ypr_description(ctx, feat->dsc, feat->exts, &flag);
579 ypr_reference(ctx, feat->ref, feat->exts, &flag);
580 LEVEL--;
581 ypr_close(ctx, flag);
582}
583
584static void
585yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200586{
587 int flag = 0;
588 unsigned int u;
589
590 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
591 LEVEL++;
592
Radek Krejci693262f2019-04-29 15:23:20 +0200593 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
594 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200595
596 LY_ARRAY_FOR(ident->bases, u) {
597 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200598 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200599 }
600
Radek Krejci693262f2019-04-29 15:23:20 +0200601 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200602 ypr_description(ctx, ident->dsc, ident->exts, &flag);
603 ypr_reference(ctx, ident->ref, ident->exts, &flag);
604
605 LEVEL--;
606 ypr_close(ctx, flag);
607}
608
609static void
Radek Krejci693262f2019-04-29 15:23:20 +0200610yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
611{
612 int flag = 0;
613 unsigned int u;
614
615 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
616 LEVEL++;
617
618 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
619 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
620
621 LY_ARRAY_FOR(ident->derived, u) {
622 ypr_open(ctx->out, &flag);
623 if (ctx->module != ident->derived[u]->module) {
624 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
625 } else {
626 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
627 }
628 }
629
630 ypr_status(ctx, ident->flags, ident->exts, &flag);
631 ypr_description(ctx, ident->dsc, ident->exts, &flag);
632 ypr_reference(ctx, ident->ref, ident->exts, &flag);
633
634 LEVEL--;
635 ypr_close(ctx, flag);
636}
637
638static void
639yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200640{
641 int inner_flag = 0;
642
643 if (!restr) {
644 return;
645 }
646
647 ypr_open(ctx->out, flag);
648 ly_print(ctx->out, "%*s%s \"", INDENT, name);
649 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
650 ly_print(ctx->out, "\"");
651
652 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200653 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200654 if (restr->arg[0] == 0x15) {
655 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
656 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200657 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200658 }
659 if (restr->emsg) {
660 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200661 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200662 }
663 if (restr->eapptag) {
664 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200665 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200666 }
Radek Krejci693262f2019-04-29 15:23:20 +0200667 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
668 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
669
Radek Krejcid3ca0632019-04-16 16:54:54 +0200670 LEVEL--;
671 ypr_close(ctx, inner_flag);
672}
673
674static void
Radek Krejci693262f2019-04-29 15:23:20 +0200675yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
676{
677 int inner_flag = 0;
678
679 ypr_open(ctx->out, flag);
680 ly_print(ctx->out, "%*smust \"", INDENT);
681 ypr_encode(ctx->out, must->cond->expr, -1);
682 ly_print(ctx->out, "\"");
683
684 LEVEL++;
685 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
686 if (must->emsg) {
687 ypr_open(ctx->out, &inner_flag);
688 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
689 }
690 if (must->eapptag) {
691 ypr_open(ctx->out, &inner_flag);
692 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
693 }
694 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
695 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
696
697 LEVEL--;
698 ypr_close(ctx, inner_flag);
699}
700
701static void
702yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
703{
704 int inner_flag = 0;
705 unsigned int u;
706
Radek Krejci334ccc72019-06-12 13:49:29 +0200707 if (!range) {
708 return;
709 }
710
Radek Krejci693262f2019-04-29 15:23:20 +0200711 ypr_open(ctx->out, flag);
Radek Krejci334ccc72019-06-12 13:49:29 +0200712 ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200713 LY_ARRAY_FOR(range->parts, u) {
714 if (u > 0) {
715 ly_print(ctx->out, " | ");
716 }
717 if (range->parts[u].max_64 == range->parts[u].min_64) {
718 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
719 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
720 } else { /* signed values */
721 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
722 }
723 } else {
724 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
725 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
726 } else { /* signed values */
727 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
728 }
729 }
730 }
731 ly_print(ctx->out, "\"");
732
733 LEVEL++;
734 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
735 if (range->emsg) {
736 ypr_open(ctx->out, &inner_flag);
737 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
738 }
739 if (range->eapptag) {
740 ypr_open(ctx->out, &inner_flag);
741 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
742 }
743 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
744 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
745
746 LEVEL--;
747 ypr_close(ctx, inner_flag);
748}
749
750static void
751yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
752{
753 int inner_flag = 0;
754
755 ypr_open(ctx->out, flag);
756 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200757 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200758 ly_print(ctx->out, "\"");
759
760 LEVEL++;
761 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
762 if (pattern->inverted) {
763 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
764 ypr_open(ctx->out, &inner_flag);
765 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
766 }
767 if (pattern->emsg) {
768 ypr_open(ctx->out, &inner_flag);
769 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
770 }
771 if (pattern->eapptag) {
772 ypr_open(ctx->out, &inner_flag);
773 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
774 }
775 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
776 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
777
778 LEVEL--;
779 ypr_close(ctx, inner_flag);
780}
781
782static void
783yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200784{
785 int inner_flag = 0;
786
787 if (!when) {
788 return;
789 }
790 ypr_open(ctx->out, flag);
791
792 ly_print(ctx->out, "%*swhen \"", INDENT);
793 ypr_encode(ctx->out, when->cond, -1);
794 ly_print(ctx->out, "\"");
795
796 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200797 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200798 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
799 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
800 LEVEL--;
801 ypr_close(ctx, inner_flag);
802}
803
804static void
Radek Krejci693262f2019-04-29 15:23:20 +0200805yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
806{
807 int inner_flag = 0;
808
809 if (!when) {
810 return;
811 }
812 ypr_open(ctx->out, flag);
813
814 ly_print(ctx->out, "%*swhen \"", INDENT);
815 ypr_encode(ctx->out, when->cond->expr, -1);
816 ly_print(ctx->out, "\"");
817
818 LEVEL++;
819 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
820 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
821 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
822 LEVEL--;
823 ypr_close(ctx, inner_flag);
824}
825
826static void
827yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200828{
829 unsigned int u;
830 int inner_flag;
831
832 LY_ARRAY_FOR(items, u) {
833 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200834 if (type == LY_TYPE_BITS) {
835 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
836 } else { /* LY_TYPE_ENUM */
837 ly_print(ctx->out, "%*senum \"", INDENT);
838 ypr_encode(ctx->out, items[u].name, -1);
839 ly_print(ctx->out, "\"");
840 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200841 inner_flag = 0;
842 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200843 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
844 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200845 if (items[u].flags & LYS_SET_VALUE) {
846 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200847 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200848 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200849 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200850 }
851 }
Radek Krejci693262f2019-04-29 15:23:20 +0200852 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200853 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
854 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
855 LEVEL--;
856 ypr_close(ctx, inner_flag);
857 }
858}
859
860static void
Radek Krejci693262f2019-04-29 15:23:20 +0200861yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200862{
863 unsigned int u;
864 int flag = 0;
865
866 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
867 LEVEL++;
868
Radek Krejci693262f2019-04-29 15:23:20 +0200869 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200870
Radek Krejci693262f2019-04-29 15:23:20 +0200871 yprp_restr(ctx, type->range, "range", &flag);
872 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200873 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200874 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875 }
Radek Krejci693262f2019-04-29 15:23:20 +0200876 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
877 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200878
879 if (type->path) {
880 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200881 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200882 }
883 if (type->flags & LYS_SET_REQINST) {
884 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200885 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200886 }
887 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200888 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200889 }
890 LY_ARRAY_FOR(type->bases, u) {
891 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200892 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200893 }
894 LY_ARRAY_FOR(type->types, u) {
895 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200896 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200897 }
898
899 LEVEL--;
900 ypr_close(ctx, flag);
901}
902
903static void
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200904yprc_dflt_value(struct ypr_ctx *ctx, const struct lyd_value *value, const struct lys_module *value_mod, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200905{
906 int dynamic;
907 const char *str;
908
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200909 str = value->realtype->plugin->print(value, LYD_JSON, lys_get_prefix, (void*)value_mod, &dynamic);
Radek Krejcia1911222019-07-22 17:24:50 +0200910 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, str, exts);
911 if (dynamic) {
912 free((void*)str);
913 }
914}
915
916static void
Radek Krejci693262f2019-04-29 15:23:20 +0200917yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
918{
919 unsigned int u;
920 int flag = 0;
921
922 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
923 LEVEL++;
924
925 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
926 if (type->dflt) {
927 ypr_open(ctx->out, &flag);
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200928 yprc_dflt_value(ctx, type->dflt, type->dflt_mod, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200929 }
930
931 switch(type->basetype) {
932 case LY_TYPE_BINARY: {
933 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
934 yprc_range(ctx, bin->length, type->basetype, &flag);
935 break;
936 }
937 case LY_TYPE_UINT8:
938 case LY_TYPE_UINT16:
939 case LY_TYPE_UINT32:
940 case LY_TYPE_UINT64:
941 case LY_TYPE_INT8:
942 case LY_TYPE_INT16:
943 case LY_TYPE_INT32:
944 case LY_TYPE_INT64: {
945 struct lysc_type_num *num = (struct lysc_type_num*)type;
946 yprc_range(ctx, num->range, type->basetype, &flag);
947 break;
948 }
949 case LY_TYPE_STRING: {
950 struct lysc_type_str *str = (struct lysc_type_str*)type;
951 yprc_range(ctx, str->length, type->basetype, &flag);
952 LY_ARRAY_FOR(str->patterns, u) {
953 yprc_pattern(ctx, str->patterns[u], &flag);
954 }
955 break;
956 }
957 case LY_TYPE_BITS:
958 case LY_TYPE_ENUM: {
959 /* bits and enums structures are compatible */
960 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
961 LY_ARRAY_FOR(bits->bits, u) {
962 struct lysc_type_bitenum_item *item = &bits->bits[u];
963 int inner_flag = 0;
964
965 ypr_open(ctx->out, &flag);
966 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
967 ypr_encode(ctx->out, item->name, -1);
968 ly_print(ctx->out, "\"");
969 LEVEL++;
970 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
971 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
972 if (type->basetype == LY_TYPE_BITS) {
973 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
974 } else { /* LY_TYPE_ENUM */
975 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
976 }
977 ypr_status(ctx, item->flags, item->exts, &inner_flag);
978 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
979 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
980 LEVEL--;
981 ypr_close(ctx, inner_flag);
982 }
983 break;
984 }
985 case LY_TYPE_BOOL:
986 case LY_TYPE_EMPTY:
987 /* nothing to do */
988 break;
989 case LY_TYPE_DEC64: {
990 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
991 ypr_open(ctx->out, &flag);
992 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
993 yprc_range(ctx, dec->range, dec->basetype, &flag);
994 break;
995 }
996 case LY_TYPE_IDENT: {
997 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
998 LY_ARRAY_FOR(ident->bases, u) {
999 ypr_open(ctx->out, &flag);
1000 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
1001 }
1002 break;
1003 }
1004 case LY_TYPE_INST: {
1005 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
1006 ypr_open(ctx->out, &flag);
1007 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
1008 break;
1009 }
1010 case LY_TYPE_LEAFREF: {
1011 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
1012 ypr_open(ctx->out, &flag);
1013 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
1014 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
1015 yprc_type(ctx, lr->realtype);
1016 break;
1017 }
1018 case LY_TYPE_UNION: {
1019 struct lysc_type_union *un = (struct lysc_type_union*)type;
1020 LY_ARRAY_FOR(un->types, u) {
1021 ypr_open(ctx->out, &flag);
1022 yprc_type(ctx, un->types[u]);
1023 }
1024 break;
1025 }
1026 default:
1027 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001028 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001029 }
1030
1031 LEVEL--;
1032 ypr_close(ctx, flag);
1033}
1034
1035static void
1036yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037{
Radek Krejci56cc0872019-04-30 09:22:27 +02001038 LYOUT_CHECK(ctx->out);
1039
Radek Krejcid3ca0632019-04-16 16:54:54 +02001040 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1041 LEVEL++;
1042
Radek Krejci693262f2019-04-29 15:23:20 +02001043 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044
Radek Krejci693262f2019-04-29 15:23:20 +02001045 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001046
1047 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001048 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049 }
1050 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001051 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052 }
1053
Radek Krejci693262f2019-04-29 15:23:20 +02001054 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1056 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1057
1058 LEVEL--;
1059 ly_print(ctx->out, "%*s}\n", INDENT);
1060}
1061
Radek Krejci693262f2019-04-29 15:23:20 +02001062static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1063static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1064static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001065
1066static void
Radek Krejci693262f2019-04-29 15:23:20 +02001067yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001068{
1069 unsigned int u;
1070 int flag = 0;
1071 struct lysp_node *data;
1072
Radek Krejci56cc0872019-04-30 09:22:27 +02001073 LYOUT_CHECK(ctx->out);
1074
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1076 LEVEL++;
1077
Radek Krejci693262f2019-04-29 15:23:20 +02001078 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1079 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001080 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1081 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082
1083 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001084 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001085 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001086 }
1087
1088 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001089 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001090 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001091 }
1092
1093 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001094 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001095 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001096 }
1097
1098 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001099 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 }
1101
1102 LEVEL--;
1103 ypr_close(ctx, flag);
1104}
1105
1106static void
Radek Krejci693262f2019-04-29 15:23:20 +02001107yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001108{
1109 unsigned int u;
1110 struct lysp_node *data;
1111
1112 if (!inout->nodetype) {
1113 /* nodetype not set -> input/output is empty */
1114 return;
1115 }
1116 ypr_open(ctx->out, flag);
1117
1118 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1119 LEVEL++;
1120
Radek Krejci693262f2019-04-29 15:23:20 +02001121 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001123 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001124 }
1125 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001126 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001127 }
1128 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001129 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001130 }
1131
1132 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001133 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001134 }
1135
1136 LEVEL--;
1137 ypr_close(ctx, 1);
1138}
1139
1140static void
Radek Krejci693262f2019-04-29 15:23:20 +02001141yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1142{
1143 unsigned int u;
1144 struct lysc_node *data;
1145
1146 if (!inout->data) {
1147 /* input/output is empty */
1148 return;
1149 }
1150 ypr_open(ctx->out, flag);
1151
1152 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1153 LEVEL++;
1154
1155 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1156 LY_ARRAY_FOR(inout->musts, u) {
1157 yprc_must(ctx, &inout->musts[u], NULL);
1158 }
1159
1160 LY_LIST_FOR(inout->data, data) {
1161 yprc_node(ctx, data);
1162 }
1163
1164 LEVEL--;
1165 ypr_close(ctx, 1);
1166}
1167
1168static void
1169yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001170{
1171 unsigned int u;
1172 int flag = 0;
1173 struct lysp_node *data;
1174
Radek Krejci56cc0872019-04-30 09:22:27 +02001175 LYOUT_CHECK(ctx->out);
1176
Radek Krejcid3ca0632019-04-16 16:54:54 +02001177 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1178
1179 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001180 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1181 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001182
1183 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001184 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001185 }
Radek Krejci693262f2019-04-29 15:23:20 +02001186 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001187 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1188 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1189
1190 LY_ARRAY_FOR(notif->typedefs, u) {
1191 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001192 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001193 }
1194
1195 LY_ARRAY_FOR(notif->groupings, u) {
1196 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001197 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001198 }
1199
1200 LY_LIST_FOR(notif->data, data) {
1201 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001202 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203 }
1204
1205 LEVEL--;
1206 ypr_close(ctx, flag);
1207}
1208
1209static void
Radek Krejci693262f2019-04-29 15:23:20 +02001210yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1211{
1212 unsigned int u;
1213 int flag = 0;
1214 struct lysc_node *data;
1215
Radek Krejci56cc0872019-04-30 09:22:27 +02001216 LYOUT_CHECK(ctx->out);
1217
Radek Krejci693262f2019-04-29 15:23:20 +02001218 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1219
1220 LEVEL++;
1221 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1222 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1223
1224 LY_ARRAY_FOR(notif->musts, u) {
1225 yprc_must(ctx, &notif->musts[u], &flag);
1226 }
1227 ypr_status(ctx, notif->flags, notif->exts, &flag);
1228 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1229 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1230
1231 LY_LIST_FOR(notif->data, data) {
1232 ypr_open(ctx->out, &flag);
1233 yprc_node(ctx, data);
1234 }
1235
1236 LEVEL--;
1237 ypr_close(ctx, flag);
1238}
1239
1240static void
1241yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001242{
1243 unsigned int u;
1244 int flag = 0;
1245
Radek Krejci56cc0872019-04-30 09:22:27 +02001246 LYOUT_CHECK(ctx->out);
1247
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1249
1250 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001251 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1252 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1253 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001254 ypr_description(ctx, action->dsc, action->exts, &flag);
1255 ypr_reference(ctx, action->ref, action->exts, &flag);
1256
1257 LY_ARRAY_FOR(action->typedefs, u) {
1258 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001259 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001260 }
1261
1262 LY_ARRAY_FOR(action->groupings, u) {
1263 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001264 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001265 }
1266
Radek Krejci693262f2019-04-29 15:23:20 +02001267 yprp_inout(ctx, &action->input, &flag);
1268 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001269
1270 LEVEL--;
1271 ypr_close(ctx, flag);
1272}
1273
1274static void
Radek Krejci693262f2019-04-29 15:23:20 +02001275yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1276{
1277 int flag = 0;
1278
Radek Krejci56cc0872019-04-30 09:22:27 +02001279 LYOUT_CHECK(ctx->out);
1280
Radek Krejci693262f2019-04-29 15:23:20 +02001281 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1282
1283 LEVEL++;
1284 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1285 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1286 ypr_status(ctx, action->flags, action->exts, &flag);
1287 ypr_description(ctx, action->dsc, action->exts, &flag);
1288 ypr_reference(ctx, action->ref, action->exts, &flag);
1289
1290 yprc_inout(ctx, action, &action->input, &flag);
1291 yprc_inout(ctx, action, &action->output, &flag);
1292
1293 LEVEL--;
1294 ypr_close(ctx, flag);
1295}
1296
1297static void
1298yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001299{
Radek Krejci7871ce52019-06-11 16:44:56 +02001300 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001301 LEVEL++;
1302
Radek Krejci693262f2019-04-29 15:23:20 +02001303 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1304 yprp_when(ctx, node->when, flag);
1305 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001306}
1307
1308static void
Radek Krejci693262f2019-04-29 15:23:20 +02001309yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001310{
Radek Krejci693262f2019-04-29 15:23:20 +02001311 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001312
Radek Krejci42903ea2019-06-14 16:24:56 +02001313 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001314 LEVEL++;
1315
1316 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1317 LY_ARRAY_FOR(node->when, u) {
1318 yprc_when(ctx, node->when[u], flag);
1319 }
1320 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1321}
1322
1323/* macr oto unify the code */
1324#define YPR_NODE_COMMON2 \
1325 ypr_config(ctx, node->flags, node->exts, flag); \
1326 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1327 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1328 } \
1329 ypr_status(ctx, node->flags, node->exts, flag); \
1330 ypr_description(ctx, node->dsc, node->exts, flag); \
1331 ypr_reference(ctx, node->ref, node->exts, flag)
1332
1333static void
1334yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1335{
1336 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001337}
1338
1339static void
Radek Krejci693262f2019-04-29 15:23:20 +02001340yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1341{
1342 YPR_NODE_COMMON2;
1343}
1344
1345#undef YPR_NODE_COMMON2
1346
1347static void
1348yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001349{
1350 unsigned int u;
1351 int flag = 0;
1352 struct lysp_node *child;
1353 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1354
Radek Krejci693262f2019-04-29 15:23:20 +02001355 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001356
1357 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001358 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001359 }
1360 if (cont->presence) {
1361 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001362 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001363 }
1364
Radek Krejci693262f2019-04-29 15:23:20 +02001365 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001366
1367 LY_ARRAY_FOR(cont->typedefs, u) {
1368 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001369 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001370 }
1371
1372 LY_ARRAY_FOR(cont->groupings, u) {
1373 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001374 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001375 }
1376
1377 LY_LIST_FOR(cont->child, child) {
1378 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001379 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001380 }
1381
1382 LY_ARRAY_FOR(cont->actions, u) {
1383 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001384 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001385 }
1386
1387 LY_ARRAY_FOR(cont->notifs, u) {
1388 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001389 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001390 }
1391
1392 LEVEL--;
1393 ypr_close(ctx, flag);
1394}
1395
1396static void
Radek Krejci693262f2019-04-29 15:23:20 +02001397yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1398{
1399 unsigned int u;
1400 int flag = 0;
1401 struct lysc_node *child;
1402 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1403
1404 yprc_node_common1(ctx, node, &flag);
1405
1406 LY_ARRAY_FOR(cont->musts, u) {
1407 yprc_must(ctx, &cont->musts[u], &flag);
1408 }
1409 if (cont->flags & LYS_PRESENCE) {
1410 ypr_open(ctx->out, &flag);
1411 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1412 }
1413
1414 yprc_node_common2(ctx, node, &flag);
1415
1416 LY_LIST_FOR(cont->child, child) {
1417 ypr_open(ctx->out, &flag);
1418 yprc_node(ctx, child);
1419 }
1420
1421 LY_ARRAY_FOR(cont->actions, u) {
1422 ypr_open(ctx->out, &flag);
1423 yprc_action(ctx, &cont->actions[u]);
1424 }
1425
1426 LY_ARRAY_FOR(cont->notifs, u) {
1427 ypr_open(ctx->out, &flag);
1428 yprc_notification(ctx, &cont->notifs[u]);
1429 }
1430
1431 LEVEL--;
1432 ypr_close(ctx, flag);
1433}
1434
1435static void
1436yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1437{
1438 int flag = 0;
1439 struct lysp_node *child;
1440 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1441
1442 yprp_node_common1(ctx, node, &flag);
1443 yprp_node_common2(ctx, node, &flag);
1444
1445 LY_LIST_FOR(cas->child, child) {
1446 ypr_open(ctx->out, &flag);
1447 yprp_node(ctx, child);
1448 }
1449
1450 LEVEL--;
1451 ypr_close(ctx, flag);
1452}
1453
1454static void
1455yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1456{
1457 int flag = 0;
1458 struct lysc_node *child;
1459
1460 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1461 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1462
1463 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1464 ypr_open(ctx->out, &flag);
1465 yprc_node(ctx, child);
1466 }
1467
1468 LEVEL--;
1469 ypr_close(ctx, flag);
1470}
1471
1472static void
1473yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001474{
1475 int flag = 0;
1476 struct lysp_node *child;
1477 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1478
Radek Krejci693262f2019-04-29 15:23:20 +02001479 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001480
1481 if (choice->dflt) {
1482 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001483 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001484 }
1485
Radek Krejci693262f2019-04-29 15:23:20 +02001486 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001487
1488 LY_LIST_FOR(choice->child, child) {
1489 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001490 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001491 }
1492
1493 LEVEL--;
1494 ypr_close(ctx, flag);
1495}
1496
1497static void
Radek Krejci693262f2019-04-29 15:23:20 +02001498yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1499{
1500 int flag = 0;
1501 struct lysc_node_case *cs;
1502 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1503
1504 yprc_node_common1(ctx, node, &flag);
1505
1506 if (choice->dflt) {
1507 ypr_open(ctx->out, &flag);
1508 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1509 }
1510
1511 yprc_node_common2(ctx, node, &flag);
1512
1513 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1514 ypr_open(ctx->out, &flag);
1515 yprc_case(ctx, cs);
1516 }
1517
1518 LEVEL--;
1519 ypr_close(ctx, flag);
1520}
1521
1522static void
1523yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001524{
1525 unsigned int u;
1526 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1527
Radek Krejci693262f2019-04-29 15:23:20 +02001528 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001529
Radek Krejci693262f2019-04-29 15:23:20 +02001530 yprp_type(ctx, &leaf->type);
1531 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001532 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001533 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534 }
Radek Krejci693262f2019-04-29 15:23:20 +02001535 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001536
Radek Krejci693262f2019-04-29 15:23:20 +02001537 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001538
1539 LEVEL--;
1540 ly_print(ctx->out, "%*s}\n", INDENT);
1541}
1542
1543static void
Radek Krejci693262f2019-04-29 15:23:20 +02001544yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1545{
1546 unsigned int u;
1547 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1548
1549 yprc_node_common1(ctx, node, NULL);
1550
1551 yprc_type(ctx, leaf->type);
1552 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1553 LY_ARRAY_FOR(leaf->musts, u) {
1554 yprc_must(ctx, &leaf->musts[u], NULL);
1555 }
Radek Krejcia1911222019-07-22 17:24:50 +02001556
1557 if (leaf->dflt) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001558 yprc_dflt_value(ctx, leaf->dflt, leaf->dflt_mod, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001559 }
Radek Krejci693262f2019-04-29 15:23:20 +02001560
1561 yprc_node_common2(ctx, node, NULL);
1562
1563 LEVEL--;
1564 ly_print(ctx->out, "%*s}\n", INDENT);
1565}
1566
1567static void
1568yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569{
1570 unsigned int u;
1571 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1572
Radek Krejci693262f2019-04-29 15:23:20 +02001573 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001574
Radek Krejci693262f2019-04-29 15:23:20 +02001575 yprp_type(ctx, &llist->type);
1576 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001577 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001578 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 }
1580 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001581 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001582 }
1583
Radek Krejci693262f2019-04-29 15:23:20 +02001584 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585
1586 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001587 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001588 }
1589 if (llist->flags & LYS_SET_MAX) {
1590 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001591 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001592 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001593 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001594 }
1595 }
1596
1597 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001598 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001599 }
1600
Radek Krejci693262f2019-04-29 15:23:20 +02001601 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001602 ypr_description(ctx, node->dsc, node->exts, NULL);
1603 ypr_reference(ctx, node->ref, node->exts, NULL);
1604
1605 LEVEL--;
1606 ly_print(ctx->out, "%*s}\n", INDENT);
1607}
1608
1609static void
Radek Krejci693262f2019-04-29 15:23:20 +02001610yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1611{
1612 unsigned int u;
1613 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1614
1615 yprc_node_common1(ctx, node, NULL);
1616
1617 yprc_type(ctx, llist->type);
1618 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1619 LY_ARRAY_FOR(llist->musts, u) {
1620 yprc_must(ctx, &llist->musts[u], NULL);
1621 }
1622 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001623 yprc_dflt_value(ctx, llist->dflts[u], llist->dflts_mods[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001624 }
1625
1626 ypr_config(ctx, node->flags, node->exts, NULL);
1627
1628 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1629 if (llist->max) {
1630 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1631 } else {
1632 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1633 }
1634
1635 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1636
1637 ypr_status(ctx, node->flags, node->exts, NULL);
1638 ypr_description(ctx, node->dsc, node->exts, NULL);
1639 ypr_reference(ctx, node->ref, node->exts, NULL);
1640
1641 LEVEL--;
1642 ly_print(ctx->out, "%*s}\n", INDENT);
1643}
1644
1645static void
1646yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647{
1648 unsigned int u;
1649 int flag = 0;
1650 struct lysp_node *child;
1651 struct lysp_node_list *list = (struct lysp_node_list *)node;
1652
Radek Krejci693262f2019-04-29 15:23:20 +02001653 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654
1655 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001656 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001657 }
1658 if (list->key) {
1659 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001660 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001661 }
1662 LY_ARRAY_FOR(list->uniques, u) {
1663 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001664 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001665 }
1666
Radek Krejci693262f2019-04-29 15:23:20 +02001667 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001668
1669 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001670 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001671 }
1672 if (list->flags & LYS_SET_MAX) {
1673 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001674 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001675 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001676 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001677 }
1678 }
1679
1680 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001681 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001682 }
1683
Radek Krejci693262f2019-04-29 15:23:20 +02001684 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001685 ypr_description(ctx, node->dsc, node->exts, NULL);
1686 ypr_reference(ctx, node->ref, node->exts, NULL);
1687
1688 LY_ARRAY_FOR(list->typedefs, u) {
1689 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001690 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001691 }
1692
1693 LY_ARRAY_FOR(list->groupings, u) {
1694 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001695 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001696 }
1697
1698 LY_LIST_FOR(list->child, child) {
1699 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001700 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001701 }
1702
1703 LY_ARRAY_FOR(list->actions, u) {
1704 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001705 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001706 }
1707
1708 LY_ARRAY_FOR(list->notifs, u) {
1709 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001710 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001711 }
1712
1713 LEVEL--;
1714 ypr_close(ctx, flag);
1715}
1716
1717static void
Radek Krejci693262f2019-04-29 15:23:20 +02001718yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1719{
1720 unsigned int u, v;
1721 int flag = 0;
1722 struct lysc_node *child;
1723 struct lysc_node_list *list = (struct lysc_node_list *)node;
1724
1725 yprc_node_common1(ctx, node, &flag);
1726
1727 LY_ARRAY_FOR(list->musts, u) {
1728 yprc_must(ctx, &list->musts[u], NULL);
1729 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001730 if (!(list->flags & LYS_KEYLESS)) {
Radek Krejci693262f2019-04-29 15:23:20 +02001731 ypr_open(ctx->out, &flag);
1732 ly_print(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001733 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
1734 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001735 }
Radek Krejci73c88f52019-06-14 16:24:19 +02001736 ly_print(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001737 }
1738 LY_ARRAY_FOR(list->uniques, u) {
1739 ypr_open(ctx->out, &flag);
1740 ly_print(ctx->out, "%*sunique \"", INDENT);
1741 LY_ARRAY_FOR(list->uniques[u], v) {
1742 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1743 }
1744 ypr_close(ctx, 0);
1745 }
1746
1747 ypr_config(ctx, node->flags, node->exts, NULL);
1748
1749 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1750 if (list->max) {
1751 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1752 } else {
1753 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1754 }
1755
1756 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1757
1758 ypr_status(ctx, node->flags, node->exts, NULL);
1759 ypr_description(ctx, node->dsc, node->exts, NULL);
1760 ypr_reference(ctx, node->ref, node->exts, NULL);
1761
1762 LY_LIST_FOR(list->child, child) {
1763 ypr_open(ctx->out, &flag);
1764 yprc_node(ctx, child);
1765 }
1766
1767 LY_ARRAY_FOR(list->actions, u) {
1768 ypr_open(ctx->out, &flag);
1769 yprc_action(ctx, &list->actions[u]);
1770 }
1771
1772 LY_ARRAY_FOR(list->notifs, u) {
1773 ypr_open(ctx->out, &flag);
1774 yprc_notification(ctx, &list->notifs[u]);
1775 }
1776
1777 LEVEL--;
1778 ypr_close(ctx, flag);
1779}
1780
1781static void
1782yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783{
1784 unsigned int u;
1785 int flag = 0;
1786
1787 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1788 LEVEL++;
1789
Radek Krejci693262f2019-04-29 15:23:20 +02001790 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1791 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792
1793 LY_ARRAY_FOR(refine->musts, u) {
1794 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001795 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796 }
1797
1798 if (refine->presence) {
1799 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001800 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801 }
1802
1803 LY_ARRAY_FOR(refine->dflts, u) {
1804 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001805 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806 }
1807
Radek Krejci693262f2019-04-29 15:23:20 +02001808 ypr_config(ctx, refine->flags, refine->exts, &flag);
1809 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810
1811 if (refine->flags & LYS_SET_MIN) {
1812 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001813 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814 }
1815 if (refine->flags & LYS_SET_MAX) {
1816 ypr_open(ctx->out, &flag);
1817 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001818 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001820 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001821 }
1822 }
1823
1824 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1825 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1826
1827 LEVEL--;
1828 ypr_close(ctx, flag);
1829}
1830
1831static void
Radek Krejci693262f2019-04-29 15:23:20 +02001832yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833{
1834 unsigned int u;
1835 struct lysp_node *child;
1836
1837 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1838 LEVEL++;
1839
Radek Krejci693262f2019-04-29 15:23:20 +02001840 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1841 yprp_when(ctx, aug->when, NULL);
1842 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1843 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1845 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1846
1847 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 }
1850
1851 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001852 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853 }
1854
1855 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001856 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001857 }
1858
1859 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001860 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001861}
1862
1863
1864static void
Radek Krejci693262f2019-04-29 15:23:20 +02001865yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866{
1867 unsigned int u;
1868 int flag = 0;
1869 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1870
Radek Krejci693262f2019-04-29 15:23:20 +02001871 yprp_node_common1(ctx, node, &flag);
1872 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873
1874 LY_ARRAY_FOR(uses->refines, u) {
1875 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001876 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877 }
1878
1879 LY_ARRAY_FOR(uses->augments, u) {
1880 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001881 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882 }
1883
1884 LEVEL--;
1885 ypr_close(ctx, flag);
1886}
1887
1888static void
Radek Krejci693262f2019-04-29 15:23:20 +02001889yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890{
1891 unsigned int u;
1892 int flag = 0;
1893 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1894
Radek Krejci693262f2019-04-29 15:23:20 +02001895 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001896
1897 LY_ARRAY_FOR(any->musts, u) {
1898 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001899 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900 }
1901
Radek Krejci693262f2019-04-29 15:23:20 +02001902 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903
1904 LEVEL--;
1905 ypr_close(ctx, flag);
1906}
1907
1908static void
Radek Krejci693262f2019-04-29 15:23:20 +02001909yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910{
Radek Krejci693262f2019-04-29 15:23:20 +02001911 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001913 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914
Radek Krejci693262f2019-04-29 15:23:20 +02001915 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916
Radek Krejci693262f2019-04-29 15:23:20 +02001917 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001919 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 }
1921
Radek Krejci693262f2019-04-29 15:23:20 +02001922 yprc_node_common2(ctx, node, &flag);
1923
Radek Krejcid3ca0632019-04-16 16:54:54 +02001924 LEVEL--;
1925 ypr_close(ctx, flag);
1926}
1927
1928static void
Radek Krejci693262f2019-04-29 15:23:20 +02001929yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930{
Radek Krejci56cc0872019-04-30 09:22:27 +02001931 LYOUT_CHECK(ctx->out);
1932
Radek Krejcid3ca0632019-04-16 16:54:54 +02001933 switch (node->nodetype) {
1934 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001935 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 break;
1937 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001938 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 break;
1940 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001941 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942 break;
1943 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001944 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 break;
1946 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001947 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001948 break;
1949 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001950 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001951 break;
1952 case LYS_ANYXML:
1953 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001954 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001955 break;
1956 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001957 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001958 break;
1959 default:
1960 break;
1961 }
1962}
1963
1964static void
Radek Krejci693262f2019-04-29 15:23:20 +02001965yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1966{
Radek Krejci56cc0872019-04-30 09:22:27 +02001967 LYOUT_CHECK(ctx->out);
1968
Radek Krejci693262f2019-04-29 15:23:20 +02001969 switch (node->nodetype) {
1970 case LYS_CONTAINER:
1971 yprc_container(ctx, node);
1972 break;
1973 case LYS_CHOICE:
1974 yprc_choice(ctx, node);
1975 break;
1976 case LYS_LEAF:
1977 yprc_leaf(ctx, node);
1978 break;
1979 case LYS_LEAFLIST:
1980 yprc_leaflist(ctx, node);
1981 break;
1982 case LYS_LIST:
1983 yprc_list(ctx, node);
1984 break;
1985 case LYS_ANYXML:
1986 case LYS_ANYDATA:
1987 yprc_anydata(ctx, node);
1988 break;
1989 default:
1990 break;
1991 }
1992}
1993
1994static void
1995yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001996{
1997 unsigned int u, v;
1998 struct lysp_deviate_add *add;
1999 struct lysp_deviate_rpl *rpl;
2000 struct lysp_deviate_del *del;
2001
2002 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
2003 LEVEL++;
2004
Radek Krejci693262f2019-04-29 15:23:20 +02002005 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
2007 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
2008
2009 LY_ARRAY_FOR(deviation->deviates, u) {
2010 ly_print(ctx->out, "%*sdeviate ", INDENT);
2011 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
2012 if (deviation->deviates[u].exts) {
2013 ly_print(ctx->out, "not-supported {\n");
2014 LEVEL++;
2015
Radek Krejci693262f2019-04-29 15:23:20 +02002016 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 } else {
2018 ly_print(ctx->out, "not-supported;\n");
2019 continue;
2020 }
2021 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
2022 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2023 ly_print(ctx->out, "add {\n");
2024 LEVEL++;
2025
Radek Krejci693262f2019-04-29 15:23:20 +02002026 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2027 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002029 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
2031 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002032 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 }
2034 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002035 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036 }
Radek Krejci693262f2019-04-29 15:23:20 +02002037 ypr_config(ctx, add->flags, add->exts, NULL);
2038 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002040 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 }
2042 if (add->flags & LYS_SET_MAX) {
2043 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002044 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002046 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 }
2048 }
2049 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2050 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2051 ly_print(ctx->out, "replace {\n");
2052 LEVEL++;
2053
Radek Krejci693262f2019-04-29 15:23:20 +02002054 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002056 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 }
Radek Krejci693262f2019-04-29 15:23:20 +02002058 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2059 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2060 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2061 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002063 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064 }
2065 if (rpl->flags & LYS_SET_MAX) {
2066 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002067 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002069 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 }
2071 }
2072 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2073 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2074 ly_print(ctx->out, "delete {\n");
2075 LEVEL++;
2076
Radek Krejci693262f2019-04-29 15:23:20 +02002077 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2078 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002080 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002081 }
2082 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002083 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084 }
2085 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002086 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087 }
2088 }
2089
2090 LEVEL--;
2091 ypr_close(ctx, 1);
2092 }
2093
2094 LEVEL--;
2095 ypr_close(ctx, 1);
2096}
2097
Radek Krejci693262f2019-04-29 15:23:20 +02002098/**
2099 * @brief Minimal print of a schema.
2100 *
2101 * To print
2102 * a) compiled schema when it is not compiled or
2103 * b) parsed when the parsed form was already removed
2104 */
2105static LY_ERR
2106ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2107{
2108 /* module-header-stmts */
2109 if (module->version) {
2110 if (module->version) {
2111 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2112 }
2113 }
2114 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2115 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2116
2117 /* meta-stmts */
2118 if (module->org || module->contact || module->dsc || module->ref) {
2119 ly_print(ctx->out, "\n");
2120 }
2121 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2122 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2123 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2124 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2125
2126 /* revision-stmts */
2127 if (module->revision) {
2128 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2129 }
2130
2131 LEVEL--;
2132 ly_print(ctx->out, "%*s}\n", INDENT);
2133 ly_print_flush(ctx->out);
2134
2135 return LY_SUCCESS;
2136}
2137
Radek Krejcid3ca0632019-04-16 16:54:54 +02002138LY_ERR
2139yang_print_parsed(struct lyout *out, const struct lys_module *module)
2140{
2141 unsigned int u;
2142 struct lysp_node *data;
2143 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002144 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145
2146 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2147 LEVEL++;
2148
Radek Krejci693262f2019-04-29 15:23:20 +02002149 if (!modp) {
2150 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2151 return ypr_missing_format(ctx, module);
2152 }
2153
Radek Krejcid3ca0632019-04-16 16:54:54 +02002154 /* module-header-stmts */
2155 if (module->version) {
2156 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002157 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002158 }
2159 }
Radek Krejci693262f2019-04-29 15:23:20 +02002160 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2161 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002162
2163 /* linkage-stmts */
2164 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002165 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002166 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002167 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2168 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002169 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002170 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002171 }
Radek Krejci693262f2019-04-29 15:23:20 +02002172 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2173 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002174 LEVEL--;
2175 ly_print(out, "%*s}\n", INDENT);
2176 }
2177 LY_ARRAY_FOR(modp->includes, u) {
2178 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002179 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002181 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002182 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002183 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002184 }
Radek Krejci693262f2019-04-29 15:23:20 +02002185 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2186 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 LEVEL--;
2188 ly_print(out, "%*s}\n", INDENT);
2189 } else {
2190 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2191 }
2192 }
2193
2194 /* meta-stmts */
2195 if (module->org || module->contact || module->dsc || module->ref) {
2196 ly_print(out, "\n");
2197 }
Radek Krejci693262f2019-04-29 15:23:20 +02002198 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2199 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2200 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2201 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202
2203 /* revision-stmts */
2204 if (modp->revs) {
2205 ly_print(out, "\n");
2206 }
2207 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002208 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002209 }
2210 /* body-stmts */
2211 LY_ARRAY_FOR(modp->extensions, u) {
2212 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002213 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002214 }
2215 if (modp->exts) {
2216 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002217 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002218 }
2219
2220 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002221 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002222 }
2223
2224 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002225 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002226 }
2227
2228 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002229 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002230 }
2231
2232 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002233 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002234 }
2235
2236 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002237 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002238 }
2239
2240 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002241 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002242 }
2243
2244 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002245 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002246 }
2247
2248 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002249 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002250 }
2251
2252 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002253 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002254 }
2255
2256 LEVEL--;
2257 ly_print(out, "%*s}\n", INDENT);
2258 ly_print_flush(out);
2259
2260 return LY_SUCCESS;
2261}
2262
2263LY_ERR
2264yang_print_compiled(struct lyout *out, const struct lys_module *module)
2265{
Radek Krejci693262f2019-04-29 15:23:20 +02002266 unsigned int u;
2267 struct lysc_node *data;
2268 struct lysc_module *modc = module->compiled;
2269 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2270
2271 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2272 LEVEL++;
2273
2274 if (!modc) {
2275 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2276 return ypr_missing_format(ctx, module);
2277 }
2278
2279 /* module-header-stmts */
2280 if (module->version) {
2281 if (module->version) {
2282 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2283 }
2284 }
2285 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2286 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2287
2288 /* linkage-stmts */
2289 LY_ARRAY_FOR(modc->imports, u) {
2290 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2291 LEVEL++;
2292 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2293 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2294 if (modc->imports[u].module->revision) {
2295 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2296 }
2297 LEVEL--;
2298 ly_print(out, "%*s}\n", INDENT);
2299 }
2300
2301 /* meta-stmts */
2302 if (module->org || module->contact || module->dsc || module->ref) {
2303 ly_print(out, "\n");
2304 }
2305 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2306 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2307 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2308 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2309
2310 /* revision-stmts */
2311 if (module->revision) {
2312 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2313 }
2314
2315 /* body-stmts */
2316 if (modc->exts) {
2317 ly_print(out, "\n");
2318 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2319 }
2320
2321 LY_ARRAY_FOR(modc->features, u) {
2322 yprc_feature(ctx, &modc->features[u]);
2323 }
2324
2325 LY_ARRAY_FOR(modc->identities, u) {
2326 yprc_identity(ctx, &modc->identities[u]);
2327 }
2328
2329 LY_LIST_FOR(modc->data, data) {
2330 yprc_node(ctx, data);
2331 }
2332
2333 LY_ARRAY_FOR(modc->rpcs, u) {
2334 yprc_action(ctx, &modc->rpcs[u]);
2335 }
2336
2337 LY_ARRAY_FOR(modc->notifs, u) {
2338 yprc_notification(ctx, &modc->notifs[u]);
2339 }
2340
2341 LEVEL--;
2342 ly_print(out, "%*s}\n", INDENT);
2343 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002344
2345 return LY_SUCCESS;
2346}