blob: 9d7921d10dd30b6dd20d8bca4fbe0eb3d40dcbd7 [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>
18
Radek Krejcid3ca0632019-04-16 16:54:54 +020019#include "printer_internal.h"
20#include "tree_schema.h"
21#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020022#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020023
24#define LEVEL ctx->level
25#define INDENT (LEVEL)*2,""
26
Radek Krejci693262f2019-04-29 15:23:20 +020027enum schema_type {
28 YPR_PARSED,
29 YPR_COMPILED
30};
31
Radek Krejcid3ca0632019-04-16 16:54:54 +020032struct ypr_ctx {
33 struct lyout *out;
34 unsigned int level;
35 const struct lys_module *module;
Radek Krejci693262f2019-04-29 15:23:20 +020036 enum schema_type schema;
Radek Krejcid3ca0632019-04-16 16:54:54 +020037};
38
39static void
40ypr_encode(struct lyout *out, const char *text, int len)
41{
42 int i, start_len;
43 const char *start;
44 char special = 0;
45
46 if (!len) {
47 return;
48 }
49
50 if (len < 0) {
51 len = strlen(text);
52 }
53
54 start = text;
55 start_len = 0;
56 for (i = 0; i < len; ++i) {
57 switch (text[i]) {
58 case '\n':
59 case '\t':
60 case '\"':
61 case '\\':
62 special = text[i];
63 break;
64 default:
65 ++start_len;
66 break;
67 }
68
69 if (special) {
70 ly_write(out, start, start_len);
71 switch (special) {
72 case '\n':
73 ly_write(out, "\\n", 2);
74 break;
75 case '\t':
76 ly_write(out, "\\t", 2);
77 break;
78 case '\"':
79 ly_write(out, "\\\"", 2);
80 break;
81 case '\\':
82 ly_write(out, "\\\\", 2);
83 break;
84 }
85
86 start += start_len + 1;
87 start_len = 0;
88
89 special = 0;
90 }
91 }
92
93 ly_write(out, start, start_len);
94}
95
96static void
97ypr_open(struct lyout *out, int *flag)
98{
99 if (flag && !*flag) {
100 *flag = 1;
101 ly_print(out, " {\n");
102 }
103}
104
105static void
106ypr_close(struct ypr_ctx *ctx, int flag)
107{
108 if (flag) {
109 ly_print(ctx->out, "%*s}\n", INDENT);
110 } else {
111 ly_print(ctx->out, ";\n");
112 }
113}
114
115static void
116ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
117{
118 const char *s, *t;
119
120 if (singleline) {
121 ly_print(ctx->out, "%*s%s \"", INDENT, name);
122 } else {
123 ly_print(ctx->out, "%*s%s\n", INDENT, name);
124 LEVEL++;
125
126 ly_print(ctx->out, "%*s\"", INDENT);
127 }
128 t = text;
129 while ((s = strchr(t, '\n'))) {
130 ypr_encode(ctx->out, t, s - t);
131 ly_print(ctx->out, "\n");
132 t = s + 1;
133 if (*t != '\n') {
134 ly_print(ctx->out, "%*s ", INDENT);
135 }
136 }
137
138 ypr_encode(ctx->out, t, strlen(t));
139 if (closed) {
140 ly_print(ctx->out, "\";\n");
141 } else {
142 ly_print(ctx->out, "\"");
143 }
144 if (!singleline) {
145 LEVEL--;
146 }
147}
148
149static void
Radek Krejci693262f2019-04-29 15:23:20 +0200150yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 struct lysp_stmt *childstmt;
153 const char *s, *t;
154
155 if (stmt->arg) {
156 if (stmt->flags) {
157 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
158 LEVEL++;
159 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
160 t = stmt->arg;
161 while ((s = strchr(t, '\n'))) {
162 ypr_encode(ctx->out, t, s - t);
163 ly_print(ctx->out, "\n");
164 t = s + 1;
165 if (*t != '\n') {
166 ly_print(ctx->out, "%*s ", INDENT);
167 }
168 }
169 LEVEL--;
170 ypr_encode(ctx->out, t, strlen(t));
171 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
172 } else {
173 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
174 }
175 } else {
176 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
177 }
178
179 if (stmt->child) {
180 LEVEL++;
181 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200182 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200183 }
184 LEVEL--;
185 ly_print(ctx->out, "%*s}\n", INDENT);
186 }
187}
188
189/**
190 * @param[in] count Number of extensions to print, 0 to print them all.
191 */
192static void
Radek Krejci693262f2019-04-29 15:23:20 +0200193yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 struct lysp_ext_instance *ext, int *flag, unsigned int count)
195{
196 unsigned int u;
197 struct lysp_stmt *stmt;
198
199 if (!count && ext) {
200 count = LY_ARRAY_SIZE(ext);
201 }
202 LY_ARRAY_FOR(ext, u) {
203 if (!count) {
204 break;
205 }
206 if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
207 ypr_open(ctx->out, flag);
208 if (ext[u].argument) {
209 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
210 } else {
211 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
212 }
213
214 if (ext[u].child) {
215 LEVEL++;
216 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200217 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200218 }
219 LEVEL--;
220 ly_print(ctx->out, "%*s}\n", INDENT);
221 }
222 }
223 count--;
224 }
225}
226
Radek Krejci693262f2019-04-29 15:23:20 +0200227/**
228 * @param[in] count Number of extensions to print, 0 to print them all.
229 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230static void
Radek Krejci693262f2019-04-29 15:23:20 +0200231yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
232 struct lysc_ext_instance *ext, int *flag, unsigned int count)
233{
234 unsigned int u;
235
236 if (!count && ext) {
237 count = LY_ARRAY_SIZE(ext);
238 }
239 LY_ARRAY_FOR(ext, u) {
240 if (!count) {
241 break;
242 }
243 /* TODO compiled extensions */
244 (void) ctx;
245 (void) substmt;
246 (void) substmt_index;
247 (void) flag;
248
249 count--;
250 }
251}
252
253static void
254ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255{
256 unsigned int u;
257 int extflag = 0;
258
259 if (!text) {
260 /* nothing to print */
261 return;
262 }
263
264 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
265 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
266 } else {
267 ypr_text(ctx, ext_substmt_info[substmt].name, text,
268 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
269 }
270
271 LEVEL++;
272 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200273 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 +0200274 continue;
275 }
Radek Krejci693262f2019-04-29 15:23:20 +0200276 if (ctx->schema == YPR_PARSED) {
277 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
278 } else {
279 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
280 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 }
282 LEVEL--;
283 ypr_close(ctx, extflag);
284}
285
286static void
Radek Krejci693262f2019-04-29 15:23:20 +0200287ypr_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 +0200288{
289 char *str;
290
291 if (asprintf(&str, "%u", attr_value) == -1) {
292 LOGMEM(ctx->module->ctx);
293 return;
294 }
295 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200296 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200297 free(str);
298}
299
300static void
Radek Krejci693262f2019-04-29 15:23:20 +0200301ypr_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 +0200302{
303 char *str;
304
305 if (asprintf(&str, "%d", attr_value) == -1) {
306 LOGMEM(ctx->module->ctx);
307 return;
308 }
309 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200310 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200311 free(str);
312}
313
314static void
Radek Krejci693262f2019-04-29 15:23:20 +0200315yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200316{
317 if (rev->dsc || rev->ref || rev->exts) {
318 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
319 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200320 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
321 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
322 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200323 LEVEL--;
324 ly_print(ctx->out, "%*s}\n", INDENT);
325 } else {
326 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
327 }
328}
329
330static void
Radek Krejci693262f2019-04-29 15:23:20 +0200331ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200332{
333 if (flags & LYS_MAND_MASK) {
334 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200335 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 }
337}
338
339static void
Radek Krejci693262f2019-04-29 15:23:20 +0200340ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200341{
342 if (flags & LYS_CONFIG_MASK) {
343 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200344 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200345 }
346}
347
348static void
Radek Krejci693262f2019-04-29 15:23:20 +0200349ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200350{
351 const char *status = NULL;
352
353 if (flags & LYS_STATUS_CURR) {
354 ypr_open(ctx->out, flag);
355 status = "current";
356 } else if (flags & LYS_STATUS_DEPRC) {
357 ypr_open(ctx->out, flag);
358 status = "deprecated";
359 } else if (flags & LYS_STATUS_OBSLT) {
360 ypr_open(ctx->out, flag);
361 status = "obsolete";
362 }
Radek Krejci693262f2019-04-29 15:23:20 +0200363
364 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200365}
366
367static void
Radek Krejci693262f2019-04-29 15:23:20 +0200368ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200369{
370 if (dsc) {
371 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200372 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373 }
374}
375
376static void
Radek Krejci693262f2019-04-29 15:23:20 +0200377ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378{
379 if (ref) {
380 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200381 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382 }
383}
384
385static void
Radek Krejci693262f2019-04-29 15:23:20 +0200386yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200387{
388 unsigned int u;
389 int extflag;
390
391 LY_ARRAY_FOR(iff, u) {
392 ypr_open(ctx->out, flag);
393 extflag = 0;
394
395 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
396
397 /* extensions */
398 LEVEL++;
399 LY_ARRAY_FOR(exts, u) {
400 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
401 continue;
402 }
Radek Krejci693262f2019-04-29 15:23:20 +0200403 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200404 }
405 LEVEL--;
406 ypr_close(ctx, extflag);
407 }
408}
409
410static void
Radek Krejci693262f2019-04-29 15:23:20 +0200411yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
412{
413 int brackets_flag = *index_e;
414 uint8_t op;
415
416 op = lysc_iff_getop(feat->expr, *index_e);
417 (*index_e)++;
418
419 switch (op) {
420 case LYS_IFF_F:
421 if (ctx->module == feat->features[*index_f]->module) {
422 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
423 } else {
424 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
425 }
426 (*index_f)++;
427 break;
428 case LYS_IFF_NOT:
429 ly_print(ctx->out, "not ");
430 yprc_iffeature(ctx, feat, index_e, index_f);
431 break;
432 case LYS_IFF_AND:
433 if (brackets_flag) {
434 /* AND need brackets only if previous op was not */
435 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
436 brackets_flag = 0;
437 }
438 }
439 /* falls through */
440 case LYS_IFF_OR:
441 if (brackets_flag) {
442 ly_print(ctx->out, "(");
443 }
444 yprc_iffeature(ctx, feat, index_e, index_f);
445 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
446 yprc_iffeature(ctx, feat, index_e, index_f);
447 if (brackets_flag) {
448 ly_print(ctx->out, ")");
449 }
450 }
451}
452
453static void
454yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
455{
456 unsigned int u;
457 int extflag;
458
459 LY_ARRAY_FOR(iff, u) {
460 int index_e = 0, index_f = 0;
461
462 ypr_open(ctx->out, flag);
463 extflag = 0;
464
465 yprc_iffeature(ctx, iff, &index_e, &index_f);
466
467 /* extensions */
468 LEVEL++;
469 LY_ARRAY_FOR(exts, u) {
470 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
471 continue;
472 }
473 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
474 }
475 LEVEL--;
476 ypr_close(ctx, extflag);
477 }
478}
479
480static void
481yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200482{
483 int flag = 0, flag2 = 0;
484 unsigned int i;
485
486 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
487 LEVEL++;
488
489 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200490 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 }
492
493 if (ext->argument) {
494 ypr_open(ctx->out, &flag);
495 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
496 if (ext->exts) {
497 LEVEL++;
498 i = -1;
499 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 +0200500 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200501 }
502 LEVEL--;
503 }
504 if ((ext->flags & LYS_YINELEM_MASK) ||
505 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
506 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200507 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200508 }
509 ypr_close(ctx, flag2);
510 }
511
Radek Krejci693262f2019-04-29 15:23:20 +0200512 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200513 ypr_description(ctx, ext->dsc, ext->exts, &flag);
514 ypr_reference(ctx, ext->ref, ext->exts, &flag);
515
516 LEVEL--;
517 ypr_close(ctx, flag);
518}
519
520static void
Radek Krejci693262f2019-04-29 15:23:20 +0200521yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200522{
523 int flag = 0;
524
525 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
526 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200527 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
528 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
529 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200530 ypr_description(ctx, feat->dsc, feat->exts, &flag);
531 ypr_reference(ctx, feat->ref, feat->exts, &flag);
532 LEVEL--;
533 ypr_close(ctx, flag);
534}
535
536static void
Radek Krejci693262f2019-04-29 15:23:20 +0200537yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
538{
539 int flag = 0;
540
541 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
542 LEVEL++;
543 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
544 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
545 ypr_status(ctx, feat->flags, feat->exts, &flag);
546 ypr_description(ctx, feat->dsc, feat->exts, &flag);
547 ypr_reference(ctx, feat->ref, feat->exts, &flag);
548 LEVEL--;
549 ypr_close(ctx, flag);
550}
551
552static void
553yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200554{
555 int flag = 0;
556 unsigned int u;
557
558 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
559 LEVEL++;
560
Radek Krejci693262f2019-04-29 15:23:20 +0200561 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
562 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563
564 LY_ARRAY_FOR(ident->bases, u) {
565 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200566 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200567 }
568
Radek Krejci693262f2019-04-29 15:23:20 +0200569 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200570 ypr_description(ctx, ident->dsc, ident->exts, &flag);
571 ypr_reference(ctx, ident->ref, ident->exts, &flag);
572
573 LEVEL--;
574 ypr_close(ctx, flag);
575}
576
577static void
Radek Krejci693262f2019-04-29 15:23:20 +0200578yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
579{
580 int flag = 0;
581 unsigned int u;
582
583 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
584 LEVEL++;
585
586 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
587 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
588
589 LY_ARRAY_FOR(ident->derived, u) {
590 ypr_open(ctx->out, &flag);
591 if (ctx->module != ident->derived[u]->module) {
592 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
593 } else {
594 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
595 }
596 }
597
598 ypr_status(ctx, ident->flags, ident->exts, &flag);
599 ypr_description(ctx, ident->dsc, ident->exts, &flag);
600 ypr_reference(ctx, ident->ref, ident->exts, &flag);
601
602 LEVEL--;
603 ypr_close(ctx, flag);
604}
605
606static void
607yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200608{
609 int inner_flag = 0;
610
611 if (!restr) {
612 return;
613 }
614
615 ypr_open(ctx->out, flag);
616 ly_print(ctx->out, "%*s%s \"", INDENT, name);
617 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
618 ly_print(ctx->out, "\"");
619
620 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200621 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200622 if (restr->arg[0] == 0x15) {
623 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
624 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200625 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200626 }
627 if (restr->emsg) {
628 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200629 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200630 }
631 if (restr->eapptag) {
632 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200633 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200634 }
Radek Krejci693262f2019-04-29 15:23:20 +0200635 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
636 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
637
Radek Krejcid3ca0632019-04-16 16:54:54 +0200638 LEVEL--;
639 ypr_close(ctx, inner_flag);
640}
641
642static void
Radek Krejci693262f2019-04-29 15:23:20 +0200643yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
644{
645 int inner_flag = 0;
646
647 ypr_open(ctx->out, flag);
648 ly_print(ctx->out, "%*smust \"", INDENT);
649 ypr_encode(ctx->out, must->cond->expr, -1);
650 ly_print(ctx->out, "\"");
651
652 LEVEL++;
653 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
654 if (must->emsg) {
655 ypr_open(ctx->out, &inner_flag);
656 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
657 }
658 if (must->eapptag) {
659 ypr_open(ctx->out, &inner_flag);
660 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
661 }
662 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
663 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
664
665 LEVEL--;
666 ypr_close(ctx, inner_flag);
667}
668
669static void
670yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
671{
672 int inner_flag = 0;
673 unsigned int u;
674
675 ypr_open(ctx->out, flag);
676 ly_print(ctx->out, "%*s%s \"", (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY)? "length" : "range", INDENT);
677 LY_ARRAY_FOR(range->parts, u) {
678 if (u > 0) {
679 ly_print(ctx->out, " | ");
680 }
681 if (range->parts[u].max_64 == range->parts[u].min_64) {
682 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
683 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
684 } else { /* signed values */
685 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
686 }
687 } else {
688 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
689 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
690 } else { /* signed values */
691 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
692 }
693 }
694 }
695 ly_print(ctx->out, "\"");
696
697 LEVEL++;
698 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
699 if (range->emsg) {
700 ypr_open(ctx->out, &inner_flag);
701 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
702 }
703 if (range->eapptag) {
704 ypr_open(ctx->out, &inner_flag);
705 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
706 }
707 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
708 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
709
710 LEVEL--;
711 ypr_close(ctx, inner_flag);
712}
713
714static void
715yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
716{
717 int inner_flag = 0;
718
719 ypr_open(ctx->out, flag);
720 ly_print(ctx->out, "%*spattern \"", INDENT);
721 ypr_encode(ctx->out, pattern->orig, -1);
722 ly_print(ctx->out, "\"");
723
724 LEVEL++;
725 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
726 if (pattern->inverted) {
727 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
728 ypr_open(ctx->out, &inner_flag);
729 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
730 }
731 if (pattern->emsg) {
732 ypr_open(ctx->out, &inner_flag);
733 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
734 }
735 if (pattern->eapptag) {
736 ypr_open(ctx->out, &inner_flag);
737 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
738 }
739 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
740 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
741
742 LEVEL--;
743 ypr_close(ctx, inner_flag);
744}
745
746static void
747yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200748{
749 int inner_flag = 0;
750
751 if (!when) {
752 return;
753 }
754 ypr_open(ctx->out, flag);
755
756 ly_print(ctx->out, "%*swhen \"", INDENT);
757 ypr_encode(ctx->out, when->cond, -1);
758 ly_print(ctx->out, "\"");
759
760 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200761 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200762 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
763 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
764 LEVEL--;
765 ypr_close(ctx, inner_flag);
766}
767
768static void
Radek Krejci693262f2019-04-29 15:23:20 +0200769yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
770{
771 int inner_flag = 0;
772
773 if (!when) {
774 return;
775 }
776 ypr_open(ctx->out, flag);
777
778 ly_print(ctx->out, "%*swhen \"", INDENT);
779 ypr_encode(ctx->out, when->cond->expr, -1);
780 ly_print(ctx->out, "\"");
781
782 LEVEL++;
783 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
784 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
785 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
786 LEVEL--;
787 ypr_close(ctx, inner_flag);
788}
789
790static void
791yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200792{
793 unsigned int u;
794 int inner_flag;
795
796 LY_ARRAY_FOR(items, u) {
797 ypr_open(ctx->out, flag);
798 ly_print(ctx->out, "%*s%s \"", INDENT, type == LY_TYPE_BITS ? "bit" : "enum");
799 ypr_encode(ctx->out, items[u].name, -1);
800 ly_print(ctx->out, "\"");
801 inner_flag = 0;
802 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200803 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
804 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200805 if (items[u].flags & LYS_SET_VALUE) {
806 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200807 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200808 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200809 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200810 }
811 }
Radek Krejci693262f2019-04-29 15:23:20 +0200812 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200813 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
814 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
815 LEVEL--;
816 ypr_close(ctx, inner_flag);
817 }
818}
819
820static void
Radek Krejci693262f2019-04-29 15:23:20 +0200821yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200822{
823 unsigned int u;
824 int flag = 0;
825
826 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
827 LEVEL++;
828
Radek Krejci693262f2019-04-29 15:23:20 +0200829 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200830
Radek Krejci693262f2019-04-29 15:23:20 +0200831 yprp_restr(ctx, type->range, "range", &flag);
832 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200833 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200834 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200835 }
Radek Krejci693262f2019-04-29 15:23:20 +0200836 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
837 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200838
839 if (type->path) {
840 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200841 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842 }
843 if (type->flags & LYS_SET_REQINST) {
844 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200845 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200846 }
847 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200848 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200849 }
850 LY_ARRAY_FOR(type->bases, u) {
851 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200852 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200853 }
854 LY_ARRAY_FOR(type->types, u) {
855 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200856 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200857 }
858
859 LEVEL--;
860 ypr_close(ctx, flag);
861}
862
863static void
Radek Krejci693262f2019-04-29 15:23:20 +0200864yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
865{
866 unsigned int u;
867 int flag = 0;
868
869 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
870 LEVEL++;
871
872 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
873 if (type->dflt) {
874 ypr_open(ctx->out, &flag);
875 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
876 }
877
878 switch(type->basetype) {
879 case LY_TYPE_BINARY: {
880 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
881 yprc_range(ctx, bin->length, type->basetype, &flag);
882 break;
883 }
884 case LY_TYPE_UINT8:
885 case LY_TYPE_UINT16:
886 case LY_TYPE_UINT32:
887 case LY_TYPE_UINT64:
888 case LY_TYPE_INT8:
889 case LY_TYPE_INT16:
890 case LY_TYPE_INT32:
891 case LY_TYPE_INT64: {
892 struct lysc_type_num *num = (struct lysc_type_num*)type;
893 yprc_range(ctx, num->range, type->basetype, &flag);
894 break;
895 }
896 case LY_TYPE_STRING: {
897 struct lysc_type_str *str = (struct lysc_type_str*)type;
898 yprc_range(ctx, str->length, type->basetype, &flag);
899 LY_ARRAY_FOR(str->patterns, u) {
900 yprc_pattern(ctx, str->patterns[u], &flag);
901 }
902 break;
903 }
904 case LY_TYPE_BITS:
905 case LY_TYPE_ENUM: {
906 /* bits and enums structures are compatible */
907 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
908 LY_ARRAY_FOR(bits->bits, u) {
909 struct lysc_type_bitenum_item *item = &bits->bits[u];
910 int inner_flag = 0;
911
912 ypr_open(ctx->out, &flag);
913 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
914 ypr_encode(ctx->out, item->name, -1);
915 ly_print(ctx->out, "\"");
916 LEVEL++;
917 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
918 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
919 if (type->basetype == LY_TYPE_BITS) {
920 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
921 } else { /* LY_TYPE_ENUM */
922 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
923 }
924 ypr_status(ctx, item->flags, item->exts, &inner_flag);
925 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
926 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
927 LEVEL--;
928 ypr_close(ctx, inner_flag);
929 }
930 break;
931 }
932 case LY_TYPE_BOOL:
933 case LY_TYPE_EMPTY:
934 /* nothing to do */
935 break;
936 case LY_TYPE_DEC64: {
937 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
938 ypr_open(ctx->out, &flag);
939 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
940 yprc_range(ctx, dec->range, dec->basetype, &flag);
941 break;
942 }
943 case LY_TYPE_IDENT: {
944 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
945 LY_ARRAY_FOR(ident->bases, u) {
946 ypr_open(ctx->out, &flag);
947 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
948 }
949 break;
950 }
951 case LY_TYPE_INST: {
952 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
953 ypr_open(ctx->out, &flag);
954 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
955 break;
956 }
957 case LY_TYPE_LEAFREF: {
958 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
959 ypr_open(ctx->out, &flag);
960 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
961 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
962 yprc_type(ctx, lr->realtype);
963 break;
964 }
965 case LY_TYPE_UNION: {
966 struct lysc_type_union *un = (struct lysc_type_union*)type;
967 LY_ARRAY_FOR(un->types, u) {
968 ypr_open(ctx->out, &flag);
969 yprc_type(ctx, un->types[u]);
970 }
971 break;
972 }
973 default:
974 LOGINT(ctx->module->ctx);
975 }
976
977 LEVEL--;
978 ypr_close(ctx, flag);
979}
980
981static void
982yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200983{
984 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
985 LEVEL++;
986
Radek Krejci693262f2019-04-29 15:23:20 +0200987 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200988
Radek Krejci693262f2019-04-29 15:23:20 +0200989 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200990
991 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +0200992 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200993 }
994 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200995 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200996 }
997
Radek Krejci693262f2019-04-29 15:23:20 +0200998 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200999 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1000 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1001
1002 LEVEL--;
1003 ly_print(ctx->out, "%*s}\n", INDENT);
1004}
1005
Radek Krejci693262f2019-04-29 15:23:20 +02001006static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1007static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1008static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001009
1010static void
Radek Krejci693262f2019-04-29 15:23:20 +02001011yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001012{
1013 unsigned int u;
1014 int flag = 0;
1015 struct lysp_node *data;
1016
1017 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1018 LEVEL++;
1019
Radek Krejci693262f2019-04-29 15:23:20 +02001020 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1021 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001022 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1023 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024
1025 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001026 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001027 }
1028
1029 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001030 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001031 }
1032
1033 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001034 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001035 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001036 }
1037
1038 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001039 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001040 }
1041
1042 LEVEL--;
1043 ypr_close(ctx, flag);
1044}
1045
1046static void
Radek Krejci693262f2019-04-29 15:23:20 +02001047yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001048{
1049 unsigned int u;
1050 struct lysp_node *data;
1051
1052 if (!inout->nodetype) {
1053 /* nodetype not set -> input/output is empty */
1054 return;
1055 }
1056 ypr_open(ctx->out, flag);
1057
1058 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1059 LEVEL++;
1060
Radek Krejci693262f2019-04-29 15:23:20 +02001061 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001063 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001064 }
1065 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001066 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 }
1068 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001069 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 }
1071
1072 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001073 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074 }
1075
1076 LEVEL--;
1077 ypr_close(ctx, 1);
1078}
1079
1080static void
Radek Krejci693262f2019-04-29 15:23:20 +02001081yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1082{
1083 unsigned int u;
1084 struct lysc_node *data;
1085
1086 if (!inout->data) {
1087 /* input/output is empty */
1088 return;
1089 }
1090 ypr_open(ctx->out, flag);
1091
1092 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1093 LEVEL++;
1094
1095 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1096 LY_ARRAY_FOR(inout->musts, u) {
1097 yprc_must(ctx, &inout->musts[u], NULL);
1098 }
1099
1100 LY_LIST_FOR(inout->data, data) {
1101 yprc_node(ctx, data);
1102 }
1103
1104 LEVEL--;
1105 ypr_close(ctx, 1);
1106}
1107
1108static void
1109yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110{
1111 unsigned int u;
1112 int flag = 0;
1113 struct lysp_node *data;
1114
1115 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1116
1117 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001118 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1119 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120
1121 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001122 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001123 }
Radek Krejci693262f2019-04-29 15:23:20 +02001124 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001125 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1126 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1127
1128 LY_ARRAY_FOR(notif->typedefs, u) {
1129 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001130 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001131 }
1132
1133 LY_ARRAY_FOR(notif->groupings, u) {
1134 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001135 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001136 }
1137
1138 LY_LIST_FOR(notif->data, data) {
1139 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001140 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001141 }
1142
1143 LEVEL--;
1144 ypr_close(ctx, flag);
1145}
1146
1147static void
Radek Krejci693262f2019-04-29 15:23:20 +02001148yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1149{
1150 unsigned int u;
1151 int flag = 0;
1152 struct lysc_node *data;
1153
1154 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1155
1156 LEVEL++;
1157 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1158 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1159
1160 LY_ARRAY_FOR(notif->musts, u) {
1161 yprc_must(ctx, &notif->musts[u], &flag);
1162 }
1163 ypr_status(ctx, notif->flags, notif->exts, &flag);
1164 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1165 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1166
1167 LY_LIST_FOR(notif->data, data) {
1168 ypr_open(ctx->out, &flag);
1169 yprc_node(ctx, data);
1170 }
1171
1172 LEVEL--;
1173 ypr_close(ctx, flag);
1174}
1175
1176static void
1177yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001178{
1179 unsigned int u;
1180 int flag = 0;
1181
1182 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1183
1184 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001185 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1186 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1187 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001188 ypr_description(ctx, action->dsc, action->exts, &flag);
1189 ypr_reference(ctx, action->ref, action->exts, &flag);
1190
1191 LY_ARRAY_FOR(action->typedefs, u) {
1192 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001193 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001194 }
1195
1196 LY_ARRAY_FOR(action->groupings, u) {
1197 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001198 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001199 }
1200
Radek Krejci693262f2019-04-29 15:23:20 +02001201 yprp_inout(ctx, &action->input, &flag);
1202 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203
1204 LEVEL--;
1205 ypr_close(ctx, flag);
1206}
1207
1208static void
Radek Krejci693262f2019-04-29 15:23:20 +02001209yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1210{
1211 int flag = 0;
1212
1213 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1214
1215 LEVEL++;
1216 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1217 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1218 ypr_status(ctx, action->flags, action->exts, &flag);
1219 ypr_description(ctx, action->dsc, action->exts, &flag);
1220 ypr_reference(ctx, action->ref, action->exts, &flag);
1221
1222 yprc_inout(ctx, action, &action->input, &flag);
1223 yprc_inout(ctx, action, &action->output, &flag);
1224
1225 LEVEL--;
1226 ypr_close(ctx, flag);
1227}
1228
1229static void
1230yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001231{
1232 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1233 LEVEL++;
1234
Radek Krejci693262f2019-04-29 15:23:20 +02001235 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1236 yprp_when(ctx, node->when, flag);
1237 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001238}
1239
1240static void
Radek Krejci693262f2019-04-29 15:23:20 +02001241yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001242{
Radek Krejci693262f2019-04-29 15:23:20 +02001243 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001244
Radek Krejci693262f2019-04-29 15:23:20 +02001245 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1246 LEVEL++;
1247
1248 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1249 LY_ARRAY_FOR(node->when, u) {
1250 yprc_when(ctx, node->when[u], flag);
1251 }
1252 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1253}
1254
1255/* macr oto unify the code */
1256#define YPR_NODE_COMMON2 \
1257 ypr_config(ctx, node->flags, node->exts, flag); \
1258 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1259 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1260 } \
1261 ypr_status(ctx, node->flags, node->exts, flag); \
1262 ypr_description(ctx, node->dsc, node->exts, flag); \
1263 ypr_reference(ctx, node->ref, node->exts, flag)
1264
1265static void
1266yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1267{
1268 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001269}
1270
1271static void
Radek Krejci693262f2019-04-29 15:23:20 +02001272yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1273{
1274 YPR_NODE_COMMON2;
1275}
1276
1277#undef YPR_NODE_COMMON2
1278
1279static void
1280yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281{
1282 unsigned int u;
1283 int flag = 0;
1284 struct lysp_node *child;
1285 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1286
Radek Krejci693262f2019-04-29 15:23:20 +02001287 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288
1289 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001290 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001291 }
1292 if (cont->presence) {
1293 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001294 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001295 }
1296
Radek Krejci693262f2019-04-29 15:23:20 +02001297 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001298
1299 LY_ARRAY_FOR(cont->typedefs, u) {
1300 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001301 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001302 }
1303
1304 LY_ARRAY_FOR(cont->groupings, u) {
1305 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001306 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001307 }
1308
1309 LY_LIST_FOR(cont->child, child) {
1310 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001311 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001312 }
1313
1314 LY_ARRAY_FOR(cont->actions, u) {
1315 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001316 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001317 }
1318
1319 LY_ARRAY_FOR(cont->notifs, u) {
1320 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001321 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001322 }
1323
1324 LEVEL--;
1325 ypr_close(ctx, flag);
1326}
1327
1328static void
Radek Krejci693262f2019-04-29 15:23:20 +02001329yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1330{
1331 unsigned int u;
1332 int flag = 0;
1333 struct lysc_node *child;
1334 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1335
1336 yprc_node_common1(ctx, node, &flag);
1337
1338 LY_ARRAY_FOR(cont->musts, u) {
1339 yprc_must(ctx, &cont->musts[u], &flag);
1340 }
1341 if (cont->flags & LYS_PRESENCE) {
1342 ypr_open(ctx->out, &flag);
1343 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1344 }
1345
1346 yprc_node_common2(ctx, node, &flag);
1347
1348 LY_LIST_FOR(cont->child, child) {
1349 ypr_open(ctx->out, &flag);
1350 yprc_node(ctx, child);
1351 }
1352
1353 LY_ARRAY_FOR(cont->actions, u) {
1354 ypr_open(ctx->out, &flag);
1355 yprc_action(ctx, &cont->actions[u]);
1356 }
1357
1358 LY_ARRAY_FOR(cont->notifs, u) {
1359 ypr_open(ctx->out, &flag);
1360 yprc_notification(ctx, &cont->notifs[u]);
1361 }
1362
1363 LEVEL--;
1364 ypr_close(ctx, flag);
1365}
1366
1367static void
1368yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1369{
1370 int flag = 0;
1371 struct lysp_node *child;
1372 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1373
1374 yprp_node_common1(ctx, node, &flag);
1375 yprp_node_common2(ctx, node, &flag);
1376
1377 LY_LIST_FOR(cas->child, child) {
1378 ypr_open(ctx->out, &flag);
1379 yprp_node(ctx, child);
1380 }
1381
1382 LEVEL--;
1383 ypr_close(ctx, flag);
1384}
1385
1386static void
1387yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1388{
1389 int flag = 0;
1390 struct lysc_node *child;
1391
1392 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1393 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1394
1395 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1396 ypr_open(ctx->out, &flag);
1397 yprc_node(ctx, child);
1398 }
1399
1400 LEVEL--;
1401 ypr_close(ctx, flag);
1402}
1403
1404static void
1405yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001406{
1407 int flag = 0;
1408 struct lysp_node *child;
1409 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1410
Radek Krejci693262f2019-04-29 15:23:20 +02001411 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001412
1413 if (choice->dflt) {
1414 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001415 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001416 }
1417
Radek Krejci693262f2019-04-29 15:23:20 +02001418 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001419
1420 LY_LIST_FOR(choice->child, child) {
1421 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001422 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001423 }
1424
1425 LEVEL--;
1426 ypr_close(ctx, flag);
1427}
1428
1429static void
Radek Krejci693262f2019-04-29 15:23:20 +02001430yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1431{
1432 int flag = 0;
1433 struct lysc_node_case *cs;
1434 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1435
1436 yprc_node_common1(ctx, node, &flag);
1437
1438 if (choice->dflt) {
1439 ypr_open(ctx->out, &flag);
1440 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1441 }
1442
1443 yprc_node_common2(ctx, node, &flag);
1444
1445 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1446 ypr_open(ctx->out, &flag);
1447 yprc_case(ctx, cs);
1448 }
1449
1450 LEVEL--;
1451 ypr_close(ctx, flag);
1452}
1453
1454static void
1455yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001456{
1457 unsigned int u;
1458 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1459
Radek Krejci693262f2019-04-29 15:23:20 +02001460 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001461
Radek Krejci693262f2019-04-29 15:23:20 +02001462 yprp_type(ctx, &leaf->type);
1463 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001464 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001465 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001466 }
Radek Krejci693262f2019-04-29 15:23:20 +02001467 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001468
Radek Krejci693262f2019-04-29 15:23:20 +02001469 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470
1471 LEVEL--;
1472 ly_print(ctx->out, "%*s}\n", INDENT);
1473}
1474
1475static void
Radek Krejci693262f2019-04-29 15:23:20 +02001476yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1477{
1478 unsigned int u;
1479 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1480
1481 yprc_node_common1(ctx, node, NULL);
1482
1483 yprc_type(ctx, leaf->type);
1484 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1485 LY_ARRAY_FOR(leaf->musts, u) {
1486 yprc_must(ctx, &leaf->musts[u], NULL);
1487 }
1488 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1489
1490 yprc_node_common2(ctx, node, NULL);
1491
1492 LEVEL--;
1493 ly_print(ctx->out, "%*s}\n", INDENT);
1494}
1495
1496static void
1497yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001498{
1499 unsigned int u;
1500 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1501
Radek Krejci693262f2019-04-29 15:23:20 +02001502 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001503
Radek Krejci693262f2019-04-29 15:23:20 +02001504 yprp_type(ctx, &llist->type);
1505 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001506 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001507 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508 }
1509 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001510 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001511 }
1512
Radek Krejci693262f2019-04-29 15:23:20 +02001513 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514
1515 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001516 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517 }
1518 if (llist->flags & LYS_SET_MAX) {
1519 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001520 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001521 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001522 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523 }
1524 }
1525
1526 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001527 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001528 }
1529
Radek Krejci693262f2019-04-29 15:23:20 +02001530 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001531 ypr_description(ctx, node->dsc, node->exts, NULL);
1532 ypr_reference(ctx, node->ref, node->exts, NULL);
1533
1534 LEVEL--;
1535 ly_print(ctx->out, "%*s}\n", INDENT);
1536}
1537
1538static void
Radek Krejci693262f2019-04-29 15:23:20 +02001539yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1540{
1541 unsigned int u;
1542 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1543
1544 yprc_node_common1(ctx, node, NULL);
1545
1546 yprc_type(ctx, llist->type);
1547 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1548 LY_ARRAY_FOR(llist->musts, u) {
1549 yprc_must(ctx, &llist->musts[u], NULL);
1550 }
1551 LY_ARRAY_FOR(llist->dflts, u) {
1552 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1553 }
1554
1555 ypr_config(ctx, node->flags, node->exts, NULL);
1556
1557 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1558 if (llist->max) {
1559 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1560 } else {
1561 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1562 }
1563
1564 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1565
1566 ypr_status(ctx, node->flags, node->exts, NULL);
1567 ypr_description(ctx, node->dsc, node->exts, NULL);
1568 ypr_reference(ctx, node->ref, node->exts, NULL);
1569
1570 LEVEL--;
1571 ly_print(ctx->out, "%*s}\n", INDENT);
1572}
1573
1574static void
1575yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576{
1577 unsigned int u;
1578 int flag = 0;
1579 struct lysp_node *child;
1580 struct lysp_node_list *list = (struct lysp_node_list *)node;
1581
Radek Krejci693262f2019-04-29 15:23:20 +02001582 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583
1584 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001585 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001586 }
1587 if (list->key) {
1588 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001589 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590 }
1591 LY_ARRAY_FOR(list->uniques, u) {
1592 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001593 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001594 }
1595
Radek Krejci693262f2019-04-29 15:23:20 +02001596 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597
1598 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001599 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600 }
1601 if (list->flags & LYS_SET_MAX) {
1602 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001603 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001604 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001605 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001606 }
1607 }
1608
1609 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001610 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001611 }
1612
Radek Krejci693262f2019-04-29 15:23:20 +02001613 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001614 ypr_description(ctx, node->dsc, node->exts, NULL);
1615 ypr_reference(ctx, node->ref, node->exts, NULL);
1616
1617 LY_ARRAY_FOR(list->typedefs, u) {
1618 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001619 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001620 }
1621
1622 LY_ARRAY_FOR(list->groupings, u) {
1623 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001624 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001625 }
1626
1627 LY_LIST_FOR(list->child, child) {
1628 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001629 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001630 }
1631
1632 LY_ARRAY_FOR(list->actions, u) {
1633 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001634 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001635 }
1636
1637 LY_ARRAY_FOR(list->notifs, u) {
1638 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001639 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001640 }
1641
1642 LEVEL--;
1643 ypr_close(ctx, flag);
1644}
1645
1646static void
Radek Krejci693262f2019-04-29 15:23:20 +02001647yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1648{
1649 unsigned int u, v;
1650 int flag = 0;
1651 struct lysc_node *child;
1652 struct lysc_node_list *list = (struct lysc_node_list *)node;
1653
1654 yprc_node_common1(ctx, node, &flag);
1655
1656 LY_ARRAY_FOR(list->musts, u) {
1657 yprc_must(ctx, &list->musts[u], NULL);
1658 }
1659 if (list->keys) {
1660 ypr_open(ctx->out, &flag);
1661 ly_print(ctx->out, "%*skey \"", INDENT);
1662 LY_ARRAY_FOR(list->keys, u) {
1663 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1664 }
1665 ypr_close(ctx, 0);
1666 }
1667 LY_ARRAY_FOR(list->uniques, u) {
1668 ypr_open(ctx->out, &flag);
1669 ly_print(ctx->out, "%*sunique \"", INDENT);
1670 LY_ARRAY_FOR(list->uniques[u], v) {
1671 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1672 }
1673 ypr_close(ctx, 0);
1674 }
1675
1676 ypr_config(ctx, node->flags, node->exts, NULL);
1677
1678 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1679 if (list->max) {
1680 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1681 } else {
1682 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1683 }
1684
1685 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1686
1687 ypr_status(ctx, node->flags, node->exts, NULL);
1688 ypr_description(ctx, node->dsc, node->exts, NULL);
1689 ypr_reference(ctx, node->ref, node->exts, NULL);
1690
1691 LY_LIST_FOR(list->child, child) {
1692 ypr_open(ctx->out, &flag);
1693 yprc_node(ctx, child);
1694 }
1695
1696 LY_ARRAY_FOR(list->actions, u) {
1697 ypr_open(ctx->out, &flag);
1698 yprc_action(ctx, &list->actions[u]);
1699 }
1700
1701 LY_ARRAY_FOR(list->notifs, u) {
1702 ypr_open(ctx->out, &flag);
1703 yprc_notification(ctx, &list->notifs[u]);
1704 }
1705
1706 LEVEL--;
1707 ypr_close(ctx, flag);
1708}
1709
1710static void
1711yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001712{
1713 unsigned int u;
1714 int flag = 0;
1715
1716 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1717 LEVEL++;
1718
Radek Krejci693262f2019-04-29 15:23:20 +02001719 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1720 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001721
1722 LY_ARRAY_FOR(refine->musts, u) {
1723 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001724 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001725 }
1726
1727 if (refine->presence) {
1728 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001729 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001730 }
1731
1732 LY_ARRAY_FOR(refine->dflts, u) {
1733 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001734 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001735 }
1736
Radek Krejci693262f2019-04-29 15:23:20 +02001737 ypr_config(ctx, refine->flags, refine->exts, &flag);
1738 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001739
1740 if (refine->flags & LYS_SET_MIN) {
1741 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001742 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001743 }
1744 if (refine->flags & LYS_SET_MAX) {
1745 ypr_open(ctx->out, &flag);
1746 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001747 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001748 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001749 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001750 }
1751 }
1752
1753 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1754 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1755
1756 LEVEL--;
1757 ypr_close(ctx, flag);
1758}
1759
1760static void
Radek Krejci693262f2019-04-29 15:23:20 +02001761yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001762{
1763 unsigned int u;
1764 struct lysp_node *child;
1765
1766 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1767 LEVEL++;
1768
Radek Krejci693262f2019-04-29 15:23:20 +02001769 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1770 yprp_when(ctx, aug->when, NULL);
1771 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1772 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001773 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1774 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1775
1776 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001777 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001778 }
1779
1780 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001781 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001782 }
1783
1784 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001785 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001786 }
1787
1788 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001789 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790}
1791
1792
1793static void
Radek Krejci693262f2019-04-29 15:23:20 +02001794yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795{
1796 unsigned int u;
1797 int flag = 0;
1798 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1799
Radek Krejci693262f2019-04-29 15:23:20 +02001800 yprp_node_common1(ctx, node, &flag);
1801 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802
1803 LY_ARRAY_FOR(uses->refines, u) {
1804 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001805 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806 }
1807
1808 LY_ARRAY_FOR(uses->augments, u) {
1809 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001810 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001811 }
1812
1813 LEVEL--;
1814 ypr_close(ctx, flag);
1815}
1816
1817static void
Radek Krejci693262f2019-04-29 15:23:20 +02001818yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819{
1820 unsigned int u;
1821 int flag = 0;
1822 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1823
Radek Krejci693262f2019-04-29 15:23:20 +02001824 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825
1826 LY_ARRAY_FOR(any->musts, u) {
1827 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001828 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001829 }
1830
Radek Krejci693262f2019-04-29 15:23:20 +02001831 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001832
1833 LEVEL--;
1834 ypr_close(ctx, flag);
1835}
1836
1837static void
Radek Krejci693262f2019-04-29 15:23:20 +02001838yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839{
Radek Krejci693262f2019-04-29 15:23:20 +02001840 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001842 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843
Radek Krejci693262f2019-04-29 15:23:20 +02001844 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001845
Radek Krejci693262f2019-04-29 15:23:20 +02001846 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849 }
1850
Radek Krejci693262f2019-04-29 15:23:20 +02001851 yprc_node_common2(ctx, node, &flag);
1852
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853 LEVEL--;
1854 ypr_close(ctx, flag);
1855}
1856
1857static void
Radek Krejci693262f2019-04-29 15:23:20 +02001858yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859{
1860 switch (node->nodetype) {
1861 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001862 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863 break;
1864 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001865 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866 break;
1867 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001868 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869 break;
1870 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001871 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872 break;
1873 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001874 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001875 break;
1876 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001877 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001878 break;
1879 case LYS_ANYXML:
1880 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001881 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882 break;
1883 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001884 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 break;
1886 default:
1887 break;
1888 }
1889}
1890
1891static void
Radek Krejci693262f2019-04-29 15:23:20 +02001892yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1893{
1894 switch (node->nodetype) {
1895 case LYS_CONTAINER:
1896 yprc_container(ctx, node);
1897 break;
1898 case LYS_CHOICE:
1899 yprc_choice(ctx, node);
1900 break;
1901 case LYS_LEAF:
1902 yprc_leaf(ctx, node);
1903 break;
1904 case LYS_LEAFLIST:
1905 yprc_leaflist(ctx, node);
1906 break;
1907 case LYS_LIST:
1908 yprc_list(ctx, node);
1909 break;
1910 case LYS_ANYXML:
1911 case LYS_ANYDATA:
1912 yprc_anydata(ctx, node);
1913 break;
1914 default:
1915 break;
1916 }
1917}
1918
1919static void
1920yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921{
1922 unsigned int u, v;
1923 struct lysp_deviate_add *add;
1924 struct lysp_deviate_rpl *rpl;
1925 struct lysp_deviate_del *del;
1926
1927 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1928 LEVEL++;
1929
Radek Krejci693262f2019-04-29 15:23:20 +02001930 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1932 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1933
1934 LY_ARRAY_FOR(deviation->deviates, u) {
1935 ly_print(ctx->out, "%*sdeviate ", INDENT);
1936 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1937 if (deviation->deviates[u].exts) {
1938 ly_print(ctx->out, "not-supported {\n");
1939 LEVEL++;
1940
Radek Krejci693262f2019-04-29 15:23:20 +02001941 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942 } else {
1943 ly_print(ctx->out, "not-supported;\n");
1944 continue;
1945 }
1946 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
1947 add = (struct lysp_deviate_add*)&deviation->deviates[u];
1948 ly_print(ctx->out, "add {\n");
1949 LEVEL++;
1950
Radek Krejci693262f2019-04-29 15:23:20 +02001951 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
1952 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001954 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001955 }
1956 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001957 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001958 }
1959 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001960 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001961 }
Radek Krejci693262f2019-04-29 15:23:20 +02001962 ypr_config(ctx, add->flags, add->exts, NULL);
1963 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001964 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001965 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001966 }
1967 if (add->flags & LYS_SET_MAX) {
1968 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001969 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001970 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001971 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001972 }
1973 }
1974 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
1975 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
1976 ly_print(ctx->out, "replace {\n");
1977 LEVEL++;
1978
Radek Krejci693262f2019-04-29 15:23:20 +02001979 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001980 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001981 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982 }
Radek Krejci693262f2019-04-29 15:23:20 +02001983 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
1984 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
1985 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1986 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001988 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989 }
1990 if (rpl->flags & LYS_SET_MAX) {
1991 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001992 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001994 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995 }
1996 }
1997 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
1998 del = (struct lysp_deviate_del*)&deviation->deviates[u];
1999 ly_print(ctx->out, "delete {\n");
2000 LEVEL++;
2001
Radek Krejci693262f2019-04-29 15:23:20 +02002002 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2003 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002005 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 }
2007 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002008 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 }
2010 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002011 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 }
2013 }
2014
2015 LEVEL--;
2016 ypr_close(ctx, 1);
2017 }
2018
2019 LEVEL--;
2020 ypr_close(ctx, 1);
2021}
2022
Radek Krejci693262f2019-04-29 15:23:20 +02002023/**
2024 * @brief Minimal print of a schema.
2025 *
2026 * To print
2027 * a) compiled schema when it is not compiled or
2028 * b) parsed when the parsed form was already removed
2029 */
2030static LY_ERR
2031ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2032{
2033 /* module-header-stmts */
2034 if (module->version) {
2035 if (module->version) {
2036 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2037 }
2038 }
2039 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2040 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2041
2042 /* meta-stmts */
2043 if (module->org || module->contact || module->dsc || module->ref) {
2044 ly_print(ctx->out, "\n");
2045 }
2046 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2047 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2048 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2049 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2050
2051 /* revision-stmts */
2052 if (module->revision) {
2053 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2054 }
2055
2056 LEVEL--;
2057 ly_print(ctx->out, "%*s}\n", INDENT);
2058 ly_print_flush(ctx->out);
2059
2060 return LY_SUCCESS;
2061}
2062
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063LY_ERR
2064yang_print_parsed(struct lyout *out, const struct lys_module *module)
2065{
2066 unsigned int u;
2067 struct lysp_node *data;
2068 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002069 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070
2071 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2072 LEVEL++;
2073
Radek Krejci693262f2019-04-29 15:23:20 +02002074 if (!modp) {
2075 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2076 return ypr_missing_format(ctx, module);
2077 }
2078
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 /* module-header-stmts */
2080 if (module->version) {
2081 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002082 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 +02002083 }
2084 }
Radek Krejci693262f2019-04-29 15:23:20 +02002085 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2086 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087
2088 /* linkage-stmts */
2089 LY_ARRAY_FOR(modp->imports, u) {
2090 ly_print(out, "\n%*simport %s {\n", INDENT, modp->imports[u].module->name);
2091 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002092 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2093 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002094 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002095 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002096 }
Radek Krejci693262f2019-04-29 15:23:20 +02002097 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2098 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002099 LEVEL--;
2100 ly_print(out, "%*s}\n", INDENT);
2101 }
2102 LY_ARRAY_FOR(modp->includes, u) {
2103 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
2104 ly_print(out, "\n%*sinclude %s {\n", INDENT, modp->includes[u].submodule->name);
2105 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002106 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002107 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002108 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002109 }
Radek Krejci693262f2019-04-29 15:23:20 +02002110 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2111 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002112 LEVEL--;
2113 ly_print(out, "%*s}\n", INDENT);
2114 } else {
2115 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2116 }
2117 }
2118
2119 /* meta-stmts */
2120 if (module->org || module->contact || module->dsc || module->ref) {
2121 ly_print(out, "\n");
2122 }
Radek Krejci693262f2019-04-29 15:23:20 +02002123 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2124 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2125 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2126 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127
2128 /* revision-stmts */
2129 if (modp->revs) {
2130 ly_print(out, "\n");
2131 }
2132 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002133 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002134 }
2135 /* body-stmts */
2136 LY_ARRAY_FOR(modp->extensions, u) {
2137 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002138 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139 }
2140 if (modp->exts) {
2141 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002142 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143 }
2144
2145 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002146 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 }
2148
2149 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002150 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002151 }
2152
2153 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002154 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 }
2156
2157 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002158 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002159 }
2160
2161 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002162 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002163 }
2164
2165 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002166 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002167 }
2168
2169 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002170 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002171 }
2172
2173 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002174 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175 }
2176
2177 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002178 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002179 }
2180
2181 LEVEL--;
2182 ly_print(out, "%*s}\n", INDENT);
2183 ly_print_flush(out);
2184
2185 return LY_SUCCESS;
2186}
2187
2188LY_ERR
2189yang_print_compiled(struct lyout *out, const struct lys_module *module)
2190{
Radek Krejci693262f2019-04-29 15:23:20 +02002191 unsigned int u;
2192 struct lysc_node *data;
2193 struct lysc_module *modc = module->compiled;
2194 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2195
2196 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2197 LEVEL++;
2198
2199 if (!modc) {
2200 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2201 return ypr_missing_format(ctx, module);
2202 }
2203
2204 /* module-header-stmts */
2205 if (module->version) {
2206 if (module->version) {
2207 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2208 }
2209 }
2210 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2211 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2212
2213 /* linkage-stmts */
2214 LY_ARRAY_FOR(modc->imports, u) {
2215 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2216 LEVEL++;
2217 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2218 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2219 if (modc->imports[u].module->revision) {
2220 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2221 }
2222 LEVEL--;
2223 ly_print(out, "%*s}\n", INDENT);
2224 }
2225
2226 /* meta-stmts */
2227 if (module->org || module->contact || module->dsc || module->ref) {
2228 ly_print(out, "\n");
2229 }
2230 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2231 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2232 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2233 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2234
2235 /* revision-stmts */
2236 if (module->revision) {
2237 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2238 }
2239
2240 /* body-stmts */
2241 if (modc->exts) {
2242 ly_print(out, "\n");
2243 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2244 }
2245
2246 LY_ARRAY_FOR(modc->features, u) {
2247 yprc_feature(ctx, &modc->features[u]);
2248 }
2249
2250 LY_ARRAY_FOR(modc->identities, u) {
2251 yprc_identity(ctx, &modc->identities[u]);
2252 }
2253
2254 LY_LIST_FOR(modc->data, data) {
2255 yprc_node(ctx, data);
2256 }
2257
2258 LY_ARRAY_FOR(modc->rpcs, u) {
2259 yprc_action(ctx, &modc->rpcs[u]);
2260 }
2261
2262 LY_ARRAY_FOR(modc->notifs, u) {
2263 yprc_notification(ctx, &modc->notifs[u]);
2264 }
2265
2266 LEVEL--;
2267 ly_print(out, "%*s}\n", INDENT);
2268 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002269
2270 return LY_SUCCESS;
2271}