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