blob: 88c820cf8d54317baf3ce7d7708736d05b46af31 [file] [log] [blame]
Michal Vasko85217a32015-07-07 11:40:08 +02001/**
2 * @file printer/info.c
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief INFO printer for libyang data model structure
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci54f6fb32016-02-24 12:56:39 +01008 * 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
Michal Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko85217a32015-07-07 11:40:08 +020013 */
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <string.h>
18#include <assert.h>
19
Radek Krejci998a0b82015-08-17 13:14:36 +020020#include "common.h"
Radek Krejci76b07902015-10-09 09:11:25 +020021#include "printer.h"
Michal Vasko2d162e12015-09-24 14:33:29 +020022#include "tree_schema.h"
Radek Krejci998a0b82015-08-17 13:14:36 +020023#include "resolve.h"
Michal Vasko85217a32015-07-07 11:40:08 +020024
25#define INDENT_LEN 11
26
Michal Vasko85217a32015-07-07 11:40:08 +020027static void
Radek Krejci76b07902015-10-09 09:11:25 +020028info_print_text(struct lyout *out, const char *text, const char *label)
Michal Vasko2d86ca92015-07-15 12:08:06 +020029{
30 const char *ptr1, *ptr2;
31 int first = 1;
32
Radek Krejci76b07902015-10-09 09:11:25 +020033 ly_print(out, "%-*s", INDENT_LEN, label);
Michal Vasko2d86ca92015-07-15 12:08:06 +020034
35 if (text) {
36 ptr1 = text;
37 while (1) {
38 ptr2 = strchr(ptr1, '\n');
39 if (!ptr2) {
40 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +020041 ly_print(out, "%s\n", ptr1);
Michal Vasko2d86ca92015-07-15 12:08:06 +020042 first = 0;
43 } else {
Radek Krejci76b07902015-10-09 09:11:25 +020044 ly_print(out, "%*s%s\n", INDENT_LEN, "", ptr1);
Michal Vasko2d86ca92015-07-15 12:08:06 +020045 }
46 break;
47 }
48 ++ptr2;
49 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +020050 ly_print(out, "%.*s", (int)(ptr2-ptr1), ptr1);
Michal Vasko2d86ca92015-07-15 12:08:06 +020051 first = 0;
52 } else {
Radek Krejci76b07902015-10-09 09:11:25 +020053 ly_print(out, "%*s%.*s", INDENT_LEN, "", (int)(ptr2-ptr1), ptr1);
Michal Vasko2d86ca92015-07-15 12:08:06 +020054 }
55 ptr1 = ptr2;
56 }
57 }
58
59 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +020060 ly_print(out, "\n");
Michal Vasko2d86ca92015-07-15 12:08:06 +020061 }
62}
63
64static void
Michal Vasko1e62a092015-12-01 12:27:20 +010065info_print_snode(struct lyout *out, const struct lys_node *parent, const struct lys_node *node, const char *label)
Michal Vasko85217a32015-07-07 11:40:08 +020066{
67 assert(strlen(label) < INDENT_LEN-1);
68
Radek Krejci76b07902015-10-09 09:11:25 +020069 ly_print(out, "%-*s", INDENT_LEN, label);
Michal Vasko85217a32015-07-07 11:40:08 +020070
Radek Krejci1d82ef62015-08-07 14:44:40 +020071 if (node) {
72 if (node->name) {
Radek Krejci76b07902015-10-09 09:11:25 +020073 ly_print(out, "%s \"", strnodetype(node->nodetype));
Michal Vaskodcf98e62016-05-05 17:53:53 +020074 if (parent != lys_parent(node)) {
Radek Krejci76b07902015-10-09 09:11:25 +020075 ly_print(out, "%s:", node->module->prefix);
Michal Vasko93df9ea2015-08-06 11:32:21 +020076 }
Radek Krejci76b07902015-10-09 09:11:25 +020077 ly_print(out, "%s\"\n", node->name);
Michal Vasko85217a32015-07-07 11:40:08 +020078 } else {
Radek Krejci76b07902015-10-09 09:11:25 +020079 ly_print(out, "%s\n", (node->nodetype == LYS_INPUT ? "input" : "output"));
Michal Vasko85217a32015-07-07 11:40:08 +020080 }
Radek Krejci1d82ef62015-08-07 14:44:40 +020081 node = node->next;
82 for (; node; node = node->next) {
83 if (node->name) {
Radek Krejci76b07902015-10-09 09:11:25 +020084 ly_print(out, "%*s%s \"", INDENT_LEN, "", strnodetype(node->nodetype));
Michal Vaskodcf98e62016-05-05 17:53:53 +020085 if (parent != lys_parent(node)) {
Radek Krejci76b07902015-10-09 09:11:25 +020086 ly_print(out, "%s:", node->module->prefix);
Michal Vasko93df9ea2015-08-06 11:32:21 +020087 }
Radek Krejci76b07902015-10-09 09:11:25 +020088 ly_print(out, "%s\"\n", node->name);
Michal Vasko85217a32015-07-07 11:40:08 +020089 } else {
Radek Krejci76b07902015-10-09 09:11:25 +020090 ly_print(out, "%*s%s\n", INDENT_LEN, "", (node->nodetype == LYS_INPUT ? "input" : "output"));
Michal Vasko85217a32015-07-07 11:40:08 +020091 }
92 }
93 } else {
Radek Krejci76b07902015-10-09 09:11:25 +020094 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +020095 }
96}
97
98static void
Radek Krejci4372b4e2016-04-14 17:42:16 +020099info_print_flags(struct lyout *out, uint16_t flags, uint16_t mask, int is_list)
Michal Vasko85217a32015-07-07 11:40:08 +0200100{
Radek Krejci1574a8d2015-08-03 14:16:52 +0200101 if (mask & LYS_CONFIG_MASK) {
Radek Krejci76b07902015-10-09 09:11:25 +0200102 ly_print(out, "%-*s", INDENT_LEN, "Config: ");
Radek Krejci1574a8d2015-08-03 14:16:52 +0200103 if (flags & LYS_CONFIG_R) {
Radek Krejci76b07902015-10-09 09:11:25 +0200104 ly_print(out, "read-only\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200105 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200106 ly_print(out, "read-write\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200107 }
Michal Vasko85217a32015-07-07 11:40:08 +0200108 }
109
Radek Krejci1574a8d2015-08-03 14:16:52 +0200110 if (mask & LYS_STATUS_MASK) {
Radek Krejci76b07902015-10-09 09:11:25 +0200111 ly_print(out, "%-*s", INDENT_LEN, "Status: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200112
Radek Krejci1574a8d2015-08-03 14:16:52 +0200113 if (flags & LYS_STATUS_DEPRC) {
Radek Krejci76b07902015-10-09 09:11:25 +0200114 ly_print(out, "deprecated\n");
Radek Krejci1574a8d2015-08-03 14:16:52 +0200115 } else if (flags & LYS_STATUS_OBSLT) {
Radek Krejci76b07902015-10-09 09:11:25 +0200116 ly_print(out, "obsolete\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200117 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200118 ly_print(out, "current\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200119 }
Michal Vasko85217a32015-07-07 11:40:08 +0200120 }
121
Radek Krejci1574a8d2015-08-03 14:16:52 +0200122 if (mask & LYS_MAND_MASK) {
Radek Krejci76b07902015-10-09 09:11:25 +0200123 ly_print(out, "%-*s", INDENT_LEN, "Mandatory: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200124
Radek Krejci1574a8d2015-08-03 14:16:52 +0200125 if (flags & LYS_MAND_TRUE) {
Radek Krejci76b07902015-10-09 09:11:25 +0200126 ly_print(out, "yes\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200127 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200128 ly_print(out, "no\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200129 }
Michal Vasko85217a32015-07-07 11:40:08 +0200130 }
131
Radek Krejci1574a8d2015-08-03 14:16:52 +0200132 if (is_list && (mask & LYS_USERORDERED)) {
Radek Krejci76b07902015-10-09 09:11:25 +0200133 ly_print(out, "%-*s", INDENT_LEN, "Order: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200134
Radek Krejci1574a8d2015-08-03 14:16:52 +0200135 if (flags & LYS_USERORDERED) {
Radek Krejci76b07902015-10-09 09:11:25 +0200136 ly_print(out, "user-ordered\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200137 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200138 ly_print(out, "system-ordered\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200139 }
Michal Vasko85217a32015-07-07 11:40:08 +0200140 }
141
Radek Krejci1574a8d2015-08-03 14:16:52 +0200142 if (!is_list && (mask & LYS_FENABLED)) {
Radek Krejci76b07902015-10-09 09:11:25 +0200143 ly_print(out, "%-*s", INDENT_LEN, "Enabled: ");
Michal Vasko46bcb1e2015-07-15 12:09:57 +0200144
Radek Krejci1574a8d2015-08-03 14:16:52 +0200145 if (flags & LYS_FENABLED) {
Radek Krejci76b07902015-10-09 09:11:25 +0200146 ly_print(out, "yes\n");
Michal Vasko46bcb1e2015-07-15 12:09:57 +0200147 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200148 ly_print(out, "no\n");
Michal Vasko46bcb1e2015-07-15 12:09:57 +0200149 }
Michal Vasko85217a32015-07-07 11:40:08 +0200150 }
151}
152
153static void
Radek Krejci9ff0a922016-07-14 13:08:05 +0200154info_print_if_feature(struct lyout *out, const struct lys_module *module,
155 struct lys_iffeature *iffeature, uint8_t iffeature_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200156{
157 int i;
158
Radek Krejci76b07902015-10-09 09:11:25 +0200159 ly_print(out, "%-*s", INDENT_LEN, "If-feats: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200160
Michal Vaskoc5c26b02016-06-29 11:10:29 +0200161 if (iffeature_size) {
Radek Krejci9ff0a922016-07-14 13:08:05 +0200162 ly_print_iffeature(out, module, &iffeature[0]);
163 ly_print(out, "\n");
Michal Vaskoc5c26b02016-06-29 11:10:29 +0200164 for (i = 1; i < iffeature_size; ++i) {
Radek Krejci9ff0a922016-07-14 13:08:05 +0200165 ly_print(out, "%*s", INDENT_LEN, "");
166 ly_print_iffeature(out, module, &iffeature[i]);
167 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200168 }
169 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200170 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200171 }
172}
173
174static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100175info_print_when(struct lyout *out, const struct lys_when *when)
Michal Vasko85217a32015-07-07 11:40:08 +0200176{
Radek Krejci76b07902015-10-09 09:11:25 +0200177 ly_print(out, "%-*s", INDENT_LEN, "When: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200178 if (when) {
Radek Krejci76b07902015-10-09 09:11:25 +0200179 ly_print(out, "%s\n", when->cond);
Michal Vasko85217a32015-07-07 11:40:08 +0200180 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200181 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200182 }
183}
184
185static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100186info_print_must(struct lyout *out, const struct lys_restr *must, uint8_t must_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200187{
188 int i;
189
Radek Krejci76b07902015-10-09 09:11:25 +0200190 ly_print(out, "%-*s", INDENT_LEN, "Must: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200191
192 if (must_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200193 ly_print(out, "%s\n", must[0].expr);
Michal Vasko85217a32015-07-07 11:40:08 +0200194 for (i = 1; i < must_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200195 ly_print(out, "%*s%s\n", INDENT_LEN, "", must[i].expr);
Michal Vasko85217a32015-07-07 11:40:08 +0200196 }
197 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200198 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200199 }
200}
201
202static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100203info_print_typedef(struct lyout *out, const struct lys_tpdf *tpdf, uint8_t tpdf_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200204{
205 int i;
206
Radek Krejci76b07902015-10-09 09:11:25 +0200207 ly_print(out, "%-*s", INDENT_LEN, "Typedefs: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200208
209 if (tpdf_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200210 ly_print(out, "%s\n", tpdf[0].name);
Michal Vasko593695e2015-07-15 10:44:52 +0200211 for (i = 1; i < tpdf_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200212 ly_print(out, "%*s%s", INDENT_LEN, "", tpdf[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200213 }
214 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200215 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200216 }
217}
218
219static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100220info_print_typedef_with_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200221{
Michal Vasko10e80972015-07-24 12:02:14 +0200222 int i, j, first = 1;
223
Radek Krejci76b07902015-10-09 09:11:25 +0200224 ly_print(out, "%-*s", INDENT_LEN, "Typedefs: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200225
226 if (mod->tpdf_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200227 ly_print(out, "%s\n", mod->tpdf[0].name);
Michal Vasko10e80972015-07-24 12:02:14 +0200228 first = 0;
Michal Vasko85217a32015-07-07 11:40:08 +0200229
Radek Krejci24a05b02015-08-13 10:03:46 +0200230 for (i = 1; i < mod->tpdf_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200231 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->tpdf[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200232 }
233 }
234
235 for (i = 0; i < mod->inc_size; ++i) {
Michal Vasko10e80972015-07-24 12:02:14 +0200236 if (mod->inc[i].submodule->tpdf_size) {
237 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200238 ly_print(out, "%s\n", mod->inc[i].submodule->tpdf[0].name);
Michal Vasko10e80972015-07-24 12:02:14 +0200239 j = 1;
240 } else {
241 j = 0;
242 }
243 first = 0;
244
245 for (; j < mod->inc[i].submodule->tpdf_size; ++j) {
Radek Krejci76b07902015-10-09 09:11:25 +0200246 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->inc[i].submodule->tpdf[j].name);
Michal Vasko10e80972015-07-24 12:02:14 +0200247 }
248 }
Michal Vasko85217a32015-07-07 11:40:08 +0200249 }
Michal Vasko85217a32015-07-07 11:40:08 +0200250
251 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200252 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200253 }
254}
255
256static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100257info_print_type_detail(struct lyout *out, const struct lys_type *type, int uni)
Michal Vasko85217a32015-07-07 11:40:08 +0200258{
Michal Vasko7df7f142015-07-15 12:10:53 +0200259 int i;
260
Michal Vasko2e74dc32015-08-04 08:58:34 +0200261 if (uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200262 ly_print(out, " ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200263 }
264
Michal Vasko7df7f142015-07-15 12:10:53 +0200265 switch (type->base) {
266 case LY_TYPE_DER:
Radek Krejci25b9fd32015-08-10 15:06:07 +0200267 /* unused, but what the hack */
Radek Krejci76b07902015-10-09 09:11:25 +0200268 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "derived");
Michal Vasko7df7f142015-07-15 12:10:53 +0200269 break;
270 case LY_TYPE_BINARY:
Radek Krejci76b07902015-10-09 09:11:25 +0200271 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "binary");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200272 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200273 info_print_text(out, (type->info.binary.length ? type->info.binary.length->expr : NULL), "Length: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200274 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200275 break;
276 case LY_TYPE_BITS:
Radek Krejci76b07902015-10-09 09:11:25 +0200277 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "bits");
Michal Vasko7df7f142015-07-15 12:10:53 +0200278
279 assert(type->info.bits.count);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200280 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200281 ly_print(out, "%-*s%u %s\n", INDENT_LEN, "Bits: ", type->info.bits.bit[0].pos, type->info.bits.bit[0].name);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200282 for (i = 1; i < type->info.bits.count; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200283 ly_print(out, "%*s%u %s\n", INDENT_LEN, "", type->info.bits.bit[i].pos, type->info.bits.bit[i].name);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200284 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200285 }
286
287 break;
288 case LY_TYPE_BOOL:
Radek Krejci8c2f1782016-06-24 11:21:57 +0200289 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "boolean");
Michal Vasko7df7f142015-07-15 12:10:53 +0200290 break;
291 case LY_TYPE_DEC64:
Radek Krejci76b07902015-10-09 09:11:25 +0200292 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "decimal64");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200293 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200294 info_print_text(out, (type->info.dec64.range ? type->info.dec64.range->expr : NULL), "Range: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200295 assert(type->info.dec64.dig);
Radek Krejci76b07902015-10-09 09:11:25 +0200296 ly_print(out, "%-*s%u\n", INDENT_LEN, "Frac dig: ", type->info.dec64.dig);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200297 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200298 break;
299 case LY_TYPE_EMPTY:
Radek Krejci76b07902015-10-09 09:11:25 +0200300 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "empty");
Michal Vasko7df7f142015-07-15 12:10:53 +0200301 break;
302 case LY_TYPE_ENUM:
Radek Krejci8c2f1782016-06-24 11:21:57 +0200303 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "enumeration");
Michal Vasko7df7f142015-07-15 12:10:53 +0200304
305 assert(type->info.enums.count);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200306 if (!uni) {
Radek Krejcifc8d5392016-06-24 11:22:44 +0200307 ly_print(out, "%-*s%s (%d)\n", INDENT_LEN, "Values: ",
308 type->info.enums.enm[0].name, type->info.enums.enm[0].value);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200309 for (i = 1; i < type->info.enums.count; ++i) {
Radek Krejcifc8d5392016-06-24 11:22:44 +0200310 ly_print(out, "%*s%s (%d)\n", INDENT_LEN, "",
311 type->info.enums.enm[i].name, type->info.enums.enm[i].value);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200312 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200313 }
314
315 break;
316 case LY_TYPE_IDENT:
Radek Krejci76b07902015-10-09 09:11:25 +0200317 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "identityref");
Michal Vasko7df7f142015-07-15 12:10:53 +0200318 assert(type->info.ident.ref);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200319 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200320 info_print_text(out, type->info.ident.ref->name, "Identity: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200321 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200322 break;
323 case LY_TYPE_INST:
Radek Krejci76b07902015-10-09 09:11:25 +0200324 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "instance-identifier");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200325 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200326 ly_print(out, "%-*s%s\n", INDENT_LEN, "Required: ", (type->info.inst.req < 1 ? "no" : "yes"));
Michal Vasko2e74dc32015-08-04 08:58:34 +0200327 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200328 break;
329 case LY_TYPE_INT8:
Radek Krejci76b07902015-10-09 09:11:25 +0200330 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "int8");
Michal Vasko7df7f142015-07-15 12:10:53 +0200331 goto int_range;
332 case LY_TYPE_INT16:
Radek Krejci76b07902015-10-09 09:11:25 +0200333 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "int16");
Michal Vasko7df7f142015-07-15 12:10:53 +0200334 goto int_range;
335 case LY_TYPE_INT32:
Radek Krejci76b07902015-10-09 09:11:25 +0200336 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "int32");
Michal Vasko7df7f142015-07-15 12:10:53 +0200337 goto int_range;
338 case LY_TYPE_INT64:
Radek Krejci76b07902015-10-09 09:11:25 +0200339 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "int64");
Michal Vasko7df7f142015-07-15 12:10:53 +0200340 goto int_range;
341 case LY_TYPE_UINT8:
Radek Krejci76b07902015-10-09 09:11:25 +0200342 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "uint8");
Michal Vasko7df7f142015-07-15 12:10:53 +0200343 goto int_range;
344 case LY_TYPE_UINT16:
Radek Krejci76b07902015-10-09 09:11:25 +0200345 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "uint16");
Michal Vasko7df7f142015-07-15 12:10:53 +0200346 goto int_range;
347 case LY_TYPE_UINT32:
Radek Krejci76b07902015-10-09 09:11:25 +0200348 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "uint32");
Michal Vasko7df7f142015-07-15 12:10:53 +0200349 goto int_range;
350 case LY_TYPE_UINT64:
Radek Krejci76b07902015-10-09 09:11:25 +0200351 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "uint64");
Michal Vasko7df7f142015-07-15 12:10:53 +0200352
353int_range:
Michal Vasko2e74dc32015-08-04 08:58:34 +0200354 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200355 info_print_text(out, (type->info.num.range ? type->info.num.range->expr : NULL), "Range: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200356 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200357 break;
358 case LY_TYPE_LEAFREF:
Radek Krejci76b07902015-10-09 09:11:25 +0200359 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "leafref");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200360 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200361 info_print_text(out, type->info.lref.path, "Path: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200362 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200363 break;
364 case LY_TYPE_STRING:
Radek Krejci76b07902015-10-09 09:11:25 +0200365 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "string");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200366 if (!uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200367 info_print_text(out, (type->info.str.length ? type->info.str.length->expr : NULL), "Length: ");
Michal Vasko7df7f142015-07-15 12:10:53 +0200368
Radek Krejci76b07902015-10-09 09:11:25 +0200369 ly_print(out, "%-*s", INDENT_LEN, "Pattern: ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200370 if (type->info.str.pat_count) {
Radek Krejci76b07902015-10-09 09:11:25 +0200371 ly_print(out, "%s\n", type->info.str.patterns[0].expr);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200372 for (i = 1; i < type->info.str.pat_count; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200373 ly_print(out, "%*s%s\n", INDENT_LEN, "", type->info.str.patterns[i].expr);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200374 }
375 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200376 ly_print(out, "\n");
Michal Vasko7df7f142015-07-15 12:10:53 +0200377 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200378 }
379
380 break;
381 case LY_TYPE_UNION:
Radek Krejci76b07902015-10-09 09:11:25 +0200382 ly_print(out, "%-*s%s\n", INDENT_LEN, "Base type: ", "union");
Michal Vasko7df7f142015-07-15 12:10:53 +0200383
Michal Vasko2e74dc32015-08-04 08:58:34 +0200384 if (!uni) {
385 for (i = 0; i < type->info.uni.count; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200386 info_print_type_detail(out, &type->info.uni.types[i], 1);
Michal Vasko2e74dc32015-08-04 08:58:34 +0200387 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200388 }
Michal Vasko7df7f142015-07-15 12:10:53 +0200389 break;
Michal Vasko85217a32015-07-07 11:40:08 +0200390 }
391
Michal Vasko2e74dc32015-08-04 08:58:34 +0200392 if (uni) {
Radek Krejci76b07902015-10-09 09:11:25 +0200393 ly_print(out, " ");
Michal Vasko2e74dc32015-08-04 08:58:34 +0200394 }
Radek Krejci76b07902015-10-09 09:11:25 +0200395 ly_print(out, "%-*s", INDENT_LEN, "Superior: ");
Michal Vasko7df7f142015-07-15 12:10:53 +0200396 if (type->der) {
Michal Vasko1dca6882015-10-22 14:29:42 +0200397 if (type->module_name) {
398 ly_print(out, "%s:", type->module_name);
Michal Vasko7df7f142015-07-15 12:10:53 +0200399 }
Radek Krejci76b07902015-10-09 09:11:25 +0200400 ly_print(out, "%s\n", type->der->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200401 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200402 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200403 }
404}
405
406static void
Radek Krejci76b07902015-10-09 09:11:25 +0200407info_print_list_constr(struct lyout *out, uint32_t min, uint32_t max)
Michal Vasko85217a32015-07-07 11:40:08 +0200408{
Radek Krejci76b07902015-10-09 09:11:25 +0200409 ly_print(out, "%-*s%u..", INDENT_LEN, "Elements: ", min);
Michal Vasko85217a32015-07-07 11:40:08 +0200410 if (max) {
Radek Krejci76b07902015-10-09 09:11:25 +0200411 ly_print(out, "%u\n", max);
Michal Vasko85217a32015-07-07 11:40:08 +0200412 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200413 ly_print(out, "unbounded\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200414 }
415}
416
417static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100418info_print_keys(struct lyout *out, struct lys_node_leaf ** const keys, uint8_t keys_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200419{
420 int i;
421
Radek Krejci76b07902015-10-09 09:11:25 +0200422 ly_print(out, "%-*s", INDENT_LEN, "Keys: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200423
424 if (keys_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200425 ly_print(out, "%s\n", keys[0]->name);
Michal Vasko593695e2015-07-15 10:44:52 +0200426 for (i = 1; i < keys_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200427 ly_print(out, "%*s%s\n", INDENT_LEN, "", keys[i]->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200428 }
429 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200430 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200431 }
432}
433
434static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100435info_print_unique(struct lyout *out, const struct lys_unique *unique, uint8_t unique_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200436{
437 int i, j;
438
Radek Krejci76b07902015-10-09 09:11:25 +0200439 ly_print(out, "%-*s", INDENT_LEN, "Unique: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200440
441 if (unique_size) {
Radek Krejci581ce772015-11-10 17:22:40 +0100442 ly_print(out, "%s\n", unique[0].expr[0]);
Michal Vasko85217a32015-07-07 11:40:08 +0200443 for (i = 0; i < unique_size; ++i) {
Radek Krejci581ce772015-11-10 17:22:40 +0100444 for (j = (!i ? 1 : 0); j < unique[i].expr_size; ++j) {
445 ly_print(out, "%*s%s\n", INDENT_LEN, "", unique[i].expr[j]);
Michal Vasko85217a32015-07-07 11:40:08 +0200446 }
447 }
448 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200449 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200450 }
451}
452
453static void
Radek Krejci76b07902015-10-09 09:11:25 +0200454info_print_nacmext(struct lyout *out, uint8_t nacm)
Michal Vaskoc96eaf02015-07-08 11:30:15 +0200455{
Radek Krejci76b07902015-10-09 09:11:25 +0200456 ly_print(out, "%-*s", INDENT_LEN, "NACM: ");
Michal Vaskoc96eaf02015-07-08 11:30:15 +0200457
458 if (nacm) {
Radek Krejci1574a8d2015-08-03 14:16:52 +0200459 if (nacm & LYS_NACM_DENYW) {
Radek Krejci76b07902015-10-09 09:11:25 +0200460 ly_print(out, "default-deny-write\n");
Radek Krejci1574a8d2015-08-03 14:16:52 +0200461 } else if (nacm & LYS_NACM_DENYA) {
Radek Krejci76b07902015-10-09 09:11:25 +0200462 ly_print(out, "default-deny-all\n");
Michal Vaskoc96eaf02015-07-08 11:30:15 +0200463 }
464 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200465 ly_print(out, "\n");
Michal Vaskoc96eaf02015-07-08 11:30:15 +0200466 }
467}
468
469static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100470info_print_revision(struct lyout *out, const struct lys_revision *rev, uint8_t rev_size)
Michal Vasko85217a32015-07-07 11:40:08 +0200471{
472 int i;
473
Radek Krejci76b07902015-10-09 09:11:25 +0200474 ly_print(out, "%-*s", INDENT_LEN, "Revisions: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200475
476 if (rev_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200477 ly_print(out, "%s\n", rev[0].date);
Michal Vasko593695e2015-07-15 10:44:52 +0200478 for (i = 1; i < rev_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200479 ly_print(out, "%*s%s\n", INDENT_LEN, "", rev[i].date);
Michal Vasko85217a32015-07-07 11:40:08 +0200480 }
481 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200482 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200483 }
484}
485
486static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100487info_print_import_with_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200488{
489 int first = 1, i, j;
490
Radek Krejci76b07902015-10-09 09:11:25 +0200491 ly_print(out, "%-*s", INDENT_LEN, "Imports: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200492 if (mod->imp_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200493 ly_print(out, "%s:%s\n", mod->imp[0].prefix, mod->imp[0].module->name);
Michal Vasko101e00d2015-07-08 10:08:27 +0200494 i = 1;
Michal Vasko85217a32015-07-07 11:40:08 +0200495 first = 0;
496
497 for (; i < mod->imp_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200498 ly_print(out, "%*s%s:%s\n", INDENT_LEN, "", mod->imp[i].prefix, mod->imp[i].module->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200499 }
500 }
501
502 for (j = 0; j < mod->inc_size; ++j) {
503 if (mod->inc[j].submodule->imp_size) {
504 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200505 ly_print(out, "%s:%s\n",
Michal Vasko192baa52015-07-14 15:52:00 +0200506 mod->inc[j].submodule->imp[0].prefix, mod->inc[j].submodule->imp[0].module->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200507 i = 1;
508 } else {
509 i = 0;
510 }
511 first = 0;
512
513 for (; i < mod->inc[j].submodule->imp_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200514 ly_print(out, "%*s%s:%s\n", INDENT_LEN, "",
Michal Vasko192baa52015-07-14 15:52:00 +0200515 mod->inc[j].submodule->imp[i].prefix, mod->inc[j].submodule->imp[i].module->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200516 }
517 }
518 }
519
520 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200521 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200522 }
523}
524
525static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100526info_print_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200527{
528 int first = 1, i;
529
Radek Krejci76b07902015-10-09 09:11:25 +0200530 ly_print(out, "%-*s", INDENT_LEN, "Includes: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200531 if (mod->inc_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200532 ly_print(out, "%s\n", mod->inc[0].submodule->name);
Michal Vasko101e00d2015-07-08 10:08:27 +0200533 i = 1;
Michal Vasko85217a32015-07-07 11:40:08 +0200534 first = 0;
535
536 for (; i < mod->inc_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200537 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->inc[i].submodule->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200538 }
539 }
540
541 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200542 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200543 }
544}
545
546static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100547info_print_augment(struct lyout *out, const struct lys_module *mod)
Michal Vaskoe00908c2015-07-14 15:52:45 +0200548{
549 int first = 1, i;
550
Radek Krejci76b07902015-10-09 09:11:25 +0200551 ly_print(out, "%-*s", INDENT_LEN, "Augments: ");
Michal Vaskoe00908c2015-07-14 15:52:45 +0200552 if (mod->augment_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200553 ly_print(out, "\"%s\"\n", mod->augment[0].target_name);
Michal Vaskoe00908c2015-07-14 15:52:45 +0200554 i = 1;
555 first = 0;
556
557 for (; i < mod->augment_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200558 ly_print(out, "%*s\"%s\"\n", INDENT_LEN, "", mod->augment[i].target_name);
Michal Vaskoe00908c2015-07-14 15:52:45 +0200559 }
560 }
561
562 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200563 ly_print(out, "\n");
Michal Vaskoe00908c2015-07-14 15:52:45 +0200564 }
565}
566
567static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100568info_print_deviation(struct lyout *out, const struct lys_module *mod)
Michal Vaskoe00908c2015-07-14 15:52:45 +0200569{
570 int first = 1, i;
571
Radek Krejci76b07902015-10-09 09:11:25 +0200572 ly_print(out, "%-*s", INDENT_LEN, "Deviation: ");
Michal Vaskoe00908c2015-07-14 15:52:45 +0200573 if (mod->deviation_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200574 ly_print(out, "\"%s\"\n", mod->deviation[0].target_name);
Michal Vaskoe00908c2015-07-14 15:52:45 +0200575 i = 1;
576 first = 0;
577
578 for (; i < mod->deviation_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200579 ly_print(out, "%*s\"%s\"\n", INDENT_LEN, "", mod->deviation[i].target_name);
Michal Vaskoe00908c2015-07-14 15:52:45 +0200580 }
581 }
582
583 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200584 ly_print(out, "\n");
Michal Vaskoe00908c2015-07-14 15:52:45 +0200585 }
586}
587
588static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100589info_print_ident_with_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200590{
591 int first = 1, i, j;
592
Radek Krejci76b07902015-10-09 09:11:25 +0200593 ly_print(out, "%-*s", INDENT_LEN, "Idents: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200594 if (mod->ident_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200595 ly_print(out, "%s\n", mod->ident[0].name);
Michal Vasko101e00d2015-07-08 10:08:27 +0200596 i = 1;
Michal Vasko85217a32015-07-07 11:40:08 +0200597 first = 0;
598
599 for (; i < (signed)mod->ident_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200600 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->ident[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200601 }
602 }
603
604 for (j = 0; j < mod->inc_size; ++j) {
605 if (mod->inc[j].submodule->ident_size) {
606 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200607 ly_print(out, "%s\n", mod->inc[j].submodule->ident[0].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200608 i = 1;
609 } else {
610 i = 0;
611 }
612 first = 0;
613
614 for (; i < (signed)mod->inc[j].submodule->ident_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200615 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->inc[j].submodule->ident[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200616 }
617 }
618 }
619
620 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200621 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200622 }
623}
624
625static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100626info_print_features_with_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200627{
628 int first = 1, i, j;
629
Radek Krejci76b07902015-10-09 09:11:25 +0200630 ly_print(out, "%-*s", INDENT_LEN, "Features: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200631 if (mod->features_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200632 ly_print(out, "%s\n", mod->features[0].name);
Michal Vasko101e00d2015-07-08 10:08:27 +0200633 i = 1;
Michal Vasko85217a32015-07-07 11:40:08 +0200634 first = 0;
635
636 for (; i < mod->features_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200637 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->features[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200638 }
639 }
640
641 for (j = 0; j < mod->inc_size; ++j) {
642 if (mod->inc[j].submodule->features_size) {
643 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200644 ly_print(out, "%s\n", mod->inc[j].submodule->features[0].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200645 i = 1;
646 } else {
647 i = 0;
648 }
649 first = 0;
650
651 for (; i < mod->inc[j].submodule->features_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200652 ly_print(out, "%*s%s\n", INDENT_LEN, "", mod->inc[j].submodule->features[i].name);
Michal Vasko85217a32015-07-07 11:40:08 +0200653 }
654 }
655 }
656
657 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200658 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200659 }
660}
661
662static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100663info_print_data_with_include(struct lyout *out, const struct lys_module *mod)
Michal Vasko85217a32015-07-07 11:40:08 +0200664
Michal Vasko85217a32015-07-07 11:40:08 +0200665{
Radek Krejcic071c542016-01-27 14:57:51 +0100666 int first = 1;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200667 struct lys_node *node;
Michal Vasko85217a32015-07-07 11:40:08 +0200668
Radek Krejci76b07902015-10-09 09:11:25 +0200669 ly_print(out, "%-*s", INDENT_LEN, "Data: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200670
671 if (mod->data) {
Radek Krejci76b07902015-10-09 09:11:25 +0200672 ly_print(out, "%s \"%s\"\n", strnodetype(mod->data->nodetype), mod->data->name);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200673 node = mod->data->next;
Michal Vasko85217a32015-07-07 11:40:08 +0200674 first = 0;
675
Radek Krejci1d82ef62015-08-07 14:44:40 +0200676 for (; node; node = node->next) {
Radek Krejci76b07902015-10-09 09:11:25 +0200677 ly_print(out, "%*s%s \"%s\"\n", INDENT_LEN, "", strnodetype(node->nodetype), node->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200678 }
679 }
680
Michal Vasko85217a32015-07-07 11:40:08 +0200681 if (first) {
Radek Krejci76b07902015-10-09 09:11:25 +0200682 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200683 }
684}
685
686static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100687info_print_typedef_detail(struct lyout *outf, const struct lys_tpdf *tpdf)
Michal Vasko7df7f142015-07-15 12:10:53 +0200688{
Radek Krejci76b07902015-10-09 09:11:25 +0200689 ly_print(outf, "%-*s%s\n", INDENT_LEN, "Typedef: ", tpdf->name);
690 ly_print(outf, "%-*s%s\n", INDENT_LEN, "Module: ", tpdf->module->name);
691 info_print_text(outf, tpdf->dsc, "Desc: ");
692 info_print_text(outf, tpdf->ref, "Reference: ");
693 info_print_flags(outf, tpdf->flags, LYS_STATUS_MASK, 0);
694 info_print_type_detail(outf, &tpdf->type, 0);
695 info_print_text(outf, tpdf->units, "Units: ");
696 info_print_text(outf, tpdf->dflt, "Default: ");
Michal Vasko7df7f142015-07-15 12:10:53 +0200697}
698
699static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100700info_print_ident_detail(struct lyout *out, const struct lys_ident *ident)
Michal Vasko7df7f142015-07-15 12:10:53 +0200701{
Radek Krejci1b61d0e2016-04-15 13:55:44 +0200702 int i;
Michal Vasko7df7f142015-07-15 12:10:53 +0200703
Radek Krejci76b07902015-10-09 09:11:25 +0200704 ly_print(out, "%-*s%s\n", INDENT_LEN, "Identity: ", ident->name);
705 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", ident->module->name);
706 info_print_text(out, ident->dsc, "Desc: ");
707 info_print_text(out, ident->ref, "Reference: ");
708 info_print_flags(out, ident->flags, LYS_STATUS_MASK, 0);
709 info_print_text(out, (ident->base ? ident->base->name : NULL), "Base: ");
Michal Vasko7df7f142015-07-15 12:10:53 +0200710
Radek Krejci76b07902015-10-09 09:11:25 +0200711 ly_print(out, "%-*s", INDENT_LEN, "Derived: ");
Michal Vasko7df7f142015-07-15 12:10:53 +0200712 if (ident->der) {
Radek Krejci1b61d0e2016-04-15 13:55:44 +0200713 for (i = 0; ident->der[i]; i++) {
714 ly_print(out, "%*s%s\n", i ? INDENT_LEN : 0, "", ident->der[i]->name);
Michal Vasko7df7f142015-07-15 12:10:53 +0200715 }
716 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200717 ly_print(out, "\n");
Michal Vasko7df7f142015-07-15 12:10:53 +0200718 }
719}
720
721static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100722info_print_feature_detail(struct lyout *out, const struct lys_feature *feat)
Michal Vasko7df7f142015-07-15 12:10:53 +0200723{
Radek Krejci76b07902015-10-09 09:11:25 +0200724 ly_print(out, "%-*s%s\n", INDENT_LEN, "Feature: ", feat->name);
725 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", feat->module->name);
726 info_print_text(out, feat->dsc, "Desc: ");
727 info_print_text(out, feat->ref, "Reference: ");
728 info_print_flags(out, feat->flags, LYS_STATUS_MASK | LYS_FENABLED, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200729 info_print_if_feature(out, feat->module, feat->iffeature, feat->iffeature_size);
Michal Vasko7df7f142015-07-15 12:10:53 +0200730}
731
732static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100733info_print_module(struct lyout *out, const struct lys_module *module)
Michal Vasko85217a32015-07-07 11:40:08 +0200734{
Radek Krejci76b07902015-10-09 09:11:25 +0200735 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", module->name);
736 ly_print(out, "%-*s%s\n", INDENT_LEN, "Namespace: ", module->ns);
737 ly_print(out, "%-*s%s\n", INDENT_LEN, "Prefix: ", module->prefix);
738 info_print_text(out, module->dsc, "Desc: ");
739 info_print_text(out, module->ref, "Reference: ");
740 info_print_text(out, module->org, "Org: ");
741 info_print_text(out, module->contact, "Contact: ");
742 ly_print(out, "%-*s%s\n", INDENT_LEN, "YANG ver: ", (module->version == 2 ? "1.1" : "1.0"));
743 ly_print(out, "%-*s%s\n", INDENT_LEN, "Deviated: ", (module->deviated ? "yes" : "no"));
744 ly_print(out, "%-*s%s\n", INDENT_LEN, "Implement: ", (module->implemented ? "yes" : "no"));
Radek Krejcia77904e2016-02-25 16:23:45 +0100745 info_print_text(out, module->filepath, "URI: file://");
Michal Vasko85217a32015-07-07 11:40:08 +0200746
Radek Krejci76b07902015-10-09 09:11:25 +0200747 info_print_revision(out, module->rev, module->rev_size);
748 info_print_include(out, module);
749 info_print_import_with_include(out, module);
750 info_print_typedef_with_include(out, module);
751 info_print_ident_with_include(out, module);
752 info_print_features_with_include(out, module);
753 info_print_augment(out, module);
754 info_print_deviation(out, module);
Michal Vasko85217a32015-07-07 11:40:08 +0200755
Radek Krejcibac81762015-10-09 10:19:52 +0200756 info_print_data_with_include(out, module);
Michal Vasko85217a32015-07-07 11:40:08 +0200757}
758
759static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100760info_print_submodule(struct lyout *out, const struct lys_submodule *module)
Michal Vasko85217a32015-07-07 11:40:08 +0200761{
Radek Krejci76b07902015-10-09 09:11:25 +0200762 ly_print(out, "%-*s%s\n", INDENT_LEN, "Submodule: ", module->name);
763 ly_print(out, "%-*s%s\n", INDENT_LEN, "Parent: ", module->belongsto->name);
764 ly_print(out, "%-*s%s\n", INDENT_LEN, "Prefix: ", module->prefix);
765 info_print_text(out, module->dsc, "Desc: ");
766 info_print_text(out, module->ref, "Reference: ");
767 info_print_text(out, module->org, "Org: ");
768 info_print_text(out, module->contact, "Contact: ");
Radek Krejcic071c542016-01-27 14:57:51 +0100769
770 /* inherited from main module */
771 ly_print(out, "%-*s%s\n", INDENT_LEN, "YANG ver: ", (module->belongsto->version == 2 ? "1.1" : "1.0"));
772 ly_print(out, "%-*s%s\n", INDENT_LEN, "Deviated: ", (module->belongsto->deviated ? "yes" : "no"));
773 ly_print(out, "%-*s%s\n", INDENT_LEN, "Implement: ", (module->belongsto->implemented ? "yes" : "no"));
774
Radek Krejcia77904e2016-02-25 16:23:45 +0100775 info_print_text(out, module->filepath, "URI: file://");
Michal Vasko85217a32015-07-07 11:40:08 +0200776
Radek Krejci76b07902015-10-09 09:11:25 +0200777 info_print_revision(out, module->rev, module->rev_size);
778 info_print_include(out, (struct lys_module *)module);
779 info_print_import_with_include(out, (struct lys_module *)module);
780 info_print_typedef_with_include(out, (struct lys_module *)module);
781 info_print_ident_with_include(out, (struct lys_module *)module);
782 info_print_features_with_include(out, (struct lys_module *)module);
783 info_print_augment(out, (struct lys_module *)module);
784 info_print_deviation(out, (struct lys_module *)module);
Michal Vasko85217a32015-07-07 11:40:08 +0200785
Radek Krejcibac81762015-10-09 10:19:52 +0200786 info_print_data_with_include(out, (struct lys_module *)module);
Michal Vasko85217a32015-07-07 11:40:08 +0200787}
788
789static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100790info_print_container(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200791{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200792 struct lys_node_container *cont = (struct lys_node_container *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200793
Radek Krejci76b07902015-10-09 09:11:25 +0200794 ly_print(out, "%-*s%s\n", INDENT_LEN, "Container: ", cont->name);
795 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", cont->module->name);
796 info_print_text(out, cont->dsc, "Desc: ");
797 info_print_text(out, cont->ref, "Reference: ");
798 info_print_flags(out, cont->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK, 0);
799 info_print_text(out, cont->presence, "Presence: ");
Radek Krejci9ff0a922016-07-14 13:08:05 +0200800 info_print_if_feature(out, cont->module, cont->iffeature, cont->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200801 info_print_when(out, cont->when);
802 info_print_must(out, cont->must, cont->must_size);
803 info_print_typedef(out, cont->tpdf, cont->tpdf_size);
804 info_print_nacmext(out, cont->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200805
Radek Krejci76b07902015-10-09 09:11:25 +0200806 info_print_snode(out, (struct lys_node *)cont, cont->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200807}
808
809static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100810info_print_choice(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200811{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200812 struct lys_node_choice *choice = (struct lys_node_choice *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200813
Radek Krejci76b07902015-10-09 09:11:25 +0200814 ly_print(out, "%-*s%s\n", INDENT_LEN, "Choice: ", choice->name);
815 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", choice->module->name);
816 info_print_text(out, choice->dsc, "Desc: ");
817 info_print_text(out, choice->ref, "Reference: ");
818 info_print_flags(out, choice->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK, 0);
819 ly_print(out, "%-*s", INDENT_LEN, "Default: ");
Michal Vasko85217a32015-07-07 11:40:08 +0200820 if (choice->dflt) {
Radek Krejci76b07902015-10-09 09:11:25 +0200821 ly_print(out, "%s\n", choice->dflt->name);
Michal Vasko85217a32015-07-07 11:40:08 +0200822 } else {
Radek Krejci76b07902015-10-09 09:11:25 +0200823 ly_print(out, "\n");
Michal Vasko85217a32015-07-07 11:40:08 +0200824 }
Radek Krejci9ff0a922016-07-14 13:08:05 +0200825 info_print_if_feature(out, choice->module, choice->iffeature, choice->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200826 info_print_when(out, choice->when);
827 info_print_nacmext(out, choice->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200828
Radek Krejci76b07902015-10-09 09:11:25 +0200829 info_print_snode(out, (struct lys_node *)choice, choice->child, "Cases:");
Michal Vasko85217a32015-07-07 11:40:08 +0200830}
831
832static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100833info_print_leaf(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200834{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200835 struct lys_node_leaf *leaf = (struct lys_node_leaf *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200836
Radek Krejci76b07902015-10-09 09:11:25 +0200837 ly_print(out, "%-*s%s\n", INDENT_LEN, "Leaf: ", leaf->name);
838 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", leaf->module->name);
839 info_print_text(out, leaf->dsc, "Desc: ");
840 info_print_text(out, leaf->ref, "Reference: ");
841 info_print_flags(out, leaf->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK, 0);
842 info_print_text(out, leaf->type.der->name, "Type: ");
843 info_print_text(out, leaf->units, "Units: ");
844 info_print_text(out, leaf->dflt, "Default: ");
Radek Krejci9ff0a922016-07-14 13:08:05 +0200845 info_print_if_feature(out, leaf->module, leaf->iffeature, leaf->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200846 info_print_when(out, leaf->when);
847 info_print_must(out, leaf->must, leaf->must_size);
848 info_print_nacmext(out, leaf->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200849}
850
851static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100852info_print_leaflist(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200853{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200854 struct lys_node_leaflist *llist = (struct lys_node_leaflist *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200855
Radek Krejci76b07902015-10-09 09:11:25 +0200856 ly_print(out, "%-*s%s\n", INDENT_LEN, "Leaflist: ", llist->name);
857 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", llist->module->name);
858 info_print_text(out, llist->dsc, "Desc: ");
859 info_print_text(out, llist->ref, "Reference: ");
860 info_print_flags(out, llist->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK | LYS_USERORDERED, 1);
861 info_print_text(out, llist->type.der->name, "Type: ");
862 info_print_text(out, llist->units, "Units: ");
863 info_print_list_constr(out, llist->min, llist->max);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200864 info_print_if_feature(out, llist->module, llist->iffeature, llist->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200865 info_print_when(out, llist->when);
866 info_print_must(out, llist->must, llist->must_size);
867 info_print_nacmext(out, llist->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200868}
869
870static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100871info_print_list(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200872{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200873 struct lys_node_list *list = (struct lys_node_list *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200874
Radek Krejci76b07902015-10-09 09:11:25 +0200875 ly_print(out, "%-*s%s\n", INDENT_LEN, "List: ", list->name);
876 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", list->module->name);
877 info_print_text(out, list->dsc, "Desc: ");
878 info_print_text(out, list->ref, "Reference: ");
879 info_print_flags(out, list->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK | LYS_USERORDERED, 1);
880 info_print_list_constr(out, list->min, list->max);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200881 info_print_if_feature(out, list->module, list->iffeature, list->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200882 info_print_when(out, list->when);
883 info_print_must(out, list->must, list->must_size);
884 info_print_keys(out, list->keys, list->keys_size);
885 info_print_unique(out, list->unique, list->unique_size);
886 info_print_typedef(out, list->tpdf, list->tpdf_size);
887 info_print_nacmext(out, list->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200888
Radek Krejci76b07902015-10-09 09:11:25 +0200889 info_print_snode(out, (struct lys_node *)list, list->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200890}
891
892static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100893info_print_anyxml(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200894{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200895 struct lys_node_anyxml *axml = (struct lys_node_anyxml *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200896
Radek Krejci76b07902015-10-09 09:11:25 +0200897 ly_print(out, "%-*s%s\n", INDENT_LEN, "Anyxml: ", axml->name);
898 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", axml->module->name);
899 info_print_text(out, axml->dsc, "Desc: ");
900 info_print_text(out, axml->ref, "Reference: ");
901 info_print_flags(out, axml->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200902 info_print_if_feature(out, axml->module, axml->iffeature, axml->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200903 info_print_when(out, axml->when);
904 info_print_must(out, axml->must, axml->must_size);
905 info_print_nacmext(out, axml->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200906}
907
908static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100909info_print_grouping(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200910{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200911 struct lys_node_grp *group = (struct lys_node_grp *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200912
Radek Krejci76b07902015-10-09 09:11:25 +0200913 ly_print(out, "%-*s%s\n", INDENT_LEN, "Grouping: ", group->name);
914 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", group->module->name);
915 info_print_text(out, group->dsc, "Desc: ");
916 info_print_text(out, group->ref, "Reference: ");
917 info_print_flags(out, group->flags, LYS_STATUS_MASK, 0);
918 info_print_typedef(out, group->tpdf, group->tpdf_size);
919 info_print_nacmext(out, group->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200920
Radek Krejci76b07902015-10-09 09:11:25 +0200921 info_print_snode(out, (struct lys_node *)group, group->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200922}
923
924static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100925info_print_case(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200926{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200927 struct lys_node_case *cas = (struct lys_node_case *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200928
Radek Krejci76b07902015-10-09 09:11:25 +0200929 ly_print(out, "%-*s%s\n", INDENT_LEN, "Case: ", cas->name);
930 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", cas->module->name);
931 info_print_text(out, cas->dsc, "Desc: ");
932 info_print_text(out, cas->ref, "Reference: ");
933 info_print_flags(out, cas->flags, LYS_CONFIG_MASK | LYS_STATUS_MASK | LYS_MAND_MASK, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200934 info_print_if_feature(out, cas->module, cas->iffeature, cas->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200935 info_print_when(out, cas->when);
936 info_print_nacmext(out, cas->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200937
Radek Krejci76b07902015-10-09 09:11:25 +0200938 info_print_snode(out, (struct lys_node *)cas, cas->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200939}
940
941static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100942info_print_input(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200943{
Michal Vasko44fb6382016-06-29 11:12:27 +0200944 struct lys_node_inout *input = (struct lys_node_inout *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200945
Michal Vaskodcf98e62016-05-05 17:53:53 +0200946 assert(lys_parent(node) && lys_parent(node)->nodetype == LYS_RPC);
Michal Vasko85217a32015-07-07 11:40:08 +0200947
Michal Vaskodcf98e62016-05-05 17:53:53 +0200948 ly_print(out, "%-*s%s\n", INDENT_LEN, "Input of: ", lys_parent(node)->name);
Radek Krejci76b07902015-10-09 09:11:25 +0200949 info_print_typedef(out, input->tpdf, input->tpdf_size);
Radek Krejci12032a52016-07-29 15:42:56 +0200950 info_print_must(out, input->must, input->must_size);
Michal Vasko85217a32015-07-07 11:40:08 +0200951
Radek Krejci76b07902015-10-09 09:11:25 +0200952 info_print_snode(out, (struct lys_node *)input, input->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200953}
954
955static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100956info_print_output(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200957{
Michal Vasko44fb6382016-06-29 11:12:27 +0200958 struct lys_node_inout *output = (struct lys_node_inout *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200959
Michal Vaskodcf98e62016-05-05 17:53:53 +0200960 assert(lys_parent(node) && lys_parent(node)->nodetype == LYS_RPC);
Michal Vasko85217a32015-07-07 11:40:08 +0200961
Michal Vaskodcf98e62016-05-05 17:53:53 +0200962 ly_print(out, "%-*s%s\n", INDENT_LEN, "Output of: ", lys_parent(node)->name);
Radek Krejci76b07902015-10-09 09:11:25 +0200963 info_print_typedef(out, output->tpdf, output->tpdf_size);
Radek Krejci12032a52016-07-29 15:42:56 +0200964 info_print_must(out, output->must, output->must_size);
Michal Vasko85217a32015-07-07 11:40:08 +0200965
Radek Krejci76b07902015-10-09 09:11:25 +0200966 info_print_snode(out, (struct lys_node *)output, output->child, "Children:");
Michal Vasko85217a32015-07-07 11:40:08 +0200967}
968
969static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100970info_print_notif(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200971{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200972 struct lys_node_notif *ntf = (struct lys_node_notif *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200973
Radek Krejci76b07902015-10-09 09:11:25 +0200974 ly_print(out, "%-*s%s\n", INDENT_LEN, "Notif: ", ntf->name);
975 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", ntf->module->name);
976 info_print_text(out, ntf->dsc, "Desc: ");
977 info_print_text(out, ntf->ref, "Reference: ");
978 info_print_flags(out, ntf->flags, LYS_STATUS_MASK, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200979 info_print_if_feature(out, ntf->module, ntf->iffeature, ntf->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200980 info_print_typedef(out, ntf->tpdf, ntf->tpdf_size);
Radek Krejci12032a52016-07-29 15:42:56 +0200981 info_print_must(out, ntf->must, ntf->must_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200982 info_print_nacmext(out, ntf->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +0200983
Radek Krejci76b07902015-10-09 09:11:25 +0200984 info_print_snode(out, (struct lys_node *)ntf, ntf->child, "Params:");
Michal Vasko85217a32015-07-07 11:40:08 +0200985}
986
987static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100988info_print_rpc(struct lyout *out, const struct lys_node *node)
Michal Vasko85217a32015-07-07 11:40:08 +0200989{
Michal Vaskoc5c26b02016-06-29 11:10:29 +0200990 struct lys_node_rpc_action *rpc = (struct lys_node_rpc_action *)node;
Michal Vasko85217a32015-07-07 11:40:08 +0200991
Radek Krejci76b07902015-10-09 09:11:25 +0200992 ly_print(out, "%-*s%s\n", INDENT_LEN, "RPC: ", rpc->name);
993 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", rpc->module->name);
994 info_print_text(out, rpc->dsc, "Desc: ");
995 info_print_text(out, rpc->ref, "Reference: ");
996 info_print_flags(out, rpc->flags, LYS_STATUS_MASK, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +0200997 info_print_if_feature(out, rpc->module, rpc->iffeature, rpc->iffeature_size);
Radek Krejci76b07902015-10-09 09:11:25 +0200998 info_print_typedef(out, rpc->tpdf, rpc->tpdf_size);
999 info_print_nacmext(out, rpc->nacm);
Michal Vasko85217a32015-07-07 11:40:08 +02001000
Radek Krejci76b07902015-10-09 09:11:25 +02001001 info_print_snode(out, (struct lys_node *)rpc, rpc->child, "Data:");
Michal Vasko85217a32015-07-07 11:40:08 +02001002}
1003
Michal Vaskoca7cbc42016-07-01 11:36:53 +02001004static void
1005info_print_action(struct lyout *out, const struct lys_node *node)
1006{
1007 struct lys_node_rpc_action *act = (struct lys_node_rpc_action *)node;
1008
1009 ly_print(out, "%-*s%s\n", INDENT_LEN, "Action: ", act->name);
1010 ly_print(out, "%-*s%s\n", INDENT_LEN, "Module: ", act->module->name);
1011 info_print_text(out, act->dsc, "Desc: ");
1012 info_print_text(out, act->ref, "Reference: ");
1013 info_print_flags(out, act->flags, LYS_STATUS_MASK, 0);
Radek Krejci9ff0a922016-07-14 13:08:05 +02001014 info_print_if_feature(out, act->module, act->iffeature, act->iffeature_size);
Michal Vaskoca7cbc42016-07-01 11:36:53 +02001015 info_print_typedef(out, act->tpdf, act->tpdf_size);
1016 info_print_nacmext(out, act->nacm);
1017
1018 info_print_snode(out, (struct lys_node *)act, act->child, "Data:");
1019}
1020
Michal Vasko85217a32015-07-07 11:40:08 +02001021int
Michal Vasko1e62a092015-12-01 12:27:20 +01001022info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node)
Michal Vasko85217a32015-07-07 11:40:08 +02001023{
Michal Vasko3ab70fc2015-08-17 14:06:23 +02001024 int i, rc;
Michal Vaskod04dbea2015-08-06 15:10:19 +02001025 char *grouping_target = NULL;
Michal Vasko3edeaf72016-02-11 13:17:43 +01001026 struct lys_node *target = NULL;
Michal Vasko85217a32015-07-07 11:40:08 +02001027
1028 if (!target_node) {
Michal Vasko85217a32015-07-07 11:40:08 +02001029 if (module->type == 0) {
Radek Krejci76b07902015-10-09 09:11:25 +02001030 info_print_module(out, module);
Michal Vasko85217a32015-07-07 11:40:08 +02001031 } else {
Radek Krejci76b07902015-10-09 09:11:25 +02001032 info_print_submodule(out, (struct lys_submodule *)module);
Michal Vasko85217a32015-07-07 11:40:08 +02001033 }
1034 } else {
Michal Vasko035f5232015-07-15 12:26:52 +02001035 if ((target_node[0] == '/') || !strncmp(target_node, "type/", 5)) {
Michal Vasko3edeaf72016-02-11 13:17:43 +01001036 rc = resolve_augment_schema_nodeid((target_node[0] == '/' ? target_node : target_node + 4), NULL, module,
1037 (const struct lys_node **)&target);
1038 if (rc || !target) {
1039 ly_print(out, "Target %s could not be resolved.\n", (target_node[0] == '/' ? target_node : target_node + 4));
Michal Vasko7df7f142015-07-15 12:10:53 +02001040 return EXIT_FAILURE;
1041 }
Michal Vaskod04dbea2015-08-06 15:10:19 +02001042 } else if (!strncmp(target_node, "grouping/", 9)) {
1043 /* cut the data part off */
Michal Vasko3edeaf72016-02-11 13:17:43 +01001044 if (strchr(target_node + 9, '/')) {
Michal Vaskod04dbea2015-08-06 15:10:19 +02001045 /* HACK only temporary */
Michal Vasko3edeaf72016-02-11 13:17:43 +01001046 *strchr(target_node + 9, '/') = '\0';
1047 grouping_target = (char *)(target_node + strlen(target_node) + 1);
Michal Vaskod04dbea2015-08-06 15:10:19 +02001048 }
Michal Vasko3edeaf72016-02-11 13:17:43 +01001049 rc = resolve_absolute_schema_nodeid(target_node + 9, module, LYS_GROUPING, (const struct lys_node **)&target);
1050 if (rc || !target) {
Radek Krejci76b07902015-10-09 09:11:25 +02001051 ly_print(out, "Grouping %s not found.\n", target_node+9);
Michal Vaskod04dbea2015-08-06 15:10:19 +02001052 return EXIT_FAILURE;
1053 }
Michal Vasko7df7f142015-07-15 12:10:53 +02001054 } else if (!strncmp(target_node, "typedef/", 8)) {
1055 target_node += 8;
1056 for (i = 0; i < module->tpdf_size; ++i) {
1057 if (!strcmp(module->tpdf[i].name, target_node)) {
1058 break;
1059 }
1060 }
1061 if (i == module->tpdf_size) {
Radek Krejci76b07902015-10-09 09:11:25 +02001062 ly_print(out, "Typedef %s not found.\n", target_node);
Michal Vasko7df7f142015-07-15 12:10:53 +02001063 return EXIT_FAILURE;
1064 }
1065
Radek Krejci76b07902015-10-09 09:11:25 +02001066 info_print_typedef_detail(out, &module->tpdf[i]);
Michal Vasko7df7f142015-07-15 12:10:53 +02001067 return EXIT_SUCCESS;
1068
1069 } else if (!strncmp(target_node, "identity/", 9)) {
1070 target_node += 9;
1071 for (i = 0; i < (signed)module->ident_size; ++i) {
1072 if (!strcmp(module->ident[i].name, target_node)) {
1073 break;
1074 }
1075 }
1076 if (i == (signed)module->ident_size) {
Radek Krejci76b07902015-10-09 09:11:25 +02001077 ly_print(out, "Identity %s not found.\n", target_node);
Michal Vasko7df7f142015-07-15 12:10:53 +02001078 return EXIT_FAILURE;
1079 }
1080
Radek Krejci76b07902015-10-09 09:11:25 +02001081 info_print_ident_detail(out, &module->ident[i]);
Michal Vasko7df7f142015-07-15 12:10:53 +02001082 return EXIT_SUCCESS;
1083
1084 } else if (!strncmp(target_node, "feature/", 8)) {
1085 target_node += 8;
1086 for (i = 0; i < module->features_size; ++i) {
1087 if (!strcmp(module->features[i].name, target_node)) {
1088 break;
1089 }
1090 }
1091 if (i == module->features_size) {
Radek Krejci76b07902015-10-09 09:11:25 +02001092 ly_print(out, "Feature %s not found.\n", target_node);
Michal Vasko7df7f142015-07-15 12:10:53 +02001093 return EXIT_FAILURE;
1094 }
1095
Radek Krejci76b07902015-10-09 09:11:25 +02001096 info_print_feature_detail(out, &module->features[i]);
Michal Vasko7df7f142015-07-15 12:10:53 +02001097 return EXIT_SUCCESS;
1098 } else {
Radek Krejci76b07902015-10-09 09:11:25 +02001099 ly_print(out, "Target could not be resolved.\n");
Michal Vasko85217a32015-07-07 11:40:08 +02001100 return EXIT_FAILURE;
1101 }
1102
Michal Vaskod04dbea2015-08-06 15:10:19 +02001103 if (!strncmp(target_node, "type/", 5)) {
Radek Krejci76512572015-08-04 09:47:08 +02001104 if (!(target->nodetype & (LYS_LEAF | LYS_LEAFLIST))) {
Radek Krejci76b07902015-10-09 09:11:25 +02001105 ly_print(out, "Target is not a leaf or a leaf-list.\n");
Michal Vasko035f5232015-07-15 12:26:52 +02001106 return EXIT_FAILURE;
1107 }
Radek Krejci76b07902015-10-09 09:11:25 +02001108 info_print_type_detail(out, &((struct lys_node_leaf *)target)->type, 0);
Michal Vasko035f5232015-07-15 12:26:52 +02001109 return EXIT_SUCCESS;
Michal Vaskod04dbea2015-08-06 15:10:19 +02001110 } else if (!strncmp(target_node, "grouping/", 9) && !grouping_target) {
Radek Krejci76b07902015-10-09 09:11:25 +02001111 info_print_grouping(out, target);
Michal Vaskod04dbea2015-08-06 15:10:19 +02001112 return EXIT_SUCCESS;
1113 }
1114
1115 /* find the node in the grouping */
1116 if (grouping_target) {
Michal Vasko3edeaf72016-02-11 13:17:43 +01001117 rc = resolve_descendant_schema_nodeid(grouping_target, target->child, LYS_NO_RPC_NOTIF_NODE,
Radek Krejcif3c71de2016-04-11 12:45:46 +02001118 1, 0, (const struct lys_node **)&target);
Michal Vasko3edeaf72016-02-11 13:17:43 +01001119 if (rc || !target) {
1120 ly_print(out, "Grouping %s child \"%s\" not found.\n", target_node + 9, grouping_target);
Michal Vaskod04dbea2015-08-06 15:10:19 +02001121 return EXIT_FAILURE;
1122 }
1123 /* HACK return previous hack */
1124 --grouping_target;
1125 grouping_target[0] = '/';
Michal Vasko035f5232015-07-15 12:26:52 +02001126 }
1127
Michal Vasko85217a32015-07-07 11:40:08 +02001128 switch (target->nodetype) {
Radek Krejci76512572015-08-04 09:47:08 +02001129 case LYS_CONTAINER:
Radek Krejci76b07902015-10-09 09:11:25 +02001130 info_print_container(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001131 break;
Radek Krejci76512572015-08-04 09:47:08 +02001132 case LYS_CHOICE:
Radek Krejci76b07902015-10-09 09:11:25 +02001133 info_print_choice(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001134 break;
Radek Krejci76512572015-08-04 09:47:08 +02001135 case LYS_LEAF:
Radek Krejci76b07902015-10-09 09:11:25 +02001136 info_print_leaf(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001137 break;
Radek Krejci76512572015-08-04 09:47:08 +02001138 case LYS_LEAFLIST:
Radek Krejci76b07902015-10-09 09:11:25 +02001139 info_print_leaflist(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001140 break;
Radek Krejci76512572015-08-04 09:47:08 +02001141 case LYS_LIST:
Radek Krejci76b07902015-10-09 09:11:25 +02001142 info_print_list(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001143 break;
Radek Krejci76512572015-08-04 09:47:08 +02001144 case LYS_ANYXML:
Radek Krejci76b07902015-10-09 09:11:25 +02001145 info_print_anyxml(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001146 break;
Radek Krejci76512572015-08-04 09:47:08 +02001147 case LYS_CASE:
Radek Krejci76b07902015-10-09 09:11:25 +02001148 info_print_case(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001149 break;
Radek Krejci76512572015-08-04 09:47:08 +02001150 case LYS_NOTIF:
Radek Krejci76b07902015-10-09 09:11:25 +02001151 info_print_notif(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001152 break;
Radek Krejci76512572015-08-04 09:47:08 +02001153 case LYS_RPC:
Radek Krejci76b07902015-10-09 09:11:25 +02001154 info_print_rpc(out, target);
Michal Vasko2750f822016-07-13 15:15:23 +02001155 break;
Michal Vaskoca7cbc42016-07-01 11:36:53 +02001156 case LYS_ACTION:
1157 info_print_action(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001158 break;
Radek Krejci76512572015-08-04 09:47:08 +02001159 case LYS_INPUT:
Radek Krejci76b07902015-10-09 09:11:25 +02001160 info_print_input(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001161 break;
Radek Krejci76512572015-08-04 09:47:08 +02001162 case LYS_OUTPUT:
Radek Krejci76b07902015-10-09 09:11:25 +02001163 info_print_output(out, target);
Michal Vasko85217a32015-07-07 11:40:08 +02001164 break;
1165 default:
Radek Krejci76b07902015-10-09 09:11:25 +02001166 ly_print(out, "Nodetype %s not supported.\n", strnodetype(target->nodetype));
Michal Vasko85217a32015-07-07 11:40:08 +02001167 break;
1168 }
1169 }
Michal Vasko95068c42016-03-24 14:58:11 +01001170 ly_print_flush(out);
Michal Vasko85217a32015-07-07 11:40:08 +02001171
1172 return EXIT_SUCCESS;
1173}