Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 2 | * @file printer/yang.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 4 | * @brief YANG printer for libyang data model structure |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 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 |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 13 | */ |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 14 | #define _GNU_SOURCE |
| 15 | #include <stdio.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 16 | #include <stdlib.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 17 | #include <string.h> |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 18 | #include <stdint.h> |
Michal Vasko | f30ea3e | 2016-12-06 12:16:02 +0100 | [diff] [blame] | 19 | #include <assert.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 20 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 21 | #include "common.h" |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 22 | #include "printer.h" |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 23 | #include "tree_schema.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 24 | |
| 25 | #define INDENT "" |
| 26 | #define LEVEL (level*2) |
| 27 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 28 | static void yang_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 29 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 30 | static void |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 31 | yang_encode(struct lyout *out, const char *text, int len) |
| 32 | { |
| 33 | int i, start_len; |
| 34 | const char *start; |
| 35 | char special = 0; |
| 36 | |
| 37 | if (!len) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if (len < 0) { |
| 42 | len = strlen(text); |
| 43 | } |
| 44 | |
| 45 | start = text; |
| 46 | start_len = 0; |
| 47 | for (i = 0; i < len; ++i) { |
| 48 | switch (text[i]) { |
| 49 | case '\n': |
| 50 | case '\t': |
| 51 | case '\"': |
| 52 | case '\\': |
| 53 | special = text[i]; |
| 54 | break; |
| 55 | default: |
| 56 | ++start_len; |
| 57 | break; |
| 58 | } |
| 59 | |
| 60 | if (special) { |
| 61 | ly_write(out, start, start_len); |
| 62 | switch (special) { |
| 63 | case '\n': |
| 64 | ly_write(out, "\\n", 2); |
| 65 | break; |
| 66 | case '\t': |
| 67 | ly_write(out, "\\t", 2); |
| 68 | break; |
| 69 | case '\"': |
| 70 | ly_write(out, "\\\"", 2); |
| 71 | break; |
| 72 | case '\\': |
| 73 | ly_write(out, "\\\\", 2); |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | start += start_len + 1; |
| 78 | start_len = 0; |
| 79 | |
| 80 | special = 0; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | ly_write(out, start, start_len); |
| 85 | } |
| 86 | |
| 87 | static void |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 88 | yang_print_open(struct lyout *out, int *flag) |
| 89 | { |
| 90 | if (flag && !*flag) { |
| 91 | *flag = 1; |
| 92 | ly_print(out, " {\n"); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | yang_print_close(struct lyout *out, int level, int flag) |
| 98 | { |
| 99 | if (flag) { |
| 100 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
| 101 | } else { |
| 102 | ly_print(out, ";\n"); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 107 | yang_print_text(struct lyout *out, int level, const char *name, const char *text, int singleline, int closed) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 108 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 109 | const char *s, *t; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 110 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 111 | if (singleline) { |
| 112 | ly_print(out, "%*s%s \"", LEVEL, INDENT, name); |
| 113 | } else { |
| 114 | ly_print(out, "%*s%s\n", LEVEL, INDENT, name); |
| 115 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 116 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 117 | ly_print(out, "%*s\"", LEVEL, INDENT); |
| 118 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 119 | t = text; |
| 120 | while ((s = strchr(t, '\n'))) { |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 121 | yang_encode(out, t, s - t); |
| 122 | ly_print(out, "\n"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 123 | t = s + 1; |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 124 | ly_print(out, "%*s ", LEVEL, INDENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 125 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 126 | |
范昌虎10069952 | 77de5fc | 2016-10-08 07:33:29 -0400 | [diff] [blame] | 127 | yang_encode(out, t, strlen(t)); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 128 | if (closed) { |
| 129 | ly_print(out, "\";\n"); |
| 130 | } else { |
| 131 | ly_print(out, "\""); |
| 132 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 133 | level--; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 134 | |
| 135 | } |
| 136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 137 | static void |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 138 | yang_print_extension_instances(struct lyout *out, int level, const struct lys_module *module, |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 139 | LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 140 | struct lys_ext_instance **ext, unsigned int count) |
| 141 | { |
| 142 | unsigned int u, x; |
| 143 | struct lys_module *mod; |
| 144 | const char *prefix = NULL; |
| 145 | int flag; |
| 146 | |
| 147 | for (u = 0; u < count; u++) { |
Radek Krejci | 80056d5 | 2017-01-05 13:13:33 +0100 | [diff] [blame] | 148 | if (ext[u]->flags & LYEXT_OPT_INHERIT) { |
| 149 | /* ignore the inherited extensions which were not explicitely instantiated in the module */ |
| 150 | continue; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 151 | } else if (ext[u]->substmt != substmt || ext[u]->substmt_index != substmt_index) { |
| 152 | /* do not print the other substatement than the required */ |
| 153 | continue; |
Radek Krejci | 80056d5 | 2017-01-05 13:13:33 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 156 | mod = lys_main_module(ext[u]->def->module); |
Radek Krejci | 9160218 | 2017-01-13 12:41:33 +0100 | [diff] [blame] | 157 | if (mod == lys_main_module(module)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 158 | prefix = module->prefix; |
| 159 | } else { |
| 160 | for (x = 0; x < module->imp_size; x++) { |
| 161 | if (mod == module->imp[x].module) { |
| 162 | prefix = module->imp[x].prefix; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | flag = 0; |
| 169 | ly_print(out, "%*s%s:%s", LEVEL, INDENT, prefix, ext[u]->def->name); |
Radek Krejci | 0aa821a | 2016-12-08 11:21:35 +0100 | [diff] [blame] | 170 | /* extension - generic part */ |
| 171 | if (ext[u]->arg_value) { |
| 172 | ly_print(out, " \"%s\"", ext[u]->arg_value); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Radek Krejci | 0aa821a | 2016-12-08 11:21:35 +0100 | [diff] [blame] | 175 | /* extension - type-specific part */ |
| 176 | switch(lys_ext_instance_type(ext[u])) { |
| 177 | case LYEXT_FLAG: |
| 178 | /* flag extension - nothing special */ |
Radek Krejci | 17000ac | 2017-01-04 16:16:13 +0100 | [diff] [blame] | 179 | break; |
Radek Krejci | 0aa821a | 2016-12-08 11:21:35 +0100 | [diff] [blame] | 180 | case LYEXT_ERR: |
| 181 | LOGINT; |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | /* extensions in extension instance */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 186 | if (ext[u]->ext_size) { |
| 187 | yang_print_open(out, &flag); |
Radek Krejci | c65474c | 2017-01-16 10:38:35 +0100 | [diff] [blame] | 188 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_SELF, 0, |
| 189 | ext[u]->ext, ext[u]->ext_size); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* close extension */ |
| 193 | yang_print_close(out, level, flag); |
| 194 | } |
| 195 | } |
| 196 | |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 197 | static void |
| 198 | yang_print_substmt(struct lyout *out, int level, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, |
| 199 | const struct lys_module *module, struct lys_ext_instance **ext, unsigned int ext_size) |
| 200 | { |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 201 | int i = -1; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 202 | |
| 203 | if (!text) { |
| 204 | /* nothing to print */ |
| 205 | return; |
| 206 | } |
| 207 | |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 208 | do { |
| 209 | i = ly_print_ext_iter(ext, ext_size, i + 1, substmt); |
| 210 | } while (i != -1 && ext[i]->substmt_index != substmt_index); |
| 211 | |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 212 | if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) { |
| 213 | ly_print(out, "%*s%s %s%s", LEVEL, INDENT, ext_substmt_info[substmt].name, text, i == -1 ? ";\n" : ""); |
| 214 | } else { |
| 215 | yang_print_text(out, level, ext_substmt_info[substmt].name, text, |
| 216 | (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, i == -1 ? 1 : 0); |
| 217 | } |
| 218 | |
| 219 | if (i != -1) { |
| 220 | ly_print(out, " {\n"); |
| 221 | do { |
| 222 | yang_print_extension_instances(out, level + 1, module, substmt, substmt_index, &ext[i], 1); |
| 223 | do { |
| 224 | i = ly_print_ext_iter(ext, ext_size, i + 1, substmt); |
| 225 | } while (i != -1 && ext[i]->substmt_index != substmt_index); |
| 226 | } while (i != -1); |
| 227 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
| 228 | } |
| 229 | } |
| 230 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 231 | static void |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 232 | yang_print_iffeature(struct lyout *out, int level, const struct lys_module *module, struct lys_iffeature *iffeature) |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 233 | { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 234 | ly_print(out, "%*sif-feature \"", LEVEL, INDENT); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 235 | ly_print_iffeature(out, module, iffeature); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 236 | |
| 237 | /* extensions */ |
| 238 | if (iffeature->ext_size) { |
| 239 | ly_print(out, "\" {\n"); |
| 240 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_SELF, 0, iffeature->ext, iffeature->ext_size); |
| 241 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
| 242 | } else { |
| 243 | ly_print(out, "\";\n"); |
| 244 | } |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 247 | /* |
| 248 | * Covers: |
| 249 | * extension (instances), if-features, config, mandatory, status, description, reference |
| 250 | */ |
| 251 | #define SNODE_COMMON_EXT 0x01 |
| 252 | #define SNODE_COMMON_IFF 0x02 |
| 253 | #define SNODE_COMMON_CONFIG 0x04 |
| 254 | #define SNODE_COMMON_MAND 0x08 |
| 255 | #define SNODE_COMMON_STATUS 0x10 |
| 256 | #define SNODE_COMMON_DSC 0x20 |
| 257 | #define SNODE_COMMON_REF 0x40 |
| 258 | static void |
| 259 | yang_print_snode_common(struct lyout *out, int level, const struct lys_node *node, const struct lys_module *module, |
| 260 | int *flag, int mask) |
| 261 | { |
| 262 | int i; |
| 263 | const char *status = NULL; |
| 264 | |
| 265 | /* extensions */ |
| 266 | if ((mask & SNODE_COMMON_EXT) && node->ext_size) { |
| 267 | yang_print_open(out, flag); |
| 268 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, node->ext, node->ext_size); |
| 269 | } |
| 270 | |
| 271 | /* if-features */ |
| 272 | if (mask & SNODE_COMMON_IFF) { |
| 273 | for (i = 0; i < node->iffeature_size; ++i) { |
| 274 | yang_print_open(out, flag); |
| 275 | yang_print_iffeature(out, level, module, &node->iffeature[i]); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /* config */ |
| 280 | if (mask & SNODE_COMMON_CONFIG) { |
| 281 | /* get info if there is an extension for the config statement */ |
| 282 | i = ly_print_ext_iter(node->ext, node->ext_size, 0, LYEXT_SUBSTMT_CONFIG); |
| 283 | |
| 284 | if (lys_parent(node)) { |
| 285 | if ((node->flags & LYS_CONFIG_SET) || i != -1) { |
| 286 | /* print config when it differs from the parent or if it has an extension instance ... */ |
| 287 | if (node->flags & LYS_CONFIG_W) { |
| 288 | yang_print_open(out, flag); |
| 289 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "true", |
| 290 | module, node->ext, node->ext_size); |
| 291 | } else if (node->flags & LYS_CONFIG_R) { |
| 292 | yang_print_open(out, flag); |
| 293 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "false", |
| 294 | module, node->ext, node->ext_size); |
| 295 | } |
| 296 | } |
| 297 | } else if (node->flags & LYS_CONFIG_R) { |
| 298 | /* ... or it's a top-level state node */ |
| 299 | yang_print_open(out, flag); |
| 300 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "false", |
| 301 | module, node->ext, node->ext_size); |
| 302 | } else if (i != -1) { |
| 303 | /* the config has an extension, so we have to print it */ |
| 304 | yang_print_open(out, flag); |
| 305 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "true", |
| 306 | module, node->ext, node->ext_size); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* mandatory */ |
| 311 | if ((mask & SNODE_COMMON_MAND) && (node->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
| 312 | if (node->flags & LYS_MAND_TRUE) { |
| 313 | yang_print_open(out, flag); |
| 314 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "true", |
| 315 | module, node->ext, node->ext_size); |
| 316 | } else if (node->flags & LYS_MAND_FALSE) { |
| 317 | yang_print_open(out, flag); |
| 318 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "false", |
| 319 | module, node->ext, node->ext_size); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /* status */ |
| 324 | if (mask & SNODE_COMMON_STATUS) { |
| 325 | if (node->flags & LYS_STATUS_CURR) { |
| 326 | yang_print_open(out, flag); |
| 327 | status = "current"; |
| 328 | } else if (node->flags & LYS_STATUS_DEPRC) { |
| 329 | yang_print_open(out, flag); |
| 330 | status = "deprecated"; |
| 331 | } else if (node->flags & LYS_STATUS_OBSLT) { |
| 332 | yang_print_open(out, flag); |
| 333 | status = "obsolete"; |
| 334 | } |
| 335 | yang_print_substmt(out, level, LYEXT_SUBSTMT_STATUS, 0, status, module, node->ext, node->ext_size); |
| 336 | } |
| 337 | |
| 338 | /* description */ |
| 339 | if ((mask & SNODE_COMMON_DSC) && node->dsc) { |
| 340 | yang_print_open(out, flag); |
| 341 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, node->dsc, |
| 342 | module, node->ext, node->ext_size); |
| 343 | } |
| 344 | |
| 345 | /* reference */ |
| 346 | if ((mask & SNODE_COMMON_REF) && node->ref) { |
| 347 | yang_print_open(out, flag); |
| 348 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, node->ref, |
| 349 | module, node->ext, node->ext_size); |
| 350 | } |
| 351 | } |
| 352 | |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 353 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 354 | yang_print_feature(struct lyout *out, int level, const struct lys_feature *feat) |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 355 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 356 | int flag = 0; |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 357 | |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 358 | ly_print(out, "%*sfeature %s", LEVEL, INDENT, feat->name); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 359 | yang_print_snode_common(out, level + 1, (struct lys_node *)feat, feat->module, &flag, SNODE_COMMON_EXT | |
| 360 | SNODE_COMMON_IFF | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 361 | yang_print_close(out, level, flag); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static void |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 365 | yang_print_extension(struct lyout *out, int level, const struct lys_ext *ext) |
| 366 | { |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 367 | int flag = 0, flag2 = 0, i; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 368 | |
| 369 | ly_print(out, "%*sextension %s", LEVEL, INDENT, ext->name); |
| 370 | level++; |
| 371 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 372 | yang_print_snode_common(out, level, (struct lys_node *)ext, ext->module, &flag, |
| 373 | SNODE_COMMON_EXT); |
| 374 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 375 | if (ext->argument) { |
| 376 | yang_print_open(out, &flag); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 377 | |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 378 | ly_print(out, "%*sargument %s", LEVEL, INDENT, ext->argument); |
| 379 | i = -1; |
| 380 | while ((i = ly_print_ext_iter(ext->ext, ext->ext_size, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != -1) { |
| 381 | yang_print_open(out, &flag2); |
| 382 | yang_print_extension_instances(out, level + 1, ext->module, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->ext[i], 1); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 383 | } |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 384 | if (ext->flags & LYS_YINELEM) { |
| 385 | yang_print_open(out, &flag2); |
| 386 | yang_print_substmt(out, level + 1, LYEXT_SUBSTMT_YINELEM, 0, "true", ext->module, ext->ext, ext->ext_size); |
| 387 | } |
| 388 | yang_print_close(out, level, flag2); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 389 | } |
| 390 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 391 | yang_print_snode_common(out, level, (struct lys_node *)ext, ext->module, &flag, |
| 392 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
| 393 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 394 | level--; |
| 395 | yang_print_close(out, level, flag); |
| 396 | } |
| 397 | |
| 398 | static void |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 399 | yang_print_restr(struct lyout *out, int level, const struct lys_module *module, const struct lys_restr *restr, int *flag) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 400 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 401 | if (restr->ext_size) { |
| 402 | yang_print_open(out, flag); |
| 403 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, restr->ext, restr->ext_size); |
| 404 | } |
Radek Krejci | daa95c4 | 2017-01-16 10:25:29 +0100 | [diff] [blame] | 405 | if (restr->expr[0] == 0x15) { |
| 406 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
| 407 | yang_print_open(out, flag); |
| 408 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", |
| 409 | module, restr->ext, restr->ext_size); |
| 410 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 411 | if (restr->emsg != NULL) { |
| 412 | yang_print_open(out, flag); |
| 413 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, |
| 414 | module, restr->ext, restr->ext_size); |
| 415 | } |
| 416 | if (restr->eapptag != NULL) { |
| 417 | yang_print_open(out, flag); |
| 418 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, |
| 419 | module, restr->ext, restr->ext_size); |
| 420 | } |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 421 | if (restr->dsc != NULL) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 422 | yang_print_open(out, flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 423 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, restr->dsc, |
| 424 | module, restr->ext, restr->ext_size); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 425 | } |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 426 | if (restr->ref != NULL) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 427 | yang_print_open(out, flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 428 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, restr->ref, |
| 429 | module, restr->ext, restr->ext_size); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 430 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 434 | yang_print_when(struct lyout *out, int level, const struct lys_module *module, const struct lys_when *when) |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 435 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 436 | int flag = 0; |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 437 | const char *str; |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 438 | |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 439 | str = transform_json2schema(module, when->cond); |
| 440 | if (!str) { |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 441 | ly_print(out, "(!error!)"); |
| 442 | return; |
| 443 | } |
| 444 | |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 445 | ly_print(out, "%*swhen \"", LEVEL, INDENT); |
| 446 | yang_encode(out, str, -1); |
| 447 | ly_print(out, "\""); |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 448 | lydict_remove(module->ctx, str); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 449 | |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 450 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 451 | |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 452 | if (when->ext_size) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 453 | /* extension is stored in lys_when incompatible with lys_node, so we cannot use yang_print_snode_common() */ |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 454 | yang_print_open(out, &flag); |
| 455 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, when->ext, when->ext_size); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 456 | } |
Radek Krejci | 11e88fd | 2017-01-16 15:34:37 +0100 | [diff] [blame] | 457 | if (when->dsc != NULL) { |
| 458 | yang_print_open(out, &flag); |
| 459 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, when->dsc, |
| 460 | module, when->ext, when->ext_size); |
| 461 | } |
| 462 | if (when->ref != NULL) { |
| 463 | yang_print_open(out, &flag); |
| 464 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, when->ref, |
| 465 | module, when->ext, when->ext_size); |
| 466 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 467 | |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 468 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 469 | yang_print_close(out, level, flag); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 473 | yang_print_type(struct lyout *out, int level, const struct lys_module *module, const struct lys_type *type) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 474 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 475 | int i; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 476 | int flag = 0, flag2; |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 477 | const char *str; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 478 | char *s; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 479 | struct lys_module *mod; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 480 | |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 481 | if (type->module_name) { |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 482 | ly_print(out, "%*stype %s:%s", LEVEL, INDENT, |
| 483 | transform_module_name2import_prefix(module, type->module_name), type->der->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 484 | } else { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 485 | ly_print(out, "%*stype %s", LEVEL, INDENT, type->der->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 486 | } |
| 487 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 488 | |
| 489 | /* extensions */ |
| 490 | if (type->ext_size) { |
| 491 | yang_print_open(out, &flag); |
| 492 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, type->ext, type->ext_size); |
| 493 | } |
| 494 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 495 | switch (type->base) { |
| 496 | case LY_TYPE_BINARY: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 497 | if (type->info.binary.length) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 498 | yang_print_open(out, &flag); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 499 | ly_print(out, "%*slength \"", LEVEL, INDENT); |
| 500 | yang_encode(out, type->info.binary.length->expr, -1); |
| 501 | ly_print(out, "\""); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 502 | flag2 = 0; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 503 | yang_print_restr(out, level + 1, module, type->info.binary.length, &flag2); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 504 | yang_print_close(out, level, flag2); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 505 | } |
| 506 | break; |
| 507 | case LY_TYPE_BITS: |
| 508 | for (i = 0; i < type->info.bits.count; ++i) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 509 | yang_print_open(out, &flag); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 510 | ly_print(out, "%*sbit %s", LEVEL, INDENT, type->info.bits.bit[i].name); |
| 511 | flag2 = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 512 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 513 | yang_print_snode_common(out, level, (struct lys_node *)&type->info.bits.bit[i], module, &flag2, |
| 514 | SNODE_COMMON_EXT | SNODE_COMMON_IFF); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 515 | if (!(type->info.bits.bit[i].flags & LYS_AUTOASSIGNED)) { |
| 516 | yang_print_open(out, &flag2); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 517 | asprintf(&s, "%u", type->info.bits.bit[i].pos); |
| 518 | yang_print_substmt(out, level, LYEXT_SUBSTMT_POSITION, 0, s, |
| 519 | module, type->info.bits.bit[i].ext, type->info.bits.bit[i].ext_size); |
| 520 | free(s); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 521 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 522 | yang_print_snode_common(out, level, (struct lys_node *)&type->info.bits.bit[i], module, &flag2, |
| 523 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 524 | level--; |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 525 | yang_print_close(out, level, flag2); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 526 | } |
| 527 | break; |
| 528 | case LY_TYPE_DEC64: |
Radek Krejci | b51d593 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 529 | if (!type->der->type.der) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 530 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 531 | asprintf(&s, "%d", type->info.dec64.dig); |
| 532 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DIGITS, 0, s, module, type->ext, type->ext_size); |
| 533 | free(s); |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 534 | } |
Michal Vasko | ea505ee | 2015-07-07 14:01:00 +0200 | [diff] [blame] | 535 | if (type->info.dec64.range != NULL) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 536 | yang_print_open(out, &flag); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 537 | ly_print(out, "%*srange \"", LEVEL, INDENT); |
| 538 | yang_encode(out, type->info.dec64.range->expr, -1); |
| 539 | ly_print(out, "\""); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 540 | flag2 = 0; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 541 | yang_print_restr(out, level + 1, module, type->info.dec64.range, &flag2); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 542 | yang_print_close(out, level, flag2); |
Michal Vasko | ea505ee | 2015-07-07 14:01:00 +0200 | [diff] [blame] | 543 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 544 | break; |
| 545 | case LY_TYPE_ENUM: |
| 546 | for (i = 0; i < type->info.enums.count; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 547 | yang_print_open(out, &flag); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 548 | ly_print(out, "%*senum \"%s\"", LEVEL, INDENT, type->info.enums.enm[i].name); |
| 549 | flag2 = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 550 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 551 | yang_print_snode_common(out, level, (struct lys_node *)&type->info.enums.enm[i], module, &flag2, |
| 552 | SNODE_COMMON_EXT | SNODE_COMMON_IFF); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 553 | if (!(type->info.enums.enm[i].flags & LYS_AUTOASSIGNED)) { |
| 554 | yang_print_open(out, &flag2); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 555 | asprintf(&s, "%d", type->info.enums.enm[i].value); |
| 556 | yang_print_substmt(out, level, LYEXT_SUBSTMT_VALUE, 0, s, |
| 557 | module, type->info.enums.enm[i].ext, type->info.enums.enm[i].ext_size); |
| 558 | free(s); |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 559 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 560 | yang_print_snode_common(out, level, (struct lys_node *)&type->info.enums.enm[i], module, &flag2, |
| 561 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 562 | level--; |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 563 | yang_print_close(out, level, flag2); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 564 | } |
| 565 | break; |
| 566 | case LY_TYPE_IDENT: |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 567 | if (type->info.ident.count) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 568 | yang_print_open(out, &flag); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 569 | for (i = 0; i < type->info.ident.count; ++i) { |
| 570 | mod = lys_main_module(type->info.ident.ref[i]->module); |
| 571 | if (lys_main_module(module) == mod) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 572 | yang_print_substmt(out, level, LYEXT_SUBSTMT_BASE, 0, type->info.ident.ref[i]->name, |
| 573 | module, type->info.ident.ref[i]->ext, type->info.ident.ref[i]->ext_size); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 574 | } else { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 575 | asprintf(&s, "%s:%s", transform_module_name2import_prefix(module, mod->name), |
| 576 | type->info.ident.ref[i]->name); |
| 577 | yang_print_substmt(out, level, LYEXT_SUBSTMT_BASE, 0, s, |
| 578 | module, type->info.ident.ref[i]->ext, type->info.ident.ref[i]->ext_size); |
| 579 | free(s); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 580 | } |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 581 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 582 | } |
| 583 | break; |
| 584 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 585 | if (type->info.inst.req == 1) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 586 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 587 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REQINST, 0, "true", module, type->ext, type->ext_size); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 588 | } else if (type->info.inst.req == -1) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 589 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 590 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REQINST, 0, "false", module, type->ext, type->ext_size); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 591 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 592 | break; |
| 593 | case LY_TYPE_INT8: |
| 594 | case LY_TYPE_INT16: |
| 595 | case LY_TYPE_INT32: |
| 596 | case LY_TYPE_INT64: |
| 597 | case LY_TYPE_UINT8: |
| 598 | case LY_TYPE_UINT16: |
| 599 | case LY_TYPE_UINT32: |
| 600 | case LY_TYPE_UINT64: |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 601 | if (type->info.num.range) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 602 | yang_print_open(out, &flag); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 603 | ly_print(out, "%*srange \"", LEVEL, INDENT); |
| 604 | yang_encode(out, type->info.num.range->expr, -1); |
| 605 | ly_print(out, "\""); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 606 | flag2 = 0; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 607 | yang_print_restr(out, level + 1, module, type->info.num.range, &flag2); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 608 | yang_print_close(out, level, flag2); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 609 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 610 | break; |
| 611 | case LY_TYPE_LEAFREF: |
Radek Krejci | 0dbff6a | 2016-07-17 12:40:18 +0200 | [diff] [blame] | 612 | if (ly_strequal(type->der->name, "leafref", 0)) { |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 613 | yang_print_open(out, &flag); |
| 614 | str = transform_json2schema(module, type->info.lref.path); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 615 | yang_print_substmt(out, level, LYEXT_SUBSTMT_PATH, 0, str, module, type->ext, type->ext_size); |
Michal Vasko | 4634cda | 2016-02-16 09:22:09 +0100 | [diff] [blame] | 616 | lydict_remove(module->ctx, str); |
| 617 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 618 | if (type->info.lref.req == 1) { |
| 619 | yang_print_open(out, &flag); |
| 620 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REQINST, 0, "true", module, type->ext, type->ext_size); |
| 621 | } else if (type->info.lref.req == -1) { |
| 622 | yang_print_open(out, &flag); |
| 623 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REQINST, 0, "false", module, type->ext, type->ext_size); |
| 624 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 625 | break; |
| 626 | case LY_TYPE_STRING: |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 627 | if (type->info.str.length) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 628 | yang_print_open(out, &flag); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 629 | ly_print(out, "%*slength \"", LEVEL, INDENT); |
| 630 | yang_encode(out, type->info.str.length->expr, -1); |
| 631 | ly_print(out, "\""); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 632 | flag2 = 0; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 633 | yang_print_restr(out, level + 1, module, type->info.str.length, &flag2); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 634 | yang_print_close(out, level, flag2); |
Radek Krejci | 061bd52 | 2015-06-19 13:45:16 +0200 | [diff] [blame] | 635 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 636 | for (i = 0; i < type->info.str.pat_count; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 637 | yang_print_open(out, &flag); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 638 | ly_print(out, "%*spattern \"", LEVEL, INDENT); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 639 | yang_encode(out, &type->info.str.patterns[i].expr[1], -1); |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 640 | ly_print(out, "\""); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 641 | flag2 = 0; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 642 | yang_print_restr(out, level + 1, module, &type->info.str.patterns[i], &flag2); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 643 | yang_print_close(out, level, flag2); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 644 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 645 | break; |
| 646 | case LY_TYPE_UNION: |
| 647 | for (i = 0; i < type->info.uni.count; ++i) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 648 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 649 | yang_print_type(out, level, module, &type->info.uni.types[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 650 | } |
| 651 | break; |
| 652 | default: |
| 653 | /* other types do not have substatements */ |
| 654 | break; |
| 655 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 657 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 658 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 659 | } |
| 660 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 661 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 662 | yang_print_must(struct lyout *out, int level, const struct lys_module *module, const struct lys_restr *must) |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 663 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 664 | int flag = 0; |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 665 | const char *str; |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 666 | |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 667 | str = transform_json2schema(module, must->expr); |
| 668 | if (!str) { |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 669 | ly_print(out, "(!error!)"); |
| 670 | return; |
| 671 | } |
| 672 | |
Michal Vasko | 25cb6c6 | 2016-02-12 14:36:21 +0100 | [diff] [blame] | 673 | ly_print(out, "%*smust \"", LEVEL, INDENT); |
| 674 | yang_encode(out, str, -1); |
| 675 | ly_print(out, "\""); |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 676 | lydict_remove(module->ctx, str); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 677 | |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 678 | yang_print_restr(out, level + 1, module, must, &flag); |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 679 | yang_print_close(out, level, flag); |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 682 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 683 | yang_print_unique(struct lyout *out, int level, const struct lys_unique *uniq) |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 684 | { |
| 685 | int i; |
| 686 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 687 | ly_print(out, "%*sunique \"", LEVEL, INDENT); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 688 | for (i = 0; i < uniq->expr_size; i++) { |
| 689 | ly_print(out, "%s%s", uniq->expr[i], i + 1 < uniq->expr_size ? " " : ""); |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 690 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 691 | ly_print(out, "\""); |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 695 | yang_print_refine(struct lyout *out, int level, const struct lys_module *module, const struct lys_refine *refine) |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 696 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 697 | int i, flag = 0; |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 698 | const char *str; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 699 | char *s; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 700 | |
Michal Vasko | 5d11285 | 2016-02-12 16:47:13 +0100 | [diff] [blame] | 701 | str = transform_json2schema(module, refine->target_name); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 702 | ly_print(out, "%*srefine \"%s\"", LEVEL, INDENT, str); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 703 | lydict_remove(module->ctx, str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 704 | level++; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 705 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 706 | yang_print_snode_common(out, level, (struct lys_node *)refine, module, &flag, SNODE_COMMON_EXT | SNODE_COMMON_IFF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 707 | for (i = 0; i < refine->must_size; ++i) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 708 | yang_print_open(out, &flag); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 709 | yang_print_must(out, level, module, &refine->must[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 710 | } |
Pavol Vican | 3e7c73a | 2016-08-17 10:24:11 +0200 | [diff] [blame] | 711 | if (refine->target_type == LYS_CONTAINER) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 712 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 713 | yang_print_substmt(out, level, LYEXT_SUBSTMT_PRESENCE, 0, refine->mod.presence, |
| 714 | module, refine->ext, refine->ext_size); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 715 | } |
| 716 | for (i = 0; i < refine->dflt_size; ++i) { |
| 717 | yang_print_open(out, &flag); |
| 718 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, i, refine->dflt[i], module, refine->ext, refine->ext_size); |
| 719 | } |
| 720 | if (refine->flags & LYS_CONFIG_W) { |
| 721 | yang_print_open(out, &flag); |
| 722 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "true", module, refine->ext, refine->ext_size); |
| 723 | } else if (refine->flags & LYS_CONFIG_R) { |
| 724 | yang_print_open(out, &flag); |
| 725 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "false", module, refine->ext, refine->ext_size); |
| 726 | } |
| 727 | if (refine->flags & LYS_MAND_TRUE) { |
| 728 | yang_print_open(out, &flag); |
| 729 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "true", module, refine->ext, refine->ext_size); |
| 730 | } else if (refine->flags & LYS_MAND_FALSE) { |
| 731 | yang_print_open(out, &flag); |
| 732 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "false", module, refine->ext, refine->ext_size); |
| 733 | } |
| 734 | if (refine->target_type & (LYS_LIST | LYS_LEAFLIST)) { |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 735 | if (refine->flags & LYS_RFN_MINSET) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 736 | asprintf(&s, "%u", refine->mod.list.min); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 737 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 738 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MIN, 0, s, module, refine->ext, refine->ext_size); |
| 739 | free(s); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 740 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 741 | if (refine->flags & LYS_RFN_MAXSET) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 742 | if (refine->mod.list.max) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 743 | asprintf(&s, "%u", refine->mod.list.max); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 744 | } else { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 745 | s = NULL; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 746 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 747 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 748 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MIN, 0, s ? s : "unbounded", module, refine->ext, refine->ext_size); |
| 749 | free(s); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 750 | } |
| 751 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 752 | yang_print_snode_common(out, level, (struct lys_node *)refine, module, &flag, SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 753 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 754 | level--; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 755 | yang_print_close(out, level, flag); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 758 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 759 | yang_print_deviation(struct lyout *out, int level, const struct lys_module *module, |
| 760 | const struct lys_deviation *deviation) |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 761 | { |
Radek Krejci | 033983b | 2017-01-13 12:43:20 +0100 | [diff] [blame] | 762 | int i, j, p; |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 763 | const char *str; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 764 | char *s; |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 765 | |
Michal Vasko | 5d11285 | 2016-02-12 16:47:13 +0100 | [diff] [blame] | 766 | str = transform_json2schema(module, deviation->target_name); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 767 | ly_print(out, "%*sdeviation \"%s\" {\n", LEVEL, INDENT, str); |
| 768 | lydict_remove(module->ctx, str); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 769 | level++; |
| 770 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 771 | if (deviation->ext_size) { |
| 772 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, deviation->ext, deviation->ext_size); |
| 773 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 774 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, deviation->dsc, |
| 775 | module, deviation->ext, deviation->ext_size); |
| 776 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, deviation->ref, |
| 777 | module, deviation->ext, deviation->ext_size); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 778 | |
| 779 | for (i = 0; i < deviation->deviate_size; ++i) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 780 | ly_print(out, "%*sdeviate ", LEVEL, INDENT); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 781 | if (deviation->deviate[i].mod == LY_DEVIATE_NO) { |
Michal Vasko | d875e88 | 2016-05-19 10:57:30 +0200 | [diff] [blame] | 782 | ly_print(out, "not-supported;\n"); |
| 783 | continue; |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 784 | } else if (deviation->deviate[i].mod == LY_DEVIATE_ADD) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 785 | ly_print(out, "add {\n"); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 786 | } else if (deviation->deviate[i].mod == LY_DEVIATE_RPL) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 787 | ly_print(out, "replace {\n"); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 788 | } else if (deviation->deviate[i].mod == LY_DEVIATE_DEL) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 789 | ly_print(out, "delete {\n"); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 790 | } |
| 791 | level++; |
| 792 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 793 | /* extensions */ |
| 794 | if (deviation->deviate[i].ext_size) { |
| 795 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_SELF, 0, |
| 796 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 799 | /* type */ |
| 800 | if (deviation->deviate[i].type) { |
| 801 | yang_print_type(out, level, module, deviation->deviate[i].type); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 802 | } |
| 803 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 804 | /* units */ |
| 805 | yang_print_substmt(out, level, LYEXT_SUBSTMT_UNITS, 0, deviation->deviate[i].units, module, |
| 806 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 807 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 808 | /* must */ |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 809 | for (j = 0; j < deviation->deviate[i].must_size; ++j) { |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 810 | yang_print_must(out, level, module, &deviation->deviate[i].must[j]); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 811 | } |
| 812 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 813 | /* unique */ |
| 814 | |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 815 | for (j = 0; j < deviation->deviate[i].unique_size; ++j) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 816 | yang_print_unique(out, level, &deviation->deviate[i].unique[j]); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 817 | /* unique's extensions */ |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 818 | p = -1; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 819 | do { |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 820 | p = ly_print_ext_iter(deviation->deviate[i].ext, deviation->deviate[i].ext_size, |
| 821 | p + 1, LYEXT_SUBSTMT_UNIQUE); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 822 | } while (p != -1 && deviation->deviate[i].ext[p]->substmt_index != j); |
| 823 | if (p != -1) { |
| 824 | ly_print(out, " {\n"); |
| 825 | do { |
| 826 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_UNIQUE, j, |
| 827 | &deviation->deviate[i].ext[p], 1); |
| 828 | do { |
| 829 | p = ly_print_ext_iter(deviation->deviate[i].ext, deviation->deviate[i].ext_size, |
| 830 | p + 1, LYEXT_SUBSTMT_UNIQUE); |
| 831 | } while (p != -1 && deviation->deviate[i].ext[p]->substmt_index != j); |
| 832 | } while (p != -1); |
| 833 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
| 834 | } else { |
| 835 | ly_print(out, ";\n"); |
| 836 | } |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 837 | } |
| 838 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 839 | /* default */ |
Radek Krejci | 033983b | 2017-01-13 12:43:20 +0100 | [diff] [blame] | 840 | for (j = 0; j < deviation->deviate[i].dflt_size; ++j) { |
| 841 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, j, deviation->deviate[i].dflt[j], module, |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 842 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 843 | } |
| 844 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 845 | /* config */ |
| 846 | if (deviation->deviate[i].flags & LYS_CONFIG_W) { |
| 847 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "true", module, |
| 848 | deviation->deviate->ext, deviation->deviate[i].ext_size); |
| 849 | } else if (deviation->deviate[i].flags & LYS_CONFIG_R) { |
| 850 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONFIG, 0, "false", module, |
| 851 | deviation->deviate->ext, deviation->deviate[i].ext_size); |
| 852 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 853 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 854 | /* mandatory */ |
| 855 | if (deviation->deviate[i].flags & LYS_MAND_TRUE) { |
| 856 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "true", module, |
| 857 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
| 858 | } else if (deviation->deviate[i].flags & LYS_MAND_FALSE) { |
| 859 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MANDATORY, 0, "false", module, |
| 860 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
| 861 | } |
| 862 | |
| 863 | /* min-elements */ |
| 864 | if (deviation->deviate[i].min_set) { |
| 865 | asprintf(&s, "%u", deviation->deviate[i].min); |
| 866 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MIN, 0, s, module, |
| 867 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
| 868 | free(s); |
| 869 | } |
| 870 | |
| 871 | /* max-elements */ |
| 872 | if (deviation->deviate[i].max_set) { |
| 873 | if (deviation->deviate[i].max) { |
| 874 | asprintf(&s, "%u", deviation->deviate[i].max); |
| 875 | } else { |
| 876 | s = NULL; |
| 877 | } |
| 878 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MAX, 0, s ? s : "unbounded", module, |
| 879 | deviation->deviate[i].ext, deviation->deviate[i].ext_size); |
| 880 | free(s); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 884 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 888 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | static void |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 892 | yang_print_augment(struct lyout *out, int level, const struct lys_node_augment *augment) |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 893 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 894 | struct lys_node *sub; |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 895 | const char *str; |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 896 | |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 897 | str = transform_json2schema(augment->module, augment->target_name); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 898 | ly_print(out, "%*saugment \"%s\" {\n", LEVEL, INDENT, str); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 899 | lydict_remove(augment->module->ctx, str); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 900 | level++; |
| 901 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 902 | yang_print_snode_common(out, level, (struct lys_node *)augment, augment->module, NULL, SNODE_COMMON_EXT); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 903 | if (augment->when) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 904 | yang_print_when(out, level, augment->module, augment->when); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 905 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 906 | yang_print_snode_common(out, level, (struct lys_node *)augment, augment->module, NULL, |
| 907 | SNODE_COMMON_IFF | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 908 | |
| 909 | LY_TREE_FOR(augment->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 910 | /* only our augment */ |
| 911 | if (sub->parent != (struct lys_node *)augment) { |
| 912 | continue; |
| 913 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 914 | yang_print_snode(out, level, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 915 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 916 | LYS_USES | LYS_ANYDATA | LYS_CASE | LYS_ACTION | LYS_NOTIF); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 920 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 924 | yang_print_typedef(struct lyout *out, int level, const struct lys_module *module, const struct lys_tpdf *tpdf) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 925 | { |
Radek Krejci | 033983b | 2017-01-13 12:43:20 +0100 | [diff] [blame] | 926 | const char *dflt; |
| 927 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 928 | ly_print(out, "%*stypedef %s {\n", LEVEL, INDENT, tpdf->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 929 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 930 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 931 | yang_print_snode_common(out, level, (struct lys_node *)tpdf, module, NULL, SNODE_COMMON_EXT); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 932 | yang_print_type(out, level, module, &tpdf->type); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 933 | if (tpdf->units != NULL) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 934 | yang_print_substmt(out, level, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, module, tpdf->ext, tpdf->ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 935 | } |
| 936 | if (tpdf->dflt != NULL) { |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 937 | if (tpdf->flags & LYS_DFLTJSON) { |
Michal Vasko | f30ea3e | 2016-12-06 12:16:02 +0100 | [diff] [blame] | 938 | assert(strchr(tpdf->dflt, ':')); |
| 939 | if (!strncmp(tpdf->dflt, module->name, strchr(tpdf->dflt, ':') - tpdf->dflt)) { |
| 940 | /* local module */ |
| 941 | dflt = lydict_insert(module->ctx, strchr(tpdf->dflt, ':') + 1, 0); |
| 942 | } else { |
| 943 | dflt = transform_json2schema(module, tpdf->dflt); |
| 944 | } |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 945 | } else { |
| 946 | dflt = tpdf->dflt; |
| 947 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 948 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, 0, dflt, module, tpdf->ext, tpdf->ext_size); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 949 | if (tpdf->flags & LYS_DFLTJSON) { |
| 950 | lydict_remove(module->ctx, dflt); |
| 951 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 952 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 953 | yang_print_snode_common(out, level, (struct lys_node *)tpdf, module, NULL, |
| 954 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 955 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 956 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 957 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 960 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 961 | yang_print_identity(struct lyout *out, int level, const struct lys_ident *ident) |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 962 | { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 963 | int flag = 0, i; |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 964 | struct lys_module *mod; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 965 | char *str; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 966 | |
| 967 | ly_print(out, "%*sidentity %s", LEVEL, INDENT, ident->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 968 | level++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 969 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 970 | yang_print_snode_common(out, level, (struct lys_node *)ident, ident->module, &flag, |
| 971 | SNODE_COMMON_EXT | SNODE_COMMON_IFF); |
| 972 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 973 | for (i = 0; i < ident->base_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 974 | yang_print_open(out, &flag); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 975 | mod = lys_main_module(ident->base[i]->module); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 976 | if (lys_main_module(ident->module) == mod) { |
| 977 | yang_print_substmt(out, level, LYEXT_SUBSTMT_BASE, 0, ident->base[i]->name, |
| 978 | ident->module, ident->ext, ident->ext_size); |
| 979 | } else { |
| 980 | asprintf(&str, "%s:%s", transform_module_name2import_prefix(ident->module, mod->name), ident->base[i]->name); |
| 981 | yang_print_substmt(out, level, LYEXT_SUBSTMT_BASE, 0, str, |
| 982 | ident->module, ident->ext, ident->ext_size); |
| 983 | free(str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 984 | } |
| 985 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 986 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 987 | yang_print_snode_common(out, level, (struct lys_node *)ident, ident->module, &flag, |
| 988 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
| 989 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 990 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 991 | yang_print_close(out, level, flag); |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 994 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 995 | yang_print_container(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 996 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 997 | int i, flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 998 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 999 | struct lys_node_container *cont = (struct lys_node_container *)node; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1000 | |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1001 | ly_print(out, "%*scontainer %s", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1002 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1003 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1004 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1005 | if (cont->when) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1006 | yang_print_open(out, &flag); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1007 | yang_print_when(out, level, node->module, cont->when); |
| 1008 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1009 | for (i = 0; i < cont->iffeature_size; i++) { |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1010 | yang_print_open(out, &flag); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1011 | yang_print_iffeature(out, level, node->module, &cont->iffeature[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1012 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1013 | for (i = 0; i < cont->must_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1014 | yang_print_open(out, &flag); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1015 | yang_print_must(out, level, node->module, &cont->must[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1016 | } |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1017 | if (cont->presence != NULL) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1018 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1019 | yang_print_substmt(out, level, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, |
| 1020 | node->module, node->ext, node->ext_size); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1021 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1022 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_CONFIG | |
| 1023 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1024 | for (i = 0; i < cont->tpdf_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1025 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1026 | yang_print_typedef(out, level, node->module, &cont->tpdf[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1027 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1028 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1029 | /* augments */ |
| 1030 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1031 | continue; |
| 1032 | } |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1033 | yang_print_open(out, &flag); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1034 | yang_print_snode(out, level, sub, LYS_GROUPING); |
| 1035 | } |
| 1036 | LY_TREE_FOR(node->child, sub) { |
| 1037 | /* augments */ |
| 1038 | if (sub->parent != node) { |
| 1039 | continue; |
| 1040 | } |
| 1041 | yang_print_open(out, &flag); |
| 1042 | yang_print_snode(out, level, sub, LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1043 | LYS_USES | LYS_ANYDATA ); |
| 1044 | } |
| 1045 | LY_TREE_FOR(node->child, sub) { |
| 1046 | /* augments */ |
| 1047 | if (sub->parent != node) { |
| 1048 | continue; |
| 1049 | } |
| 1050 | yang_print_open(out, &flag); |
| 1051 | yang_print_snode(out, level, sub, LYS_ACTION); |
| 1052 | } |
| 1053 | LY_TREE_FOR(node->child, sub) { |
| 1054 | /* augments */ |
| 1055 | if (sub->parent != node) { |
| 1056 | continue; |
| 1057 | } |
| 1058 | yang_print_open(out, &flag); |
Radek Krejci | 033983b | 2017-01-13 12:43:20 +0100 | [diff] [blame] | 1059 | yang_print_snode(out, level, sub, LYS_NOTIF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1060 | } |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 1061 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1062 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1063 | yang_print_close(out, level, flag); |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 1064 | } |
| 1065 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1066 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1067 | yang_print_case(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 1068 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1069 | int flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1070 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1071 | struct lys_node_case *cas = (struct lys_node_case *)node; |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 1072 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1073 | ly_print(out, "%*scase %s", LEVEL, INDENT, cas->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1074 | level++; |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 1075 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1076 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1077 | if (cas->when) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1078 | yang_print_open(out, &flag); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1079 | yang_print_when(out, level, node->module, cas->when); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1080 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1081 | yang_print_snode_common(out, level, node, node->module, &flag, |
| 1082 | SNODE_COMMON_IFF | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1083 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1084 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1085 | /* augments */ |
| 1086 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1087 | continue; |
| 1088 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1089 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1090 | yang_print_snode(out, level, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1091 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1092 | LYS_USES | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1093 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1094 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1095 | level--; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1096 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1099 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1100 | yang_print_choice(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1101 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1102 | int i, flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1103 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1104 | struct lys_node_choice *choice = (struct lys_node_choice *)node; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1105 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1106 | ly_print(out, "%*schoice %s", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1107 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1108 | |
| 1109 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
| 1110 | if (choice->when) { |
| 1111 | yang_print_open(out, &flag); |
| 1112 | yang_print_when(out, level, node->module, choice->when); |
| 1113 | } |
| 1114 | for (i = 0; i < choice->iffeature_size; i++) { |
| 1115 | yang_print_open(out, &flag); |
| 1116 | yang_print_iffeature(out, level, node->module, &choice->iffeature[i]); |
| 1117 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1118 | if (choice->dflt != NULL) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1119 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1120 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, |
| 1121 | node->module, node->ext, node->ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1122 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1123 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_CONFIG | SNODE_COMMON_MAND | |
| 1124 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1125 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1126 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1127 | /* augments */ |
| 1128 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1129 | continue; |
| 1130 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1131 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1132 | yang_print_snode(out, level, sub, |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1133 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYDATA | LYS_CASE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1134 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1135 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1136 | level--; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1137 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1140 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1141 | yang_print_leaf(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1142 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1143 | int i; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1144 | struct lys_node_leaf *leaf = (struct lys_node_leaf *)node; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1145 | const char *dflt; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1146 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1147 | ly_print(out, "%*sleaf %s {\n", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1148 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1149 | |
| 1150 | yang_print_snode_common(out, level, node, node->module, NULL, SNODE_COMMON_EXT); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1151 | if (leaf->when) { |
| 1152 | yang_print_when(out, level, node->module, leaf->when); |
| 1153 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1154 | for (i = 0; i < leaf->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1155 | yang_print_iffeature(out, level, node->module, &leaf->iffeature[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1156 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1157 | yang_print_type(out, level, node->module, &leaf->type); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1158 | yang_print_substmt(out, level, LYEXT_SUBSTMT_UNITS, 0, leaf->units, |
| 1159 | node->module, node->ext, node->ext_size); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1160 | for (i = 0; i < leaf->must_size; i++) { |
| 1161 | yang_print_must(out, level, node->module, &leaf->must[i]); |
| 1162 | } |
Michal Vasko | d875e88 | 2016-05-19 10:57:30 +0200 | [diff] [blame] | 1163 | if (leaf->dflt) { |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1164 | if (leaf->flags & LYS_DFLTJSON) { |
Michal Vasko | f30ea3e | 2016-12-06 12:16:02 +0100 | [diff] [blame] | 1165 | assert(strchr(leaf->dflt, ':')); |
| 1166 | if (!strncmp(leaf->dflt, lys_node_module(node)->name, strchr(leaf->dflt, ':') - leaf->dflt)) { |
| 1167 | /* local module */ |
| 1168 | dflt = lydict_insert(node->module->ctx, strchr(leaf->dflt, ':') + 1, 0); |
| 1169 | } else { |
| 1170 | dflt = transform_json2schema(node->module, leaf->dflt); |
| 1171 | } |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1172 | } else { |
| 1173 | dflt = leaf->dflt; |
| 1174 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1175 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, 0, dflt, |
| 1176 | node->module, node->ext, node->ext_size); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1177 | if (leaf->flags & LYS_DFLTJSON) { |
| 1178 | lydict_remove(node->module->ctx, dflt); |
| 1179 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1180 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1181 | yang_print_snode_common(out, level, node, node->module, NULL, SNODE_COMMON_CONFIG | SNODE_COMMON_MAND | |
| 1182 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1183 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1184 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1187 | static void |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1188 | yang_print_anydata(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 1189 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1190 | int i, flag = 0; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1191 | struct lys_node_anydata *any = (struct lys_node_anydata *)node; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 1192 | |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1193 | ly_print(out, "%*s%s %s", LEVEL, INDENT, any->nodetype == LYS_ANYXML ? "anyxml" : "anydata", any->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1194 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1195 | |
| 1196 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
| 1197 | if (any->when) { |
| 1198 | yang_print_open(out, &flag); |
| 1199 | yang_print_when(out, level, node->module, any->when); |
| 1200 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1201 | for (i = 0; i < any->iffeature_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1202 | yang_print_open(out, &flag); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1203 | yang_print_iffeature(out, level, node->module, &any->iffeature[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1204 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1205 | for (i = 0; i < any->must_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1206 | yang_print_open(out, &flag); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1207 | yang_print_must(out, level, node->module, &any->must[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1208 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1209 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_CONFIG | SNODE_COMMON_MAND | |
| 1210 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1211 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1212 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1215 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1216 | yang_print_leaflist(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1217 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1218 | int i; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1219 | struct lys_node_leaflist *llist = (struct lys_node_leaflist *)node; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1220 | const char *dflt; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1221 | char *str; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1222 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1223 | ly_print(out, "%*sleaf-list %s {\n", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1224 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1225 | yang_print_snode_common(out, level, node, node->module, NULL, SNODE_COMMON_EXT); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1226 | if (llist->when) { |
| 1227 | yang_print_when(out, level, llist->module, llist->when); |
| 1228 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1229 | for (i = 0; i < llist->iffeature_size; i++) { |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1230 | yang_print_iffeature(out, level, node->module, &llist->iffeature[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1231 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1232 | yang_print_type(out, level, node->module, &llist->type); |
| 1233 | yang_print_substmt(out, level, LYEXT_SUBSTMT_UNITS, 0, llist->units, |
| 1234 | node->module, node->ext, node->ext_size); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1235 | for (i = 0; i < llist->must_size; i++) { |
| 1236 | yang_print_must(out, level, node->module, &llist->must[i]); |
| 1237 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1238 | for (i = 0; i < llist->dflt_size; ++i) { |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1239 | if (llist->flags & LYS_DFLTJSON) { |
Michal Vasko | f30ea3e | 2016-12-06 12:16:02 +0100 | [diff] [blame] | 1240 | assert(strchr(llist->dflt[i], ':')); |
| 1241 | if (!strncmp(llist->dflt[i], lys_node_module(node)->name, strchr(llist->dflt[i], ':') - llist->dflt[i])) { |
| 1242 | /* local module */ |
| 1243 | dflt = lydict_insert(node->module->ctx, strchr(llist->dflt[i], ':') + 1, 0); |
| 1244 | } else { |
| 1245 | dflt = transform_json2schema(node->module, llist->dflt[i]); |
| 1246 | } |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1247 | } else { |
| 1248 | dflt = llist->dflt[i]; |
| 1249 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1250 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DEFAULT, i, dflt, |
| 1251 | node->module, node->ext, node->ext_size); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1252 | if (llist->flags & LYS_DFLTJSON) { |
| 1253 | lydict_remove(node->module->ctx, dflt); |
| 1254 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1255 | } |
Radek Krejci | 178a094 | 2017-01-16 15:36:35 +0100 | [diff] [blame^] | 1256 | yang_print_snode_common(out, level, node, node->module, NULL, SNODE_COMMON_CONFIG); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1257 | if (llist->min > 0) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1258 | asprintf(&str, "%u", llist->min); |
| 1259 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MIN, 0, str, |
| 1260 | node->module, node->ext, node->ext_size); |
| 1261 | free(str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1262 | } |
| 1263 | if (llist->max > 0) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1264 | asprintf(&str, "%u", llist->max); |
| 1265 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MAX, 0, str, |
| 1266 | node->module, node->ext, node->ext_size); |
| 1267 | free(str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1268 | } |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1269 | if (llist->flags & LYS_USERORDERED) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1270 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ORDEREDBY, 0, "user", |
| 1271 | node->module, node->ext, node->ext_size); |
| 1272 | } else if (ly_print_ext_iter(node->ext, node->ext_size, 0, LYEXT_SUBSTMT_ORDEREDBY) != -1) { |
| 1273 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ORDEREDBY, 0, "system", |
| 1274 | node->module, node->ext, node->ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1275 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1276 | yang_print_snode_common(out, level, node, node->module, NULL, |
| 1277 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1278 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1279 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1282 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1283 | yang_print_list(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1284 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1285 | int i, p, flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1286 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1287 | struct lys_node_list *list = (struct lys_node_list *)node; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1288 | char *str; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1289 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1290 | ly_print(out, "%*slist %s", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1291 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1292 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1293 | if (list->when) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1294 | yang_print_open(out, &flag); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1295 | yang_print_when(out, level, list->module, list->when); |
| 1296 | } |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1297 | for (i = 0; i < list->iffeature_size; i++) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1298 | yang_print_open(out, &flag); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 1299 | yang_print_iffeature(out, level, node->module, &list->iffeature[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1300 | } |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1301 | for (i = 0; i < list->must_size; i++) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1302 | yang_print_open(out, &flag); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1303 | yang_print_must(out, level, list->module, &list->must[i]); |
| 1304 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1305 | if (list->keys_size) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1306 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1307 | yang_print_substmt(out, level, LYEXT_SUBSTMT_KEY, 0, list->keys_str, |
| 1308 | node->module, node->ext, node->ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1309 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1310 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1311 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1312 | yang_print_unique(out, level, &list->unique[i]); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1313 | /* unique's extensions */ |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 1314 | p = -1; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1315 | do { |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 1316 | p = ly_print_ext_iter(list->ext, list->ext_size, p + 1, LYEXT_SUBSTMT_UNIQUE); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1317 | } while (p != -1 && list->ext[p]->substmt_index != i); |
| 1318 | if (p != -1) { |
| 1319 | ly_print(out, " {\n"); |
| 1320 | do { |
| 1321 | yang_print_extension_instances(out, level + 1, list->module, LYEXT_SUBSTMT_UNIQUE, i, &list->ext[p], 1); |
| 1322 | do { |
| 1323 | p = ly_print_ext_iter(list->ext, list->ext_size, p + 1, LYEXT_SUBSTMT_UNIQUE); |
| 1324 | } while (p != -1 && list->ext[p]->substmt_index != i); |
| 1325 | } while (p != -1); |
| 1326 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
| 1327 | } else { |
| 1328 | ly_print(out, ";\n"); |
| 1329 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1330 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1331 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_CONFIG); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1332 | if (list->min > 0) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1333 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1334 | asprintf(&str, "%u", list->min); |
| 1335 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MIN, 0, str, |
| 1336 | node->module, node->ext, node->ext_size); |
| 1337 | free(str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1338 | } |
| 1339 | if (list->max > 0) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1340 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1341 | asprintf(&str, "%u", list->max); |
| 1342 | yang_print_substmt(out, level, LYEXT_SUBSTMT_MAX, 0, str, |
| 1343 | node->module, node->ext, node->ext_size); |
| 1344 | free(str); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1345 | } |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1346 | if (list->flags & LYS_USERORDERED) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1347 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1348 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ORDEREDBY, 0, "user", |
| 1349 | node->module, node->ext, node->ext_size); |
| 1350 | } else if (ly_print_ext_iter(node->ext, node->ext_size, 0, LYEXT_SUBSTMT_ORDEREDBY) != -1) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1351 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1352 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ORDEREDBY, 0, "system", |
| 1353 | node->module, node->ext, node->ext_size); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1354 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1355 | yang_print_snode_common(out, level, node, node->module, &flag, |
| 1356 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1357 | for (i = 0; i < list->tpdf_size; i++) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1358 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1359 | yang_print_typedef(out, level, list->module, &list->tpdf[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1360 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1361 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1362 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1363 | /* augments */ |
| 1364 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1365 | continue; |
| 1366 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1367 | yang_print_open(out, &flag); |
| 1368 | yang_print_snode(out, level, sub, LYS_GROUPING); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1369 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1370 | |
| 1371 | LY_TREE_FOR(node->child, sub) { |
| 1372 | /* augments */ |
| 1373 | if (sub->parent != node) { |
| 1374 | continue; |
| 1375 | } |
| 1376 | yang_print_open(out, &flag); |
| 1377 | yang_print_snode(out, level, sub, LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1378 | LYS_USES | LYS_GROUPING | LYS_ANYDATA); |
| 1379 | } |
| 1380 | |
| 1381 | LY_TREE_FOR(node->child, sub) { |
| 1382 | /* augments */ |
| 1383 | if (sub->parent != node) { |
| 1384 | continue; |
| 1385 | } |
| 1386 | yang_print_open(out, &flag); |
| 1387 | yang_print_snode(out, level, sub, LYS_ACTION); |
| 1388 | } |
| 1389 | |
| 1390 | LY_TREE_FOR(node->child, sub) { |
| 1391 | /* augments */ |
| 1392 | if (sub->parent != node) { |
| 1393 | continue; |
| 1394 | } |
| 1395 | yang_print_open(out, &flag); |
| 1396 | yang_print_snode(out, level, sub, LYS_NOTIF); |
| 1397 | } |
| 1398 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1399 | level--; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1400 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1403 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1404 | yang_print_grouping(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1405 | { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1406 | int i, flag = 0; |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1407 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1408 | struct lys_node_grp *grp = (struct lys_node_grp *)node; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1409 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1410 | ly_print(out, "%*sgrouping %s", LEVEL, INDENT, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1411 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1412 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1413 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT | SNODE_COMMON_STATUS | |
| 1414 | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1415 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1416 | for (i = 0; i < grp->tpdf_size; i++) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1417 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1418 | yang_print_typedef(out, level, node->module, &grp->tpdf[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1419 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1420 | |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1421 | LY_TREE_FOR(node->child, sub) { |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1422 | yang_print_open(out, &flag); |
| 1423 | yang_print_snode(out, level, sub, LYS_GROUPING); |
| 1424 | } |
| 1425 | |
| 1426 | LY_TREE_FOR(node->child, sub) { |
| 1427 | yang_print_open(out, &flag); |
| 1428 | yang_print_snode(out, level, sub, LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1429 | LYS_USES | LYS_ANYDATA); |
| 1430 | } |
| 1431 | |
| 1432 | LY_TREE_FOR(node->child, sub) { |
| 1433 | yang_print_open(out, &flag); |
| 1434 | yang_print_snode(out, level, sub, LYS_ACTION); |
| 1435 | } |
| 1436 | |
| 1437 | LY_TREE_FOR(node->child, sub) { |
| 1438 | yang_print_open(out, &flag); |
| 1439 | yang_print_snode(out, level, sub, LYS_NOTIF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1440 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1441 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1442 | level--; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1443 | yang_print_close(out, level, flag); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1446 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1447 | yang_print_uses(struct lyout *out, int level, const struct lys_node *node) |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 1448 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1449 | int i, flag = 0; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1450 | struct lys_node_uses *uses = (struct lys_node_uses *)node; |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 1451 | struct lys_module *mod; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 1452 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1453 | ly_print(out, "%*suses ", LEVEL, INDENT); |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 1454 | if (node->child) { |
Michal Vasko | 6c629ac | 2016-02-15 14:08:23 +0100 | [diff] [blame] | 1455 | mod = lys_node_module(node->child); |
Michal Vasko | 1dae8ec | 2016-02-15 14:49:01 +0100 | [diff] [blame] | 1456 | if (lys_node_module(node) != mod) { |
Michal Vasko | 1bb7a5a | 2016-02-05 14:28:02 +0100 | [diff] [blame] | 1457 | ly_print(out, "%s:", transform_module_name2import_prefix(node->module, mod->name)); |
| 1458 | } |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 1459 | } |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1460 | ly_print(out, "%s", uses->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1461 | level++; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 1462 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1463 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1464 | if (uses->when) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1465 | yang_print_open(out, &flag); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1466 | yang_print_when(out, level, node->module, uses->when); |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 1467 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1468 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_IFF | |
| 1469 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1470 | for (i = 0; i < uses->refine_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1471 | yang_print_open(out, &flag); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1472 | yang_print_refine(out, level, node->module, &uses->refine[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1473 | } |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 1474 | for (i = 0; i < uses->augment_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1475 | yang_print_open(out, &flag); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1476 | yang_print_augment(out, level, &uses->augment[i]); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1479 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1480 | yang_print_close(out, level, flag); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 1481 | } |
| 1482 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1483 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1484 | yang_print_input_output(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 1485 | { |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1486 | int i; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1487 | struct lys_node *sub; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 1488 | struct lys_node_inout *inout = (struct lys_node_inout *)node; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1489 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1490 | ly_print(out, "%*s%s {\n", LEVEL, INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output")); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1491 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1492 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1493 | if (node->ext_size) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1494 | yang_print_extension_instances(out, level, node->module, LYEXT_SUBSTMT_SELF, 0, node->ext, node->ext_size); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1495 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1496 | for (i = 0; i < inout->must_size; i++) { |
| 1497 | yang_print_must(out, level, node->module, &inout->must[i]); |
| 1498 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1499 | for (i = 0; i < inout->tpdf_size; i++) { |
| 1500 | yang_print_typedef(out, level, node->module, &inout->tpdf[i]); |
| 1501 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1502 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1503 | /* augments */ |
| 1504 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1505 | continue; |
| 1506 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1507 | yang_print_snode(out, level, sub, LYS_GROUPING); |
| 1508 | } |
| 1509 | LY_TREE_FOR(node->child, sub) { |
| 1510 | /* augments */ |
| 1511 | if (sub->parent != node) { |
| 1512 | continue; |
| 1513 | } |
| 1514 | yang_print_snode(out, level, sub, LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1515 | LYS_USES | LYS_ANYDATA); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1519 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | static void |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1523 | yang_print_rpc_action(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1524 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1525 | int i, flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1526 | struct lys_node *sub; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 1527 | struct lys_node_rpc_action *rpc = (struct lys_node_rpc_action *)node; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1528 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1529 | ly_print(out, "%*s%s %s", LEVEL, INDENT, (node->nodetype == LYS_RPC ? "rpc" : "action"), node->name); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1530 | |
| 1531 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1532 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT | SNODE_COMMON_IFF | |
| 1533 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 1534 | |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1535 | for (i = 0; i < rpc->tpdf_size; i++) { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1536 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1537 | yang_print_typedef(out, level, node->module, &rpc->tpdf[i]); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1538 | } |
| 1539 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1540 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1541 | /* augments */ |
| 1542 | if (sub->parent != node) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 1543 | continue; |
| 1544 | } |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1545 | yang_print_open(out, &flag); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1546 | yang_print_snode(out, level, sub, LYS_GROUPING); |
| 1547 | } |
| 1548 | |
| 1549 | LY_TREE_FOR(node->child, sub) { |
| 1550 | /* augments */ |
| 1551 | if (sub->parent != node) { |
| 1552 | continue; |
| 1553 | } |
| 1554 | yang_print_open(out, &flag); |
| 1555 | yang_print_snode(out, level, sub, LYS_INPUT); |
| 1556 | } |
| 1557 | |
| 1558 | LY_TREE_FOR(node->child, sub) { |
| 1559 | /* augments */ |
| 1560 | if (sub->parent != node) { |
| 1561 | continue; |
| 1562 | } |
| 1563 | yang_print_open(out, &flag); |
| 1564 | yang_print_snode(out, level, sub, LYS_OUTPUT); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1568 | yang_print_close(out, level, flag); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1572 | yang_print_notif(struct lyout *out, int level, const struct lys_node *node) |
Michal Vasko | 7690bc1 | 2015-06-16 12:26:05 +0200 | [diff] [blame] | 1573 | { |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1574 | int i, flag = 0; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1575 | struct lys_node *sub; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1576 | struct lys_node_notif *notif = (struct lys_node_notif *)node; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1577 | |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1578 | ly_print(out, "%*snotification %s", LEVEL, INDENT, node->name); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1579 | |
| 1580 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1581 | yang_print_snode_common(out, level, node, node->module, &flag, SNODE_COMMON_EXT | SNODE_COMMON_IFF); |
Radek Krejci | 12032a5 | 2016-07-29 15:42:56 +0200 | [diff] [blame] | 1582 | for (i = 0; i < notif->must_size; i++) { |
| 1583 | yang_print_open(out, &flag); |
| 1584 | yang_print_must(out, level, node->module, ¬if->must[i]); |
| 1585 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1586 | yang_print_snode_common(out, level, node, node->module, &flag, |
| 1587 | SNODE_COMMON_STATUS | SNODE_COMMON_DSC | SNODE_COMMON_REF); |
| 1588 | for (i = 0; i < notif->tpdf_size; i++) { |
| 1589 | yang_print_open(out, &flag); |
| 1590 | yang_print_typedef(out, level, node->module, ¬if->tpdf[i]); |
| 1591 | } |
| 1592 | LY_TREE_FOR(node->child, sub) { |
| 1593 | /* augments */ |
| 1594 | if (sub->parent != node) { |
| 1595 | continue; |
| 1596 | } |
| 1597 | yang_print_open(out, &flag); |
| 1598 | yang_print_snode(out, level, sub, LYS_GROUPING); |
| 1599 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1600 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1601 | /* augments */ |
| 1602 | if (sub->parent != node) { |
Michal Vasko | 15b4870 | 2015-07-07 15:49:34 +0200 | [diff] [blame] | 1603 | continue; |
| 1604 | } |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1605 | yang_print_open(out, &flag); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1606 | yang_print_snode(out, level, sub, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1607 | LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1608 | LYS_USES | LYS_ANYDATA); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | level--; |
Radek Krejci | 32cce7c | 2015-12-09 16:44:13 +0100 | [diff] [blame] | 1612 | yang_print_close(out, level, flag); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | static void |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1616 | yang_print_snode(struct lyout *out, int level, const struct lys_node *node, int mask) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1617 | { |
Radek Krejci | 2c99a62 | 2017-01-12 10:11:13 +0100 | [diff] [blame] | 1618 | if (node->nodetype & mask) { |
| 1619 | if ((node->nodetype & (LYS_INPUT | LYS_OUTPUT)) && (node->flags & LYS_IMPLICIT)) { |
| 1620 | /* implicit input/output node is not supposed to be printed */ |
| 1621 | return; |
| 1622 | } else if (!node->parent || |
| 1623 | (node->parent->nodetype == LYS_AUGMENT && node != node->parent->child) || |
| 1624 | (node->parent->nodetype != LYS_AUGMENT && node->prev->next)) { |
| 1625 | /* do not print the blank line before the first data-def node */ |
| 1626 | ly_print(out, "\n"); |
| 1627 | } |
| 1628 | } |
| 1629 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1630 | switch (node->nodetype & mask) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1631 | case LYS_CONTAINER: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1632 | yang_print_container(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1633 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1634 | case LYS_CHOICE: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1635 | yang_print_choice(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1636 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1637 | case LYS_LEAF: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1638 | yang_print_leaf(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1639 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1640 | case LYS_LEAFLIST: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1641 | yang_print_leaflist(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1642 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1643 | case LYS_LIST: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1644 | yang_print_list(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1645 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1646 | case LYS_USES: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1647 | yang_print_uses(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1648 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1649 | case LYS_GROUPING: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1650 | yang_print_grouping(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1651 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1652 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1653 | case LYS_ANYDATA: |
| 1654 | yang_print_anydata(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1655 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1656 | case LYS_CASE: |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1657 | yang_print_case(out, level, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1658 | break; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1659 | case LYS_RPC: |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1660 | case LYS_ACTION: |
| 1661 | yang_print_rpc_action(out, level, node); |
| 1662 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1663 | case LYS_INPUT: |
| 1664 | case LYS_OUTPUT: |
Radek Krejci | 2c99a62 | 2017-01-12 10:11:13 +0100 | [diff] [blame] | 1665 | yang_print_input_output(out, level, node); |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1666 | break; |
Michal Vasko | b15cae2 | 2016-09-15 09:40:56 +0200 | [diff] [blame] | 1667 | case LYS_NOTIF: |
| 1668 | yang_print_notif(out, level, node); |
| 1669 | break; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1670 | default: |
| 1671 | break; |
| 1672 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1673 | } |
| 1674 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1675 | int |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1676 | yang_print_model(struct lyout *out, const struct lys_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1677 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1678 | unsigned int i; |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1679 | int level = 0, p; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1680 | #define LEVEL (level*2) |
| 1681 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1682 | struct lys_node *node; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1683 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1684 | /* (sub)module-header-stmts */ |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 1685 | if (module->type) { |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 1686 | ly_print(out, "submodule %s {%s\n", module->name, (module->deviated == 1 ? " // DEVIATED" : "")); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 1687 | level++; |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1688 | if (module->version) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1689 | yang_print_substmt(out, level, LYEXT_SUBSTMT_VERSION, 0, |
| 1690 | ((struct lys_submodule *)module)->belongsto->version == 2 ? "1.1" : "1", |
| 1691 | module, module->ext, module->ext_size); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1692 | } |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1693 | ly_print(out, "%*sbelongs-to %s {\n", LEVEL, INDENT, ((struct lys_submodule *)module)->belongsto->name); |
Radek Krejci | cfce029 | 2017-01-13 12:37:57 +0100 | [diff] [blame] | 1694 | p = -1; |
| 1695 | while ((p = ly_print_ext_iter(module->ext, module->ext_size, p + 1, LYEXT_SUBSTMT_BELONGSTO)) != -1) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1696 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_BELONGSTO, 0, &module->ext[p], 1); |
| 1697 | } |
| 1698 | yang_print_substmt(out, level + 1, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, |
| 1699 | module, module->ext, module->ext_size); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1700 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 1701 | } else { |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 1702 | ly_print(out, "module %s {%s\n", module->name, (module->deviated == 1 ? " // DEVIATED" : "")); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 1703 | level++; |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1704 | if (module->version) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1705 | yang_print_substmt(out, level, LYEXT_SUBSTMT_VERSION, 0, module->version == 2 ? "1.1" : "1", |
| 1706 | module, module->ext, module->ext_size); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1707 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1708 | yang_print_substmt(out, level, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, |
| 1709 | module, module->ext, module->ext_size); |
| 1710 | yang_print_substmt(out, level, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, |
| 1711 | module, module->ext, module->ext_size); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 1712 | } |
Radek Krejci | b0594bf | 2015-05-21 23:51:27 +0200 | [diff] [blame] | 1713 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1714 | /* linkage-stmts */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1715 | for (i = 0; i < module->imp_size; i++) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1716 | ly_print(out, "\n%*simport %s {\n", LEVEL, INDENT, module->imp[i].module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1717 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1718 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, |
| 1719 | module->imp[i].ext, module->imp[i].ext_size); |
Radek Krejci | 39228d2 | 2017-01-13 12:43:55 +0100 | [diff] [blame] | 1720 | yang_print_substmt(out, level, LYEXT_SUBSTMT_PREFIX, 0, module->imp[i].prefix, |
| 1721 | module, module->imp[i].ext, module->imp[i].ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1722 | if (module->imp[i].rev[0]) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1723 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REVISIONDATE, 0, module->imp[i].rev, |
| 1724 | module, module->imp[i].ext, module->imp[i].ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1725 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1726 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, module->imp[i].dsc, |
| 1727 | module, module->imp[i].ext, module->imp[i].ext_size); |
| 1728 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, module->imp[i].ref, |
| 1729 | module, module->imp[i].ext, module->imp[i].ext_size); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1730 | level--; |
Michal Vasko | c8e3ce0 | 2016-02-12 14:28:35 +0100 | [diff] [blame] | 1731 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1732 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1733 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 1734 | if (module->inc[i].external) { |
| 1735 | continue; |
| 1736 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1737 | if (module->inc[i].rev[0] || module->inc[i].dsc || module->inc[i].ref || module->inc[i].ext_size) { |
| 1738 | ly_print(out, "\n%*sinclude %s {\n", LEVEL, INDENT, module->inc[i].submodule->name); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1739 | level++; |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1740 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, |
| 1741 | module->inc[i].ext, module->inc[i].ext_size); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1742 | if (module->inc[i].rev[0]) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1743 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REVISIONDATE, 0, module->inc[i].rev, |
| 1744 | module, module->inc[i].ext, module->inc[i].ext_size); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1745 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1746 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, module->inc[i].dsc, |
| 1747 | module, module->inc[i].ext, module->inc[i].ext_size); |
| 1748 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, module->inc[i].ref, |
| 1749 | module, module->inc[i].ext, module->inc[i].ext_size); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1750 | level--; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1751 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1752 | } else { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1753 | ly_print(out, "\n%*sinclude \"%s\";\n", LEVEL, INDENT, module->inc[i].submodule->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1754 | } |
| 1755 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 1756 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1757 | /* meta-stmts */ |
| 1758 | if (module->org || module->contact || module->dsc || module->ref) { |
| 1759 | ly_print(out, "\n"); |
| 1760 | } |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1761 | yang_print_substmt(out, level, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, |
| 1762 | module, module->ext, module->ext_size); |
| 1763 | yang_print_substmt(out, level, LYEXT_SUBSTMT_CONTACT, 0, module->contact, |
| 1764 | module, module->ext, module->ext_size); |
| 1765 | yang_print_substmt(out, level, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, |
| 1766 | module, module->ext, module->ext_size); |
| 1767 | yang_print_substmt(out, level, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, |
| 1768 | module, module->ext, module->ext_size); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1769 | |
| 1770 | /* revision-stmts */ |
| 1771 | if (module->rev_size) { |
| 1772 | ly_print(out, "\n"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1773 | } |
| 1774 | for (i = 0; i < module->rev_size; i++) { |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1775 | if (module->rev[i].dsc || module->rev[i].ref || module->rev[i].ext_size) { |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1776 | ly_print(out, "%*srevision \"%s\" {\n", LEVEL, INDENT, module->rev[i].date); |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1777 | yang_print_extension_instances(out, level + 1, module, LYEXT_SUBSTMT_SELF, 0, |
| 1778 | module->rev[i].ext, module->rev[i].ext_size); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1779 | yang_print_substmt(out, level + 1, LYEXT_SUBSTMT_DESCRIPTION, 0, module->rev[i].dsc, |
| 1780 | module, module->rev[i].ext, module->rev[i].ext_size); |
| 1781 | yang_print_substmt(out, level + 1, LYEXT_SUBSTMT_REFERENCE, 0, module->rev[i].ref, |
| 1782 | module, module->rev[i].ext, module->rev[i].ext_size); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1783 | ly_print(out, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1784 | } else { |
Michal Vasko | 86dfd26 | 2016-02-15 14:26:31 +0100 | [diff] [blame] | 1785 | ly_print(out, "%*srevision %s;\n", LEVEL, INDENT, module->rev[i].date); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1786 | } |
| 1787 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1788 | |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1789 | /* body-stmts */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1790 | for (i = 0; i < module->extensions_size; i++) { |
| 1791 | ly_print(out, "\n"); |
| 1792 | yang_print_extension(out, level, &module->extensions[i]); |
| 1793 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1794 | if (module->ext_size) { |
| 1795 | ly_print(out, "\n"); |
| 1796 | yang_print_extension_instances(out, level, module, LYEXT_SUBSTMT_SELF, 0, module->ext, module->ext_size); |
| 1797 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1798 | |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 1799 | for (i = 0; i < module->features_size; i++) { |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1800 | ly_print(out, "\n"); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1801 | yang_print_feature(out, level, &module->features[i]); |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 1802 | } |
| 1803 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1804 | for (i = 0; i < module->ident_size; i++) { |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1805 | ly_print(out, "\n"); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1806 | yang_print_identity(out, level, &module->ident[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1807 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 1808 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1809 | for (i = 0; i < module->tpdf_size; i++) { |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1810 | ly_print(out, "\n"); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1811 | yang_print_typedef(out, level, module, &module->tpdf[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1812 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1813 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1814 | LY_TREE_FOR(lys_main_module(module)->data, node) { |
| 1815 | if (node->module != module) { |
| 1816 | /* data from submodules */ |
| 1817 | continue; |
| 1818 | } |
| 1819 | yang_print_snode(out, level, node, LYS_GROUPING); |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 1822 | LY_TREE_FOR(lys_main_module(module)->data, node) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 1823 | if (node->module != module) { |
Michal Vasko | 0c5e928 | 2016-02-15 13:11:57 +0100 | [diff] [blame] | 1824 | /* data from submodules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 1825 | continue; |
| 1826 | } |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1827 | yang_print_snode(out, level, node, LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | |
| 1828 | LYS_USES | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1829 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1830 | |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 1831 | for (i = 0; i < module->augment_size; i++) { |
Radek Krejci | 8d81e00 | 2015-12-10 11:18:59 +0100 | [diff] [blame] | 1832 | ly_print(out, "\n"); |
Radek Krejci | 43e3c31 | 2017-01-11 11:34:44 +0100 | [diff] [blame] | 1833 | yang_print_augment(out, level, &module->augment[i]); |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
Radek Krejci | 5dd2512 | 2017-01-11 17:28:13 +0100 | [diff] [blame] | 1836 | LY_TREE_FOR(lys_main_module(module)->data, node) { |
| 1837 | if (node->module != module) { |
| 1838 | /* data from submodules */ |
| 1839 | continue; |
| 1840 | } |
| 1841 | yang_print_snode(out, level, node, LYS_RPC | LYS_ACTION); |
| 1842 | } |
| 1843 | |
| 1844 | LY_TREE_FOR(lys_main_module(module)->data, node) { |
| 1845 | if (node->module != module) { |
| 1846 | /* data from submodules */ |
| 1847 | continue; |
| 1848 | } |
| 1849 | yang_print_snode(out, level, node, LYS_NOTIF); |
| 1850 | } |
| 1851 | |
| 1852 | for (i = 0; i < module->deviation_size; ++i) { |
| 1853 | ly_print(out, "\n"); |
| 1854 | yang_print_deviation(out, level, module, &module->deviation[i]); |
| 1855 | } |
| 1856 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1857 | ly_print(out, "}\n"); |
Michal Vasko | 95068c4 | 2016-03-24 14:58:11 +0100 | [diff] [blame] | 1858 | ly_print_flush(out); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1859 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1860 | return EXIT_SUCCESS; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1861 | #undef LEVEL |
| 1862 | } |