Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file printer_yin.c |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief YIN printer for libyang data model structure |
| 5 | * |
| 6 | * Copyright (c) 2016 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
| 17 | |
| 18 | #include "common.h" |
| 19 | #include "printer.h" |
| 20 | #include "tree_schema.h" |
| 21 | #include "xml_internal.h" |
| 22 | |
| 23 | #define INDENT "" |
| 24 | #define LEVEL (level*2) |
| 25 | |
| 26 | static void yin_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask); |
| 27 | |
| 28 | static void |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 29 | yin_print_open(struct lyout *out, int level, const char *elem_name, const char *attr_name, const char *attr_value, |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 30 | int close) |
| 31 | { |
| 32 | ly_print(out, "%*s<%s %s=\"%s\"%s>\n", LEVEL, INDENT, elem_name, attr_name, attr_value, (close ? "/" : "")); |
| 33 | } |
| 34 | |
| 35 | static void |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 36 | yin_print_close(struct lyout *out, int level, const char *elem_name) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 37 | { |
| 38 | ly_print(out, "%*s</%s>\n", LEVEL, INDENT, elem_name); |
| 39 | } |
| 40 | |
| 41 | static void |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 42 | yin_print_unsigned(struct lyout *out, int level, const char *elem_name, const char *attr_name, unsigned int attr_value) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 43 | { |
| 44 | ly_print(out, "%*s<%s %s=\"%u\"/>\n", LEVEL, INDENT, elem_name, attr_name, attr_value); |
| 45 | } |
| 46 | |
| 47 | static void |
| 48 | yin_print_text(struct lyout *out, int level, const char *elem_name, const char *text) |
| 49 | { |
| 50 | ly_print(out, "%*s<%s>\n", LEVEL, INDENT, elem_name); |
| 51 | |
| 52 | level++; |
| 53 | ly_print(out, "%*s<text>", LEVEL, INDENT); |
| 54 | lyxml_dump_text(out, text); |
| 55 | ly_print(out, "</text>\n"); |
| 56 | level--; |
| 57 | |
| 58 | ly_print(out, "%*s</%s>\n", LEVEL, INDENT, elem_name); |
| 59 | } |
| 60 | |
| 61 | static void |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 62 | yin_print_restr_sub(struct lyout *out, int level, const struct lys_restr *restr) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 63 | { |
| 64 | if (restr->dsc) { |
| 65 | yin_print_text(out, level, "description", restr->dsc); |
| 66 | } |
| 67 | if (restr->ref) { |
| 68 | yin_print_text(out, level, "reference", restr->ref); |
| 69 | } |
| 70 | if (restr->eapptag) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 71 | yin_print_open(out, level, "error-app-tag", "value", restr->eapptag, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 72 | } |
| 73 | if (restr->emsg) { |
| 74 | ly_print(out, "%*s<error-message>\n", LEVEL, INDENT); |
| 75 | |
| 76 | level++; |
| 77 | ly_print(out, "%*s<value>", LEVEL, INDENT, restr->emsg); |
| 78 | lyxml_dump_text(out, restr->emsg); |
| 79 | ly_print(out, "</value>\n"); |
| 80 | level--; |
| 81 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 82 | yin_print_close(out, level, "error-message"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | static void |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 87 | yin_print_restr(struct lyout *out, int level, const char *elem_name, const struct lys_restr *restr) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 88 | { |
| 89 | int close; |
| 90 | |
| 91 | close = (restr->dsc || restr->ref || restr->eapptag || restr->emsg ? 0 : 1); |
| 92 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 93 | yin_print_open(out, level, elem_name, "value", restr->expr, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 94 | if (!close) { |
Michal Vasko | 70983bd | 2016-05-17 16:14:00 +0200 | [diff] [blame] | 95 | yin_print_restr_sub(out, level + 1, restr); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 96 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 97 | yin_print_close(out, level, elem_name); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | static int |
| 102 | yin_has_nacmext(const struct lys_node *node) |
| 103 | { |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 104 | if (node->nacm && (!lys_parent(node) || lys_parent(node)->nacm != node->nacm)) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 105 | return 1; |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | yin_print_nacmext(struct lyout *out, int level, const struct lys_node *node, const struct lys_module *module) |
| 112 | { |
| 113 | int i, j; |
| 114 | const char *prefix = NULL; |
| 115 | |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 116 | if (node->nacm && (!lys_parent(node) || lys_parent(node)->nacm != node->nacm)) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 117 | /* locate ietf-netconf-acm module in imports */ |
| 118 | if (!strcmp(module->name, "ietf-netconf-acm")) { |
| 119 | prefix = module->prefix; |
| 120 | } else { |
| 121 | /* search in imports */ |
| 122 | for (i = 0; i < module->imp_size; i++) { |
| 123 | if (!strcmp(module->imp[i].module->name, "ietf-netconf-acm")) { |
| 124 | prefix = module->imp[i].prefix; |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | /* and in imports of includes */ |
| 129 | if (!prefix) { |
| 130 | for (j = 0; j < module->inc_size; j++) { |
| 131 | for (i = 0; i < module->inc[j].submodule->imp_size; i++) { |
| 132 | if (!strcmp(module->inc[j].submodule->imp[i].module->name, "ietf-netconf-acm")) { |
| 133 | prefix = module->inc[j].submodule->imp[i].prefix; |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 141 | if ((node->nacm & LYS_NACM_DENYW) && (!lys_parent(node) || !(lys_parent(node)->nacm & LYS_NACM_DENYW))) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 142 | ly_print(out, "%*s<%s:default-deny-write/>\n", LEVEL, INDENT, prefix); |
| 143 | } |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 144 | if ((node->nacm & LYS_NACM_DENYA) && (!lys_parent(node) || !(lys_parent(node)->nacm & LYS_NACM_DENYA))) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 145 | ly_print(out, "%*s<%s:default-deny-all/>\n", LEVEL, INDENT, prefix); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static int |
| 151 | yin_has_snode_common(const struct lys_node *node) |
| 152 | { |
| 153 | if ((node->flags & LYS_STATUS_MASK) || node->dsc || node->ref) { |
| 154 | return 1; |
| 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Covers: |
| 161 | * description, reference, status |
| 162 | */ |
| 163 | static void |
| 164 | yin_print_snode_common(struct lyout *out, int level, const struct lys_node *node) |
| 165 | { |
| 166 | if (node->flags & LYS_STATUS_CURR) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 167 | yin_print_open(out, level, "status", "value", "current", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 168 | } else if (node->flags & LYS_STATUS_DEPRC) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 169 | yin_print_open(out, level, "status", "value", "deprecated", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 170 | } else if (node->flags & LYS_STATUS_OBSLT) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 171 | yin_print_open(out, level, "status", "value", "obsolete", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | if (node->dsc) { |
| 175 | yin_print_text(out, level, "description", node->dsc); |
| 176 | } |
| 177 | if (node->ref) { |
| 178 | yin_print_text(out, level, "reference", node->ref); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static int |
| 183 | yin_has_snode_common2(const struct lys_node *node) |
| 184 | { |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 185 | if ((lys_parent(node) && (lys_parent(node)->flags & LYS_CONFIG_MASK) != (node->flags & LYS_CONFIG_MASK)) |
| 186 | || (!lys_parent(node) && (node->flags & LYS_CONFIG_R)) || (node->flags & LYS_MAND_MASK)) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 187 | return 1; |
| 188 | } |
| 189 | return yin_has_snode_common(node); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Covers: |
| 194 | * config, mandatory |
| 195 | * description, reference, status |
| 196 | */ |
| 197 | static void |
| 198 | yin_print_snode_common2(struct lyout *out, int level, const struct lys_node *node) |
| 199 | { |
Michal Vasko | dcf98e6 | 2016-05-05 17:53:53 +0200 | [diff] [blame] | 200 | if (lys_parent(node)) { |
Radek Krejci | 32c7bd6 | 2016-04-14 17:47:04 +0200 | [diff] [blame] | 201 | if (node->flags & LYS_CONFIG_SET) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 202 | /* print config when it differs from the parent ... */ |
| 203 | if (node->flags & LYS_CONFIG_W) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 204 | yin_print_open(out, level, "config", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 205 | } else if (node->flags & LYS_CONFIG_R) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 206 | yin_print_open(out, level, "config", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | } else if (node->flags & LYS_CONFIG_R) { |
| 210 | /* ... or is a top-level state node */ |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 211 | yin_print_open(out, level, "config", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | if (node->flags & LYS_MAND_TRUE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 215 | yin_print_open(out, level, "mandatory", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 216 | } else if (node->flags & LYS_MAND_FALSE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 217 | yin_print_open(out, level, "mandatory", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | yin_print_snode_common(out, level, node); |
| 221 | } |
| 222 | |
| 223 | static void |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 224 | yin_print_iffeature(struct lyout *out, int level, const struct lys_module *module, struct lys_iffeature *iffeature) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 225 | { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 226 | ly_print(out, "%*s<if-feature name=\"", LEVEL, INDENT); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 227 | ly_print_iffeature(out, module, iffeature); |
| 228 | ly_print(out, "\"/>\n"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static void |
| 232 | yin_print_feature(struct lyout *out, int level, const struct lys_feature *feat) |
| 233 | { |
| 234 | int i, close; |
| 235 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 236 | close = (yin_has_snode_common((struct lys_node *)feat) || feat->iffeature_size ? 0 : 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 237 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 238 | yin_print_open(out, level, "feature", "name", feat->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 239 | |
| 240 | if (!close) { |
| 241 | level++; |
| 242 | yin_print_snode_common(out, level, (struct lys_node *)feat); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 243 | for (i = 0; i < feat->iffeature_size; ++i) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 244 | yin_print_iffeature(out, level, feat->module, &feat->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 245 | } |
| 246 | level--; |
| 247 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 248 | yin_print_close(out, level, "feature"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | yin_print_when(struct lyout *out, int level, const struct lys_module *module, const struct lys_when *when) |
| 254 | { |
| 255 | int close; |
| 256 | const char *str; |
| 257 | |
| 258 | close = (when->dsc || when->ref ? 0 : 1); |
| 259 | |
| 260 | str = transform_json2schema(module, when->cond); |
| 261 | if (!str) { |
| 262 | ly_print(out, "(!error!)"); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | ly_print(out, "%*s<when condition=\"", LEVEL, INDENT); |
| 267 | lyxml_dump_text(out, str); |
| 268 | ly_print(out, "\"%s>\n", (close ? "/" : "")); |
| 269 | |
| 270 | lydict_remove(module->ctx, str); |
| 271 | |
| 272 | if (!close) { |
| 273 | level++; |
| 274 | if (when->dsc) { |
| 275 | yin_print_text(out, level, "description", when->dsc); |
| 276 | } |
| 277 | if (when->ref) { |
| 278 | yin_print_text(out, level, "reference", when->ref); |
| 279 | } |
| 280 | level--; |
| 281 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 282 | yin_print_close(out, level, "when"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
| 286 | static void |
| 287 | yin_print_type(struct lyout *out, int level, const struct lys_module *module, const struct lys_type *type) |
| 288 | { |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 289 | int i, close, close2; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 290 | const char *str; |
| 291 | struct lys_module *mod; |
| 292 | |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 293 | /* decide whether the type will have any substatements */ |
| 294 | close = 1; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 295 | switch (type->base) { |
| 296 | case LY_TYPE_BINARY: |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 297 | if (type->info.binary.length) { |
| 298 | close = 0; |
| 299 | } |
| 300 | break; |
| 301 | case LY_TYPE_DEC64: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 302 | if (type->info.dec64.dig || type->info.dec64.range) { |
| 303 | close = 0; |
| 304 | } |
| 305 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 306 | case LY_TYPE_ENUM: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 307 | if (type->info.enums.count) { |
| 308 | close = 0; |
| 309 | } |
| 310 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 311 | case LY_TYPE_IDENT: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 312 | if (type->info.ident.ref) { |
| 313 | close = 0; |
| 314 | } |
| 315 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 316 | case LY_TYPE_BITS: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 317 | if (type->info.bits.count) { |
| 318 | close = 0; |
| 319 | } |
| 320 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 321 | case LY_TYPE_UNION: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 322 | if (type->info.uni.count) { |
| 323 | close = 0; |
| 324 | } |
| 325 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 326 | case LY_TYPE_LEAFREF: |
Radek Krejci | 0dbff6a | 2016-07-17 12:40:18 +0200 | [diff] [blame] | 327 | if (ly_strequal(type->der->name, "leafref", 0)) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 328 | close = 0; |
| 329 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 330 | break; |
| 331 | case LY_TYPE_INST: |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 332 | if (type->info.inst.req) { |
| 333 | close = 0; |
| 334 | } |
| 335 | break; |
| 336 | case LY_TYPE_INT8: |
| 337 | case LY_TYPE_INT16: |
| 338 | case LY_TYPE_INT32: |
| 339 | case LY_TYPE_INT64: |
| 340 | case LY_TYPE_UINT8: |
| 341 | case LY_TYPE_UINT16: |
| 342 | case LY_TYPE_UINT32: |
| 343 | case LY_TYPE_UINT64: |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 344 | if (type->info.num.range) { |
| 345 | close = 0; |
| 346 | } |
| 347 | break; |
| 348 | case LY_TYPE_STRING: |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 349 | if (type->info.str.length || type->info.str.pat_count) { |
| 350 | close = 0; |
| 351 | } |
| 352 | break; |
| 353 | default: |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 354 | break; |
| 355 | } |
| 356 | |
| 357 | if (type->module_name) { |
| 358 | ly_print(out, "%*s<type name=\"%s:%s\"%s>\n", LEVEL, INDENT, |
| 359 | transform_module_name2import_prefix(module, type->module_name), type->der->name, (close ? "/" : "")); |
| 360 | } else { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 361 | yin_print_open(out, level, "type", "name", type->der->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | if (!close) { |
| 365 | level++; |
| 366 | switch (type->base) { |
| 367 | case LY_TYPE_BINARY: |
| 368 | if (type->info.binary.length) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 369 | yin_print_restr(out, level, "length", type->info.binary.length); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 370 | } |
| 371 | break; |
| 372 | case LY_TYPE_BITS: |
| 373 | for (i = 0; i < type->info.bits.count; ++i) { |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 374 | close2 = !yin_has_snode_common((struct lys_node *)&type->info.bits.bit[i]) |
| 375 | && (type->info.bits.bit[i].flags & LYS_AUTOASSIGNED); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 376 | |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 377 | yin_print_open(out, level, "bit", "name", type->info.bits.bit[i].name, close2); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 378 | |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 379 | if (!close2) { |
| 380 | level++; |
| 381 | yin_print_snode_common(out, level, (struct lys_node *)&type->info.bits.bit[i]); |
| 382 | if (!(type->info.bits.bit[i].flags & LYS_AUTOASSIGNED)) { |
| 383 | yin_print_unsigned(out, level, "position", "value", type->info.bits.bit[i].pos); |
| 384 | } |
| 385 | level--; |
| 386 | |
| 387 | yin_print_close(out, level, "bit"); |
| 388 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 389 | } |
| 390 | break; |
| 391 | case LY_TYPE_DEC64: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 392 | if (type->info.dec64.dig) { |
| 393 | yin_print_unsigned(out, level, "fraction-digits", "value", type->info.dec64.dig); |
| 394 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 395 | if (type->info.dec64.range) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 396 | yin_print_restr(out, level, "range", type->info.dec64.range); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 397 | } |
| 398 | break; |
| 399 | case LY_TYPE_ENUM: |
| 400 | for (i = 0; i < type->info.enums.count; i++) { |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 401 | close2 = !yin_has_snode_common((struct lys_node *)&type->info.enums.enm[i]) |
| 402 | && (type->info.enums.enm[i].flags & LYS_AUTOASSIGNED); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 403 | |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 404 | yin_print_open(out, level, "enum", "name", type->info.enums.enm[i].name, close2); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 405 | |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 406 | if (!close2) { |
| 407 | level++; |
| 408 | yin_print_snode_common(out, level, (struct lys_node *)&type->info.enums.enm[i]); |
| 409 | if (!(type->info.enums.enm[i].flags & LYS_AUTOASSIGNED)) { |
| 410 | ly_print(out, "%*s<value value=\"%d\"/>\n", LEVEL, INDENT, type->info.enums.enm[i].value); |
| 411 | } |
| 412 | level--; |
| 413 | |
| 414 | yin_print_close(out, level, "enum"); |
| 415 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 416 | } |
| 417 | break; |
| 418 | case LY_TYPE_IDENT: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 419 | if (type->info.ident.ref) { |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 420 | mod = lys_main_module(type->info.ident.ref->module); |
| 421 | if (lys_main_module(module) == mod) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 422 | ly_print(out, "%*s<base name=\"%s\"/>\n", LEVEL, INDENT, type->info.ident.ref->name); |
| 423 | } else { |
| 424 | ly_print(out, "%*s<base name=\"%s:%s\"/>\n", LEVEL, INDENT, |
| 425 | transform_module_name2import_prefix(module, mod->name), type->info.ident.ref->name); |
| 426 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 427 | } |
| 428 | break; |
| 429 | case LY_TYPE_INST: |
| 430 | if (type->info.inst.req == 1) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 431 | yin_print_open(out, level, "require-instance", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 432 | } else if (type->info.inst.req == -1) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 433 | yin_print_open(out, level, "require-instance", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 434 | } |
| 435 | break; |
| 436 | case LY_TYPE_INT8: |
| 437 | case LY_TYPE_INT16: |
| 438 | case LY_TYPE_INT32: |
| 439 | case LY_TYPE_INT64: |
| 440 | case LY_TYPE_UINT8: |
| 441 | case LY_TYPE_UINT16: |
| 442 | case LY_TYPE_UINT32: |
| 443 | case LY_TYPE_UINT64: |
| 444 | if (type->info.num.range) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 445 | yin_print_restr(out, level, "range", type->info.num.range); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 446 | } |
| 447 | break; |
| 448 | case LY_TYPE_LEAFREF: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 449 | if (type->info.lref.path) { |
| 450 | str = transform_json2schema(module, type->info.lref.path); |
| 451 | yin_print_open(out, level, "path", "value", str, 1); |
| 452 | lydict_remove(module->ctx, str); |
| 453 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 454 | break; |
| 455 | case LY_TYPE_STRING: |
| 456 | if (type->info.str.length) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 457 | yin_print_restr(out, level, "length", type->info.str.length); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 458 | } |
| 459 | for (i = 0; i < type->info.str.pat_count; i++) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 460 | yin_print_restr(out, level, "pattern", &type->info.str.patterns[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 461 | } |
| 462 | break; |
| 463 | case LY_TYPE_UNION: |
| 464 | for (i = 0; i < type->info.uni.count; ++i) { |
| 465 | yin_print_type(out, level, module, &type->info.uni.types[i]); |
| 466 | } |
| 467 | break; |
| 468 | default: |
| 469 | /* other types do not have substatements */ |
| 470 | break; |
| 471 | } |
| 472 | level--; |
| 473 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 474 | yin_print_close(out, level, "type"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | static void |
| 479 | yin_print_must(struct lyout *out, int level, const struct lys_module *module, const struct lys_restr *must) |
| 480 | { |
| 481 | const char *str; |
| 482 | int close; |
| 483 | |
| 484 | close = (must->dsc || must->ref || must->eapptag || must->emsg ? 0 : 1); |
| 485 | |
| 486 | str = transform_json2schema(module, must->expr); |
| 487 | if (!str) { |
| 488 | ly_print(out, "(!error!)"); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | ly_print(out, "%*s<must condition=\"", LEVEL, INDENT); |
| 493 | lyxml_dump_text(out, str); |
| 494 | ly_print(out, "\"%s>\n", (close ? "/" : "")); |
| 495 | |
| 496 | lydict_remove(module->ctx, str); |
| 497 | |
| 498 | if (!close) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 499 | yin_print_restr_sub(out, level + 1, must); |
| 500 | yin_print_close(out, level, "must"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
| 504 | static void |
| 505 | yin_print_unique(struct lyout *out, int level, const struct lys_unique *uniq) |
| 506 | { |
| 507 | int i; |
| 508 | |
| 509 | ly_print(out, "%*s<unique tag=\"", LEVEL, INDENT); |
| 510 | for (i = 0; i < uniq->expr_size; i++) { |
| 511 | ly_print(out, "%s%s", uniq->expr[i], i + 1 < uniq->expr_size ? " " : ""); |
| 512 | } |
| 513 | ly_print(out, "\"/>\n"); |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | yin_print_refine(struct lyout *out, int level, const struct lys_module *module, const struct lys_refine *refine) |
| 518 | { |
| 519 | int i; |
| 520 | const char *str; |
| 521 | |
| 522 | str = transform_json2xml(module, refine->target_name, NULL, NULL, NULL); |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 523 | yin_print_open(out, level, "refine", "target-node", str, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 524 | lydict_remove(module->ctx, str); |
| 525 | |
| 526 | level++; |
| 527 | if (refine->flags & LYS_CONFIG_W) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 528 | yin_print_open(out, level, "config", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 529 | } else if (refine->flags & LYS_CONFIG_R) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 530 | yin_print_open(out, level, "config", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (refine->flags & LYS_MAND_TRUE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 534 | yin_print_open(out, level, "mandatory", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 535 | } else if (refine->flags & LYS_MAND_FALSE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 536 | yin_print_open(out, level, "mandatory", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | yin_print_snode_common(out, level, (struct lys_node *)refine); |
| 540 | |
| 541 | for (i = 0; i < refine->must_size; ++i) { |
| 542 | yin_print_must(out, level, module, &refine->must[i]); |
| 543 | } |
Radek Krejci | bf06c4f | 2016-07-29 15:49:56 +0200 | [diff] [blame] | 544 | for (i = 0; i < refine->iffeature_size; i++) { |
| 545 | yin_print_iffeature(out, level, module, &refine->iffeature[i]); |
| 546 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 547 | |
| 548 | if (refine->target_type & (LYS_LEAF | LYS_CHOICE)) { |
| 549 | if (refine->mod.dflt) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 550 | yin_print_open(out, level, "default", "value", refine->mod.dflt, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 551 | } |
| 552 | } else if (refine->target_type == LYS_CONTAINER) { |
| 553 | if (refine->mod.presence) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 554 | yin_print_open(out, level, "presence", "value", refine->mod.presence, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 555 | } |
| 556 | } else if (refine->target_type & (LYS_LIST | LYS_LEAFLIST)) { |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 557 | if (refine->flags & LYS_RFN_MINSET) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 558 | yin_print_unsigned(out, level, "min-elements", "value", refine->mod.list.min); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 559 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 560 | if (refine->flags & LYS_RFN_MAXSET) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 561 | if (refine->mod.list.max) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 562 | yin_print_unsigned(out, level, "max-elements", "value", refine->mod.list.max); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 563 | } else { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 564 | yin_print_open(out, level, "max-elements", "value", "unbounded", 1); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 565 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | level--; |
| 569 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 570 | yin_print_close(out, level, "refine"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static void |
| 574 | yin_print_deviation(struct lyout *out, int level, const struct lys_module *module, |
| 575 | const struct lys_deviation *deviation) |
| 576 | { |
| 577 | int i, j; |
| 578 | const char *str; |
| 579 | |
Michal Vasko | 5d11285 | 2016-02-12 16:47:13 +0100 | [diff] [blame] | 580 | str = transform_json2schema(module, deviation->target_name); |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 581 | yin_print_open(out, level, "deviation", "target-node", str, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 582 | lydict_remove(module->ctx, str); |
| 583 | |
| 584 | level++; |
| 585 | if (deviation->dsc) { |
| 586 | yin_print_text(out, level, "description", deviation->dsc); |
| 587 | } |
| 588 | if (deviation->ref) { |
| 589 | yin_print_text(out, level, "reference", deviation->ref); |
| 590 | } |
| 591 | |
| 592 | for (i = 0; i < deviation->deviate_size; ++i) { |
| 593 | ly_print(out, "%*s<deviate value=", LEVEL, INDENT); |
| 594 | if (deviation->deviate[i].mod == LY_DEVIATE_NO) { |
Michal Vasko | d875e88 | 2016-05-19 10:57:30 +0200 | [diff] [blame] | 595 | ly_print(out, "\"not-supported\"/>\n"); |
| 596 | continue; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 597 | } else if (deviation->deviate[i].mod == LY_DEVIATE_ADD) { |
| 598 | ly_print(out, "\"add\">\n"); |
| 599 | } else if (deviation->deviate[i].mod == LY_DEVIATE_RPL) { |
| 600 | ly_print(out, "\"replace\">\n"); |
| 601 | } else if (deviation->deviate[i].mod == LY_DEVIATE_DEL) { |
| 602 | ly_print(out, "\"delete\">\n"); |
| 603 | } |
| 604 | |
| 605 | level++; |
| 606 | if (deviation->deviate[i].flags & LYS_CONFIG_W) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 607 | yin_print_open(out, level, "config", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 608 | } else if (deviation->deviate[i].flags & LYS_CONFIG_R) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 609 | yin_print_open(out, level, "config", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | if (deviation->deviate[i].flags & LYS_MAND_TRUE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 613 | yin_print_open(out, level, "mandatory", "value", "true", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 614 | } else if (deviation->deviate[i].flags & LYS_MAND_FALSE) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 615 | yin_print_open(out, level, "mandatory", "value", "false", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if (deviation->deviate[i].dflt) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 619 | yin_print_open(out, level, "default", "value", deviation->deviate[i].dflt, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 622 | if (deviation->deviate[i].min_set) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 623 | yin_print_unsigned(out, level, "min-elements", "value", deviation->deviate[i].min); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 624 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 625 | if (deviation->deviate[i].max_set) { |
Michal Vasko | 87ea6cb | 2016-05-19 10:58:01 +0200 | [diff] [blame] | 626 | if (deviation->deviate[i].max) { |
| 627 | yin_print_unsigned(out, level, "max-elements", "value", deviation->deviate[i].max); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 628 | } else { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 629 | yin_print_open(out, level, "max-elements", "value", "unbounded", 1); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 630 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | for (j = 0; j < deviation->deviate[i].must_size; ++j) { |
| 634 | yin_print_must(out, level, module, &deviation->deviate[i].must[j]); |
| 635 | } |
| 636 | |
| 637 | for (j = 0; j < deviation->deviate[i].unique_size; ++j) { |
| 638 | yin_print_unique(out, level, &deviation->deviate[i].unique[j]); |
| 639 | } |
| 640 | |
| 641 | if (deviation->deviate[i].type) { |
| 642 | yin_print_type(out, level, module, deviation->deviate[i].type); |
| 643 | } |
| 644 | |
| 645 | if (deviation->deviate[i].units) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 646 | yin_print_open(out, level, "units", "name", deviation->deviate[i].units, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 647 | } |
| 648 | level--; |
| 649 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 650 | yin_print_close(out, level, "deviate"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 651 | } |
| 652 | level--; |
| 653 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 654 | yin_print_close(out, level, "deviation"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | static void |
| 658 | yin_print_augment(struct lyout *out, int level, const struct lys_module *module, |
| 659 | const struct lys_node_augment *augment) |
| 660 | { |
| 661 | int i; |
| 662 | struct lys_node *sub; |
| 663 | const char *str; |
| 664 | |
Michal Vasko | 5d11285 | 2016-02-12 16:47:13 +0100 | [diff] [blame] | 665 | str = transform_json2schema(module, augment->target_name); |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 666 | yin_print_open(out, level, "augment", "target-node", str, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 667 | lydict_remove(module->ctx, str); |
| 668 | |
| 669 | level++; |
| 670 | yin_print_nacmext(out, level, (struct lys_node *)augment, module); |
| 671 | yin_print_snode_common(out, level, (struct lys_node *)augment); |
| 672 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 673 | for (i = 0; i < augment->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 674 | yin_print_iffeature(out, level, module, &augment->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | if (augment->when) { |
| 678 | yin_print_when(out, level, module, augment->when); |
| 679 | } |
| 680 | |
| 681 | LY_TREE_FOR(augment->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 682 | /* only our augment */ |
| 683 | if (sub->parent != (struct lys_node *)augment) { |
| 684 | continue; |
| 685 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 686 | yin_print_snode(out, level, sub, |
| 687 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 688 | LYS_USES | LYS_ANYXML | LYS_CASE | LYS_ACTION); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 689 | } |
| 690 | level--; |
| 691 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 692 | yin_print_close(out, level, "augment"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void |
| 696 | yin_print_typedef(struct lyout *out, int level, const struct lys_module *module, const struct lys_tpdf *tpdf) |
| 697 | { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 698 | yin_print_open(out, level, "typedef", "name", tpdf->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 699 | |
| 700 | level++; |
| 701 | yin_print_snode_common(out, level, (struct lys_node *)tpdf); |
| 702 | yin_print_type(out, level, module, &tpdf->type); |
| 703 | if (tpdf->units) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 704 | yin_print_open(out, level, "units", "name", tpdf->units, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 705 | } |
| 706 | if (tpdf->dflt) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 707 | yin_print_open(out, level, "default", "value", tpdf->dflt, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 708 | } |
| 709 | level--; |
| 710 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 711 | yin_print_close(out, level, "typedef"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static void |
| 715 | yin_print_identity(struct lyout *out, int level, const struct lys_ident *ident) |
| 716 | { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame^] | 717 | int close, i; |
Michal Vasko | 6c629ac | 2016-02-15 14:08:23 +0100 | [diff] [blame] | 718 | struct lys_module *mod; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 719 | |
| 720 | close = (yin_has_snode_common((struct lys_node *)ident) || ident->base ? 0 : 1); |
| 721 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 722 | yin_print_open(out, level, "identity", "name", ident->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 723 | |
| 724 | if (!close) { |
| 725 | level++; |
| 726 | yin_print_snode_common(out, level, (struct lys_node *)ident); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame^] | 727 | for (i = 0; i < ident->base_size; i++) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 728 | ly_print(out, "%*s<base name=\"", LEVEL, INDENT); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame^] | 729 | mod = lys_main_module(ident->base[i]->module); |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 730 | if (lys_main_module(ident->module) != mod) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 731 | ly_print(out, "%s:", transform_module_name2import_prefix(ident->module, mod->name)); |
| 732 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame^] | 733 | ly_print(out, "%s\"/>\n", ident->base[i]->name); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 734 | } |
| 735 | level--; |
| 736 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 737 | yin_print_close(out, level, "identity"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | static void |
| 742 | yin_print_container(struct lyout *out, int level, const struct lys_node *node) |
| 743 | { |
| 744 | int i; |
| 745 | struct lys_node *sub; |
| 746 | struct lys_node_container *cont = (struct lys_node_container *)node; |
| 747 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 748 | yin_print_open(out, level, "container", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 749 | |
| 750 | level++; |
| 751 | yin_print_nacmext(out, level, node, node->module); |
| 752 | |
| 753 | if (cont->when) { |
| 754 | yin_print_when(out, level, node->module, cont->when); |
| 755 | } |
| 756 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 757 | for (i = 0; i < cont->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 758 | yin_print_iffeature(out, level, node->module, &cont->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | for (i = 0; i < cont->must_size; i++) { |
| 762 | yin_print_must(out, level, node->module, &cont->must[i]); |
| 763 | } |
| 764 | |
| 765 | if (cont->presence) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 766 | yin_print_open(out, level, "presence", "value", cont->presence, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | yin_print_snode_common2(out, level, node); |
| 770 | |
| 771 | for (i = 0; i < cont->tpdf_size; i++) { |
| 772 | yin_print_typedef(out, level, node->module, &cont->tpdf[i]); |
| 773 | } |
| 774 | |
| 775 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 776 | /* augments */ |
| 777 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 778 | continue; |
| 779 | } |
| 780 | yin_print_snode(out, level, sub, |
| 781 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 782 | LYS_USES | LYS_GROUPING | LYS_ANYXML | LYS_ACTION); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 783 | } |
| 784 | level--; |
| 785 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 786 | yin_print_close(out, level, "container"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | static void |
| 790 | yin_print_case(struct lyout *out, int level, const struct lys_node *node) |
| 791 | { |
| 792 | int i; |
| 793 | struct lys_node *sub; |
| 794 | struct lys_node_case *cas = (struct lys_node_case *)node; |
| 795 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 796 | yin_print_open(out, level, "case", "name", cas->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 797 | |
| 798 | level++; |
| 799 | yin_print_nacmext(out, level, node, node->module); |
| 800 | yin_print_snode_common2(out, level, node); |
| 801 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 802 | for (i = 0; i < cas->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 803 | yin_print_iffeature(out, level, node->module, &cas->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | if (cas->when) { |
| 807 | yin_print_when(out, level, node->module, cas->when); |
| 808 | } |
| 809 | |
| 810 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 811 | /* augments */ |
| 812 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 813 | continue; |
| 814 | } |
| 815 | yin_print_snode(out, level, sub, |
| 816 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 817 | LYS_USES | LYS_ANYXML); |
| 818 | } |
| 819 | level--; |
| 820 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 821 | yin_print_close(out, level, "case"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void |
| 825 | yin_print_choice(struct lyout *out, int level, const struct lys_node *node) |
| 826 | { |
| 827 | int i; |
| 828 | struct lys_node *sub; |
| 829 | struct lys_node_choice *choice = (struct lys_node_choice *)node; |
| 830 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 831 | yin_print_open(out, level, "choice", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 832 | |
| 833 | level++; |
| 834 | yin_print_nacmext(out, level, node, node->module); |
| 835 | if (choice->dflt) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 836 | yin_print_open(out, level, "default", "value", choice->dflt->name, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | yin_print_snode_common2(out, level, node); |
| 840 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 841 | for (i = 0; i < choice->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 842 | yin_print_iffeature(out, level, node->module, &choice->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | if (choice->when) { |
| 846 | yin_print_when(out, level, node->module, choice->when); |
| 847 | } |
| 848 | |
| 849 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 850 | /* augments */ |
| 851 | if (sub->parent != node) { |
| 852 | continue; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 853 | } |
| 854 | yin_print_snode(out, level, sub, |
| 855 | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_CASE); |
| 856 | } |
| 857 | level--; |
| 858 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 859 | yin_print_close(out, level, "choice"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | static void |
| 863 | yin_print_leaf(struct lyout *out, int level, const struct lys_node *node) |
| 864 | { |
| 865 | int i; |
| 866 | struct lys_node_leaf *leaf = (struct lys_node_leaf *)node; |
| 867 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 868 | yin_print_open(out, level, "leaf", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 869 | |
| 870 | level++; |
| 871 | yin_print_nacmext(out, level, node, node->module); |
| 872 | if (leaf->when) { |
| 873 | yin_print_when(out, level, node->module, leaf->when); |
| 874 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 875 | for (i = 0; i < leaf->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 876 | yin_print_iffeature(out, level, node->module, &leaf->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 877 | } |
| 878 | for (i = 0; i < leaf->must_size; i++) { |
| 879 | yin_print_must(out, level, node->module, &leaf->must[i]); |
| 880 | } |
| 881 | yin_print_snode_common2(out, level, node); |
| 882 | yin_print_type(out, level, node->module, &leaf->type); |
| 883 | if (leaf->units) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 884 | yin_print_open(out, level, "units", "name", leaf->units, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 885 | } |
| 886 | if (leaf->dflt) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 887 | yin_print_open(out, level, "default", "value", leaf->dflt, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 888 | } |
| 889 | level--; |
| 890 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 891 | yin_print_close(out, level, "leaf"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | static void |
| 895 | yin_print_anyxml(struct lyout *out, int level, const struct lys_node *node) |
| 896 | { |
| 897 | int i, close; |
| 898 | struct lys_node_anyxml *anyxml = (struct lys_node_anyxml *)node; |
| 899 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 900 | close = (yin_has_nacmext(node) || yin_has_snode_common2(node) || anyxml->iffeature_size || anyxml->must_size |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 901 | || anyxml->when ? 0 : 1); |
| 902 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 903 | yin_print_open(out, level, "anyxml", "name", anyxml->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 904 | |
| 905 | if (!close) { |
| 906 | level++; |
| 907 | yin_print_nacmext(out, level, node, node->module); |
| 908 | yin_print_snode_common2(out, level, node); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 909 | for (i = 0; i < anyxml->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 910 | yin_print_iffeature(out, level, node->module, &anyxml->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 911 | } |
| 912 | for (i = 0; i < anyxml->must_size; i++) { |
| 913 | yin_print_must(out, level, node->module, &anyxml->must[i]); |
| 914 | } |
| 915 | if (anyxml->when) { |
| 916 | yin_print_when(out, level, node->module, anyxml->when); |
| 917 | } |
| 918 | level--; |
| 919 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 920 | yin_print_close(out, level, "anyxml"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
| 924 | static void |
| 925 | yin_print_leaflist(struct lyout *out, int level, const struct lys_node *node) |
| 926 | { |
| 927 | int i; |
| 928 | struct lys_node_leaflist *llist = (struct lys_node_leaflist *)node; |
| 929 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 930 | yin_print_open(out, level, "leaf-list", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 931 | |
| 932 | level++; |
| 933 | yin_print_nacmext(out, level, node, node->module); |
| 934 | if (llist->when) { |
| 935 | yin_print_when(out, level, llist->module, llist->when); |
| 936 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 937 | for (i = 0; i < llist->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 938 | yin_print_iffeature(out, level, node->module, &llist->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 939 | } |
| 940 | for (i = 0; i < llist->must_size; i++) { |
| 941 | yin_print_must(out, level, node->module, &llist->must[i]); |
| 942 | } |
| 943 | yin_print_snode_common2(out, level, node); |
| 944 | yin_print_type(out, level, node->module, &llist->type); |
| 945 | if (llist->units) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 946 | yin_print_open(out, level, "units", "name", llist->units, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 947 | } |
| 948 | if (llist->min > 0) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 949 | yin_print_unsigned(out, level, "min-elements", "value", llist->min); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 950 | } |
| 951 | if (llist->max > 0) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 952 | yin_print_unsigned(out, level, "max-elements", "value", llist->max); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 953 | } |
| 954 | if (llist->flags & LYS_USERORDERED) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 955 | yin_print_open(out, level, "ordered-by", "value", "user", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 956 | } |
| 957 | level--; |
| 958 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 959 | yin_print_close(out, level, "leaf-list"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static void |
| 963 | yin_print_list(struct lyout *out, int level, const struct lys_node *node) |
| 964 | { |
| 965 | int i; |
| 966 | struct lys_node *sub; |
| 967 | struct lys_node_list *list = (struct lys_node_list *)node; |
| 968 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 969 | yin_print_open(out, level, "list", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 970 | |
| 971 | level++; |
| 972 | yin_print_nacmext(out, level, node, node->module); |
| 973 | if (list->when) { |
| 974 | yin_print_when(out, level, list->module, list->when); |
| 975 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 976 | for (i = 0; i < list->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 977 | yin_print_iffeature(out, level, node->module, &list->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 978 | } |
| 979 | for (i = 0; i < list->must_size; i++) { |
| 980 | yin_print_must(out, level, list->module, &list->must[i]); |
| 981 | } |
| 982 | if (list->keys_size) { |
| 983 | ly_print(out, "%*s<key value=\"", LEVEL, INDENT); |
| 984 | for (i = 0; i < list->keys_size; i++) { |
| 985 | ly_print(out, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : ""); |
| 986 | } |
| 987 | ly_print(out, "\"/>\n"); |
| 988 | } |
| 989 | for (i = 0; i < list->unique_size; i++) { |
| 990 | yin_print_unique(out, level, &list->unique[i]); |
| 991 | } |
| 992 | yin_print_snode_common2(out, level, node); |
| 993 | if (list->min > 0) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 994 | yin_print_unsigned(out, level, "min-elements", "value", list->min); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 995 | } |
| 996 | if (list->max > 0) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 997 | yin_print_unsigned(out, level, "max-elements", "value", list->max); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 998 | } |
| 999 | if (list->flags & LYS_USERORDERED) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1000 | yin_print_open(out, level, "ordered-by", "value", "user", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | for (i = 0; i < list->tpdf_size; i++) { |
| 1004 | yin_print_typedef(out, level, list->module, &list->tpdf[i]); |
| 1005 | } |
| 1006 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1007 | /* augments */ |
| 1008 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1009 | continue; |
| 1010 | } |
| 1011 | yin_print_snode(out, level, sub, |
| 1012 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1013 | LYS_USES | LYS_GROUPING | LYS_ANYXML | LYS_ACTION); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1014 | } |
| 1015 | level--; |
| 1016 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1017 | yin_print_close(out, level, "list"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | yin_print_grouping(struct lyout *out, int level, const struct lys_node *node) |
| 1022 | { |
| 1023 | int i; |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1024 | struct lys_node *sub; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1025 | struct lys_node_grp *grp = (struct lys_node_grp *)node; |
| 1026 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1027 | yin_print_open(out, level, "grouping", "name", node->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1028 | |
| 1029 | level++; |
| 1030 | yin_print_snode_common(out, level, node); |
| 1031 | |
| 1032 | for (i = 0; i < grp->tpdf_size; i++) { |
| 1033 | yin_print_typedef(out, level, node->module, &grp->tpdf[i]); |
| 1034 | } |
| 1035 | |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1036 | LY_TREE_FOR(node->child, sub) { |
| 1037 | yin_print_snode(out, level, sub, |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1038 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1039 | LYS_USES | LYS_GROUPING | LYS_ANYXML | LYS_ACTION); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1040 | } |
| 1041 | level--; |
| 1042 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1043 | yin_print_close(out, level, "grouping"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | static void |
| 1047 | yin_print_uses(struct lyout *out, int level, const struct lys_node *node) |
| 1048 | { |
| 1049 | int i, close; |
| 1050 | struct lys_node_uses *uses = (struct lys_node_uses *)node; |
Michal Vasko | 6c629ac | 2016-02-15 14:08:23 +0100 | [diff] [blame] | 1051 | struct lys_module *mod; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1052 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1053 | close = (yin_has_nacmext(node) || yin_has_snode_common(node) || uses->iffeature_size || uses->when |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1054 | || uses->refine_size || uses->augment_size ? 0 : 1); |
| 1055 | |
| 1056 | ly_print(out, "%*s<uses name=\"", LEVEL, INDENT); |
| 1057 | if (node->child) { |
Michal Vasko | 6c629ac | 2016-02-15 14:08:23 +0100 | [diff] [blame] | 1058 | mod = lys_node_module(node->child); |
Michal Vasko | 1dae8ec | 2016-02-15 14:49:01 +0100 | [diff] [blame] | 1059 | if (lys_node_module(node) != mod) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1060 | ly_print(out, "%s:", transform_module_name2import_prefix(node->module, mod->name)); |
| 1061 | } |
| 1062 | } |
| 1063 | ly_print(out, "%s\"%s>\n", uses->name, (close ? "/" : "")); |
| 1064 | |
| 1065 | if (!close) { |
| 1066 | level++; |
| 1067 | yin_print_nacmext(out, level, node, node->module); |
| 1068 | yin_print_snode_common(out, level, node); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1069 | for (i = 0; i < uses->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1070 | yin_print_iffeature(out, level, node->module, &uses->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1071 | } |
| 1072 | if (uses->when) { |
| 1073 | yin_print_when(out, level, node->module, uses->when); |
| 1074 | } |
| 1075 | |
| 1076 | for (i = 0; i < uses->refine_size; i++) { |
| 1077 | yin_print_refine(out, level, node->module, &uses->refine[i]); |
| 1078 | } |
| 1079 | |
| 1080 | for (i = 0; i < uses->augment_size; i++) { |
| 1081 | yin_print_augment(out, level, node->module, &uses->augment[i]); |
| 1082 | } |
| 1083 | level--; |
| 1084 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1085 | yin_print_close(out, level, "uses"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | yin_print_input_output(struct lyout *out, int level, const struct lys_node *node) |
| 1091 | { |
| 1092 | int i; |
| 1093 | struct lys_node *sub; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 1094 | struct lys_node_inout *inout = (struct lys_node_inout *)node; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1095 | |
| 1096 | ly_print(out, "%*s<%s>\n", LEVEL, INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output")); |
| 1097 | |
| 1098 | level++; |
| 1099 | for (i = 0; i < inout->tpdf_size; i++) { |
| 1100 | yin_print_typedef(out, level, node->module, &inout->tpdf[i]); |
| 1101 | } |
Radek Krejci | 12032a5 | 2016-07-29 15:42:56 +0200 | [diff] [blame] | 1102 | for (i = 0; i < inout->must_size; i++) { |
| 1103 | yin_print_must(out, level, node->module, &inout->must[i]); |
| 1104 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1105 | |
| 1106 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1107 | /* augments */ |
| 1108 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1109 | continue; |
| 1110 | } |
| 1111 | yin_print_snode(out, level, sub, |
| 1112 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1113 | LYS_USES | LYS_GROUPING | LYS_ANYXML); |
| 1114 | } |
| 1115 | level--; |
| 1116 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1117 | yin_print_close(out, level, (inout->nodetype == LYS_INPUT ? "input" : "output")); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | static void |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1121 | yin_print_rpc_action(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1122 | { |
| 1123 | int i, close; |
| 1124 | struct lys_node *sub; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 1125 | struct lys_node_rpc_action *rpc = (struct lys_node_rpc_action *)node; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1126 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1127 | close = (yin_has_snode_common(node) || rpc->iffeature_size || rpc->tpdf_size || node->child ? 0 : 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1128 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1129 | yin_print_open(out, level, (node->nodetype == LYS_RPC ? "rpc" : "action"), "name", node->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1130 | |
| 1131 | if (!close) { |
| 1132 | level++; |
| 1133 | yin_print_snode_common(out, level, node); |
| 1134 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1135 | for (i = 0; i < rpc->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1136 | yin_print_iffeature(out, level, node->module, &rpc->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | for (i = 0; i < rpc->tpdf_size; i++) { |
| 1140 | yin_print_typedef(out, level, node->module, &rpc->tpdf[i]); |
| 1141 | } |
| 1142 | |
| 1143 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1144 | /* augments */ |
| 1145 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1146 | continue; |
| 1147 | } |
| 1148 | yin_print_snode(out, level, sub, LYS_GROUPING | LYS_INPUT | LYS_OUTPUT); |
| 1149 | } |
| 1150 | level--; |
| 1151 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1152 | yin_print_close(out, level, (node->nodetype == LYS_RPC ? "rpc" : "action")); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | yin_print_notif(struct lyout *out, int level, const struct lys_node *node) |
| 1158 | { |
| 1159 | int i, close; |
| 1160 | struct lys_node *sub; |
| 1161 | struct lys_node_notif *notif = (struct lys_node_notif *)node; |
| 1162 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1163 | close = (yin_has_snode_common(node) || notif->iffeature_size || notif->tpdf_size || node->child ? 0 : 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1164 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1165 | yin_print_open(out, level, "notification", "name", node->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (!close) { |
| 1168 | level++; |
| 1169 | yin_print_snode_common(out, level, node); |
| 1170 | |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1171 | for (i = 0; i < notif->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1172 | yin_print_iffeature(out, level, node->module, ¬if->iffeature[i]); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | for (i = 0; i < notif->tpdf_size; i++) { |
| 1176 | yin_print_typedef(out, level, node->module, ¬if->tpdf[i]); |
| 1177 | } |
| 1178 | |
Radek Krejci | 12032a5 | 2016-07-29 15:42:56 +0200 | [diff] [blame] | 1179 | for (i = 0; i < notif->must_size; i++) { |
| 1180 | yin_print_must(out, level, node->module, ¬if->must[i]); |
| 1181 | } |
| 1182 | |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1183 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1184 | /* augments */ |
| 1185 | if (sub->parent != node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1186 | continue; |
| 1187 | } |
| 1188 | yin_print_snode(out, level, sub, |
| 1189 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1190 | LYS_USES | LYS_GROUPING | LYS_ANYXML); |
| 1191 | } |
| 1192 | level--; |
| 1193 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1194 | yin_print_close(out, level, "notification"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | static void |
| 1199 | yin_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask) |
| 1200 | { |
| 1201 | switch (node->nodetype & mask) { |
| 1202 | case LYS_CONTAINER: |
| 1203 | yin_print_container(out, level, node); |
| 1204 | break; |
| 1205 | case LYS_CHOICE: |
| 1206 | yin_print_choice(out, level, node); |
| 1207 | break; |
| 1208 | case LYS_LEAF: |
| 1209 | yin_print_leaf(out, level, node); |
| 1210 | break; |
| 1211 | case LYS_LEAFLIST: |
| 1212 | yin_print_leaflist(out, level, node); |
| 1213 | break; |
| 1214 | case LYS_LIST: |
| 1215 | yin_print_list(out, level, node); |
| 1216 | break; |
| 1217 | case LYS_USES: |
| 1218 | yin_print_uses(out, level, node); |
| 1219 | break; |
| 1220 | case LYS_GROUPING: |
| 1221 | yin_print_grouping(out, level, node); |
| 1222 | break; |
| 1223 | case LYS_ANYXML: |
| 1224 | yin_print_anyxml(out, level, node); |
| 1225 | break; |
| 1226 | case LYS_CASE: |
| 1227 | yin_print_case(out, level, node); |
| 1228 | break; |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1229 | case LYS_ACTION: |
| 1230 | yin_print_rpc_action(out, level, node); |
| 1231 | break; |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1232 | case LYS_INPUT: |
| 1233 | case LYS_OUTPUT: |
| 1234 | yin_print_input_output(out, level, node); |
| 1235 | break; |
| 1236 | default: |
| 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | yin_print_namespaces(struct lyout *out, const struct lys_module *module) |
| 1243 | { |
| 1244 | unsigned int i, lvl; |
| 1245 | |
| 1246 | if (module->type) { |
| 1247 | lvl = 11; |
| 1248 | } else { |
| 1249 | lvl = 8; |
| 1250 | } |
| 1251 | |
| 1252 | ly_print(out, "%*sxmlns=\"%s\"", lvl, INDENT, LY_NSYIN); |
| 1253 | if (!module->type) { |
| 1254 | ly_print(out, "\n%*sxmlns:%s=\"%s\"", lvl, INDENT, module->prefix, module->ns); |
| 1255 | } |
| 1256 | for (i = 0; i < module->imp_size; ++i) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1257 | ly_print(out, "\n%*sxmlns:%s=\"%s\"", lvl, INDENT, module->imp[i].prefix, module->imp[i].module->ns); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | int |
| 1262 | yin_print_model(struct lyout *out, const struct lys_module *module) |
| 1263 | { |
| 1264 | unsigned int i; |
| 1265 | int level = 0, close; |
| 1266 | #define LEVEL (level*2) |
| 1267 | |
| 1268 | struct lys_node *node; |
| 1269 | |
| 1270 | ly_print(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 1271 | |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 1272 | if (module->deviated == 1) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1273 | ly_print(out, "<!-- DEVIATED -->\n"); |
| 1274 | } |
| 1275 | |
| 1276 | /* (sub)module-header-stmts */ |
| 1277 | if (module->type) { |
| 1278 | ly_print(out, "<submodule name=\"%s\"\n", module->name); |
| 1279 | yin_print_namespaces(out, module); |
| 1280 | ly_print(out, ">\n"); |
| 1281 | |
| 1282 | level++; |
| 1283 | if (module->version) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1284 | yin_print_open(out, level, "yang-version", "value", |
| 1285 | ((struct lys_submodule *)module)->belongsto->version == 2 ? "1.1" : "1", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1286 | } |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1287 | yin_print_open(out, level, "belongs-to", "module", ((struct lys_submodule *)module)->belongsto->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1288 | |
| 1289 | level++; |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1290 | yin_print_open(out, level, "prefix", "value", module->prefix, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1291 | level--; |
| 1292 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1293 | yin_print_close(out, level, "belongs-to"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1294 | } else { |
| 1295 | ly_print(out, "<module name=\"%s\"\n", module->name); |
| 1296 | yin_print_namespaces(out, module); |
| 1297 | ly_print(out, ">\n"); |
| 1298 | |
| 1299 | level++; |
| 1300 | if (module->version) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1301 | yin_print_open(out, level, "yang-version", "value", module->version == 2 ? "1.1" : "1", 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1302 | } |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1303 | yin_print_open(out, level, "namespace", "uri", module->ns, 1); |
| 1304 | yin_print_open(out, level, "prefix", "value", module->prefix, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /* linkage-stmts */ |
| 1308 | for (i = 0; i < module->imp_size; i++) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1309 | yin_print_open(out, level, "import", "module", module->imp[i].module->name, 0); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1310 | |
| 1311 | level++; |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1312 | yin_print_open(out, level, "prefix", "value", module->imp[i].prefix, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1313 | if (module->imp[i].rev[0]) { |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1314 | yin_print_open(out, level, "revision-date", "date", module->imp[i].rev, 1); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1315 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 1316 | if (module->imp[i].dsc) { |
| 1317 | yin_print_text(out, level, "description", module->imp[i].dsc); |
| 1318 | } |
| 1319 | if (module->imp[i].ref) { |
| 1320 | yin_print_text(out, level, "reference", module->imp[i].ref); |
| 1321 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1322 | level--; |
| 1323 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1324 | yin_print_close(out, level, "import"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1325 | } |
| 1326 | for (i = 0; i < module->inc_size; i++) { |
| 1327 | if (module->inc[i].external) { |
| 1328 | continue; |
| 1329 | } |
| 1330 | |
| 1331 | close = (module->inc[i].rev[0] ? 0 : 1); |
Radek Krejci | 268dc5f | 2016-03-04 10:35:16 +0100 | [diff] [blame] | 1332 | yin_print_open(out, level, "include", "module", module->inc[i].submodule->name, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1333 | |
| 1334 | if (!close) { |
| 1335 | level++; |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1336 | yin_print_open(out, level, "revision-date", "date", module->inc[i].rev, 1); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 1337 | if (module->inc[i].dsc) { |
| 1338 | yin_print_text(out, level, "description", module->inc[i].dsc); |
| 1339 | } |
| 1340 | if (module->inc[i].ref) { |
| 1341 | yin_print_text(out, level, "reference", module->inc[i].ref); |
| 1342 | } |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1343 | level--; |
| 1344 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1345 | yin_print_close(out, level, "include"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /* meta-stmts */ |
| 1350 | if (module->org) { |
| 1351 | yin_print_text(out, level, "organization", module->org); |
| 1352 | } |
| 1353 | if (module->contact) { |
| 1354 | yin_print_text(out, level, "contact", module->contact); |
| 1355 | } |
| 1356 | if (module->dsc) { |
| 1357 | yin_print_text(out, level, "description", module->dsc); |
| 1358 | } |
| 1359 | if (module->ref) { |
| 1360 | yin_print_text(out, level, "reference", module->ref); |
| 1361 | } |
| 1362 | |
| 1363 | /* revision-stmts */ |
| 1364 | for (i = 0; i < module->rev_size; i++) { |
| 1365 | close = (module->rev[i].dsc || module->rev[i].ref ? 0 : 1); |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1366 | yin_print_open(out, level, "revision", "date", module->rev[i].date, close); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1367 | |
| 1368 | if (!close) { |
| 1369 | level++; |
| 1370 | if (module->rev[i].dsc) { |
| 1371 | yin_print_text(out, level, "description", module->rev[i].dsc); |
| 1372 | } |
| 1373 | if (module->rev[i].ref) { |
| 1374 | yin_print_text(out, level, "reference", module->rev[i].ref); |
| 1375 | } |
| 1376 | level--; |
| 1377 | |
Michal Vasko | 87bb46b | 2016-02-12 11:51:42 +0100 | [diff] [blame] | 1378 | yin_print_close(out, level, "revision"); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | /* body-stmts */ |
| 1383 | for (i = 0; i < module->features_size; i++) { |
| 1384 | yin_print_feature(out, level, &module->features[i]); |
| 1385 | } |
| 1386 | |
| 1387 | for (i = 0; i < module->ident_size; i++) { |
| 1388 | yin_print_identity(out, level, &module->ident[i]); |
| 1389 | } |
| 1390 | |
| 1391 | for (i = 0; i < module->tpdf_size; i++) { |
| 1392 | yin_print_typedef(out, level, module, &module->tpdf[i]); |
| 1393 | } |
| 1394 | |
| 1395 | for (i = 0; i < module->deviation_size; ++i) { |
| 1396 | yin_print_deviation(out, level, module, &module->deviation[i]); |
| 1397 | } |
| 1398 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 1399 | LY_TREE_FOR(lys_main_module(module)->data, node) { |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1400 | if (node->module != module) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1401 | /* data from submodules */ |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1402 | continue; |
| 1403 | } |
| 1404 | |
| 1405 | switch (node->nodetype) { |
| 1406 | case LYS_RPC: |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1407 | yin_print_rpc_action(out, level, node); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1408 | break; |
| 1409 | case LYS_NOTIF: |
| 1410 | yin_print_notif(out, level, node); |
| 1411 | break; |
| 1412 | default: |
| 1413 | yin_print_snode(out, level, node, |
| 1414 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1415 | LYS_USES | LYS_GROUPING | LYS_ANYXML); |
| 1416 | break; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | for (i = 0; i < module->augment_size; i++) { |
| 1421 | yin_print_augment(out, level, module, &module->augment[i]); |
| 1422 | } |
| 1423 | |
| 1424 | if (module->type) { |
| 1425 | ly_print(out, "</submodule>\n"); |
| 1426 | } else { |
| 1427 | ly_print(out, "</module>\n"); |
| 1428 | } |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame] | 1429 | ly_print_flush(out); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 1430 | |
| 1431 | return EXIT_SUCCESS; |
| 1432 | #undef LEVEL |
| 1433 | } |
| 1434 | |