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