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