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