blob: a4d612bd817267280441d40bac1f12795b71661e [file] [log] [blame]
Radek Krejcida04f4a2015-05-21 12:54:09 +02001/**
Radek Krejciefdd0ce2015-05-26 16:48:29 +02002 * @file printer/yang.c
Radek Krejcida04f4a2015-05-21 12:54:09 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejciefdd0ce2015-05-26 16:48:29 +02004 * @brief YANG printer for libyang data model structure
Radek Krejcida04f4a2015-05-21 12:54:09 +02005 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 */
21
22#include <stdlib.h>
Radek Krejcida04f4a2015-05-21 12:54:09 +020023#include <string.h>
24
Radek Krejci998a0b82015-08-17 13:14:36 +020025#include "common.h"
Radek Krejci76b07902015-10-09 09:11:25 +020026#include "printer.h"
Michal Vasko2d162e12015-09-24 14:33:29 +020027#include "tree_schema.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020028
29#define INDENT ""
30#define LEVEL (level*2)
31
Michal Vasko1e62a092015-12-01 12:27:20 +010032static void yang_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask);
Radek Krejcida04f4a2015-05-21 12:54:09 +020033
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020034static void
Radek Krejci32cce7c2015-12-09 16:44:13 +010035yang_print_open(struct lyout *out, int *flag)
36{
37 if (flag && !*flag) {
38 *flag = 1;
39 ly_print(out, " {\n");
40 }
41}
42
43static void
44yang_print_close(struct lyout *out, int level, int flag)
45{
46 if (flag) {
47 ly_print(out, "%*s}\n", LEVEL, INDENT);
48 } else {
49 ly_print(out, ";\n");
50 }
51}
52
53static void
Radek Krejci8d81e002015-12-10 11:18:59 +010054yang_print_text(struct lyout *out, int level, const char *name, const char *text, int singleline)
Radek Krejcida04f4a2015-05-21 12:54:09 +020055{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020056 const char *s, *t;
Radek Krejcida04f4a2015-05-21 12:54:09 +020057
Radek Krejci8d81e002015-12-10 11:18:59 +010058 if (singleline) {
59 ly_print(out, "%*s%s \"", LEVEL, INDENT, name);
60 } else {
61 ly_print(out, "%*s%s\n", LEVEL, INDENT, name);
62 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +020063
Radek Krejci8d81e002015-12-10 11:18:59 +010064 ly_print(out, "%*s\"", LEVEL, INDENT);
65 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020066 t = text;
67 while ((s = strchr(t, '\n'))) {
Radek Krejci76b07902015-10-09 09:11:25 +020068 ly_write(out, t, (s - t) + 1);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020069 t = s + 1;
Radek Krejci76b07902015-10-09 09:11:25 +020070 ly_print(out, "%*s", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020071 }
Radek Krejcida04f4a2015-05-21 12:54:09 +020072
Radek Krejci8d81e002015-12-10 11:18:59 +010073 ly_print(out, "%s\";\n", t);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020074 level--;
Radek Krejcida04f4a2015-05-21 12:54:09 +020075
76}
77
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020078static void
Radek Krejci32cce7c2015-12-09 16:44:13 +010079yang_print_nacmext(struct lyout *out, int level, const struct lys_node *node, const struct lys_module *module, int *flag)
Radek Krejcida04f4a2015-05-21 12:54:09 +020080{
Radek Krejci6764bb32015-07-03 15:16:04 +020081 int i, j;
Radek Krejci86909d22015-07-03 16:11:25 +020082 const char *prefix = NULL;
Radek Krejci6764bb32015-07-03 15:16:04 +020083
Radek Krejci1d82ef62015-08-07 14:44:40 +020084 if (node->nacm && (!node->parent || node->parent->nacm != node->nacm)) {
Radek Krejci6764bb32015-07-03 15:16:04 +020085 /* locate ietf-netconf-acm module in imports */
Michal Vaskodb7aa992015-07-08 09:37:38 +020086 if (!strcmp(module->name, "ietf-netconf-acm")) {
87 prefix = module->prefix;
Radek Krejci6764bb32015-07-03 15:16:04 +020088 } else {
89 /* search in imports */
Michal Vaskodb7aa992015-07-08 09:37:38 +020090 for (i = 0; i < module->imp_size; i++) {
91 if (!strcmp(module->imp[i].module->name, "ietf-netconf-acm")) {
92 prefix = module->imp[i].prefix;
Radek Krejci6764bb32015-07-03 15:16:04 +020093 break;
94 }
95 }
96 /* and in imports of includes */
97 if (!prefix) {
Michal Vaskodb7aa992015-07-08 09:37:38 +020098 for (j = 0; j < module->inc_size; j++) {
99 for (i = 0; i < module->inc[j].submodule->imp_size; i++) {
100 if (!strcmp(module->inc[j].submodule->imp[i].module->name, "ietf-netconf-acm")) {
101 prefix = module->inc[j].submodule->imp[i].prefix;
Radek Krejci6764bb32015-07-03 15:16:04 +0200102 break;
103 }
104 }
105 }
106 }
107 }
108
Radek Krejci1d82ef62015-08-07 14:44:40 +0200109 if ((node->nacm & LYS_NACM_DENYW) && (!node->parent || !(node->parent->nacm & LYS_NACM_DENYW))) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100110 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200111 ly_print(out, "%*s%s:default-deny-write;\n", LEVEL, INDENT, prefix);
Radek Krejci6764bb32015-07-03 15:16:04 +0200112 }
Radek Krejci1d82ef62015-08-07 14:44:40 +0200113 if ((node->nacm & LYS_NACM_DENYA) && (!node->parent || !(node->parent->nacm & LYS_NACM_DENYA))) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100114 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200115 ly_print(out, "%*s%s:default-deny-all;\n", LEVEL, INDENT, prefix);
Radek Krejci6764bb32015-07-03 15:16:04 +0200116 }
117 }
Radek Krejci6a113852015-07-03 16:04:20 +0200118}
119
120/*
121 * Covers:
122 * description, reference, status
123 */
124static void
Radek Krejci32cce7c2015-12-09 16:44:13 +0100125yang_print_snode_common(struct lyout *out, int level, const struct lys_node *node, int *flag)
Radek Krejci6a113852015-07-03 16:04:20 +0200126{
Radek Krejci1d82ef62015-08-07 14:44:40 +0200127 if (node->flags & LYS_STATUS_CURR) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100128 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200129 ly_print(out, "%*sstatus \"current\";\n", LEVEL, INDENT);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200130 } else if (node->flags & LYS_STATUS_DEPRC) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100131 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200132 ly_print(out, "%*sstatus \"deprecated\";\n", LEVEL, INDENT);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200133 } else if (node->flags & LYS_STATUS_OBSLT) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100134 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200135 ly_print(out, "%*sstatus \"obsolete\";\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200136 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200137
Radek Krejci1d82ef62015-08-07 14:44:40 +0200138 if (node->dsc) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100139 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100140 yang_print_text(out, level, "description", node->dsc, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200141 }
Radek Krejci1d82ef62015-08-07 14:44:40 +0200142 if (node->ref) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100143 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100144 yang_print_text(out, level, "reference", node->ref, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200145 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200146}
147
148/*
149 * Covers:
Michal Vasko2b8faed2015-06-09 12:51:20 +0200150 * config, mandatory
Radek Krejcida04f4a2015-05-21 12:54:09 +0200151 * description, reference, status
152 */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200153static void
Radek Krejci32cce7c2015-12-09 16:44:13 +0100154yang_print_snode_common2(struct lyout *out, int level, const struct lys_node *node, int *flag)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200155{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100156 if (node->parent && (node->parent->flags & LYS_CONFIG_MASK) != (node->flags & LYS_CONFIG_MASK)) {
157 /* print config only when it differs from the parent */
Radek Krejci1d82ef62015-08-07 14:44:40 +0200158 if (node->flags & LYS_CONFIG_W) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100159 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100160 ly_print(out, "%*sconfig true;\n", LEVEL, INDENT);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200161 } else if (node->flags & LYS_CONFIG_R) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100162 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100163 ly_print(out, "%*sconfig false;\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200164 }
165 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200166
Radek Krejci1d82ef62015-08-07 14:44:40 +0200167 if (node->flags & LYS_MAND_TRUE) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100168 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100169 ly_print(out, "%*smandatory true;\n", LEVEL, INDENT);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200170 } else if (node->flags & LYS_MAND_FALSE) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100171 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100172 ly_print(out, "%*smandatory false;\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200173 }
Michal Vasko2b8faed2015-06-09 12:51:20 +0200174
Radek Krejci32cce7c2015-12-09 16:44:13 +0100175 yang_print_snode_common(out, level, node, flag);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200176}
177
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200178static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100179yang_print_iffeature(struct lyout *out, int level, const struct lys_module *module, const struct lys_feature *feat)
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200180{
Radek Krejci76b07902015-10-09 09:11:25 +0200181 ly_print(out, "%*sif-feature ", LEVEL, INDENT);
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200182 if ((feat->module != module) && !feat->module->type) {
Michal Vasko2d851a92015-10-20 16:16:36 +0200183 ly_print(out, "%s:", feat->module->name);
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200184 }
Radek Krejci76b07902015-10-09 09:11:25 +0200185 ly_print(out, "%s;\n", feat->name);
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200186}
187
188static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100189yang_print_feature(struct lyout *out, int level, const struct lys_feature *feat)
Michal Vasko4773b762015-07-07 12:15:10 +0200190{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100191 int i, flag = 0;
Michal Vasko30f6e912015-07-07 12:24:27 +0200192
Radek Krejci32cce7c2015-12-09 16:44:13 +0100193 ly_print(out, "%*sfeature %s", LEVEL, INDENT, feat->name);
Michal Vasko4773b762015-07-07 12:15:10 +0200194 level++;
195
Radek Krejci32cce7c2015-12-09 16:44:13 +0100196 yang_print_snode_common(out, level, (struct lys_node *)feat, &flag);
Michal Vasko30f6e912015-07-07 12:24:27 +0200197 for (i = 0; i < feat->features_size; ++i) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100198 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200199 yang_print_iffeature(out, level, feat->module, feat->features[i]);
Michal Vasko30f6e912015-07-07 12:24:27 +0200200 }
Michal Vasko4773b762015-07-07 12:15:10 +0200201
202 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100203 yang_print_close(out, level, flag);
Michal Vasko4773b762015-07-07 12:15:10 +0200204}
205
206static void
Radek Krejci32cce7c2015-12-09 16:44:13 +0100207yang_print_restr(struct lyout *out, int level, const struct lys_restr *restr, int *flag)
Radek Krejci41726f92015-06-19 13:11:05 +0200208{
Radek Krejci0bd5db42015-06-19 13:30:07 +0200209 if (restr->dsc != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100210 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100211 yang_print_text(out, level, "description", restr->dsc, 0);
Radek Krejci41726f92015-06-19 13:11:05 +0200212 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200213 if (restr->ref != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100214 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100215 yang_print_text(out, level, "reference", restr->ref, 0);
Radek Krejci41726f92015-06-19 13:11:05 +0200216 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200217 if (restr->eapptag != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100218 yang_print_open(out, flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200219 ly_print(out, "%*serror-app-tag \"%s\";\n", LEVEL, INDENT, restr->eapptag);
Radek Krejci41726f92015-06-19 13:11:05 +0200220 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200221 if (restr->emsg != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100222 yang_print_open(out, flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100223 yang_print_text(out, level, "error-message", restr->emsg, 0);
Radek Krejci41726f92015-06-19 13:11:05 +0200224 }
225}
226
227static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100228yang_print_when(struct lyout *out, int level, const struct lys_module *module, const struct lys_when *when)
Michal Vasko1f0428a2015-07-07 14:55:04 +0200229{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100230 int flag = 0;
Michal Vaskof9893382015-10-09 14:03:04 +0200231 const char *xml_expr;
232
Michal Vaskofba15262015-10-21 12:10:28 +0200233 xml_expr = transform_json2xml(module, when->cond, NULL, NULL, NULL);
Michal Vaskof9893382015-10-09 14:03:04 +0200234 if (!xml_expr) {
235 ly_print(out, "(!error!)");
236 return;
237 }
238
Radek Krejci32cce7c2015-12-09 16:44:13 +0100239 ly_print(out, "%*swhen \"%s\"", LEVEL, INDENT, xml_expr);
Michal Vaskof9893382015-10-09 14:03:04 +0200240 lydict_remove(module->ctx, xml_expr);
241
Michal Vasko1f0428a2015-07-07 14:55:04 +0200242 level++;
243 if (when->dsc) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100244 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100245 yang_print_text(out, level, "description", when->dsc, 0);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200246 }
247 if (when->ref) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100248 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100249 yang_print_text(out, level, "reference", when->ref, 0);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200250 }
251 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100252 yang_print_close(out, level, flag);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200253}
254
255static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100256yang_print_type(struct lyout *out, int level, const struct lys_module *module, const struct lys_type *type)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200257{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200258 int i;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100259 int flag = 0, flag2;
Michal Vasko0fb82c62015-10-20 13:41:53 +0200260 const char *str;
Radek Krejcic071c542016-01-27 14:57:51 +0100261 struct lys_module *mod;
Radek Krejci25d782a2015-05-22 15:03:23 +0200262
Michal Vasko0fb82c62015-10-20 13:41:53 +0200263 if (type->module_name) {
Michal Vaskofba15262015-10-21 12:10:28 +0200264 str = transform_json2xml(module, type->module_name, NULL, NULL, NULL);
Radek Krejci32cce7c2015-12-09 16:44:13 +0100265 ly_print(out, "%*stype %s:%s", LEVEL, INDENT, str, type->der->name);
Michal Vasko0fb82c62015-10-20 13:41:53 +0200266 lydict_remove(module->ctx, str);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200267 } else {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100268 ly_print(out, "%*stype %s", LEVEL, INDENT, type->der->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200269 }
270 level++;
271 switch (type->base) {
272 case LY_TYPE_BINARY:
273 if (type->info.binary.length != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100274 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200275 ly_print(out, "%*slength \"%s\" {\n", LEVEL, INDENT, type->info.binary.length->expr);
Radek Krejci32cce7c2015-12-09 16:44:13 +0100276 flag2 = 0;
277 yang_print_restr(out, level + 1, type->info.binary.length, &flag2);
278 yang_print_close(out, level, flag2);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200279 }
280 break;
281 case LY_TYPE_BITS:
282 for (i = 0; i < type->info.bits.count; ++i) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100283 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200284 ly_print(out, "%*sbit %s {\n", LEVEL, INDENT, type->info.bits.bit[i].name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200285 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100286 yang_print_snode_common(out, level, (struct lys_node *)&type->info.bits.bit[i], NULL);
Radek Krejci76b07902015-10-09 09:11:25 +0200287 ly_print(out, "%*sposition %u;\n", LEVEL, INDENT, type->info.bits.bit[i].pos);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200288 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200289 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200290 }
291 break;
292 case LY_TYPE_DEC64:
Radek Krejci32cce7c2015-12-09 16:44:13 +0100293 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200294 ly_print(out, "%*sfraction-digits %d;\n", LEVEL, INDENT, type->info.dec64.dig);
Michal Vaskoea505ee2015-07-07 14:01:00 +0200295 if (type->info.dec64.range != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100296 ly_print(out, "%*srange \"%s\"", LEVEL, INDENT, type->info.dec64.range->expr);
297 flag2 = 0;
298 yang_print_restr(out, level + 1, type->info.dec64.range, &flag2);
299 yang_print_close(out, level, flag2);
Michal Vaskoea505ee2015-07-07 14:01:00 +0200300 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200301 break;
302 case LY_TYPE_ENUM:
303 for (i = 0; i < type->info.enums.count; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100304 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100305 ly_print(out, "%*senum \"%s\" {\n", LEVEL, INDENT, type->info.enums.enm[i].name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200306 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100307 yang_print_snode_common(out, level, (struct lys_node *)&type->info.enums.enm[i], NULL);
Radek Krejci76b07902015-10-09 09:11:25 +0200308 ly_print(out, "%*svalue %d;\n", LEVEL, INDENT, type->info.enums.enm[i].value);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200309 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200310 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200311 }
312 break;
313 case LY_TYPE_IDENT:
Radek Krejci32cce7c2015-12-09 16:44:13 +0100314 yang_print_open(out, &flag);
Radek Krejcic071c542016-01-27 14:57:51 +0100315 mod = type->info.ident.ref->module->type ?
316 ((struct lys_submodule *)type->info.ident.ref->module)->belongsto :
317 type->info.ident.ref->module;
318 if (module == mod) {
Radek Krejci76b07902015-10-09 09:11:25 +0200319 ly_print(out, "%*sbase %s;\n", LEVEL, INDENT, type->info.ident.ref->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200320 } else {
Radek Krejcic071c542016-01-27 14:57:51 +0100321 ly_print(out, "%*sbase %s:%s;\n", LEVEL, INDENT, mod->prefix, type->info.ident.ref->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200322 }
323 break;
324 case LY_TYPE_INST:
Radek Krejciaf351422015-06-19 14:49:38 +0200325 if (type->info.inst.req == 1) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100326 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100327 ly_print(out, "%*srequire-instance true;\n", LEVEL, INDENT);
Radek Krejciaf351422015-06-19 14:49:38 +0200328 } else if (type->info.inst.req == -1) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100329 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100330 ly_print(out, "%*srequire-instance false;\n", LEVEL, INDENT);
Radek Krejciaf351422015-06-19 14:49:38 +0200331 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200332 break;
333 case LY_TYPE_INT8:
334 case LY_TYPE_INT16:
335 case LY_TYPE_INT32:
336 case LY_TYPE_INT64:
337 case LY_TYPE_UINT8:
338 case LY_TYPE_UINT16:
339 case LY_TYPE_UINT32:
340 case LY_TYPE_UINT64:
Radek Krejcif2860132015-06-20 12:37:20 +0200341 if (type->info.num.range != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100342 yang_print_open(out, &flag);
343 ly_print(out, "%*srange \"%s\"", LEVEL, INDENT, type->info.num.range->expr);
344 flag2 = 0;
345 yang_print_restr(out, level + 1, type->info.num.range, &flag2);
346 yang_print_close(out, level, flag2);
Radek Krejcif2860132015-06-20 12:37:20 +0200347 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200348 break;
349 case LY_TYPE_LEAFREF:
Radek Krejci32cce7c2015-12-09 16:44:13 +0100350 yang_print_open(out, &flag);
Michal Vaskofba15262015-10-21 12:10:28 +0200351 str = transform_json2xml(module, type->info.lref.path, NULL, NULL, NULL);
Michal Vasko514c4f32015-10-20 13:43:25 +0200352 ly_print(out, "%*spath \"%s\";\n", LEVEL, INDENT, str);
353 lydict_remove(module->ctx, str);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200354 break;
355 case LY_TYPE_STRING:
Radek Krejci5fbc9162015-06-19 14:11:11 +0200356 if (type->info.str.length) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100357 yang_print_open(out, &flag);
358 ly_print(out, "%*slength \"%s\"", LEVEL, INDENT, type->info.str.length->expr);
359 flag2 = 0;
360 yang_print_restr(out, level + 1, type->info.str.length, &flag2);
361 yang_print_close(out, level, flag2);
Radek Krejci061bd522015-06-19 13:45:16 +0200362 }
Radek Krejci5fbc9162015-06-19 14:11:11 +0200363 for (i = 0; i < type->info.str.pat_count; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100364 yang_print_open(out, &flag);
365 ly_print(out, "%*spattern \"%s\"", LEVEL, INDENT, type->info.str.patterns[i].expr);
366 flag2 = 0;
367 yang_print_restr(out, level + 1, &type->info.str.patterns[i], &flag2);
368 yang_print_close(out, level, flag2);
Radek Krejci5fbc9162015-06-19 14:11:11 +0200369 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200370 break;
371 case LY_TYPE_UNION:
372 for (i = 0; i < type->info.uni.count; ++i) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100373 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200374 yang_print_type(out, level, module, &type->info.uni.types[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200375 }
376 break;
377 default:
378 /* other types do not have substatements */
379 break;
380 }
381 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100382 yang_print_close(out, level, flag);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200383}
384
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200385static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100386yang_print_must(struct lyout *out, int level, const struct lys_module *module, const struct lys_restr *must)
Michal Vasko7f976ee2015-06-09 13:55:41 +0200387{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100388 int flag = 0;
Michal Vaskof9893382015-10-09 14:03:04 +0200389 const char *xml_expr;
390
Michal Vaskofba15262015-10-21 12:10:28 +0200391 xml_expr = transform_json2xml(module, must->expr, NULL, NULL, NULL);
Michal Vaskof9893382015-10-09 14:03:04 +0200392 if (!xml_expr) {
393 ly_print(out, "(!error!)");
394 return;
395 }
396
Radek Krejci32cce7c2015-12-09 16:44:13 +0100397 ly_print(out, "%*smust \"%s\"", LEVEL, INDENT, xml_expr);
Michal Vaskof9893382015-10-09 14:03:04 +0200398 lydict_remove(module->ctx, xml_expr);
399
Radek Krejci32cce7c2015-12-09 16:44:13 +0100400 yang_print_restr(out, level + 1, must, &flag);
401 yang_print_close(out, level, flag);
Michal Vasko7f976ee2015-06-09 13:55:41 +0200402}
403
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200404static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100405yang_print_unique(struct lyout *out, int level, const struct lys_unique *uniq)
Michal Vasko1ef07972015-07-07 14:01:35 +0200406{
407 int i;
408
Radek Krejci76b07902015-10-09 09:11:25 +0200409 ly_print(out, "%*sunique \"", LEVEL, INDENT);
Radek Krejci581ce772015-11-10 17:22:40 +0100410 for (i = 0; i < uniq->expr_size; i++) {
411 ly_print(out, "%s%s", uniq->expr[i], i + 1 < uniq->expr_size ? " " : "");
Michal Vasko1ef07972015-07-07 14:01:35 +0200412 }
Radek Krejci76b07902015-10-09 09:11:25 +0200413 ly_print(out, "\";\n");
Michal Vasko1ef07972015-07-07 14:01:35 +0200414}
415
416static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100417yang_print_refine(struct lyout *out, int level, const struct lys_module *module, const struct lys_refine *refine)
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200418{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200419 int i;
Michal Vaskoa8b25952015-10-20 15:30:25 +0200420 const char *str;
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200421
Michal Vaskofba15262015-10-21 12:10:28 +0200422 str = transform_json2xml(module, refine->target_name, NULL, NULL, NULL);
Michal Vaskoa8b25952015-10-20 15:30:25 +0200423 ly_print(out, "%*srefine \"%s\" {\n", LEVEL, INDENT, str);
424 lydict_remove(module->ctx, str);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200425 level++;
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200426
Radek Krejci1574a8d2015-08-03 14:16:52 +0200427 if (refine->flags & LYS_CONFIG_W) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100428 ly_print(out, "%*sconfig true;\n", LEVEL, INDENT);
Radek Krejci1574a8d2015-08-03 14:16:52 +0200429 } else if (refine->flags & LYS_CONFIG_R) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100430 ly_print(out, "%*sconfig false;\n", LEVEL, INDENT);
Radek Krejci6a113852015-07-03 16:04:20 +0200431 }
432
Radek Krejci1574a8d2015-08-03 14:16:52 +0200433 if (refine->flags & LYS_MAND_TRUE) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100434 ly_print(out, "%*smandatory true;\n", LEVEL, INDENT);
Radek Krejci1574a8d2015-08-03 14:16:52 +0200435 } else if (refine->flags & LYS_MAND_FALSE) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100436 ly_print(out, "%*smandatory false;\n", LEVEL, INDENT);
Radek Krejci6a113852015-07-03 16:04:20 +0200437 }
438
Radek Krejci32cce7c2015-12-09 16:44:13 +0100439 yang_print_snode_common(out, level, (struct lys_node *)refine, NULL);
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200440
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200441 for (i = 0; i < refine->must_size; ++i) {
Michal Vaskof9893382015-10-09 14:03:04 +0200442 yang_print_must(out, level, module, &refine->must[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200443 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200444
Radek Krejci76512572015-08-04 09:47:08 +0200445 if (refine->target_type & (LYS_LEAF | LYS_CHOICE)) {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200446 if (refine->mod.dflt != NULL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200447 ly_print(out, "%*sdefault \"%s\";\n", LEVEL, INDENT, refine->mod.dflt);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200448 }
Radek Krejci76512572015-08-04 09:47:08 +0200449 } else if (refine->target_type == LYS_CONTAINER) {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200450 if (refine->mod.presence != NULL) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100451 yang_print_text(out, level, "presence", refine->mod.presence, 1);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200452 }
Radek Krejci76512572015-08-04 09:47:08 +0200453 } else if (refine->target_type & (LYS_LIST | LYS_LEAFLIST)) {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200454 if (refine->mod.list.min > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200455 ly_print(out, "%*smin-elements %u;\n", LEVEL, INDENT, refine->mod.list.min);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200456 }
457 if (refine->mod.list.max > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200458 ly_print(out, "%*smax-elements %u;\n", LEVEL, INDENT, refine->mod.list.max);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200459 }
460 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200461
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200462 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200463 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200464}
465
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200466static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100467yang_print_deviation(struct lyout *out, int level, const struct lys_module *module,
468 const struct lys_deviation *deviation)
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200469{
470 int i, j;
Michal Vaskoa8b25952015-10-20 15:30:25 +0200471 const char *str;
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200472
Michal Vaskofba15262015-10-21 12:10:28 +0200473 str = transform_json2xml(module, deviation->target_name, NULL, NULL, NULL);
Michal Vaskoa8b25952015-10-20 15:30:25 +0200474 ly_print(out, "%*sdeviation \"%s\" {\n", LEVEL, INDENT, str);
475 lydict_remove(module->ctx, str);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200476 level++;
477
478 if (deviation->dsc) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100479 yang_print_text(out, level, "description", deviation->dsc, 0);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200480 }
481 if (deviation->ref) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100482 yang_print_text(out, level, "reference", deviation->ref, 0);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200483 }
484
485 for (i = 0; i < deviation->deviate_size; ++i) {
Radek Krejci76b07902015-10-09 09:11:25 +0200486 ly_print(out, "%*sdeviate ", LEVEL, INDENT);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200487 if (deviation->deviate[i].mod == LY_DEVIATE_NO) {
Radek Krejci76b07902015-10-09 09:11:25 +0200488 ly_print(out, "not-supported {\n");
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200489 } else if (deviation->deviate[i].mod == LY_DEVIATE_ADD) {
Radek Krejci76b07902015-10-09 09:11:25 +0200490 ly_print(out, "add {\n");
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200491 } else if (deviation->deviate[i].mod == LY_DEVIATE_RPL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200492 ly_print(out, "replace {\n");
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200493 } else if (deviation->deviate[i].mod == LY_DEVIATE_DEL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200494 ly_print(out, "delete {\n");
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200495 }
496 level++;
497
Radek Krejci1574a8d2015-08-03 14:16:52 +0200498 if (deviation->deviate[i].flags & LYS_CONFIG_W) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100499 ly_print(out, "%*sconfig true;\n", LEVEL, INDENT);
Radek Krejci1574a8d2015-08-03 14:16:52 +0200500 } else if (deviation->deviate[i].flags & LYS_CONFIG_R) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100501 ly_print(out, "%*sconfig false;\n", LEVEL, INDENT);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200502 }
503
Radek Krejci1574a8d2015-08-03 14:16:52 +0200504 if (deviation->deviate[i].flags & LYS_MAND_TRUE) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100505 ly_print(out, "%*smandatory true;\n", LEVEL, INDENT);
Radek Krejci1574a8d2015-08-03 14:16:52 +0200506 } else if (deviation->deviate[i].flags & LYS_MAND_FALSE) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100507 ly_print(out, "%*smandatory false;\n", LEVEL, INDENT);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200508 }
509
510 if (deviation->deviate[i].dflt) {
Radek Krejci76b07902015-10-09 09:11:25 +0200511 ly_print(out, "%*sdefault %s;\n", LEVEL, INDENT, deviation->deviate[i].dflt);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200512 }
513
514 if (deviation->deviate[i].min) {
Radek Krejci76b07902015-10-09 09:11:25 +0200515 ly_print(out, "%*smin-elements %u;\n", LEVEL, INDENT, deviation->deviate[i].min);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200516 }
517 if (deviation->deviate[i].max) {
Radek Krejci76b07902015-10-09 09:11:25 +0200518 ly_print(out, "%*smax-elements %u;\n", LEVEL, INDENT, deviation->deviate[i].max);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200519 }
520
521 for (j = 0; j < deviation->deviate[i].must_size; ++j) {
Michal Vaskof9893382015-10-09 14:03:04 +0200522 yang_print_must(out, level, module, &deviation->deviate[i].must[j]);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200523 }
524
525 for (j = 0; j < deviation->deviate[i].unique_size; ++j) {
Radek Krejci76b07902015-10-09 09:11:25 +0200526 yang_print_unique(out, level, &deviation->deviate[i].unique[j]);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200527 }
528
529 if (deviation->deviate[i].type) {
Radek Krejci76b07902015-10-09 09:11:25 +0200530 yang_print_type(out, level, module, deviation->deviate[i].type);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200531 }
532
533 if (deviation->deviate[i].units) {
Radek Krejci76b07902015-10-09 09:11:25 +0200534 ly_print(out, "%*sunits %s;\n", LEVEL, INDENT, deviation->deviate[i].units);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200535 }
536
537 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200538 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200539 }
540
541 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200542 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vaskoe0af1e22015-07-07 14:02:02 +0200543}
544
545static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100546yang_print_augment(struct lyout *out, int level, const struct lys_module *module,
547 const struct lys_node_augment *augment)
Michal Vasko6f25f212015-07-07 15:42:07 +0200548{
549 int i;
Radek Krejci76512572015-08-04 09:47:08 +0200550 struct lys_node *sub;
Michal Vasko488c19e2015-10-20 15:21:00 +0200551 const char *str;
Michal Vasko6f25f212015-07-07 15:42:07 +0200552
Michal Vaskofba15262015-10-21 12:10:28 +0200553 str = transform_json2xml(module, augment->target_name, NULL, NULL, NULL);
Michal Vasko488c19e2015-10-20 15:21:00 +0200554 ly_print(out, "%*saugment \"%s\" {\n", LEVEL, INDENT, str);
555 lydict_remove(module->ctx, str);
Michal Vasko6f25f212015-07-07 15:42:07 +0200556 level++;
557
Radek Krejci32cce7c2015-12-09 16:44:13 +0100558 yang_print_nacmext(out, level, (struct lys_node *)augment, module, NULL);
559 yang_print_snode_common(out, level, (struct lys_node *)augment, NULL);
Michal Vasko6f25f212015-07-07 15:42:07 +0200560
561 for (i = 0; i < augment->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200562 yang_print_iffeature(out, level, module, augment->features[i]);
Michal Vasko6f25f212015-07-07 15:42:07 +0200563 }
564
565 if (augment->when) {
Michal Vaskof9893382015-10-09 14:03:04 +0200566 yang_print_when(out, level, module, augment->when);
Michal Vasko6f25f212015-07-07 15:42:07 +0200567 }
568
569 LY_TREE_FOR(augment->child, sub) {
Radek Krejci76b07902015-10-09 09:11:25 +0200570 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200571 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
572 LYS_USES | LYS_ANYXML | LYS_CASE);
Michal Vasko6f25f212015-07-07 15:42:07 +0200573 }
574
575 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200576 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vasko6f25f212015-07-07 15:42:07 +0200577}
578
579static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100580yang_print_typedef(struct lyout *out, int level, const struct lys_module *module, const struct lys_tpdf *tpdf)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200581{
Radek Krejci76b07902015-10-09 09:11:25 +0200582 ly_print(out, "%*stypedef %s {\n", LEVEL, INDENT, tpdf->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200583 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200584
Radek Krejci32cce7c2015-12-09 16:44:13 +0100585 yang_print_snode_common(out, level, (struct lys_node *)tpdf, NULL);
Radek Krejci76b07902015-10-09 09:11:25 +0200586 yang_print_type(out, level, module, &tpdf->type);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200587 if (tpdf->units != NULL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200588 ly_print(out, "%*sunits \"%s\";\n", LEVEL, INDENT, tpdf->units);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200589 }
590 if (tpdf->dflt != NULL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200591 ly_print(out, "%*sdefault \"%s\";\n", LEVEL, INDENT, tpdf->dflt);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200592 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200593
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200594 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200595 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200596}
597
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200598static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100599yang_print_identity(struct lyout *out, int level, const struct lys_ident *ident)
Radek Krejci6793db02015-05-22 17:49:54 +0200600{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100601 int flag = 0;
602
603 ly_print(out, "%*sidentity %s", LEVEL, INDENT, ident->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200604 level++;
Radek Krejci6793db02015-05-22 17:49:54 +0200605
Radek Krejci32cce7c2015-12-09 16:44:13 +0100606 yang_print_snode_common(out, level, (struct lys_node *)ident, &flag);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200607 if (ident->base) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100608 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200609 ly_print(out, "%*sbase ", LEVEL, INDENT);
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200610 if ((ident->module != ident->base->module) && !ident->base->module->type) {
Michal Vasko2d851a92015-10-20 16:16:36 +0200611 ly_print(out, "%s:", ident->base->module->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200612 }
Radek Krejci76b07902015-10-09 09:11:25 +0200613 ly_print(out, "%s;\n", ident->base->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200614 }
Radek Krejci6793db02015-05-22 17:49:54 +0200615
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200616 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100617 yang_print_close(out, level, flag);
Radek Krejci6793db02015-05-22 17:49:54 +0200618}
619
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200620static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100621yang_print_container(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200622{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100623 int i, flag = 0;
Radek Krejci76512572015-08-04 09:47:08 +0200624 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200625 struct lys_node_container *cont = (struct lys_node_container *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200626
Radek Krejci32cce7c2015-12-09 16:44:13 +0100627 ly_print(out, "%*scontainer %s", LEVEL, INDENT, node->name);
Michal Vasko7f976ee2015-06-09 13:55:41 +0200628
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200629 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200630
Radek Krejci32cce7c2015-12-09 16:44:13 +0100631 yang_print_nacmext(out, level, node, node->module, &flag);
Radek Krejci6a113852015-07-03 16:04:20 +0200632
Radek Krejci8d81e002015-12-10 11:18:59 +0100633 if (cont->when) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100634 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100635 yang_print_when(out, level, node->module, cont->when);
636 }
637
638 for (i = 0; i < cont->features_size; i++) {
639 yang_print_open(out, &flag);
640 yang_print_iffeature(out, level, node->module, cont->features[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200641 }
Michal Vasko7f976ee2015-06-09 13:55:41 +0200642
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200643 for (i = 0; i < cont->must_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100644 yang_print_open(out, &flag);
Michal Vaskof9893382015-10-09 14:03:04 +0200645 yang_print_must(out, level, node->module, &cont->must[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200646 }
Michal Vasko7f976ee2015-06-09 13:55:41 +0200647
Radek Krejci8d81e002015-12-10 11:18:59 +0100648 if (cont->presence != NULL) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100649 yang_print_open(out, &flag);
Radek Krejci8d81e002015-12-10 11:18:59 +0100650 yang_print_text(out, level, "presence", cont->presence, 1);
Michal Vasko4773b762015-07-07 12:15:10 +0200651 }
652
Radek Krejci8d81e002015-12-10 11:18:59 +0100653 yang_print_snode_common2(out, level, node, &flag);
654
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200655 for (i = 0; i < cont->tpdf_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100656 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200657 yang_print_typedef(out, level, node->module, &cont->tpdf[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200658 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200659
Radek Krejci1d82ef62015-08-07 14:44:40 +0200660 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +0100661 /* augment and data from submodules */
662 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +0200663 continue;
664 }
Radek Krejci32cce7c2015-12-09 16:44:13 +0100665 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200666 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200667 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
668 LYS_USES | LYS_GROUPING | LYS_ANYXML);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200669 }
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200670
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200671 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100672 yang_print_close(out, level, flag);
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200673}
674
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200675static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100676yang_print_case(struct lyout *out, int level, const struct lys_node *node)
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200677{
Michal Vasko4773b762015-07-07 12:15:10 +0200678 int i;
Radek Krejci76512572015-08-04 09:47:08 +0200679 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200680 struct lys_node_case *cas = (struct lys_node_case *)node;
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200681
Radek Krejci76b07902015-10-09 09:11:25 +0200682 ly_print(out, "%*scase %s {\n", LEVEL, INDENT, cas->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200683 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100684 yang_print_nacmext(out, level, node, node->module, NULL);
685 yang_print_snode_common2(out, level, node, NULL);
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200686
Michal Vasko4773b762015-07-07 12:15:10 +0200687 for (i = 0; i < cas->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200688 yang_print_iffeature(out, level, node->module, cas->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200689 }
690
Michal Vasko1f0428a2015-07-07 14:55:04 +0200691 if (cas->when) {
Michal Vaskof9893382015-10-09 14:03:04 +0200692 yang_print_when(out, level, node->module, cas->when);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200693 }
694
Radek Krejci1d82ef62015-08-07 14:44:40 +0200695 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +0100696 /* augment and data from submodules */
697 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +0200698 continue;
699 }
Radek Krejci76b07902015-10-09 09:11:25 +0200700 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200701 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
702 LYS_USES | LYS_ANYXML);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200703 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200704
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200705 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200706 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200707}
708
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200709static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100710yang_print_choice(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200711{
Michal Vasko4773b762015-07-07 12:15:10 +0200712 int i;
Radek Krejci76512572015-08-04 09:47:08 +0200713 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200714 struct lys_node_choice *choice = (struct lys_node_choice *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200715
Radek Krejci76b07902015-10-09 09:11:25 +0200716 ly_print(out, "%*schoice %s {\n", LEVEL, INDENT, node->name);
Michal Vasko16083662015-06-09 14:00:45 +0200717
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200718 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100719 yang_print_nacmext(out, level, node, node->module, NULL);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200720 if (choice->dflt != NULL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200721 ly_print(out, "%*sdefault \"%s\";\n", LEVEL, INDENT, choice->dflt->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200722 }
Michal Vasko16083662015-06-09 14:00:45 +0200723
Radek Krejci32cce7c2015-12-09 16:44:13 +0100724 yang_print_snode_common2(out, level, node, NULL);
Michal Vasko4773b762015-07-07 12:15:10 +0200725
726 for (i = 0; i < choice->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200727 yang_print_iffeature(out, level, node->module, choice->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200728 }
729
Michal Vasko1f0428a2015-07-07 14:55:04 +0200730 if (choice->when) {
Michal Vaskof9893382015-10-09 14:03:04 +0200731 yang_print_when(out, level, node->module, choice->when);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200732 }
733
Radek Krejci1d82ef62015-08-07 14:44:40 +0200734 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +0100735 /* augment and data from submodules */
736 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +0200737 continue;
738 }
Radek Krejci76b07902015-10-09 09:11:25 +0200739 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200740 LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_CASE);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200741 }
742 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200743 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200744}
745
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200746static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100747yang_print_leaf(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200748{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200749 int i;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200750 struct lys_node_leaf *leaf = (struct lys_node_leaf *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200751
Radek Krejci76b07902015-10-09 09:11:25 +0200752 ly_print(out, "%*sleaf %s {\n", LEVEL, INDENT, node->name);
Michal Vasko16083662015-06-09 14:00:45 +0200753
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200754 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100755 yang_print_nacmext(out, level, node, node->module, NULL);
Radek Krejci8d81e002015-12-10 11:18:59 +0100756 if (leaf->when) {
757 yang_print_when(out, level, node->module, leaf->when);
758 }
Michal Vasko4773b762015-07-07 12:15:10 +0200759 for (i = 0; i < leaf->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200760 yang_print_iffeature(out, level, node->module, leaf->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200761 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200762 for (i = 0; i < leaf->must_size; i++) {
Michal Vaskof9893382015-10-09 14:03:04 +0200763 yang_print_must(out, level, node->module, &leaf->must[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200764 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100765 yang_print_snode_common2(out, level, node, NULL);
Radek Krejci76b07902015-10-09 09:11:25 +0200766 yang_print_type(out, level, node->module, &leaf->type);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200767 if (leaf->units != NULL) {
Radek Krejci76b07902015-10-09 09:11:25 +0200768 ly_print(out, "%*sunits \"%s\";\n", LEVEL, INDENT, leaf->units);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200769 }
770 if (leaf->dflt != NULL) {
Radek Krejci8d81e002015-12-10 11:18:59 +0100771 switch (leaf->type.base) {
772 case LY_TYPE_STRING:
773 case LY_TYPE_LEAFREF:
774 case LY_TYPE_IDENT:
775 case LY_TYPE_UNION:
776 ly_print(out, "%*sdefault \"%s\";\n", LEVEL, INDENT, leaf->dflt);
777 break;
778 default:
779 ly_print(out, "%*sdefault %s;\n", LEVEL, INDENT, leaf->dflt);
780 break;
781 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200782 }
783 level--;
Michal Vasko16083662015-06-09 14:00:45 +0200784
Radek Krejci76b07902015-10-09 09:11:25 +0200785 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vasko16083662015-06-09 14:00:45 +0200786}
787
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200788static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100789yang_print_anyxml(struct lyout *out, int level, const struct lys_node *node)
Michal Vasko16083662015-06-09 14:00:45 +0200790{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100791 int i, flag = 0;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200792 struct lys_node_anyxml *anyxml = (struct lys_node_anyxml *)node;
Michal Vasko16083662015-06-09 14:00:45 +0200793
Radek Krejci32cce7c2015-12-09 16:44:13 +0100794 ly_print(out, "%*sanyxml %s", LEVEL, INDENT, anyxml->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200795 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100796 yang_print_nacmext(out, level, node, node->module, &flag);
797 yang_print_snode_common2(out, level, node, &flag);
Michal Vasko4773b762015-07-07 12:15:10 +0200798 for (i = 0; i < anyxml->features_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100799 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200800 yang_print_iffeature(out, level, node->module, anyxml->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200801 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200802 for (i = 0; i < anyxml->must_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100803 yang_print_open(out, &flag);
Michal Vaskof9893382015-10-09 14:03:04 +0200804 yang_print_must(out, level, node->module, &anyxml->must[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200805 }
Michal Vasko1f0428a2015-07-07 14:55:04 +0200806 if (anyxml->when) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100807 yang_print_open(out, &flag);
Michal Vaskof9893382015-10-09 14:03:04 +0200808 yang_print_when(out, level, node->module, anyxml->when);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200809 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200810 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100811 yang_print_close(out, level, flag);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200812}
813
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200814static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100815yang_print_leaflist(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200816{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200817 int i;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200818 struct lys_node_leaflist *llist = (struct lys_node_leaflist *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200819
Radek Krejci76b07902015-10-09 09:11:25 +0200820 ly_print(out, "%*sleaf-list %s {\n", LEVEL, INDENT, node->name);
Michal Vasko16083662015-06-09 14:00:45 +0200821
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200822 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100823 yang_print_nacmext(out, level, node, node->module, NULL);
Radek Krejci8d81e002015-12-10 11:18:59 +0100824 if (llist->when) {
825 yang_print_when(out, level, llist->module, llist->when);
826 }
Michal Vasko4773b762015-07-07 12:15:10 +0200827 for (i = 0; i < llist->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200828 yang_print_iffeature(out, level, node->module, llist->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200829 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100830 for (i = 0; i < llist->must_size; i++) {
831 yang_print_must(out, level, node->module, &llist->must[i]);
832 }
833 yang_print_snode_common2(out, level, node, NULL);
834 yang_print_type(out, level, node->module, &llist->type);
835 if (llist->units != NULL) {
836 ly_print(out, "%*sunits \"%s\";\n", LEVEL, INDENT, llist->units);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200837 }
838 if (llist->min > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200839 ly_print(out, "%*smin-elements %u;\n", LEVEL, INDENT, llist->min);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200840 }
841 if (llist->max > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200842 ly_print(out, "%*smax-elements %u;\n", LEVEL, INDENT, llist->max);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200843 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100844 if (llist->flags & LYS_USERORDERED) {
845 ly_print(out, "%*sordered-by user;\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200846 }
847 level--;
Michal Vasko16083662015-06-09 14:00:45 +0200848
Radek Krejci76b07902015-10-09 09:11:25 +0200849 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200850}
851
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200852static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100853yang_print_list(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200854{
Michal Vasko1ef07972015-07-07 14:01:35 +0200855 int i;
Radek Krejci76512572015-08-04 09:47:08 +0200856 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200857 struct lys_node_list *list = (struct lys_node_list *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200858
Radek Krejci76b07902015-10-09 09:11:25 +0200859 ly_print(out, "%*slist %s {\n", LEVEL, INDENT, node->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200860 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100861 yang_print_nacmext(out, level, node, node->module, NULL);
Radek Krejci8d81e002015-12-10 11:18:59 +0100862 if (list->when) {
863 yang_print_when(out, level, list->module, list->when);
864 }
Michal Vasko4773b762015-07-07 12:15:10 +0200865 for (i = 0; i < list->features_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200866 yang_print_iffeature(out, level, node->module, list->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200867 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100868 for (i = 0; i < list->must_size; i++) {
869 yang_print_must(out, level, list->module, &list->must[i]);
870 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200871 if (list->keys_size) {
Radek Krejci76b07902015-10-09 09:11:25 +0200872 ly_print(out, "%*skey \"", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200873 for (i = 0; i < list->keys_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200874 ly_print(out, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : "");
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200875 }
Radek Krejci76b07902015-10-09 09:11:25 +0200876 ly_print(out, "\";\n");
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200877 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200878 for (i = 0; i < list->unique_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200879 yang_print_unique(out, level, &list->unique[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200880 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100881 yang_print_snode_common2(out, level, node, NULL);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200882 if (list->min > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200883 ly_print(out, "%*smin-elements %u;\n", LEVEL, INDENT, list->min);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200884 }
885 if (list->max > 0) {
Radek Krejci76b07902015-10-09 09:11:25 +0200886 ly_print(out, "%*smax-elements %u;\n", LEVEL, INDENT, list->max);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200887 }
Radek Krejci8d81e002015-12-10 11:18:59 +0100888 if (list->flags & LYS_USERORDERED) {
889 ly_print(out, "%*sordered-by user;\n", LEVEL, INDENT);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200890 }
Michal Vaskodff818b2015-06-09 14:01:12 +0200891
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200892 for (i = 0; i < list->tpdf_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200893 yang_print_typedef(out, level, list->module, &list->tpdf[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200894 }
Radek Krejci1d82ef62015-08-07 14:44:40 +0200895 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +0100896 /* augment and data from submodules */
897 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +0200898 continue;
899 }
Radek Krejci76b07902015-10-09 09:11:25 +0200900 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200901 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
902 LYS_USES | LYS_GROUPING | LYS_ANYXML);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200903 }
904 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200905 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200906}
907
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200908static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100909yang_print_grouping(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200910{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200911 int i;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200912 struct lys_node *child;
913 struct lys_node_grp *grp = (struct lys_node_grp *)node;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200914
Radek Krejci76b07902015-10-09 09:11:25 +0200915 ly_print(out, "%*sgrouping %s {\n", LEVEL, INDENT, node->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200916 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200917
Radek Krejci32cce7c2015-12-09 16:44:13 +0100918 yang_print_snode_common(out, level, node, NULL);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200919
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200920 for (i = 0; i < grp->tpdf_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200921 yang_print_typedef(out, level, node->module, &grp->tpdf[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200922 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200923
Radek Krejci1d82ef62015-08-07 14:44:40 +0200924 LY_TREE_FOR(node->child, child) {
Radek Krejci76b07902015-10-09 09:11:25 +0200925 yang_print_snode(out, level, child,
Radek Krejci76512572015-08-04 09:47:08 +0200926 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
927 LYS_USES | LYS_GROUPING | LYS_ANYXML);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200928 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200929
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200930 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200931 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200932}
933
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200934static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100935yang_print_uses(struct lyout *out, int level, const struct lys_node *node)
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200936{
Radek Krejci32cce7c2015-12-09 16:44:13 +0100937 int i, flag = 0;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200938 struct lys_node_uses *uses = (struct lys_node_uses *)node;
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200939
Radek Krejci76b07902015-10-09 09:11:25 +0200940 ly_print(out, "%*suses ", LEVEL, INDENT);
Radek Krejci1d82ef62015-08-07 14:44:40 +0200941 if (node->child && (node->module != node->child->module) && !node->child->module->type) {
Michal Vasko2d851a92015-10-20 16:16:36 +0200942 ly_print(out, "%s:", node->child->module->name);
Michal Vaskoc39c4b12015-07-07 14:55:33 +0200943 }
Radek Krejci32cce7c2015-12-09 16:44:13 +0100944 ly_print(out, "%s", uses->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200945 level++;
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200946
Radek Krejci32cce7c2015-12-09 16:44:13 +0100947 yang_print_nacmext(out, level, node, node->module, &flag);
948 yang_print_snode_common(out, level, node, &flag);
Michal Vasko4773b762015-07-07 12:15:10 +0200949 for (i = 0; i < uses->features_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100950 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200951 yang_print_iffeature(out, level, node->module, uses->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +0200952 }
Michal Vasko1f0428a2015-07-07 14:55:04 +0200953 if (uses->when) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100954 yang_print_open(out, &flag);
Michal Vaskof9893382015-10-09 14:03:04 +0200955 yang_print_when(out, level, node->module, uses->when);
Michal Vasko1f0428a2015-07-07 14:55:04 +0200956 }
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200957
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200958 for (i = 0; i < uses->refine_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100959 yang_print_open(out, &flag);
Michal Vaskof9893382015-10-09 14:03:04 +0200960 yang_print_refine(out, level, node->module, &uses->refine[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200961 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200962
Michal Vasko6f25f212015-07-07 15:42:07 +0200963 for (i = 0; i < uses->augment_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +0100964 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +0200965 yang_print_augment(out, level, node->module, &uses->augment[i]);
Michal Vasko6f25f212015-07-07 15:42:07 +0200966 }
967
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200968 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +0100969 yang_print_close(out, level, flag);
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200970}
971
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200972static void
Michal Vasko1e62a092015-12-01 12:27:20 +0100973yang_print_input_output(struct lyout *out, int level, const struct lys_node *node)
Michal Vasko5bbae102015-06-16 12:16:44 +0200974{
Michal Vaskof4d3d742015-06-16 11:51:09 +0200975 int i;
Radek Krejci76512572015-08-04 09:47:08 +0200976 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +0200977 struct lys_node_rpc_inout *inout = (struct lys_node_rpc_inout *)node;
Michal Vaskof4d3d742015-06-16 11:51:09 +0200978
Radek Krejci76b07902015-10-09 09:11:25 +0200979 ly_print(out, "%*s%s {\n", LEVEL, INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
Michal Vaskof4d3d742015-06-16 11:51:09 +0200980
981 level++;
982 for (i = 0; i < inout->tpdf_size; i++) {
Radek Krejci76b07902015-10-09 09:11:25 +0200983 yang_print_typedef(out, level, node->module, &inout->tpdf[i]);
Michal Vaskof4d3d742015-06-16 11:51:09 +0200984 }
985
Radek Krejci1d82ef62015-08-07 14:44:40 +0200986 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +0100987 /* augment and data from submodules */
988 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +0200989 continue;
990 }
Radek Krejci76b07902015-10-09 09:11:25 +0200991 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +0200992 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
993 LYS_USES | LYS_GROUPING | LYS_ANYXML);
Michal Vaskof4d3d742015-06-16 11:51:09 +0200994 }
995
996 level--;
Radek Krejci76b07902015-10-09 09:11:25 +0200997 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vaskof4d3d742015-06-16 11:51:09 +0200998}
999
1000static void
Michal Vasko1e62a092015-12-01 12:27:20 +01001001yang_print_rpc(struct lyout *out, int level, const struct lys_node *node)
Michal Vaskof4d3d742015-06-16 11:51:09 +02001002{
Radek Krejci32cce7c2015-12-09 16:44:13 +01001003 int i, flag = 0;
Radek Krejci76512572015-08-04 09:47:08 +02001004 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +02001005 struct lys_node_rpc *rpc = (struct lys_node_rpc *)node;
Michal Vaskof4d3d742015-06-16 11:51:09 +02001006
Radek Krejci32cce7c2015-12-09 16:44:13 +01001007 ly_print(out, "%*srpc %s", LEVEL, INDENT, node->name);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001008
1009 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +01001010 yang_print_snode_common(out, level, node, &flag);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001011
Michal Vasko4773b762015-07-07 12:15:10 +02001012 for (i = 0; i < rpc->features_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +01001013 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +02001014 yang_print_iffeature(out, level, node->module, rpc->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +02001015 }
1016
Michal Vaskof4d3d742015-06-16 11:51:09 +02001017 for (i = 0; i < rpc->tpdf_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +01001018 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +02001019 yang_print_typedef(out, level, node->module, &rpc->tpdf[i]);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001020 }
1021
Radek Krejci1d82ef62015-08-07 14:44:40 +02001022 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +01001023 /* augment and data from submodules */
1024 if (sub->module != node->module) {
1025 continue;
1026 }
Radek Krejci32cce7c2015-12-09 16:44:13 +01001027 yang_print_open(out, &flag);
1028 yang_print_snode(out, level, sub, LYS_GROUPING | LYS_INPUT | LYS_OUTPUT);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001029 }
1030
1031 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +01001032 yang_print_close(out, level, flag);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001033}
1034
1035static void
Michal Vasko1e62a092015-12-01 12:27:20 +01001036yang_print_notif(struct lyout *out, int level, const struct lys_node *node)
Michal Vasko7690bc12015-06-16 12:26:05 +02001037{
Radek Krejci32cce7c2015-12-09 16:44:13 +01001038 int i, flag = 0;
Radek Krejci76512572015-08-04 09:47:08 +02001039 struct lys_node *sub;
Radek Krejci1d82ef62015-08-07 14:44:40 +02001040 struct lys_node_notif *notif = (struct lys_node_notif *)node;
Michal Vaskof4d3d742015-06-16 11:51:09 +02001041
Radek Krejci32cce7c2015-12-09 16:44:13 +01001042 ly_print(out, "%*snotification %s", LEVEL, INDENT, node->name);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001043
1044 level++;
Radek Krejci32cce7c2015-12-09 16:44:13 +01001045 yang_print_snode_common(out, level, node, &flag);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001046
Michal Vasko4773b762015-07-07 12:15:10 +02001047 for (i = 0; i < notif->features_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +01001048 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +02001049 yang_print_iffeature(out, level, node->module, notif->features[i]);
Michal Vasko4773b762015-07-07 12:15:10 +02001050 }
1051
Michal Vaskof4d3d742015-06-16 11:51:09 +02001052 for (i = 0; i < notif->tpdf_size; i++) {
Radek Krejci32cce7c2015-12-09 16:44:13 +01001053 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +02001054 yang_print_typedef(out, level, node->module, &notif->tpdf[i]);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001055 }
1056
Radek Krejci1d82ef62015-08-07 14:44:40 +02001057 LY_TREE_FOR(node->child, sub) {
Radek Krejcic071c542016-01-27 14:57:51 +01001058 /* augment and data from submodules */
1059 if (sub->module != node->module) {
Michal Vasko15b48702015-07-07 15:49:34 +02001060 continue;
1061 }
Radek Krejci32cce7c2015-12-09 16:44:13 +01001062 yang_print_open(out, &flag);
Radek Krejci76b07902015-10-09 09:11:25 +02001063 yang_print_snode(out, level, sub,
Radek Krejci76512572015-08-04 09:47:08 +02001064 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
1065 LYS_USES | LYS_GROUPING | LYS_ANYXML);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001066 }
1067
1068 level--;
Radek Krejci32cce7c2015-12-09 16:44:13 +01001069 yang_print_close(out, level, flag);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001070}
1071
1072static void
Michal Vasko1e62a092015-12-01 12:27:20 +01001073yang_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask)
Radek Krejcida04f4a2015-05-21 12:54:09 +02001074{
Radek Krejci1d82ef62015-08-07 14:44:40 +02001075 switch (node->nodetype & mask) {
Radek Krejci76512572015-08-04 09:47:08 +02001076 case LYS_CONTAINER:
Radek Krejci76b07902015-10-09 09:11:25 +02001077 yang_print_container(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001078 break;
Radek Krejci76512572015-08-04 09:47:08 +02001079 case LYS_CHOICE:
Radek Krejci76b07902015-10-09 09:11:25 +02001080 yang_print_choice(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001081 break;
Radek Krejci76512572015-08-04 09:47:08 +02001082 case LYS_LEAF:
Radek Krejci76b07902015-10-09 09:11:25 +02001083 yang_print_leaf(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001084 break;
Radek Krejci76512572015-08-04 09:47:08 +02001085 case LYS_LEAFLIST:
Radek Krejci76b07902015-10-09 09:11:25 +02001086 yang_print_leaflist(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001087 break;
Radek Krejci76512572015-08-04 09:47:08 +02001088 case LYS_LIST:
Radek Krejci76b07902015-10-09 09:11:25 +02001089 yang_print_list(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001090 break;
Radek Krejci76512572015-08-04 09:47:08 +02001091 case LYS_USES:
Radek Krejci76b07902015-10-09 09:11:25 +02001092 yang_print_uses(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001093 break;
Radek Krejci76512572015-08-04 09:47:08 +02001094 case LYS_GROUPING:
Radek Krejci76b07902015-10-09 09:11:25 +02001095 yang_print_grouping(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001096 break;
Radek Krejci76512572015-08-04 09:47:08 +02001097 case LYS_ANYXML:
Radek Krejci76b07902015-10-09 09:11:25 +02001098 yang_print_anyxml(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001099 break;
Radek Krejci76512572015-08-04 09:47:08 +02001100 case LYS_CASE:
Radek Krejci76b07902015-10-09 09:11:25 +02001101 yang_print_case(out, level, node);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001102 break;
Radek Krejci76512572015-08-04 09:47:08 +02001103 case LYS_INPUT:
1104 case LYS_OUTPUT:
Radek Krejci76b07902015-10-09 09:11:25 +02001105 yang_print_input_output(out, level, node);
Michal Vaskof4d3d742015-06-16 11:51:09 +02001106 break;
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001107 default:
1108 break;
1109 }
Radek Krejcida04f4a2015-05-21 12:54:09 +02001110}
1111
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001112int
Michal Vasko1e62a092015-12-01 12:27:20 +01001113yang_print_model(struct lyout *out, const struct lys_module *module)
Radek Krejcida04f4a2015-05-21 12:54:09 +02001114{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001115 unsigned int i;
1116 int level = 0;
Radek Krejcida04f4a2015-05-21 12:54:09 +02001117#define LEVEL (level*2)
1118
Radek Krejci1d82ef62015-08-07 14:44:40 +02001119 struct lys_node *node;
Radek Krejcida04f4a2015-05-21 12:54:09 +02001120
Radek Krejci8d81e002015-12-10 11:18:59 +01001121 /* (sub)module-header-stmts */
Michal Vasko116172e2015-07-07 11:54:37 +02001122 if (module->type) {
Radek Krejci76b07902015-10-09 09:11:25 +02001123 ly_print(out, "submodule %s {%s\n", module->name, (module->deviated ? " // DEVIATED" : ""));
Michal Vasko116172e2015-07-07 11:54:37 +02001124 level++;
Radek Krejci8d81e002015-12-10 11:18:59 +01001125 if (module->version) {
Radek Krejcic071c542016-01-27 14:57:51 +01001126 ly_print(out, "%*syang-version %s;\n", LEVEL, INDENT,
1127 ((struct lys_submodule *)module)->belongsto->version == 2 ? "1.1" : "1");
Radek Krejci8d81e002015-12-10 11:18:59 +01001128 }
Radek Krejci76b07902015-10-09 09:11:25 +02001129 ly_print(out, "%*sbelongs-to %s {\n", LEVEL, INDENT, ((struct lys_submodule *)module)->belongsto->name);
Michal Vasko116172e2015-07-07 11:54:37 +02001130 level++;
Radek Krejci8d81e002015-12-10 11:18:59 +01001131 ly_print(out, "%*sprefix %s;\n", LEVEL, INDENT, module->prefix);
Michal Vasko116172e2015-07-07 11:54:37 +02001132 level--;
Radek Krejci76b07902015-10-09 09:11:25 +02001133 ly_print(out, "%*s}\n", LEVEL, INDENT);
Michal Vasko116172e2015-07-07 11:54:37 +02001134 } else {
Radek Krejci76b07902015-10-09 09:11:25 +02001135 ly_print(out, "module %s {%s\n", module->name, (module->deviated ? " // DEVIATED" : ""));
Michal Vasko116172e2015-07-07 11:54:37 +02001136 level++;
Radek Krejci8d81e002015-12-10 11:18:59 +01001137 if (module->version) {
Radek Krejcic071c542016-01-27 14:57:51 +01001138 ly_print(out, "%*syang-version %s;\n", LEVEL, INDENT, module->version == 2 ? "1.1" : "1");
Radek Krejci8d81e002015-12-10 11:18:59 +01001139 }
Radek Krejci76b07902015-10-09 09:11:25 +02001140 ly_print(out, "%*snamespace \"%s\";\n", LEVEL, INDENT, module->ns);
Radek Krejci8d81e002015-12-10 11:18:59 +01001141 ly_print(out, "%*sprefix %s;\n", LEVEL, INDENT, module->prefix);
Michal Vasko116172e2015-07-07 11:54:37 +02001142 }
Radek Krejcib0594bf2015-05-21 23:51:27 +02001143
Radek Krejci8d81e002015-12-10 11:18:59 +01001144 /* linkage-stmts */
1145 if (module->imp_size || module->inc_size) {
1146 ly_print(out, "\n");
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001147 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001148 for (i = 0; i < module->imp_size; i++) {
Radek Krejcic071c542016-01-27 14:57:51 +01001149 if (module->imp[i].external) {
1150 continue;
1151 }
Radek Krejci76b07902015-10-09 09:11:25 +02001152 ly_print(out, "%*simport \"%s\" {\n", LEVEL, INDENT, module->imp[i].module->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001153 level++;
Radek Krejci8d81e002015-12-10 11:18:59 +01001154 ly_print(out, "%*sprefix %s;\n", LEVEL, INDENT, module->imp[i].prefix);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001155 if (module->imp[i].rev[0]) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001156 ly_print(out, "%*srevision-date %s;", LEVEL, INDENT, module->imp[i].rev);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001157 }
1158 level--;
Radek Krejci8d81e002015-12-10 11:18:59 +01001159 ly_print(out, "%*s}", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001160 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001161 for (i = 0; i < module->inc_size; i++) {
Radek Krejcic071c542016-01-27 14:57:51 +01001162 if (module->inc[i].external) {
1163 continue;
1164 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001165 if (module->inc[i].rev[0]) {
Radek Krejci76b07902015-10-09 09:11:25 +02001166 ly_print(out, "%*sinclude \"%s\" {\n", LEVEL, INDENT, module->inc[i].submodule->name);
Radek Krejci8d81e002015-12-10 11:18:59 +01001167 level++;
1168 ly_print(out, "%*srevision-date %s;", LEVEL, INDENT, module->inc[i].rev);
1169 level--;
Radek Krejci76b07902015-10-09 09:11:25 +02001170 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001171 } else {
Radek Krejci76b07902015-10-09 09:11:25 +02001172 ly_print(out, "%*sinclude \"%s\";\n", LEVEL, INDENT, module->inc[i].submodule->name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001173 }
1174 }
Radek Krejciefaeba32015-05-27 14:30:57 +02001175
Radek Krejci8d81e002015-12-10 11:18:59 +01001176 /* meta-stmts */
1177 if (module->org || module->contact || module->dsc || module->ref) {
1178 ly_print(out, "\n");
1179 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001180 if (module->org) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001181 yang_print_text(out, level, "organization", module->org, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001182 }
1183 if (module->contact) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001184 yang_print_text(out, level, "contact", module->contact, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001185 }
1186 if (module->dsc) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001187 yang_print_text(out, level, "description", module->dsc, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001188 }
1189 if (module->ref) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001190 yang_print_text(out, level, "reference", module->ref, 0);
1191 }
1192
1193 /* revision-stmts */
1194 if (module->rev_size) {
1195 ly_print(out, "\n");
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001196 }
1197 for (i = 0; i < module->rev_size; i++) {
1198 if (module->rev[i].dsc || module->rev[i].ref) {
Radek Krejci76b07902015-10-09 09:11:25 +02001199 ly_print(out, "%*srevision \"%s\" {\n", LEVEL, INDENT, module->rev[i].date);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001200 level++;
1201 if (module->rev[i].dsc) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001202 yang_print_text(out, level, "description", module->rev[i].dsc, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001203 }
1204 if (module->rev[i].ref) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001205 yang_print_text(out, level, "reference", module->rev[i].ref, 0);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001206 }
1207 level--;
Radek Krejci76b07902015-10-09 09:11:25 +02001208 ly_print(out, "%*s}\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001209 } else {
Radek Krejci8d81e002015-12-10 11:18:59 +01001210 ly_print(out, "%*srevision %s;", LEVEL, INDENT, module->rev[i].date);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001211 }
1212 }
Radek Krejcida04f4a2015-05-21 12:54:09 +02001213
Radek Krejci8d81e002015-12-10 11:18:59 +01001214 /* body-stmts */
Michal Vasko30f6e912015-07-07 12:24:27 +02001215 for (i = 0; i < module->features_size; i++) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001216 ly_print(out, "\n");
Radek Krejci76b07902015-10-09 09:11:25 +02001217 yang_print_feature(out, level, &module->features[i]);
Michal Vasko30f6e912015-07-07 12:24:27 +02001218 }
1219
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001220 for (i = 0; i < module->ident_size; i++) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001221 ly_print(out, "\n");
Radek Krejci76b07902015-10-09 09:11:25 +02001222 yang_print_identity(out, level, &module->ident[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001223 }
Radek Krejci6793db02015-05-22 17:49:54 +02001224
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001225 for (i = 0; i < module->tpdf_size; i++) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001226 ly_print(out, "\n");
Radek Krejci76b07902015-10-09 09:11:25 +02001227 yang_print_typedef(out, level, module, &module->tpdf[i]);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001228 }
Radek Krejcida04f4a2015-05-21 12:54:09 +02001229
Radek Krejci8d81e002015-12-10 11:18:59 +01001230 for (i = 0; i < module->deviation_size; ++i) {
1231 ly_print(out, "\n");
1232 yang_print_deviation(out, level, module, &module->deviation[i]);
1233 }
1234
Radek Krejci1d82ef62015-08-07 14:44:40 +02001235 LY_TREE_FOR(module->data, node) {
Radek Krejcic071c542016-01-27 14:57:51 +01001236 if (node->module != module) {
1237 continue;
1238 }
Radek Krejci8d81e002015-12-10 11:18:59 +01001239 ly_print(out, "\n");
Radek Krejci92720552015-10-05 15:28:27 +02001240 switch(node->nodetype) {
1241 case LYS_RPC:
Radek Krejcibac81762015-10-09 10:19:52 +02001242 yang_print_rpc(out, level, node);
Radek Krejci92720552015-10-05 15:28:27 +02001243 break;
1244 case LYS_NOTIF:
Radek Krejcibac81762015-10-09 10:19:52 +02001245 yang_print_notif(out, level, node);
Radek Krejci92720552015-10-05 15:28:27 +02001246 break;
1247 default:
Radek Krejcibac81762015-10-09 10:19:52 +02001248 yang_print_snode(out, level, node,
Radek Krejci92720552015-10-05 15:28:27 +02001249 LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST |
1250 LYS_USES | LYS_GROUPING | LYS_ANYXML);
1251 break;
1252 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001253 }
Radek Krejcida04f4a2015-05-21 12:54:09 +02001254
Michal Vasko6f25f212015-07-07 15:42:07 +02001255 for (i = 0; i < module->augment_size; i++) {
Radek Krejci8d81e002015-12-10 11:18:59 +01001256 ly_print(out, "\n");
Radek Krejci76b07902015-10-09 09:11:25 +02001257 yang_print_augment(out, level, module, &module->augment[i]);
Michal Vasko6f25f212015-07-07 15:42:07 +02001258 }
1259
Radek Krejci76b07902015-10-09 09:11:25 +02001260 ly_print(out, "}\n");
Radek Krejcida04f4a2015-05-21 12:54:09 +02001261
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001262 return EXIT_SUCCESS;
Radek Krejcida04f4a2015-05-21 12:54:09 +02001263#undef LEVEL
1264}