blob: e9957c5fdb28a65d983d63447dc3ba9d1b3b7620 [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 "log.h"
Radek Krejci0935f412019-08-20 16:15:18 +020024#include "plugins_exts.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.
Radek Krejcif56e2a42019-09-09 14:15:25 +020062 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020063 * 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;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200224 int child_presence;
225 const char *argument;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200226
227 if (!count && ext) {
228 count = LY_ARRAY_SIZE(ext);
229 }
230 LY_ARRAY_FOR(ext, u) {
231 if (!count) {
232 break;
233 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200234
Radek Krejcid3ca0632019-04-16 16:54:54 +0200235 count--;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200236 if (ext->insubstmt != substmt || ext->insubstmt_index != substmt_index) {
237 continue;
238 }
239
240 if (!ext->compiled && ext->yin) {
241 ly_print(ctx->out, "%*s%s; // Model comes from different input format, extensions must be resolved first.\n", INDENT, ext[u].name);
242 continue;
243 }
244
245
246 ypr_open(ctx->out, flag);
247 argument = NULL;
248 if (ext[u].compiled) {
249 argument = ext[u].compiled->argument;
250 } else {
251 argument = ext[u].argument;
252 }
253 if (argument) {
254 ly_print(ctx->out, "%*s%s \"", INDENT, ext[u].name);
255 ypr_encode(ctx->out, argument, -1);
256 ly_print(ctx->out, "\"");
257 } else {
258 ly_print(ctx->out, "%*s%s", INDENT, ext[u].name);
259 }
260
261 child_presence = 0;
262 LEVEL++;
263 LY_LIST_FOR(ext[u].child, stmt) {
264 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
265 continue;
266 }
267 if (!child_presence) {
268 ly_print(ctx->out, " {\n");
269 child_presence = 1;
270 }
271 yprp_stmt(ctx, stmt);
272 }
273 LEVEL--;
274 if (child_presence) {
275 ly_print(ctx->out, "%*s}\n", INDENT);
276 } else {
277 ly_print(ctx->out, ";\n");
278 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200279 }
280}
281
Radek Krejci693262f2019-04-29 15:23:20 +0200282/**
283 * @param[in] count Number of extensions to print, 0 to print them all.
284 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200285static void
Radek Krejci693262f2019-04-29 15:23:20 +0200286yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
287 struct lysc_ext_instance *ext, int *flag, unsigned int count)
288{
289 unsigned int u;
290
291 if (!count && ext) {
292 count = LY_ARRAY_SIZE(ext);
293 }
294 LY_ARRAY_FOR(ext, u) {
295 if (!count) {
296 break;
297 }
298 /* TODO compiled extensions */
299 (void) ctx;
300 (void) substmt;
301 (void) substmt_index;
302 (void) flag;
303
304 count--;
305 }
306}
307
308static void
309ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200310{
311 unsigned int u;
312 int extflag = 0;
313
314 if (!text) {
315 /* nothing to print */
316 return;
317 }
318
319 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
320 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
321 } else {
322 ypr_text(ctx, ext_substmt_info[substmt].name, text,
323 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
324 }
325
326 LEVEL++;
327 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200328 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 +0200329 continue;
330 }
Radek Krejci693262f2019-04-29 15:23:20 +0200331 if (ctx->schema == YPR_PARSED) {
332 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
333 } else {
334 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
335 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 }
337 LEVEL--;
338 ypr_close(ctx, extflag);
339}
340
341static void
Radek Krejci693262f2019-04-29 15:23:20 +0200342ypr_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 +0200343{
344 char *str;
345
346 if (asprintf(&str, "%u", attr_value) == -1) {
347 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200348 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 return;
350 }
351 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200352 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200353 free(str);
354}
355
356static void
Radek Krejci693262f2019-04-29 15:23:20 +0200357ypr_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 +0200358{
359 char *str;
360
361 if (asprintf(&str, "%d", attr_value) == -1) {
362 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200363 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200364 return;
365 }
366 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200367 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200368 free(str);
369}
370
371static void
Radek Krejci693262f2019-04-29 15:23:20 +0200372yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373{
374 if (rev->dsc || rev->ref || rev->exts) {
375 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
376 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200377 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
378 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
379 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380 LEVEL--;
381 ly_print(ctx->out, "%*s}\n", INDENT);
382 } else {
383 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
384 }
385}
386
387static void
Radek Krejci693262f2019-04-29 15:23:20 +0200388ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200389{
390 if (flags & LYS_MAND_MASK) {
391 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200392 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393 }
394}
395
396static void
Radek Krejci693262f2019-04-29 15:23:20 +0200397ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398{
399 if (flags & LYS_CONFIG_MASK) {
400 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200401 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 }
403}
404
405static void
Radek Krejci693262f2019-04-29 15:23:20 +0200406ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407{
408 const char *status = NULL;
409
410 if (flags & LYS_STATUS_CURR) {
411 ypr_open(ctx->out, flag);
412 status = "current";
413 } else if (flags & LYS_STATUS_DEPRC) {
414 ypr_open(ctx->out, flag);
415 status = "deprecated";
416 } else if (flags & LYS_STATUS_OBSLT) {
417 ypr_open(ctx->out, flag);
418 status = "obsolete";
419 }
Radek Krejci693262f2019-04-29 15:23:20 +0200420
421 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422}
423
424static void
Radek Krejci693262f2019-04-29 15:23:20 +0200425ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200426{
427 if (dsc) {
428 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200429 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200430 }
431}
432
433static void
Radek Krejci693262f2019-04-29 15:23:20 +0200434ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200435{
436 if (ref) {
437 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200438 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200439 }
440}
441
442static void
Radek Krejci693262f2019-04-29 15:23:20 +0200443yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200444{
445 unsigned int u;
446 int extflag;
447
448 LY_ARRAY_FOR(iff, u) {
449 ypr_open(ctx->out, flag);
450 extflag = 0;
451
452 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
453
454 /* extensions */
455 LEVEL++;
456 LY_ARRAY_FOR(exts, u) {
457 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
458 continue;
459 }
Radek Krejci693262f2019-04-29 15:23:20 +0200460 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200461 }
462 LEVEL--;
463 ypr_close(ctx, extflag);
464 }
465}
466
467static void
Radek Krejci693262f2019-04-29 15:23:20 +0200468yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
469{
470 int brackets_flag = *index_e;
471 uint8_t op;
472
473 op = lysc_iff_getop(feat->expr, *index_e);
474 (*index_e)++;
475
476 switch (op) {
477 case LYS_IFF_F:
478 if (ctx->module == feat->features[*index_f]->module) {
479 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
480 } else {
481 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
482 }
483 (*index_f)++;
484 break;
485 case LYS_IFF_NOT:
486 ly_print(ctx->out, "not ");
487 yprc_iffeature(ctx, feat, index_e, index_f);
488 break;
489 case LYS_IFF_AND:
490 if (brackets_flag) {
491 /* AND need brackets only if previous op was not */
492 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
493 brackets_flag = 0;
494 }
495 }
496 /* falls through */
497 case LYS_IFF_OR:
498 if (brackets_flag) {
499 ly_print(ctx->out, "(");
500 }
501 yprc_iffeature(ctx, feat, index_e, index_f);
502 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
503 yprc_iffeature(ctx, feat, index_e, index_f);
504 if (brackets_flag) {
505 ly_print(ctx->out, ")");
506 }
507 }
508}
509
510static void
511yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
512{
Radek Krejci334ccc72019-06-12 13:49:29 +0200513 unsigned int u, v;
Radek Krejci693262f2019-04-29 15:23:20 +0200514 int extflag;
515
516 LY_ARRAY_FOR(iff, u) {
517 int index_e = 0, index_f = 0;
518
519 ypr_open(ctx->out, flag);
520 extflag = 0;
521
Radek Krejci989e53b2019-04-30 09:51:09 +0200522 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200523 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200524 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200525
526 /* extensions */
527 LEVEL++;
Radek Krejci334ccc72019-06-12 13:49:29 +0200528 LY_ARRAY_FOR(exts, v) {
529 if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200530 continue;
531 }
Radek Krejci334ccc72019-06-12 13:49:29 +0200532 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200533 }
534 LEVEL--;
535 ypr_close(ctx, extflag);
536 }
537}
538
539static void
540yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200541{
542 int flag = 0, flag2 = 0;
543 unsigned int i;
544
545 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
546 LEVEL++;
547
548 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200549 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200550 }
551
552 if (ext->argument) {
553 ypr_open(ctx->out, &flag);
554 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200555 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200556 if (ext->exts) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200557 i = -1;
558 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 +0200559 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200560 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200561 }
562 if ((ext->flags & LYS_YINELEM_MASK) ||
563 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
564 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200565 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200566 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200567 LEVEL--;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200568 ypr_close(ctx, flag2);
569 }
570
Radek Krejci693262f2019-04-29 15:23:20 +0200571 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200572 ypr_description(ctx, ext->dsc, ext->exts, &flag);
573 ypr_reference(ctx, ext->ref, ext->exts, &flag);
574
575 LEVEL--;
576 ypr_close(ctx, flag);
577}
578
579static void
Radek Krejci693262f2019-04-29 15:23:20 +0200580yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200581{
582 int flag = 0;
583
584 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
585 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200586 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
587 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
588 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200589 ypr_description(ctx, feat->dsc, feat->exts, &flag);
590 ypr_reference(ctx, feat->ref, feat->exts, &flag);
591 LEVEL--;
592 ypr_close(ctx, flag);
593}
594
595static void
Radek Krejci693262f2019-04-29 15:23:20 +0200596yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
597{
598 int flag = 0;
599
600 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
601 LEVEL++;
602 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
603 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
604 ypr_status(ctx, feat->flags, feat->exts, &flag);
605 ypr_description(ctx, feat->dsc, feat->exts, &flag);
606 ypr_reference(ctx, feat->ref, feat->exts, &flag);
607 LEVEL--;
608 ypr_close(ctx, flag);
609}
610
611static void
612yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200613{
614 int flag = 0;
615 unsigned int u;
616
617 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
618 LEVEL++;
619
Radek Krejci693262f2019-04-29 15:23:20 +0200620 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
621 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200622
623 LY_ARRAY_FOR(ident->bases, u) {
624 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200625 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200626 }
627
Radek Krejci693262f2019-04-29 15:23:20 +0200628 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200629 ypr_description(ctx, ident->dsc, ident->exts, &flag);
630 ypr_reference(ctx, ident->ref, ident->exts, &flag);
631
632 LEVEL--;
633 ypr_close(ctx, flag);
634}
635
636static void
Radek Krejci693262f2019-04-29 15:23:20 +0200637yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
638{
639 int flag = 0;
640 unsigned int u;
641
642 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
643 LEVEL++;
644
645 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
646 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
647
648 LY_ARRAY_FOR(ident->derived, u) {
649 ypr_open(ctx->out, &flag);
650 if (ctx->module != ident->derived[u]->module) {
651 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
652 } else {
653 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
654 }
655 }
656
657 ypr_status(ctx, ident->flags, ident->exts, &flag);
658 ypr_description(ctx, ident->dsc, ident->exts, &flag);
659 ypr_reference(ctx, ident->ref, ident->exts, &flag);
660
661 LEVEL--;
662 ypr_close(ctx, flag);
663}
664
665static void
666yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200667{
668 int inner_flag = 0;
669
670 if (!restr) {
671 return;
672 }
673
674 ypr_open(ctx->out, flag);
675 ly_print(ctx->out, "%*s%s \"", INDENT, name);
676 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
677 ly_print(ctx->out, "\"");
678
679 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200680 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200681 if (restr->arg[0] == 0x15) {
682 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
683 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200684 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200685 }
686 if (restr->emsg) {
687 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200688 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200689 }
690 if (restr->eapptag) {
691 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200692 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200693 }
Radek Krejci693262f2019-04-29 15:23:20 +0200694 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
695 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
696
Radek Krejcid3ca0632019-04-16 16:54:54 +0200697 LEVEL--;
698 ypr_close(ctx, inner_flag);
699}
700
701static void
Radek Krejci693262f2019-04-29 15:23:20 +0200702yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
703{
704 int inner_flag = 0;
705
706 ypr_open(ctx->out, flag);
707 ly_print(ctx->out, "%*smust \"", INDENT);
708 ypr_encode(ctx->out, must->cond->expr, -1);
709 ly_print(ctx->out, "\"");
710
711 LEVEL++;
712 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
713 if (must->emsg) {
714 ypr_open(ctx->out, &inner_flag);
715 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
716 }
717 if (must->eapptag) {
718 ypr_open(ctx->out, &inner_flag);
719 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
720 }
721 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
722 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
723
724 LEVEL--;
725 ypr_close(ctx, inner_flag);
726}
727
728static void
729yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
730{
731 int inner_flag = 0;
732 unsigned int u;
733
Radek Krejci334ccc72019-06-12 13:49:29 +0200734 if (!range) {
735 return;
736 }
737
Radek Krejci693262f2019-04-29 15:23:20 +0200738 ypr_open(ctx->out, flag);
Radek Krejci334ccc72019-06-12 13:49:29 +0200739 ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200740 LY_ARRAY_FOR(range->parts, u) {
741 if (u > 0) {
742 ly_print(ctx->out, " | ");
743 }
744 if (range->parts[u].max_64 == range->parts[u].min_64) {
745 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
746 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
747 } else { /* signed values */
748 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
749 }
750 } else {
751 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
752 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
753 } else { /* signed values */
754 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
755 }
756 }
757 }
758 ly_print(ctx->out, "\"");
759
760 LEVEL++;
761 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
762 if (range->emsg) {
763 ypr_open(ctx->out, &inner_flag);
764 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
765 }
766 if (range->eapptag) {
767 ypr_open(ctx->out, &inner_flag);
768 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
769 }
770 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
771 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
772
773 LEVEL--;
774 ypr_close(ctx, inner_flag);
775}
776
777static void
778yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
779{
780 int inner_flag = 0;
781
782 ypr_open(ctx->out, flag);
783 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200784 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200785 ly_print(ctx->out, "\"");
786
787 LEVEL++;
788 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
789 if (pattern->inverted) {
790 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
791 ypr_open(ctx->out, &inner_flag);
792 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
793 }
794 if (pattern->emsg) {
795 ypr_open(ctx->out, &inner_flag);
796 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
797 }
798 if (pattern->eapptag) {
799 ypr_open(ctx->out, &inner_flag);
800 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
801 }
802 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
803 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
804
805 LEVEL--;
806 ypr_close(ctx, inner_flag);
807}
808
809static void
810yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200811{
812 int inner_flag = 0;
813
814 if (!when) {
815 return;
816 }
817 ypr_open(ctx->out, flag);
818
819 ly_print(ctx->out, "%*swhen \"", INDENT);
820 ypr_encode(ctx->out, when->cond, -1);
821 ly_print(ctx->out, "\"");
822
823 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200824 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
826 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
827 LEVEL--;
828 ypr_close(ctx, inner_flag);
829}
830
831static void
Radek Krejci693262f2019-04-29 15:23:20 +0200832yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
833{
834 int inner_flag = 0;
835
836 if (!when) {
837 return;
838 }
839 ypr_open(ctx->out, flag);
840
841 ly_print(ctx->out, "%*swhen \"", INDENT);
842 ypr_encode(ctx->out, when->cond->expr, -1);
843 ly_print(ctx->out, "\"");
844
845 LEVEL++;
846 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
847 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
848 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
849 LEVEL--;
850 ypr_close(ctx, inner_flag);
851}
852
853static void
854yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200855{
856 unsigned int u;
857 int inner_flag;
858
859 LY_ARRAY_FOR(items, u) {
860 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200861 if (type == LY_TYPE_BITS) {
862 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
863 } else { /* LY_TYPE_ENUM */
864 ly_print(ctx->out, "%*senum \"", INDENT);
865 ypr_encode(ctx->out, items[u].name, -1);
866 ly_print(ctx->out, "\"");
867 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200868 inner_flag = 0;
869 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200870 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
871 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200872 if (items[u].flags & LYS_SET_VALUE) {
873 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200874 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200876 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200877 }
878 }
Radek Krejci693262f2019-04-29 15:23:20 +0200879 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200880 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
881 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
882 LEVEL--;
883 ypr_close(ctx, inner_flag);
884 }
885}
886
887static void
Radek Krejci693262f2019-04-29 15:23:20 +0200888yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200889{
890 unsigned int u;
891 int flag = 0;
892
893 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
894 LEVEL++;
895
Radek Krejci693262f2019-04-29 15:23:20 +0200896 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200897
Radek Krejci693262f2019-04-29 15:23:20 +0200898 yprp_restr(ctx, type->range, "range", &flag);
899 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200900 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200901 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200902 }
Radek Krejci693262f2019-04-29 15:23:20 +0200903 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
904 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200905
906 if (type->path) {
907 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200908 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200909 }
910 if (type->flags & LYS_SET_REQINST) {
911 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200912 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200913 }
914 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200915 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200916 }
917 LY_ARRAY_FOR(type->bases, u) {
918 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200919 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200920 }
921 LY_ARRAY_FOR(type->types, u) {
922 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200923 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200924 }
925
926 LEVEL--;
927 ypr_close(ctx, flag);
928}
929
930static void
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200931yprc_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 +0200932{
933 int dynamic;
934 const char *str;
935
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200936 str = value->realtype->plugin->print(value, LYD_JSON, lys_get_prefix, (void*)value_mod, &dynamic);
Radek Krejcia1911222019-07-22 17:24:50 +0200937 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, str, exts);
938 if (dynamic) {
939 free((void*)str);
940 }
941}
942
943static void
Radek Krejci693262f2019-04-29 15:23:20 +0200944yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
945{
946 unsigned int u;
947 int flag = 0;
948
949 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
950 LEVEL++;
951
952 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
953 if (type->dflt) {
954 ypr_open(ctx->out, &flag);
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200955 yprc_dflt_value(ctx, type->dflt, type->dflt_mod, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200956 }
957
958 switch(type->basetype) {
959 case LY_TYPE_BINARY: {
960 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
961 yprc_range(ctx, bin->length, type->basetype, &flag);
962 break;
963 }
964 case LY_TYPE_UINT8:
965 case LY_TYPE_UINT16:
966 case LY_TYPE_UINT32:
967 case LY_TYPE_UINT64:
968 case LY_TYPE_INT8:
969 case LY_TYPE_INT16:
970 case LY_TYPE_INT32:
971 case LY_TYPE_INT64: {
972 struct lysc_type_num *num = (struct lysc_type_num*)type;
973 yprc_range(ctx, num->range, type->basetype, &flag);
974 break;
975 }
976 case LY_TYPE_STRING: {
977 struct lysc_type_str *str = (struct lysc_type_str*)type;
978 yprc_range(ctx, str->length, type->basetype, &flag);
979 LY_ARRAY_FOR(str->patterns, u) {
980 yprc_pattern(ctx, str->patterns[u], &flag);
981 }
982 break;
983 }
984 case LY_TYPE_BITS:
985 case LY_TYPE_ENUM: {
986 /* bits and enums structures are compatible */
987 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
988 LY_ARRAY_FOR(bits->bits, u) {
989 struct lysc_type_bitenum_item *item = &bits->bits[u];
990 int inner_flag = 0;
991
992 ypr_open(ctx->out, &flag);
993 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
994 ypr_encode(ctx->out, item->name, -1);
995 ly_print(ctx->out, "\"");
996 LEVEL++;
997 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
998 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
999 if (type->basetype == LY_TYPE_BITS) {
1000 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
1001 } else { /* LY_TYPE_ENUM */
1002 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
1003 }
1004 ypr_status(ctx, item->flags, item->exts, &inner_flag);
1005 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
1006 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
1007 LEVEL--;
1008 ypr_close(ctx, inner_flag);
1009 }
1010 break;
1011 }
1012 case LY_TYPE_BOOL:
1013 case LY_TYPE_EMPTY:
1014 /* nothing to do */
1015 break;
1016 case LY_TYPE_DEC64: {
1017 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
1018 ypr_open(ctx->out, &flag);
1019 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
1020 yprc_range(ctx, dec->range, dec->basetype, &flag);
1021 break;
1022 }
1023 case LY_TYPE_IDENT: {
1024 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
1025 LY_ARRAY_FOR(ident->bases, u) {
1026 ypr_open(ctx->out, &flag);
1027 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
1028 }
1029 break;
1030 }
1031 case LY_TYPE_INST: {
1032 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
1033 ypr_open(ctx->out, &flag);
1034 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
1035 break;
1036 }
1037 case LY_TYPE_LEAFREF: {
1038 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
1039 ypr_open(ctx->out, &flag);
1040 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
1041 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
1042 yprc_type(ctx, lr->realtype);
1043 break;
1044 }
1045 case LY_TYPE_UNION: {
1046 struct lysc_type_union *un = (struct lysc_type_union*)type;
1047 LY_ARRAY_FOR(un->types, u) {
1048 ypr_open(ctx->out, &flag);
1049 yprc_type(ctx, un->types[u]);
1050 }
1051 break;
1052 }
1053 default:
1054 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001055 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001056 }
1057
1058 LEVEL--;
1059 ypr_close(ctx, flag);
1060}
1061
1062static void
1063yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001064{
Radek Krejci56cc0872019-04-30 09:22:27 +02001065 LYOUT_CHECK(ctx->out);
1066
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1068 LEVEL++;
1069
Radek Krejci693262f2019-04-29 15:23:20 +02001070 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001071
Radek Krejci693262f2019-04-29 15:23:20 +02001072 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073
1074 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001075 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076 }
1077 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001078 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001079 }
1080
Radek Krejci693262f2019-04-29 15:23:20 +02001081 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1083 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1084
1085 LEVEL--;
1086 ly_print(ctx->out, "%*s}\n", INDENT);
1087}
1088
Radek Krejci693262f2019-04-29 15:23:20 +02001089static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1090static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1091static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001092
1093static void
Radek Krejci693262f2019-04-29 15:23:20 +02001094yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001095{
1096 unsigned int u;
1097 int flag = 0;
1098 struct lysp_node *data;
1099
Radek Krejci56cc0872019-04-30 09:22:27 +02001100 LYOUT_CHECK(ctx->out);
1101
Radek Krejcid3ca0632019-04-16 16:54:54 +02001102 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1103 LEVEL++;
1104
Radek Krejci693262f2019-04-29 15:23:20 +02001105 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1106 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001107 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1108 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001109
1110 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001111 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001112 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001113 }
1114
1115 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001116 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001117 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001118 }
1119
1120 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001121 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001122 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001123 }
1124
1125 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001126 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001127 }
1128
1129 LEVEL--;
1130 ypr_close(ctx, flag);
1131}
1132
1133static void
Radek Krejci693262f2019-04-29 15:23:20 +02001134yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001135{
1136 unsigned int u;
1137 struct lysp_node *data;
1138
1139 if (!inout->nodetype) {
1140 /* nodetype not set -> input/output is empty */
1141 return;
1142 }
1143 ypr_open(ctx->out, flag);
1144
1145 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1146 LEVEL++;
1147
Radek Krejci693262f2019-04-29 15:23:20 +02001148 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001149 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001150 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001151 }
1152 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001153 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154 }
1155 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001156 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001157 }
1158
1159 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001160 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161 }
1162
1163 LEVEL--;
1164 ypr_close(ctx, 1);
1165}
1166
1167static void
Radek Krejci693262f2019-04-29 15:23:20 +02001168yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1169{
1170 unsigned int u;
1171 struct lysc_node *data;
1172
1173 if (!inout->data) {
1174 /* input/output is empty */
1175 return;
1176 }
1177 ypr_open(ctx->out, flag);
1178
1179 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1180 LEVEL++;
1181
1182 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1183 LY_ARRAY_FOR(inout->musts, u) {
1184 yprc_must(ctx, &inout->musts[u], NULL);
1185 }
1186
1187 LY_LIST_FOR(inout->data, data) {
1188 yprc_node(ctx, data);
1189 }
1190
1191 LEVEL--;
1192 ypr_close(ctx, 1);
1193}
1194
1195static void
1196yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001197{
1198 unsigned int u;
1199 int flag = 0;
1200 struct lysp_node *data;
1201
Radek Krejci56cc0872019-04-30 09:22:27 +02001202 LYOUT_CHECK(ctx->out);
1203
Radek Krejcid3ca0632019-04-16 16:54:54 +02001204 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1205
1206 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001207 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1208 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001209
1210 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001211 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001212 }
Radek Krejci693262f2019-04-29 15:23:20 +02001213 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001214 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1215 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1216
1217 LY_ARRAY_FOR(notif->typedefs, u) {
1218 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001219 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001220 }
1221
1222 LY_ARRAY_FOR(notif->groupings, u) {
1223 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001224 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001225 }
1226
1227 LY_LIST_FOR(notif->data, data) {
1228 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001229 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230 }
1231
1232 LEVEL--;
1233 ypr_close(ctx, flag);
1234}
1235
1236static void
Radek Krejci693262f2019-04-29 15:23:20 +02001237yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1238{
1239 unsigned int u;
1240 int flag = 0;
1241 struct lysc_node *data;
1242
Radek Krejci56cc0872019-04-30 09:22:27 +02001243 LYOUT_CHECK(ctx->out);
1244
Radek Krejci693262f2019-04-29 15:23:20 +02001245 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1246
1247 LEVEL++;
1248 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1249 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1250
1251 LY_ARRAY_FOR(notif->musts, u) {
1252 yprc_must(ctx, &notif->musts[u], &flag);
1253 }
1254 ypr_status(ctx, notif->flags, notif->exts, &flag);
1255 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1256 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1257
1258 LY_LIST_FOR(notif->data, data) {
1259 ypr_open(ctx->out, &flag);
1260 yprc_node(ctx, data);
1261 }
1262
1263 LEVEL--;
1264 ypr_close(ctx, flag);
1265}
1266
1267static void
1268yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001269{
1270 unsigned int u;
1271 int flag = 0;
1272
Radek Krejci56cc0872019-04-30 09:22:27 +02001273 LYOUT_CHECK(ctx->out);
1274
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1276
1277 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001278 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1279 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1280 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281 ypr_description(ctx, action->dsc, action->exts, &flag);
1282 ypr_reference(ctx, action->ref, action->exts, &flag);
1283
1284 LY_ARRAY_FOR(action->typedefs, u) {
1285 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001286 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001287 }
1288
1289 LY_ARRAY_FOR(action->groupings, u) {
1290 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001291 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292 }
1293
Radek Krejci693262f2019-04-29 15:23:20 +02001294 yprp_inout(ctx, &action->input, &flag);
1295 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001296
1297 LEVEL--;
1298 ypr_close(ctx, flag);
1299}
1300
1301static void
Radek Krejci693262f2019-04-29 15:23:20 +02001302yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1303{
1304 int flag = 0;
1305
Radek Krejci56cc0872019-04-30 09:22:27 +02001306 LYOUT_CHECK(ctx->out);
1307
Radek Krejci693262f2019-04-29 15:23:20 +02001308 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1309
1310 LEVEL++;
1311 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1312 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1313 ypr_status(ctx, action->flags, action->exts, &flag);
1314 ypr_description(ctx, action->dsc, action->exts, &flag);
1315 ypr_reference(ctx, action->ref, action->exts, &flag);
1316
1317 yprc_inout(ctx, action, &action->input, &flag);
1318 yprc_inout(ctx, action, &action->output, &flag);
1319
1320 LEVEL--;
1321 ypr_close(ctx, flag);
1322}
1323
1324static void
1325yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001326{
Radek Krejci7871ce52019-06-11 16:44:56 +02001327 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001328 LEVEL++;
1329
Radek Krejci693262f2019-04-29 15:23:20 +02001330 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1331 yprp_when(ctx, node->when, flag);
1332 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001333}
1334
1335static void
Radek Krejci693262f2019-04-29 15:23:20 +02001336yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001337{
Radek Krejci693262f2019-04-29 15:23:20 +02001338 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339
Radek Krejci42903ea2019-06-14 16:24:56 +02001340 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001341 LEVEL++;
1342
1343 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1344 LY_ARRAY_FOR(node->when, u) {
1345 yprc_when(ctx, node->when[u], flag);
1346 }
1347 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1348}
1349
1350/* macr oto unify the code */
1351#define YPR_NODE_COMMON2 \
1352 ypr_config(ctx, node->flags, node->exts, flag); \
1353 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1354 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1355 } \
1356 ypr_status(ctx, node->flags, node->exts, flag); \
1357 ypr_description(ctx, node->dsc, node->exts, flag); \
1358 ypr_reference(ctx, node->ref, node->exts, flag)
1359
1360static void
1361yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1362{
1363 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001364}
1365
1366static void
Radek Krejci693262f2019-04-29 15:23:20 +02001367yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1368{
1369 YPR_NODE_COMMON2;
1370}
1371
1372#undef YPR_NODE_COMMON2
1373
1374static void
1375yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001376{
1377 unsigned int u;
1378 int flag = 0;
1379 struct lysp_node *child;
1380 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1381
Radek Krejci693262f2019-04-29 15:23:20 +02001382 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001383
1384 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001385 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001386 }
1387 if (cont->presence) {
1388 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001389 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001390 }
1391
Radek Krejci693262f2019-04-29 15:23:20 +02001392 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001393
1394 LY_ARRAY_FOR(cont->typedefs, u) {
1395 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001396 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001397 }
1398
1399 LY_ARRAY_FOR(cont->groupings, u) {
1400 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001401 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001402 }
1403
1404 LY_LIST_FOR(cont->child, child) {
1405 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001406 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001407 }
1408
1409 LY_ARRAY_FOR(cont->actions, u) {
1410 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001411 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001412 }
1413
1414 LY_ARRAY_FOR(cont->notifs, u) {
1415 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001416 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001417 }
1418
1419 LEVEL--;
1420 ypr_close(ctx, flag);
1421}
1422
1423static void
Radek Krejci693262f2019-04-29 15:23:20 +02001424yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1425{
1426 unsigned int u;
1427 int flag = 0;
1428 struct lysc_node *child;
1429 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1430
1431 yprc_node_common1(ctx, node, &flag);
1432
1433 LY_ARRAY_FOR(cont->musts, u) {
1434 yprc_must(ctx, &cont->musts[u], &flag);
1435 }
1436 if (cont->flags & LYS_PRESENCE) {
1437 ypr_open(ctx->out, &flag);
1438 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1439 }
1440
1441 yprc_node_common2(ctx, node, &flag);
1442
1443 LY_LIST_FOR(cont->child, child) {
1444 ypr_open(ctx->out, &flag);
1445 yprc_node(ctx, child);
1446 }
1447
1448 LY_ARRAY_FOR(cont->actions, u) {
1449 ypr_open(ctx->out, &flag);
1450 yprc_action(ctx, &cont->actions[u]);
1451 }
1452
1453 LY_ARRAY_FOR(cont->notifs, u) {
1454 ypr_open(ctx->out, &flag);
1455 yprc_notification(ctx, &cont->notifs[u]);
1456 }
1457
1458 LEVEL--;
1459 ypr_close(ctx, flag);
1460}
1461
1462static void
1463yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1464{
1465 int flag = 0;
1466 struct lysp_node *child;
1467 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1468
1469 yprp_node_common1(ctx, node, &flag);
1470 yprp_node_common2(ctx, node, &flag);
1471
1472 LY_LIST_FOR(cas->child, child) {
1473 ypr_open(ctx->out, &flag);
1474 yprp_node(ctx, child);
1475 }
1476
1477 LEVEL--;
1478 ypr_close(ctx, flag);
1479}
1480
1481static void
1482yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1483{
1484 int flag = 0;
1485 struct lysc_node *child;
1486
1487 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1488 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1489
1490 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1491 ypr_open(ctx->out, &flag);
1492 yprc_node(ctx, child);
1493 }
1494
1495 LEVEL--;
1496 ypr_close(ctx, flag);
1497}
1498
1499static void
1500yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001501{
1502 int flag = 0;
1503 struct lysp_node *child;
1504 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1505
Radek Krejci693262f2019-04-29 15:23:20 +02001506 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001507
1508 if (choice->dflt) {
1509 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001510 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511 }
1512
Radek Krejci693262f2019-04-29 15:23:20 +02001513 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514
1515 LY_LIST_FOR(choice->child, child) {
1516 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001517 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518 }
1519
1520 LEVEL--;
1521 ypr_close(ctx, flag);
1522}
1523
1524static void
Radek Krejci693262f2019-04-29 15:23:20 +02001525yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1526{
1527 int flag = 0;
1528 struct lysc_node_case *cs;
1529 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1530
1531 yprc_node_common1(ctx, node, &flag);
1532
1533 if (choice->dflt) {
1534 ypr_open(ctx->out, &flag);
1535 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1536 }
1537
1538 yprc_node_common2(ctx, node, &flag);
1539
1540 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1541 ypr_open(ctx->out, &flag);
1542 yprc_case(ctx, cs);
1543 }
1544
1545 LEVEL--;
1546 ypr_close(ctx, flag);
1547}
1548
1549static void
1550yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001551{
1552 unsigned int u;
1553 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1554
Radek Krejci693262f2019-04-29 15:23:20 +02001555 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556
Radek Krejci693262f2019-04-29 15:23:20 +02001557 yprp_type(ctx, &leaf->type);
1558 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001559 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001560 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561 }
Radek Krejci693262f2019-04-29 15:23:20 +02001562 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001563
Radek Krejci693262f2019-04-29 15:23:20 +02001564 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565
1566 LEVEL--;
1567 ly_print(ctx->out, "%*s}\n", INDENT);
1568}
1569
1570static void
Radek Krejci693262f2019-04-29 15:23:20 +02001571yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1572{
1573 unsigned int u;
1574 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1575
1576 yprc_node_common1(ctx, node, NULL);
1577
1578 yprc_type(ctx, leaf->type);
1579 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1580 LY_ARRAY_FOR(leaf->musts, u) {
1581 yprc_must(ctx, &leaf->musts[u], NULL);
1582 }
Radek Krejcia1911222019-07-22 17:24:50 +02001583
1584 if (leaf->dflt) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001585 yprc_dflt_value(ctx, leaf->dflt, leaf->dflt_mod, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001586 }
Radek Krejci693262f2019-04-29 15:23:20 +02001587
1588 yprc_node_common2(ctx, node, NULL);
1589
1590 LEVEL--;
1591 ly_print(ctx->out, "%*s}\n", INDENT);
1592}
1593
1594static void
1595yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001596{
1597 unsigned int u;
1598 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1599
Radek Krejci693262f2019-04-29 15:23:20 +02001600 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001601
Radek Krejci693262f2019-04-29 15:23:20 +02001602 yprp_type(ctx, &llist->type);
1603 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001604 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001605 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001606 }
1607 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001608 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001609 }
1610
Radek Krejci693262f2019-04-29 15:23:20 +02001611 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001612
1613 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001614 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001615 }
1616 if (llist->flags & LYS_SET_MAX) {
1617 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001618 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001619 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001620 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001621 }
1622 }
1623
1624 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001625 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001626 }
1627
Radek Krejci693262f2019-04-29 15:23:20 +02001628 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001629 ypr_description(ctx, node->dsc, node->exts, NULL);
1630 ypr_reference(ctx, node->ref, node->exts, NULL);
1631
1632 LEVEL--;
1633 ly_print(ctx->out, "%*s}\n", INDENT);
1634}
1635
1636static void
Radek Krejci693262f2019-04-29 15:23:20 +02001637yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1638{
1639 unsigned int u;
1640 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1641
1642 yprc_node_common1(ctx, node, NULL);
1643
1644 yprc_type(ctx, llist->type);
1645 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1646 LY_ARRAY_FOR(llist->musts, u) {
1647 yprc_must(ctx, &llist->musts[u], NULL);
1648 }
1649 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001650 yprc_dflt_value(ctx, llist->dflts[u], llist->dflts_mods[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001651 }
1652
1653 ypr_config(ctx, node->flags, node->exts, NULL);
1654
1655 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1656 if (llist->max) {
1657 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1658 } else {
1659 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1660 }
1661
1662 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1663
1664 ypr_status(ctx, node->flags, node->exts, NULL);
1665 ypr_description(ctx, node->dsc, node->exts, NULL);
1666 ypr_reference(ctx, node->ref, node->exts, NULL);
1667
1668 LEVEL--;
1669 ly_print(ctx->out, "%*s}\n", INDENT);
1670}
1671
1672static void
1673yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001674{
1675 unsigned int u;
1676 int flag = 0;
1677 struct lysp_node *child;
1678 struct lysp_node_list *list = (struct lysp_node_list *)node;
1679
Radek Krejci693262f2019-04-29 15:23:20 +02001680 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001681
1682 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001683 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001684 }
1685 if (list->key) {
1686 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001687 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001688 }
1689 LY_ARRAY_FOR(list->uniques, u) {
1690 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001691 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001692 }
1693
Radek Krejci693262f2019-04-29 15:23:20 +02001694 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001695
1696 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001697 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001698 }
1699 if (list->flags & LYS_SET_MAX) {
1700 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001701 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001702 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001703 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001704 }
1705 }
1706
1707 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001708 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001709 }
1710
Radek Krejci693262f2019-04-29 15:23:20 +02001711 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001712 ypr_description(ctx, node->dsc, node->exts, NULL);
1713 ypr_reference(ctx, node->ref, node->exts, NULL);
1714
1715 LY_ARRAY_FOR(list->typedefs, u) {
1716 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001717 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001718 }
1719
1720 LY_ARRAY_FOR(list->groupings, u) {
1721 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001722 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001723 }
1724
1725 LY_LIST_FOR(list->child, child) {
1726 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001727 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001728 }
1729
1730 LY_ARRAY_FOR(list->actions, u) {
1731 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001732 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001733 }
1734
1735 LY_ARRAY_FOR(list->notifs, u) {
1736 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001737 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001738 }
1739
1740 LEVEL--;
1741 ypr_close(ctx, flag);
1742}
1743
1744static void
Radek Krejci693262f2019-04-29 15:23:20 +02001745yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1746{
1747 unsigned int u, v;
1748 int flag = 0;
1749 struct lysc_node *child;
1750 struct lysc_node_list *list = (struct lysc_node_list *)node;
1751
1752 yprc_node_common1(ctx, node, &flag);
1753
1754 LY_ARRAY_FOR(list->musts, u) {
1755 yprc_must(ctx, &list->musts[u], NULL);
1756 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001757 if (!(list->flags & LYS_KEYLESS)) {
Radek Krejci693262f2019-04-29 15:23:20 +02001758 ypr_open(ctx->out, &flag);
1759 ly_print(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001760 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
1761 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001762 }
Radek Krejci73c88f52019-06-14 16:24:19 +02001763 ly_print(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001764 }
1765 LY_ARRAY_FOR(list->uniques, u) {
1766 ypr_open(ctx->out, &flag);
1767 ly_print(ctx->out, "%*sunique \"", INDENT);
1768 LY_ARRAY_FOR(list->uniques[u], v) {
1769 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1770 }
1771 ypr_close(ctx, 0);
1772 }
1773
1774 ypr_config(ctx, node->flags, node->exts, NULL);
1775
1776 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1777 if (list->max) {
1778 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1779 } else {
1780 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1781 }
1782
1783 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1784
1785 ypr_status(ctx, node->flags, node->exts, NULL);
1786 ypr_description(ctx, node->dsc, node->exts, NULL);
1787 ypr_reference(ctx, node->ref, node->exts, NULL);
1788
1789 LY_LIST_FOR(list->child, child) {
1790 ypr_open(ctx->out, &flag);
1791 yprc_node(ctx, child);
1792 }
1793
1794 LY_ARRAY_FOR(list->actions, u) {
1795 ypr_open(ctx->out, &flag);
1796 yprc_action(ctx, &list->actions[u]);
1797 }
1798
1799 LY_ARRAY_FOR(list->notifs, u) {
1800 ypr_open(ctx->out, &flag);
1801 yprc_notification(ctx, &list->notifs[u]);
1802 }
1803
1804 LEVEL--;
1805 ypr_close(ctx, flag);
1806}
1807
1808static void
1809yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810{
1811 unsigned int u;
1812 int flag = 0;
1813
1814 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1815 LEVEL++;
1816
Radek Krejci693262f2019-04-29 15:23:20 +02001817 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1818 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819
1820 LY_ARRAY_FOR(refine->musts, u) {
1821 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001822 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823 }
1824
1825 if (refine->presence) {
1826 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001827 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828 }
1829
1830 LY_ARRAY_FOR(refine->dflts, u) {
1831 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001832 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001833 }
1834
Radek Krejci693262f2019-04-29 15:23:20 +02001835 ypr_config(ctx, refine->flags, refine->exts, &flag);
1836 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837
1838 if (refine->flags & LYS_SET_MIN) {
1839 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001840 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 }
1842 if (refine->flags & LYS_SET_MAX) {
1843 ypr_open(ctx->out, &flag);
1844 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001845 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001846 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001847 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001848 }
1849 }
1850
1851 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1852 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1853
1854 LEVEL--;
1855 ypr_close(ctx, flag);
1856}
1857
1858static void
Radek Krejci693262f2019-04-29 15:23:20 +02001859yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860{
1861 unsigned int u;
1862 struct lysp_node *child;
1863
1864 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1865 LEVEL++;
1866
Radek Krejci693262f2019-04-29 15:23:20 +02001867 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1868 yprp_when(ctx, aug->when, NULL);
1869 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1870 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001871 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1872 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1873
1874 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001875 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001876 }
1877
1878 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001879 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880 }
1881
1882 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001883 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 }
1885
1886 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001887 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001888}
1889
1890
1891static void
Radek Krejci693262f2019-04-29 15:23:20 +02001892yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893{
1894 unsigned int u;
1895 int flag = 0;
1896 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1897
Radek Krejci693262f2019-04-29 15:23:20 +02001898 yprp_node_common1(ctx, node, &flag);
1899 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001900
1901 LY_ARRAY_FOR(uses->refines, u) {
1902 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001903 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904 }
1905
1906 LY_ARRAY_FOR(uses->augments, u) {
1907 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001908 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909 }
1910
1911 LEVEL--;
1912 ypr_close(ctx, flag);
1913}
1914
1915static void
Radek Krejci693262f2019-04-29 15:23:20 +02001916yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917{
1918 unsigned int u;
1919 int flag = 0;
1920 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1921
Radek Krejci693262f2019-04-29 15:23:20 +02001922 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923
1924 LY_ARRAY_FOR(any->musts, u) {
1925 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001926 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001927 }
1928
Radek Krejci693262f2019-04-29 15:23:20 +02001929 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001930
1931 LEVEL--;
1932 ypr_close(ctx, flag);
1933}
1934
1935static void
Radek Krejci693262f2019-04-29 15:23:20 +02001936yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937{
Radek Krejci693262f2019-04-29 15:23:20 +02001938 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001940 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001941
Radek Krejci693262f2019-04-29 15:23:20 +02001942 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001943
Radek Krejci693262f2019-04-29 15:23:20 +02001944 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001946 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001947 }
1948
Radek Krejci693262f2019-04-29 15:23:20 +02001949 yprc_node_common2(ctx, node, &flag);
1950
Radek Krejcid3ca0632019-04-16 16:54:54 +02001951 LEVEL--;
1952 ypr_close(ctx, flag);
1953}
1954
1955static void
Radek Krejci693262f2019-04-29 15:23:20 +02001956yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001957{
Radek Krejci56cc0872019-04-30 09:22:27 +02001958 LYOUT_CHECK(ctx->out);
1959
Radek Krejcid3ca0632019-04-16 16:54:54 +02001960 switch (node->nodetype) {
1961 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001962 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 break;
1964 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001965 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001966 break;
1967 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001968 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001969 break;
1970 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001971 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001972 break;
1973 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001974 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001975 break;
1976 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001977 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001978 break;
1979 case LYS_ANYXML:
1980 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001981 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982 break;
1983 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001984 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 break;
1986 default:
1987 break;
1988 }
1989}
1990
1991static void
Radek Krejci693262f2019-04-29 15:23:20 +02001992yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1993{
Radek Krejci56cc0872019-04-30 09:22:27 +02001994 LYOUT_CHECK(ctx->out);
1995
Radek Krejci693262f2019-04-29 15:23:20 +02001996 switch (node->nodetype) {
1997 case LYS_CONTAINER:
1998 yprc_container(ctx, node);
1999 break;
2000 case LYS_CHOICE:
2001 yprc_choice(ctx, node);
2002 break;
2003 case LYS_LEAF:
2004 yprc_leaf(ctx, node);
2005 break;
2006 case LYS_LEAFLIST:
2007 yprc_leaflist(ctx, node);
2008 break;
2009 case LYS_LIST:
2010 yprc_list(ctx, node);
2011 break;
2012 case LYS_ANYXML:
2013 case LYS_ANYDATA:
2014 yprc_anydata(ctx, node);
2015 break;
2016 default:
2017 break;
2018 }
2019}
2020
2021static void
2022yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023{
2024 unsigned int u, v;
2025 struct lysp_deviate_add *add;
2026 struct lysp_deviate_rpl *rpl;
2027 struct lysp_deviate_del *del;
2028
2029 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
2030 LEVEL++;
2031
Radek Krejci693262f2019-04-29 15:23:20 +02002032 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
2034 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
2035
2036 LY_ARRAY_FOR(deviation->deviates, u) {
2037 ly_print(ctx->out, "%*sdeviate ", INDENT);
2038 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
2039 if (deviation->deviates[u].exts) {
2040 ly_print(ctx->out, "not-supported {\n");
2041 LEVEL++;
2042
Radek Krejci693262f2019-04-29 15:23:20 +02002043 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002044 } else {
2045 ly_print(ctx->out, "not-supported;\n");
2046 continue;
2047 }
2048 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
2049 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2050 ly_print(ctx->out, "add {\n");
2051 LEVEL++;
2052
Radek Krejci693262f2019-04-29 15:23:20 +02002053 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2054 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002056 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 }
2058 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002059 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060 }
2061 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002062 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 }
Radek Krejci693262f2019-04-29 15:23:20 +02002064 ypr_config(ctx, add->flags, add->exts, NULL);
2065 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002066 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002067 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
2069 if (add->flags & LYS_SET_MAX) {
2070 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002071 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002072 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002073 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002074 }
2075 }
2076 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2077 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2078 ly_print(ctx->out, "replace {\n");
2079 LEVEL++;
2080
Radek Krejci693262f2019-04-29 15:23:20 +02002081 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002082 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002083 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084 }
Radek Krejci693262f2019-04-29 15:23:20 +02002085 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2086 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2087 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2088 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002089 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002090 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 }
2092 if (rpl->flags & LYS_SET_MAX) {
2093 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002094 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002095 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002096 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002097 }
2098 }
2099 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2100 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2101 ly_print(ctx->out, "delete {\n");
2102 LEVEL++;
2103
Radek Krejci693262f2019-04-29 15:23:20 +02002104 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2105 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002106 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002107 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002108 }
2109 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002110 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111 }
2112 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002113 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002114 }
2115 }
2116
2117 LEVEL--;
2118 ypr_close(ctx, 1);
2119 }
2120
2121 LEVEL--;
2122 ypr_close(ctx, 1);
2123}
2124
Radek Krejci693262f2019-04-29 15:23:20 +02002125/**
2126 * @brief Minimal print of a schema.
2127 *
2128 * To print
2129 * a) compiled schema when it is not compiled or
2130 * b) parsed when the parsed form was already removed
2131 */
2132static LY_ERR
2133ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2134{
2135 /* module-header-stmts */
2136 if (module->version) {
2137 if (module->version) {
2138 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2139 }
2140 }
2141 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2142 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2143
2144 /* meta-stmts */
2145 if (module->org || module->contact || module->dsc || module->ref) {
2146 ly_print(ctx->out, "\n");
2147 }
2148 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2149 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2150 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2151 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2152
2153 /* revision-stmts */
2154 if (module->revision) {
2155 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2156 }
2157
2158 LEVEL--;
2159 ly_print(ctx->out, "%*s}\n", INDENT);
2160 ly_print_flush(ctx->out);
2161
2162 return LY_SUCCESS;
2163}
2164
Radek Krejcid3ca0632019-04-16 16:54:54 +02002165LY_ERR
2166yang_print_parsed(struct lyout *out, const struct lys_module *module)
2167{
2168 unsigned int u;
2169 struct lysp_node *data;
2170 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002171 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172
2173 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2174 LEVEL++;
2175
Radek Krejci693262f2019-04-29 15:23:20 +02002176 if (!modp) {
2177 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2178 return ypr_missing_format(ctx, module);
2179 }
2180
Radek Krejcid3ca0632019-04-16 16:54:54 +02002181 /* module-header-stmts */
2182 if (module->version) {
2183 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002184 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 +02002185 }
2186 }
Radek Krejci693262f2019-04-29 15:23:20 +02002187 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2188 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002189
2190 /* linkage-stmts */
2191 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002192 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002193 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002194 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2195 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002196 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002197 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002198 }
Radek Krejci693262f2019-04-29 15:23:20 +02002199 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2200 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002201 LEVEL--;
2202 ly_print(out, "%*s}\n", INDENT);
2203 }
2204 LY_ARRAY_FOR(modp->includes, u) {
2205 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 +02002206 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002208 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002209 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002210 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002211 }
Radek Krejci693262f2019-04-29 15:23:20 +02002212 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2213 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002214 LEVEL--;
2215 ly_print(out, "%*s}\n", INDENT);
2216 } else {
2217 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2218 }
2219 }
2220
2221 /* meta-stmts */
2222 if (module->org || module->contact || module->dsc || module->ref) {
2223 ly_print(out, "\n");
2224 }
Radek Krejci693262f2019-04-29 15:23:20 +02002225 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2226 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2227 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2228 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002229
2230 /* revision-stmts */
2231 if (modp->revs) {
2232 ly_print(out, "\n");
2233 }
2234 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002235 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002236 }
2237 /* body-stmts */
2238 LY_ARRAY_FOR(modp->extensions, u) {
2239 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002240 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002241 }
2242 if (modp->exts) {
2243 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002244 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002245 }
2246
2247 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002248 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002249 }
2250
2251 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002252 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002253 }
2254
2255 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002256 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002257 }
2258
2259 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002260 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002261 }
2262
2263 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002264 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002265 }
2266
2267 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002268 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002269 }
2270
2271 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002272 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002273 }
2274
2275 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002276 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002277 }
2278
2279 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002280 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002281 }
2282
2283 LEVEL--;
2284 ly_print(out, "%*s}\n", INDENT);
2285 ly_print_flush(out);
2286
2287 return LY_SUCCESS;
2288}
2289
2290LY_ERR
2291yang_print_compiled(struct lyout *out, const struct lys_module *module)
2292{
Radek Krejci693262f2019-04-29 15:23:20 +02002293 unsigned int u;
2294 struct lysc_node *data;
2295 struct lysc_module *modc = module->compiled;
2296 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2297
2298 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2299 LEVEL++;
2300
2301 if (!modc) {
2302 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2303 return ypr_missing_format(ctx, module);
2304 }
2305
2306 /* module-header-stmts */
2307 if (module->version) {
2308 if (module->version) {
2309 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2310 }
2311 }
2312 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2313 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2314
2315 /* linkage-stmts */
2316 LY_ARRAY_FOR(modc->imports, u) {
2317 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2318 LEVEL++;
2319 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2320 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2321 if (modc->imports[u].module->revision) {
2322 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2323 }
2324 LEVEL--;
2325 ly_print(out, "%*s}\n", INDENT);
2326 }
2327
2328 /* meta-stmts */
2329 if (module->org || module->contact || module->dsc || module->ref) {
2330 ly_print(out, "\n");
2331 }
2332 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2333 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2334 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2335 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2336
2337 /* revision-stmts */
2338 if (module->revision) {
2339 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2340 }
2341
2342 /* body-stmts */
2343 if (modc->exts) {
2344 ly_print(out, "\n");
2345 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2346 }
2347
2348 LY_ARRAY_FOR(modc->features, u) {
2349 yprc_feature(ctx, &modc->features[u]);
2350 }
2351
2352 LY_ARRAY_FOR(modc->identities, u) {
2353 yprc_identity(ctx, &modc->identities[u]);
2354 }
2355
2356 LY_LIST_FOR(modc->data, data) {
2357 yprc_node(ctx, data);
2358 }
2359
2360 LY_ARRAY_FOR(modc->rpcs, u) {
2361 yprc_action(ctx, &modc->rpcs[u]);
2362 }
2363
2364 LY_ARRAY_FOR(modc->notifs, u) {
2365 yprc_notification(ctx, &modc->notifs[u]);
2366 }
2367
2368 LEVEL--;
2369 ly_print(out, "%*s}\n", INDENT);
2370 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002371
2372 return LY_SUCCESS;
2373}