Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer_yang.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief YANG printer |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 CESNET, z.s.p.o. |
| 7 | * |
| 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 |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #include "common.h" |
| 16 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 17 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 22 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include "extensions.h" |
| 24 | #include "log.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 25 | #include "printer_internal.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 26 | #include "tree.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
| 28 | #include "tree_schema_internal.h" |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 29 | #include "xpath.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 30 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 31 | /** |
| 32 | * @brief Types of the YANG printers |
| 33 | */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 34 | enum schema_type { |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 35 | YPR_PARSED, /**< YANG printer of the parsed schema */ |
| 36 | YPR_COMPILED /**< YANG printer of the compiled schema */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 39 | /** |
| 40 | * @brief YANG printer context. |
| 41 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 42 | struct ypr_ctx { |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 43 | struct lyout *out; /**< output specification */ |
| 44 | unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
| 45 | const struct lys_module *module; /**< schema to print */ |
| 46 | enum schema_type schema; /**< type of the schema to print */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 49 | #define LEVEL ctx->level /**< current level */ |
| 50 | #define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */ |
| 51 | |
| 52 | /** |
| 53 | * @brief Print the given text as content of a double quoted YANG string, |
| 54 | * including encoding characters that have special meanings. The quotation marks |
| 55 | * are not printed. |
| 56 | * |
| 57 | * Follows RFC 7950, section 6.1.3. |
| 58 | * |
| 59 | * @param[in] out Output specification. |
| 60 | * @param[in] text String to be printed. |
| 61 | * @param[in] len Length of the string from @p text to be printed. In case of 0, |
| 62 | * the @p text is printed completely as a NULL-terminated string. |
| 63 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 64 | static void |
| 65 | ypr_encode(struct lyout *out, const char *text, int len) |
| 66 | { |
| 67 | int i, start_len; |
| 68 | const char *start; |
| 69 | char special = 0; |
| 70 | |
| 71 | if (!len) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (len < 0) { |
| 76 | len = strlen(text); |
| 77 | } |
| 78 | |
| 79 | start = text; |
| 80 | start_len = 0; |
| 81 | for (i = 0; i < len; ++i) { |
| 82 | switch (text[i]) { |
| 83 | case '\n': |
| 84 | case '\t': |
| 85 | case '\"': |
| 86 | case '\\': |
| 87 | special = text[i]; |
| 88 | break; |
| 89 | default: |
| 90 | ++start_len; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | if (special) { |
| 95 | ly_write(out, start, start_len); |
| 96 | switch (special) { |
| 97 | case '\n': |
| 98 | ly_write(out, "\\n", 2); |
| 99 | break; |
| 100 | case '\t': |
| 101 | ly_write(out, "\\t", 2); |
| 102 | break; |
| 103 | case '\"': |
| 104 | ly_write(out, "\\\"", 2); |
| 105 | break; |
| 106 | case '\\': |
| 107 | ly_write(out, "\\\\", 2); |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | start += start_len + 1; |
| 112 | start_len = 0; |
| 113 | |
| 114 | special = 0; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | ly_write(out, start, start_len); |
| 119 | } |
| 120 | |
| 121 | static void |
| 122 | ypr_open(struct lyout *out, int *flag) |
| 123 | { |
| 124 | if (flag && !*flag) { |
| 125 | *flag = 1; |
| 126 | ly_print(out, " {\n"); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | ypr_close(struct ypr_ctx *ctx, int flag) |
| 132 | { |
| 133 | if (flag) { |
| 134 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 135 | } else { |
| 136 | ly_print(ctx->out, ";\n"); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed) |
| 142 | { |
| 143 | const char *s, *t; |
| 144 | |
| 145 | if (singleline) { |
| 146 | ly_print(ctx->out, "%*s%s \"", INDENT, name); |
| 147 | } else { |
| 148 | ly_print(ctx->out, "%*s%s\n", INDENT, name); |
| 149 | LEVEL++; |
| 150 | |
| 151 | ly_print(ctx->out, "%*s\"", INDENT); |
| 152 | } |
| 153 | t = text; |
| 154 | while ((s = strchr(t, '\n'))) { |
| 155 | ypr_encode(ctx->out, t, s - t); |
| 156 | ly_print(ctx->out, "\n"); |
| 157 | t = s + 1; |
| 158 | if (*t != '\n') { |
| 159 | ly_print(ctx->out, "%*s ", INDENT); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | ypr_encode(ctx->out, t, strlen(t)); |
| 164 | if (closed) { |
| 165 | ly_print(ctx->out, "\";\n"); |
| 166 | } else { |
| 167 | ly_print(ctx->out, "\""); |
| 168 | } |
| 169 | if (!singleline) { |
| 170 | LEVEL--; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 175 | yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 176 | { |
| 177 | struct lysp_stmt *childstmt; |
| 178 | const char *s, *t; |
| 179 | |
| 180 | if (stmt->arg) { |
| 181 | if (stmt->flags) { |
| 182 | ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt); |
| 183 | LEVEL++; |
| 184 | ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\''); |
| 185 | t = stmt->arg; |
| 186 | while ((s = strchr(t, '\n'))) { |
| 187 | ypr_encode(ctx->out, t, s - t); |
| 188 | ly_print(ctx->out, "\n"); |
| 189 | t = s + 1; |
| 190 | if (*t != '\n') { |
| 191 | ly_print(ctx->out, "%*s ", INDENT); |
| 192 | } |
| 193 | } |
| 194 | LEVEL--; |
| 195 | ypr_encode(ctx->out, t, strlen(t)); |
| 196 | ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n"); |
| 197 | } else { |
| 198 | ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n"); |
| 199 | } |
| 200 | } else { |
| 201 | ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n"); |
| 202 | } |
| 203 | |
| 204 | if (stmt->child) { |
| 205 | LEVEL++; |
| 206 | LY_LIST_FOR(stmt->child, childstmt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 207 | yprp_stmt(ctx, childstmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 208 | } |
| 209 | LEVEL--; |
| 210 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @param[in] count Number of extensions to print, 0 to print them all. |
| 216 | */ |
| 217 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 218 | yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 219 | struct lysp_ext_instance *ext, int *flag, unsigned int count) |
| 220 | { |
| 221 | unsigned int u; |
| 222 | struct lysp_stmt *stmt; |
| 223 | |
| 224 | if (!count && ext) { |
| 225 | count = LY_ARRAY_SIZE(ext); |
| 226 | } |
| 227 | LY_ARRAY_FOR(ext, u) { |
| 228 | if (!count) { |
| 229 | break; |
| 230 | } |
| 231 | if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) { |
| 232 | ypr_open(ctx->out, flag); |
| 233 | if (ext[u].argument) { |
| 234 | ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n"); |
| 235 | } else { |
| 236 | ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n"); |
| 237 | } |
| 238 | |
| 239 | if (ext[u].child) { |
| 240 | LEVEL++; |
| 241 | LY_LIST_FOR(ext[u].child, stmt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 242 | yprp_stmt(ctx, stmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 243 | } |
| 244 | LEVEL--; |
| 245 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 246 | } |
| 247 | } |
| 248 | count--; |
| 249 | } |
| 250 | } |
| 251 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 252 | /** |
| 253 | * @param[in] count Number of extensions to print, 0 to print them all. |
| 254 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 255 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 256 | yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
| 257 | struct lysc_ext_instance *ext, int *flag, unsigned int count) |
| 258 | { |
| 259 | unsigned int u; |
| 260 | |
| 261 | if (!count && ext) { |
| 262 | count = LY_ARRAY_SIZE(ext); |
| 263 | } |
| 264 | LY_ARRAY_FOR(ext, u) { |
| 265 | if (!count) { |
| 266 | break; |
| 267 | } |
| 268 | /* TODO compiled extensions */ |
| 269 | (void) ctx; |
| 270 | (void) substmt; |
| 271 | (void) substmt_index; |
| 272 | (void) flag; |
| 273 | |
| 274 | count--; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | static void |
| 279 | ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 280 | { |
| 281 | unsigned int u; |
| 282 | int extflag = 0; |
| 283 | |
| 284 | if (!text) { |
| 285 | /* nothing to print */ |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) { |
| 290 | ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text); |
| 291 | } else { |
| 292 | ypr_text(ctx, ext_substmt_info[substmt].name, text, |
| 293 | (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0); |
| 294 | } |
| 295 | |
| 296 | LEVEL++; |
| 297 | LY_ARRAY_FOR(ext, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 298 | if (((struct lysp_ext_instance*)ext)[u].insubstmt != substmt || ((struct lysp_ext_instance*)ext)[u].insubstmt_index != substmt_index) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 299 | continue; |
| 300 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 301 | if (ctx->schema == YPR_PARSED) { |
| 302 | yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1); |
| 303 | } else { |
| 304 | yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1); |
| 305 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 306 | } |
| 307 | LEVEL--; |
| 308 | ypr_close(ctx, extflag); |
| 309 | } |
| 310 | |
| 311 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 312 | ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 313 | { |
| 314 | char *str; |
| 315 | |
| 316 | if (asprintf(&str, "%u", attr_value) == -1) { |
| 317 | LOGMEM(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 318 | ctx->out->status = LY_EMEM; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 322 | ypr_substmt(ctx, substmt, substmt_index, str, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 323 | free(str); |
| 324 | } |
| 325 | |
| 326 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 327 | ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 328 | { |
| 329 | char *str; |
| 330 | |
| 331 | if (asprintf(&str, "%d", attr_value) == -1) { |
| 332 | LOGMEM(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 333 | ctx->out->status = LY_EMEM; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 337 | ypr_substmt(ctx, substmt, substmt_index, str, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 338 | free(str); |
| 339 | } |
| 340 | |
| 341 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 342 | yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 343 | { |
| 344 | if (rev->dsc || rev->ref || rev->exts) { |
| 345 | ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date); |
| 346 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 347 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0); |
| 348 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts); |
| 349 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 350 | LEVEL--; |
| 351 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 352 | } else { |
| 353 | ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 358 | ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 359 | { |
| 360 | if (flags & LYS_MAND_MASK) { |
| 361 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 362 | ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 367 | ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 368 | { |
| 369 | if (flags & LYS_CONFIG_MASK) { |
| 370 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 371 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 376 | ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 377 | { |
| 378 | const char *status = NULL; |
| 379 | |
| 380 | if (flags & LYS_STATUS_CURR) { |
| 381 | ypr_open(ctx->out, flag); |
| 382 | status = "current"; |
| 383 | } else if (flags & LYS_STATUS_DEPRC) { |
| 384 | ypr_open(ctx->out, flag); |
| 385 | status = "deprecated"; |
| 386 | } else if (flags & LYS_STATUS_OBSLT) { |
| 387 | ypr_open(ctx->out, flag); |
| 388 | status = "obsolete"; |
| 389 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 390 | |
| 391 | ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 395 | ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 396 | { |
| 397 | if (dsc) { |
| 398 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 399 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 404 | ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 405 | { |
| 406 | if (ref) { |
| 407 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 408 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 413 | yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 414 | { |
| 415 | unsigned int u; |
| 416 | int extflag; |
| 417 | |
| 418 | LY_ARRAY_FOR(iff, u) { |
| 419 | ypr_open(ctx->out, flag); |
| 420 | extflag = 0; |
| 421 | |
| 422 | ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]); |
| 423 | |
| 424 | /* extensions */ |
| 425 | LEVEL++; |
| 426 | LY_ARRAY_FOR(exts, u) { |
| 427 | if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) { |
| 428 | continue; |
| 429 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 430 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 431 | } |
| 432 | LEVEL--; |
| 433 | ypr_close(ctx, extflag); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 438 | yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f) |
| 439 | { |
| 440 | int brackets_flag = *index_e; |
| 441 | uint8_t op; |
| 442 | |
| 443 | op = lysc_iff_getop(feat->expr, *index_e); |
| 444 | (*index_e)++; |
| 445 | |
| 446 | switch (op) { |
| 447 | case LYS_IFF_F: |
| 448 | if (ctx->module == feat->features[*index_f]->module) { |
| 449 | ly_print(ctx->out, "%s", feat->features[*index_f]->name); |
| 450 | } else { |
| 451 | ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name); |
| 452 | } |
| 453 | (*index_f)++; |
| 454 | break; |
| 455 | case LYS_IFF_NOT: |
| 456 | ly_print(ctx->out, "not "); |
| 457 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 458 | break; |
| 459 | case LYS_IFF_AND: |
| 460 | if (brackets_flag) { |
| 461 | /* AND need brackets only if previous op was not */ |
| 462 | if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) { |
| 463 | brackets_flag = 0; |
| 464 | } |
| 465 | } |
| 466 | /* falls through */ |
| 467 | case LYS_IFF_OR: |
| 468 | if (brackets_flag) { |
| 469 | ly_print(ctx->out, "("); |
| 470 | } |
| 471 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 472 | ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and"); |
| 473 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 474 | if (brackets_flag) { |
| 475 | ly_print(ctx->out, ")"); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | static void |
| 481 | yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag) |
| 482 | { |
| 483 | unsigned int u; |
| 484 | int extflag; |
| 485 | |
| 486 | LY_ARRAY_FOR(iff, u) { |
| 487 | int index_e = 0, index_f = 0; |
| 488 | |
| 489 | ypr_open(ctx->out, flag); |
| 490 | extflag = 0; |
| 491 | |
Radek Krejci | 989e53b | 2019-04-30 09:51:09 +0200 | [diff] [blame] | 492 | ly_print(ctx->out, "%*sif-feature \"", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 493 | yprc_iffeature(ctx, iff, &index_e, &index_f); |
Radek Krejci | 989e53b | 2019-04-30 09:51:09 +0200 | [diff] [blame] | 494 | ly_print(ctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 495 | |
| 496 | /* extensions */ |
| 497 | LEVEL++; |
| 498 | LY_ARRAY_FOR(exts, u) { |
| 499 | if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) { |
| 500 | continue; |
| 501 | } |
| 502 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1); |
| 503 | } |
| 504 | LEVEL--; |
| 505 | ypr_close(ctx, extflag); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | static void |
| 510 | yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 511 | { |
| 512 | int flag = 0, flag2 = 0; |
| 513 | unsigned int i; |
| 514 | |
| 515 | ly_print(ctx->out, "%*sextension %s", INDENT, ext->name); |
| 516 | LEVEL++; |
| 517 | |
| 518 | if (ext->exts) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 519 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | if (ext->argument) { |
| 523 | ypr_open(ctx->out, &flag); |
| 524 | ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument); |
| 525 | if (ext->exts) { |
| 526 | LEVEL++; |
| 527 | i = -1; |
| 528 | while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 529 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 530 | } |
| 531 | LEVEL--; |
| 532 | } |
| 533 | if ((ext->flags & LYS_YINELEM_MASK) || |
| 534 | (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) { |
| 535 | ypr_open(ctx->out, &flag2); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 536 | ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 537 | } |
| 538 | ypr_close(ctx, flag2); |
| 539 | } |
| 540 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 541 | ypr_status(ctx, ext->flags, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 542 | ypr_description(ctx, ext->dsc, ext->exts, &flag); |
| 543 | ypr_reference(ctx, ext->ref, ext->exts, &flag); |
| 544 | |
| 545 | LEVEL--; |
| 546 | ypr_close(ctx, flag); |
| 547 | } |
| 548 | |
| 549 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 550 | yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 551 | { |
| 552 | int flag = 0; |
| 553 | |
| 554 | ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name); |
| 555 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 556 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0); |
| 557 | yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag); |
| 558 | ypr_status(ctx, feat->flags, feat->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 559 | ypr_description(ctx, feat->dsc, feat->exts, &flag); |
| 560 | ypr_reference(ctx, feat->ref, feat->exts, &flag); |
| 561 | LEVEL--; |
| 562 | ypr_close(ctx, flag); |
| 563 | } |
| 564 | |
| 565 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 566 | yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat) |
| 567 | { |
| 568 | int flag = 0; |
| 569 | |
| 570 | ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name); |
| 571 | LEVEL++; |
| 572 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0); |
| 573 | yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag); |
| 574 | ypr_status(ctx, feat->flags, feat->exts, &flag); |
| 575 | ypr_description(ctx, feat->dsc, feat->exts, &flag); |
| 576 | ypr_reference(ctx, feat->ref, feat->exts, &flag); |
| 577 | LEVEL--; |
| 578 | ypr_close(ctx, flag); |
| 579 | } |
| 580 | |
| 581 | static void |
| 582 | yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 583 | { |
| 584 | int flag = 0; |
| 585 | unsigned int u; |
| 586 | |
| 587 | ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name); |
| 588 | LEVEL++; |
| 589 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 590 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0); |
| 591 | yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 592 | |
| 593 | LY_ARRAY_FOR(ident->bases, u) { |
| 594 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 595 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 598 | ypr_status(ctx, ident->flags, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 599 | ypr_description(ctx, ident->dsc, ident->exts, &flag); |
| 600 | ypr_reference(ctx, ident->ref, ident->exts, &flag); |
| 601 | |
| 602 | LEVEL--; |
| 603 | ypr_close(ctx, flag); |
| 604 | } |
| 605 | |
| 606 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 607 | yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident) |
| 608 | { |
| 609 | int flag = 0; |
| 610 | unsigned int u; |
| 611 | |
| 612 | ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name); |
| 613 | LEVEL++; |
| 614 | |
| 615 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0); |
| 616 | yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag); |
| 617 | |
| 618 | LY_ARRAY_FOR(ident->derived, u) { |
| 619 | ypr_open(ctx->out, &flag); |
| 620 | if (ctx->module != ident->derived[u]->module) { |
| 621 | ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name); |
| 622 | } else { |
| 623 | ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | ypr_status(ctx, ident->flags, ident->exts, &flag); |
| 628 | ypr_description(ctx, ident->dsc, ident->exts, &flag); |
| 629 | ypr_reference(ctx, ident->ref, ident->exts, &flag); |
| 630 | |
| 631 | LEVEL--; |
| 632 | ypr_close(ctx, flag); |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 637 | { |
| 638 | int inner_flag = 0; |
| 639 | |
| 640 | if (!restr) { |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | ypr_open(ctx->out, flag); |
| 645 | ly_print(ctx->out, "%*s%s \"", INDENT, name); |
| 646 | ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1); |
| 647 | ly_print(ctx->out, "\""); |
| 648 | |
| 649 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 650 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 651 | if (restr->arg[0] == 0x15) { |
| 652 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
| 653 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 654 | ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 655 | } |
| 656 | if (restr->emsg) { |
| 657 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 658 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 659 | } |
| 660 | if (restr->eapptag) { |
| 661 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 662 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 663 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 664 | ypr_description(ctx, restr->dsc, restr->exts, &inner_flag); |
| 665 | ypr_reference(ctx, restr->ref, restr->exts, &inner_flag); |
| 666 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 667 | LEVEL--; |
| 668 | ypr_close(ctx, inner_flag); |
| 669 | } |
| 670 | |
| 671 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 672 | yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag) |
| 673 | { |
| 674 | int inner_flag = 0; |
| 675 | |
| 676 | ypr_open(ctx->out, flag); |
| 677 | ly_print(ctx->out, "%*smust \"", INDENT); |
| 678 | ypr_encode(ctx->out, must->cond->expr, -1); |
| 679 | ly_print(ctx->out, "\""); |
| 680 | |
| 681 | LEVEL++; |
| 682 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0); |
| 683 | if (must->emsg) { |
| 684 | ypr_open(ctx->out, &inner_flag); |
| 685 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts); |
| 686 | } |
| 687 | if (must->eapptag) { |
| 688 | ypr_open(ctx->out, &inner_flag); |
| 689 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts); |
| 690 | } |
| 691 | ypr_description(ctx, must->dsc, must->exts, &inner_flag); |
| 692 | ypr_reference(ctx, must->ref, must->exts, &inner_flag); |
| 693 | |
| 694 | LEVEL--; |
| 695 | ypr_close(ctx, inner_flag); |
| 696 | } |
| 697 | |
| 698 | static void |
| 699 | yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag) |
| 700 | { |
| 701 | int inner_flag = 0; |
| 702 | unsigned int u; |
| 703 | |
| 704 | ypr_open(ctx->out, flag); |
| 705 | ly_print(ctx->out, "%*s%s \"", (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY)? "length" : "range", INDENT); |
| 706 | LY_ARRAY_FOR(range->parts, u) { |
| 707 | if (u > 0) { |
| 708 | ly_print(ctx->out, " | "); |
| 709 | } |
| 710 | if (range->parts[u].max_64 == range->parts[u].min_64) { |
| 711 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
| 712 | ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64); |
| 713 | } else { /* signed values */ |
| 714 | ly_print(ctx->out, "%"PRId64, range->parts[u].max_64); |
| 715 | } |
| 716 | } else { |
| 717 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
| 718 | ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64); |
| 719 | } else { /* signed values */ |
| 720 | ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64); |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | ly_print(ctx->out, "\""); |
| 725 | |
| 726 | LEVEL++; |
| 727 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0); |
| 728 | if (range->emsg) { |
| 729 | ypr_open(ctx->out, &inner_flag); |
| 730 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts); |
| 731 | } |
| 732 | if (range->eapptag) { |
| 733 | ypr_open(ctx->out, &inner_flag); |
| 734 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts); |
| 735 | } |
| 736 | ypr_description(ctx, range->dsc, range->exts, &inner_flag); |
| 737 | ypr_reference(ctx, range->ref, range->exts, &inner_flag); |
| 738 | |
| 739 | LEVEL--; |
| 740 | ypr_close(ctx, inner_flag); |
| 741 | } |
| 742 | |
| 743 | static void |
| 744 | yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag) |
| 745 | { |
| 746 | int inner_flag = 0; |
| 747 | |
| 748 | ypr_open(ctx->out, flag); |
| 749 | ly_print(ctx->out, "%*spattern \"", INDENT); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 750 | ypr_encode(ctx->out, pattern->expr, -1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 751 | ly_print(ctx->out, "\""); |
| 752 | |
| 753 | LEVEL++; |
| 754 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0); |
| 755 | if (pattern->inverted) { |
| 756 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
| 757 | ypr_open(ctx->out, &inner_flag); |
| 758 | ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts); |
| 759 | } |
| 760 | if (pattern->emsg) { |
| 761 | ypr_open(ctx->out, &inner_flag); |
| 762 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts); |
| 763 | } |
| 764 | if (pattern->eapptag) { |
| 765 | ypr_open(ctx->out, &inner_flag); |
| 766 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts); |
| 767 | } |
| 768 | ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag); |
| 769 | ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag); |
| 770 | |
| 771 | LEVEL--; |
| 772 | ypr_close(ctx, inner_flag); |
| 773 | } |
| 774 | |
| 775 | static void |
| 776 | yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 777 | { |
| 778 | int inner_flag = 0; |
| 779 | |
| 780 | if (!when) { |
| 781 | return; |
| 782 | } |
| 783 | ypr_open(ctx->out, flag); |
| 784 | |
| 785 | ly_print(ctx->out, "%*swhen \"", INDENT); |
| 786 | ypr_encode(ctx->out, when->cond, -1); |
| 787 | ly_print(ctx->out, "\""); |
| 788 | |
| 789 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 790 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 791 | ypr_description(ctx, when->dsc, when->exts, &inner_flag); |
| 792 | ypr_reference(ctx, when->ref, when->exts, &inner_flag); |
| 793 | LEVEL--; |
| 794 | ypr_close(ctx, inner_flag); |
| 795 | } |
| 796 | |
| 797 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 798 | yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag) |
| 799 | { |
| 800 | int inner_flag = 0; |
| 801 | |
| 802 | if (!when) { |
| 803 | return; |
| 804 | } |
| 805 | ypr_open(ctx->out, flag); |
| 806 | |
| 807 | ly_print(ctx->out, "%*swhen \"", INDENT); |
| 808 | ypr_encode(ctx->out, when->cond->expr, -1); |
| 809 | ly_print(ctx->out, "\""); |
| 810 | |
| 811 | LEVEL++; |
| 812 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0); |
| 813 | ypr_description(ctx, when->dsc, when->exts, &inner_flag); |
| 814 | ypr_reference(ctx, when->ref, when->exts, &inner_flag); |
| 815 | LEVEL--; |
| 816 | ypr_close(ctx, inner_flag); |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 821 | { |
| 822 | unsigned int u; |
| 823 | int inner_flag; |
| 824 | |
| 825 | LY_ARRAY_FOR(items, u) { |
| 826 | ypr_open(ctx->out, flag); |
| 827 | ly_print(ctx->out, "%*s%s \"", INDENT, type == LY_TYPE_BITS ? "bit" : "enum"); |
| 828 | ypr_encode(ctx->out, items[u].name, -1); |
| 829 | ly_print(ctx->out, "\""); |
| 830 | inner_flag = 0; |
| 831 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 832 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0); |
| 833 | yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 834 | if (items[u].flags & LYS_SET_VALUE) { |
| 835 | if (type == LY_TYPE_BITS) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 836 | ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 837 | } else { /* LY_TYPE_ENUM */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 838 | ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 839 | } |
| 840 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 841 | ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 842 | ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag); |
| 843 | ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag); |
| 844 | LEVEL--; |
| 845 | ypr_close(ctx, inner_flag); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 850 | yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 851 | { |
| 852 | unsigned int u; |
| 853 | int flag = 0; |
| 854 | |
| 855 | ly_print(ctx->out, "%*stype %s", INDENT, type->name); |
| 856 | LEVEL++; |
| 857 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 858 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 859 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 860 | yprp_restr(ctx, type->range, "range", &flag); |
| 861 | yprp_restr(ctx, type->length, "length", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 862 | LY_ARRAY_FOR(type->patterns, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 863 | yprp_restr(ctx, &type->patterns[u], "pattern", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 864 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 865 | yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag); |
| 866 | yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 867 | |
| 868 | if (type->path) { |
| 869 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 870 | ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 871 | } |
| 872 | if (type->flags & LYS_SET_REQINST) { |
| 873 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 874 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 875 | } |
| 876 | if (type->flags & LYS_SET_FRDIGITS) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 877 | ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 878 | } |
| 879 | LY_ARRAY_FOR(type->bases, u) { |
| 880 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 881 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 882 | } |
| 883 | LY_ARRAY_FOR(type->types, u) { |
| 884 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 885 | yprp_type(ctx, &type->types[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | LEVEL--; |
| 889 | ypr_close(ctx, flag); |
| 890 | } |
| 891 | |
| 892 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 893 | yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type) |
| 894 | { |
| 895 | unsigned int u; |
| 896 | int flag = 0; |
| 897 | |
| 898 | ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype)); |
| 899 | LEVEL++; |
| 900 | |
| 901 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0); |
| 902 | if (type->dflt) { |
| 903 | ypr_open(ctx->out, &flag); |
| 904 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts); |
| 905 | } |
| 906 | |
| 907 | switch(type->basetype) { |
| 908 | case LY_TYPE_BINARY: { |
| 909 | struct lysc_type_bin *bin = (struct lysc_type_bin*)type; |
| 910 | yprc_range(ctx, bin->length, type->basetype, &flag); |
| 911 | break; |
| 912 | } |
| 913 | case LY_TYPE_UINT8: |
| 914 | case LY_TYPE_UINT16: |
| 915 | case LY_TYPE_UINT32: |
| 916 | case LY_TYPE_UINT64: |
| 917 | case LY_TYPE_INT8: |
| 918 | case LY_TYPE_INT16: |
| 919 | case LY_TYPE_INT32: |
| 920 | case LY_TYPE_INT64: { |
| 921 | struct lysc_type_num *num = (struct lysc_type_num*)type; |
| 922 | yprc_range(ctx, num->range, type->basetype, &flag); |
| 923 | break; |
| 924 | } |
| 925 | case LY_TYPE_STRING: { |
| 926 | struct lysc_type_str *str = (struct lysc_type_str*)type; |
| 927 | yprc_range(ctx, str->length, type->basetype, &flag); |
| 928 | LY_ARRAY_FOR(str->patterns, u) { |
| 929 | yprc_pattern(ctx, str->patterns[u], &flag); |
| 930 | } |
| 931 | break; |
| 932 | } |
| 933 | case LY_TYPE_BITS: |
| 934 | case LY_TYPE_ENUM: { |
| 935 | /* bits and enums structures are compatible */ |
| 936 | struct lysc_type_bits *bits = (struct lysc_type_bits*)type; |
| 937 | LY_ARRAY_FOR(bits->bits, u) { |
| 938 | struct lysc_type_bitenum_item *item = &bits->bits[u]; |
| 939 | int inner_flag = 0; |
| 940 | |
| 941 | ypr_open(ctx->out, &flag); |
| 942 | ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum"); |
| 943 | ypr_encode(ctx->out, item->name, -1); |
| 944 | ly_print(ctx->out, "\""); |
| 945 | LEVEL++; |
| 946 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0); |
| 947 | yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag); |
| 948 | if (type->basetype == LY_TYPE_BITS) { |
| 949 | ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag); |
| 950 | } else { /* LY_TYPE_ENUM */ |
| 951 | ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag); |
| 952 | } |
| 953 | ypr_status(ctx, item->flags, item->exts, &inner_flag); |
| 954 | ypr_description(ctx, item->dsc, item->exts, &inner_flag); |
| 955 | ypr_reference(ctx, item->ref, item->exts, &inner_flag); |
| 956 | LEVEL--; |
| 957 | ypr_close(ctx, inner_flag); |
| 958 | } |
| 959 | break; |
| 960 | } |
| 961 | case LY_TYPE_BOOL: |
| 962 | case LY_TYPE_EMPTY: |
| 963 | /* nothing to do */ |
| 964 | break; |
| 965 | case LY_TYPE_DEC64: { |
| 966 | struct lysc_type_dec *dec = (struct lysc_type_dec*)type; |
| 967 | ypr_open(ctx->out, &flag); |
| 968 | ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag); |
| 969 | yprc_range(ctx, dec->range, dec->basetype, &flag); |
| 970 | break; |
| 971 | } |
| 972 | case LY_TYPE_IDENT: { |
| 973 | struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type; |
| 974 | LY_ARRAY_FOR(ident->bases, u) { |
| 975 | ypr_open(ctx->out, &flag); |
| 976 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts); |
| 977 | } |
| 978 | break; |
| 979 | } |
| 980 | case LY_TYPE_INST: { |
| 981 | struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type; |
| 982 | ypr_open(ctx->out, &flag); |
| 983 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts); |
| 984 | break; |
| 985 | } |
| 986 | case LY_TYPE_LEAFREF: { |
| 987 | struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type; |
| 988 | ypr_open(ctx->out, &flag); |
| 989 | ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts); |
| 990 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts); |
| 991 | yprc_type(ctx, lr->realtype); |
| 992 | break; |
| 993 | } |
| 994 | case LY_TYPE_UNION: { |
| 995 | struct lysc_type_union *un = (struct lysc_type_union*)type; |
| 996 | LY_ARRAY_FOR(un->types, u) { |
| 997 | ypr_open(ctx->out, &flag); |
| 998 | yprc_type(ctx, un->types[u]); |
| 999 | } |
| 1000 | break; |
| 1001 | } |
| 1002 | default: |
| 1003 | LOGINT(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1004 | ctx->out->status = LY_EINT; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | LEVEL--; |
| 1008 | ypr_close(ctx, flag); |
| 1009 | } |
| 1010 | |
| 1011 | static void |
| 1012 | yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1013 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1014 | LYOUT_CHECK(ctx->out); |
| 1015 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1016 | ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name); |
| 1017 | LEVEL++; |
| 1018 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1019 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1020 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1021 | yprp_type(ctx, &tpdf->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1022 | |
| 1023 | if (tpdf->units) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1024 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1025 | } |
| 1026 | if (tpdf->dflt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1027 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1030 | ypr_status(ctx, tpdf->flags, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1031 | ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL); |
| 1032 | ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL); |
| 1033 | |
| 1034 | LEVEL--; |
| 1035 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1036 | } |
| 1037 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1038 | static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node); |
| 1039 | static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node); |
| 1040 | static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1041 | |
| 1042 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1043 | yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1044 | { |
| 1045 | unsigned int u; |
| 1046 | int flag = 0; |
| 1047 | struct lysp_node *data; |
| 1048 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1049 | LYOUT_CHECK(ctx->out); |
| 1050 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1051 | ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name); |
| 1052 | LEVEL++; |
| 1053 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1054 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0); |
| 1055 | ypr_status(ctx, grp->flags, grp->exts, &flag); |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1056 | ypr_description(ctx, grp->dsc, grp->exts, &flag); |
| 1057 | ypr_reference(ctx, grp->ref, grp->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1058 | |
| 1059 | LY_ARRAY_FOR(grp->typedefs, u) { |
Radek Krejci | 59edcf7 | 2019-05-02 09:53:17 +0200 | [diff] [blame] | 1060 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1061 | yprp_typedef(ctx, &grp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | LY_ARRAY_FOR(grp->groupings, u) { |
Radek Krejci | 59edcf7 | 2019-05-02 09:53:17 +0200 | [diff] [blame] | 1065 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1066 | yprp_grouping(ctx, &grp->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | LY_LIST_FOR(grp->data, data) { |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1070 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1071 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | LY_ARRAY_FOR(grp->actions, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1075 | yprp_action(ctx, &grp->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | LEVEL--; |
| 1079 | ypr_close(ctx, flag); |
| 1080 | } |
| 1081 | |
| 1082 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1083 | yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1084 | { |
| 1085 | unsigned int u; |
| 1086 | struct lysp_node *data; |
| 1087 | |
| 1088 | if (!inout->nodetype) { |
| 1089 | /* nodetype not set -> input/output is empty */ |
| 1090 | return; |
| 1091 | } |
| 1092 | ypr_open(ctx->out, flag); |
| 1093 | |
| 1094 | ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output")); |
| 1095 | LEVEL++; |
| 1096 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1097 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1098 | LY_ARRAY_FOR(inout->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1099 | yprp_restr(ctx, &inout->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1100 | } |
| 1101 | LY_ARRAY_FOR(inout->typedefs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1102 | yprp_typedef(ctx, &inout->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1103 | } |
| 1104 | LY_ARRAY_FOR(inout->groupings, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1105 | yprp_grouping(ctx, &inout->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | LY_LIST_FOR(inout->data, data) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1109 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | LEVEL--; |
| 1113 | ypr_close(ctx, 1); |
| 1114 | } |
| 1115 | |
| 1116 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1117 | yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag) |
| 1118 | { |
| 1119 | unsigned int u; |
| 1120 | struct lysc_node *data; |
| 1121 | |
| 1122 | if (!inout->data) { |
| 1123 | /* input/output is empty */ |
| 1124 | return; |
| 1125 | } |
| 1126 | ypr_open(ctx->out, flag); |
| 1127 | |
| 1128 | ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output"); |
| 1129 | LEVEL++; |
| 1130 | |
| 1131 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0); |
| 1132 | LY_ARRAY_FOR(inout->musts, u) { |
| 1133 | yprc_must(ctx, &inout->musts[u], NULL); |
| 1134 | } |
| 1135 | |
| 1136 | LY_LIST_FOR(inout->data, data) { |
| 1137 | yprc_node(ctx, data); |
| 1138 | } |
| 1139 | |
| 1140 | LEVEL--; |
| 1141 | ypr_close(ctx, 1); |
| 1142 | } |
| 1143 | |
| 1144 | static void |
| 1145 | yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1146 | { |
| 1147 | unsigned int u; |
| 1148 | int flag = 0; |
| 1149 | struct lysp_node *data; |
| 1150 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1151 | LYOUT_CHECK(ctx->out); |
| 1152 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1153 | ly_print(ctx->out, "%*snotification %s", INDENT, notif->name); |
| 1154 | |
| 1155 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1156 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0); |
| 1157 | yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1158 | |
| 1159 | LY_ARRAY_FOR(notif->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1160 | yprp_restr(ctx, ¬if->musts[u], "must", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1161 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1162 | ypr_status(ctx, notif->flags, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1163 | ypr_description(ctx, notif->dsc, notif->exts, &flag); |
| 1164 | ypr_reference(ctx, notif->ref, notif->exts, &flag); |
| 1165 | |
| 1166 | LY_ARRAY_FOR(notif->typedefs, u) { |
| 1167 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1168 | yprp_typedef(ctx, ¬if->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | LY_ARRAY_FOR(notif->groupings, u) { |
| 1172 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1173 | yprp_grouping(ctx, ¬if->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | LY_LIST_FOR(notif->data, data) { |
| 1177 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1178 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | LEVEL--; |
| 1182 | ypr_close(ctx, flag); |
| 1183 | } |
| 1184 | |
| 1185 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1186 | yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif) |
| 1187 | { |
| 1188 | unsigned int u; |
| 1189 | int flag = 0; |
| 1190 | struct lysc_node *data; |
| 1191 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1192 | LYOUT_CHECK(ctx->out); |
| 1193 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1194 | ly_print(ctx->out, "%*snotification %s", INDENT, notif->name); |
| 1195 | |
| 1196 | LEVEL++; |
| 1197 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0); |
| 1198 | yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag); |
| 1199 | |
| 1200 | LY_ARRAY_FOR(notif->musts, u) { |
| 1201 | yprc_must(ctx, ¬if->musts[u], &flag); |
| 1202 | } |
| 1203 | ypr_status(ctx, notif->flags, notif->exts, &flag); |
| 1204 | ypr_description(ctx, notif->dsc, notif->exts, &flag); |
| 1205 | ypr_reference(ctx, notif->ref, notif->exts, &flag); |
| 1206 | |
| 1207 | LY_LIST_FOR(notif->data, data) { |
| 1208 | ypr_open(ctx->out, &flag); |
| 1209 | yprc_node(ctx, data); |
| 1210 | } |
| 1211 | |
| 1212 | LEVEL--; |
| 1213 | ypr_close(ctx, flag); |
| 1214 | } |
| 1215 | |
| 1216 | static void |
| 1217 | yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1218 | { |
| 1219 | unsigned int u; |
| 1220 | int flag = 0; |
| 1221 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1222 | LYOUT_CHECK(ctx->out); |
| 1223 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1224 | ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
| 1225 | |
| 1226 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1227 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0); |
| 1228 | yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag); |
| 1229 | ypr_status(ctx, action->flags, action->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1230 | ypr_description(ctx, action->dsc, action->exts, &flag); |
| 1231 | ypr_reference(ctx, action->ref, action->exts, &flag); |
| 1232 | |
| 1233 | LY_ARRAY_FOR(action->typedefs, u) { |
| 1234 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1235 | yprp_typedef(ctx, &action->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | LY_ARRAY_FOR(action->groupings, u) { |
| 1239 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1240 | yprp_grouping(ctx, &action->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1243 | yprp_inout(ctx, &action->input, &flag); |
| 1244 | yprp_inout(ctx, &action->output, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1245 | |
| 1246 | LEVEL--; |
| 1247 | ypr_close(ctx, flag); |
| 1248 | } |
| 1249 | |
| 1250 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1251 | yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action) |
| 1252 | { |
| 1253 | int flag = 0; |
| 1254 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1255 | LYOUT_CHECK(ctx->out); |
| 1256 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1257 | ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
| 1258 | |
| 1259 | LEVEL++; |
| 1260 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0); |
| 1261 | yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag); |
| 1262 | ypr_status(ctx, action->flags, action->exts, &flag); |
| 1263 | ypr_description(ctx, action->dsc, action->exts, &flag); |
| 1264 | ypr_reference(ctx, action->ref, action->exts, &flag); |
| 1265 | |
| 1266 | yprc_inout(ctx, action, &action->input, &flag); |
| 1267 | yprc_inout(ctx, action, &action->output, &flag); |
| 1268 | |
| 1269 | LEVEL--; |
| 1270 | ypr_close(ctx, flag); |
| 1271 | } |
| 1272 | |
| 1273 | static void |
| 1274 | yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1275 | { |
| 1276 | ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
| 1277 | LEVEL++; |
| 1278 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1279 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0); |
| 1280 | yprp_when(ctx, node->when, flag); |
| 1281 | yprp_iffeatures(ctx, node->iffeatures, node->exts, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1285 | yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1286 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1287 | unsigned int u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1288 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1289 | ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
| 1290 | LEVEL++; |
| 1291 | |
| 1292 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0); |
| 1293 | LY_ARRAY_FOR(node->when, u) { |
| 1294 | yprc_when(ctx, node->when[u], flag); |
| 1295 | } |
| 1296 | yprc_iffeatures(ctx, node->iffeatures, node->exts, flag); |
| 1297 | } |
| 1298 | |
| 1299 | /* macr oto unify the code */ |
| 1300 | #define YPR_NODE_COMMON2 \ |
| 1301 | ypr_config(ctx, node->flags, node->exts, flag); \ |
| 1302 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \ |
| 1303 | ypr_mandatory(ctx, node->flags, node->exts, flag); \ |
| 1304 | } \ |
| 1305 | ypr_status(ctx, node->flags, node->exts, flag); \ |
| 1306 | ypr_description(ctx, node->dsc, node->exts, flag); \ |
| 1307 | ypr_reference(ctx, node->ref, node->exts, flag) |
| 1308 | |
| 1309 | static void |
| 1310 | yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag) |
| 1311 | { |
| 1312 | YPR_NODE_COMMON2; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1316 | yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag) |
| 1317 | { |
| 1318 | YPR_NODE_COMMON2; |
| 1319 | } |
| 1320 | |
| 1321 | #undef YPR_NODE_COMMON2 |
| 1322 | |
| 1323 | static void |
| 1324 | yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1325 | { |
| 1326 | unsigned int u; |
| 1327 | int flag = 0; |
| 1328 | struct lysp_node *child; |
| 1329 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
| 1330 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1331 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1332 | |
| 1333 | LY_ARRAY_FOR(cont->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1334 | yprp_restr(ctx, &cont->musts[u], "must", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1335 | } |
| 1336 | if (cont->presence) { |
| 1337 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1338 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1341 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1342 | |
| 1343 | LY_ARRAY_FOR(cont->typedefs, u) { |
| 1344 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1345 | yprp_typedef(ctx, &cont->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | LY_ARRAY_FOR(cont->groupings, u) { |
| 1349 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1350 | yprp_grouping(ctx, &cont->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | LY_LIST_FOR(cont->child, child) { |
| 1354 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1355 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | LY_ARRAY_FOR(cont->actions, u) { |
| 1359 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1360 | yprp_action(ctx, &cont->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | LY_ARRAY_FOR(cont->notifs, u) { |
| 1364 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1365 | yprp_notification(ctx, &cont->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | LEVEL--; |
| 1369 | ypr_close(ctx, flag); |
| 1370 | } |
| 1371 | |
| 1372 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1373 | yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1374 | { |
| 1375 | unsigned int u; |
| 1376 | int flag = 0; |
| 1377 | struct lysc_node *child; |
| 1378 | struct lysc_node_container *cont = (struct lysc_node_container *)node; |
| 1379 | |
| 1380 | yprc_node_common1(ctx, node, &flag); |
| 1381 | |
| 1382 | LY_ARRAY_FOR(cont->musts, u) { |
| 1383 | yprc_must(ctx, &cont->musts[u], &flag); |
| 1384 | } |
| 1385 | if (cont->flags & LYS_PRESENCE) { |
| 1386 | ypr_open(ctx->out, &flag); |
| 1387 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts); |
| 1388 | } |
| 1389 | |
| 1390 | yprc_node_common2(ctx, node, &flag); |
| 1391 | |
| 1392 | LY_LIST_FOR(cont->child, child) { |
| 1393 | ypr_open(ctx->out, &flag); |
| 1394 | yprc_node(ctx, child); |
| 1395 | } |
| 1396 | |
| 1397 | LY_ARRAY_FOR(cont->actions, u) { |
| 1398 | ypr_open(ctx->out, &flag); |
| 1399 | yprc_action(ctx, &cont->actions[u]); |
| 1400 | } |
| 1401 | |
| 1402 | LY_ARRAY_FOR(cont->notifs, u) { |
| 1403 | ypr_open(ctx->out, &flag); |
| 1404 | yprc_notification(ctx, &cont->notifs[u]); |
| 1405 | } |
| 1406 | |
| 1407 | LEVEL--; |
| 1408 | ypr_close(ctx, flag); |
| 1409 | } |
| 1410 | |
| 1411 | static void |
| 1412 | yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node) |
| 1413 | { |
| 1414 | int flag = 0; |
| 1415 | struct lysp_node *child; |
| 1416 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
| 1417 | |
| 1418 | yprp_node_common1(ctx, node, &flag); |
| 1419 | yprp_node_common2(ctx, node, &flag); |
| 1420 | |
| 1421 | LY_LIST_FOR(cas->child, child) { |
| 1422 | ypr_open(ctx->out, &flag); |
| 1423 | yprp_node(ctx, child); |
| 1424 | } |
| 1425 | |
| 1426 | LEVEL--; |
| 1427 | ypr_close(ctx, flag); |
| 1428 | } |
| 1429 | |
| 1430 | static void |
| 1431 | yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs) |
| 1432 | { |
| 1433 | int flag = 0; |
| 1434 | struct lysc_node *child; |
| 1435 | |
| 1436 | yprc_node_common1(ctx, (struct lysc_node*)cs, &flag); |
| 1437 | yprc_node_common2(ctx, (struct lysc_node*)cs, &flag); |
| 1438 | |
| 1439 | for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) { |
| 1440 | ypr_open(ctx->out, &flag); |
| 1441 | yprc_node(ctx, child); |
| 1442 | } |
| 1443 | |
| 1444 | LEVEL--; |
| 1445 | ypr_close(ctx, flag); |
| 1446 | } |
| 1447 | |
| 1448 | static void |
| 1449 | yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1450 | { |
| 1451 | int flag = 0; |
| 1452 | struct lysp_node *child; |
| 1453 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
| 1454 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1455 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1456 | |
| 1457 | if (choice->dflt) { |
| 1458 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1459 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1460 | } |
| 1461 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1462 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1463 | |
| 1464 | LY_LIST_FOR(choice->child, child) { |
| 1465 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1466 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | LEVEL--; |
| 1470 | ypr_close(ctx, flag); |
| 1471 | } |
| 1472 | |
| 1473 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1474 | yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1475 | { |
| 1476 | int flag = 0; |
| 1477 | struct lysc_node_case *cs; |
| 1478 | struct lysc_node_choice *choice = (struct lysc_node_choice *)node; |
| 1479 | |
| 1480 | yprc_node_common1(ctx, node, &flag); |
| 1481 | |
| 1482 | if (choice->dflt) { |
| 1483 | ypr_open(ctx->out, &flag); |
| 1484 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts); |
| 1485 | } |
| 1486 | |
| 1487 | yprc_node_common2(ctx, node, &flag); |
| 1488 | |
| 1489 | for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) { |
| 1490 | ypr_open(ctx->out, &flag); |
| 1491 | yprc_case(ctx, cs); |
| 1492 | } |
| 1493 | |
| 1494 | LEVEL--; |
| 1495 | ypr_close(ctx, flag); |
| 1496 | } |
| 1497 | |
| 1498 | static void |
| 1499 | yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1500 | { |
| 1501 | unsigned int u; |
| 1502 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
| 1503 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1504 | yprp_node_common1(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1505 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1506 | yprp_type(ctx, &leaf->type); |
| 1507 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1508 | LY_ARRAY_FOR(leaf->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1509 | yprp_restr(ctx, &leaf->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1510 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1511 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1512 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1513 | yprp_node_common2(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1514 | |
| 1515 | LEVEL--; |
| 1516 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1517 | } |
| 1518 | |
| 1519 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1520 | yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1521 | { |
| 1522 | unsigned int u; |
| 1523 | struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node; |
| 1524 | |
| 1525 | yprc_node_common1(ctx, node, NULL); |
| 1526 | |
| 1527 | yprc_type(ctx, leaf->type); |
| 1528 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts); |
| 1529 | LY_ARRAY_FOR(leaf->musts, u) { |
| 1530 | yprc_must(ctx, &leaf->musts[u], NULL); |
| 1531 | } |
| 1532 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts); |
| 1533 | |
| 1534 | yprc_node_common2(ctx, node, NULL); |
| 1535 | |
| 1536 | LEVEL--; |
| 1537 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1538 | } |
| 1539 | |
| 1540 | static void |
| 1541 | yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1542 | { |
| 1543 | unsigned int u; |
| 1544 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
| 1545 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1546 | yprp_node_common1(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1547 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1548 | yprp_type(ctx, &llist->type); |
| 1549 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1550 | LY_ARRAY_FOR(llist->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1551 | yprp_restr(ctx, &llist->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1552 | } |
| 1553 | LY_ARRAY_FOR(llist->dflts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1554 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1555 | } |
| 1556 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1557 | ypr_config(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1558 | |
| 1559 | if (llist->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1560 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1561 | } |
| 1562 | if (llist->flags & LYS_SET_MAX) { |
| 1563 | if (llist->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1564 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1565 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1566 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | if (llist->flags & LYS_ORDBY_MASK) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1571 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1574 | ypr_status(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1575 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1576 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1577 | |
| 1578 | LEVEL--; |
| 1579 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1580 | } |
| 1581 | |
| 1582 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1583 | yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1584 | { |
| 1585 | unsigned int u; |
| 1586 | struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node; |
| 1587 | |
| 1588 | yprc_node_common1(ctx, node, NULL); |
| 1589 | |
| 1590 | yprc_type(ctx, llist->type); |
| 1591 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts); |
| 1592 | LY_ARRAY_FOR(llist->musts, u) { |
| 1593 | yprc_must(ctx, &llist->musts[u], NULL); |
| 1594 | } |
| 1595 | LY_ARRAY_FOR(llist->dflts, u) { |
| 1596 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts); |
| 1597 | } |
| 1598 | |
| 1599 | ypr_config(ctx, node->flags, node->exts, NULL); |
| 1600 | |
| 1601 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL); |
| 1602 | if (llist->max) { |
| 1603 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL); |
| 1604 | } else { |
| 1605 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts); |
| 1606 | } |
| 1607 | |
| 1608 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts); |
| 1609 | |
| 1610 | ypr_status(ctx, node->flags, node->exts, NULL); |
| 1611 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1612 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1613 | |
| 1614 | LEVEL--; |
| 1615 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1616 | } |
| 1617 | |
| 1618 | static void |
| 1619 | yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1620 | { |
| 1621 | unsigned int u; |
| 1622 | int flag = 0; |
| 1623 | struct lysp_node *child; |
| 1624 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
| 1625 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1626 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1627 | |
| 1628 | LY_ARRAY_FOR(list->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1629 | yprp_restr(ctx, &list->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1630 | } |
| 1631 | if (list->key) { |
| 1632 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1633 | ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1634 | } |
| 1635 | LY_ARRAY_FOR(list->uniques, u) { |
| 1636 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1637 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1640 | ypr_config(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1641 | |
| 1642 | if (list->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1643 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1644 | } |
| 1645 | if (list->flags & LYS_SET_MAX) { |
| 1646 | if (list->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1647 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1648 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1649 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | if (list->flags & LYS_ORDBY_MASK) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1654 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1655 | } |
| 1656 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1657 | ypr_status(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1658 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1659 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1660 | |
| 1661 | LY_ARRAY_FOR(list->typedefs, u) { |
| 1662 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1663 | yprp_typedef(ctx, &list->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | LY_ARRAY_FOR(list->groupings, u) { |
| 1667 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1668 | yprp_grouping(ctx, &list->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | LY_LIST_FOR(list->child, child) { |
| 1672 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1673 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | LY_ARRAY_FOR(list->actions, u) { |
| 1677 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1678 | yprp_action(ctx, &list->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | LY_ARRAY_FOR(list->notifs, u) { |
| 1682 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1683 | yprp_notification(ctx, &list->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | LEVEL--; |
| 1687 | ypr_close(ctx, flag); |
| 1688 | } |
| 1689 | |
| 1690 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1691 | yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1692 | { |
| 1693 | unsigned int u, v; |
| 1694 | int flag = 0; |
| 1695 | struct lysc_node *child; |
| 1696 | struct lysc_node_list *list = (struct lysc_node_list *)node; |
| 1697 | |
| 1698 | yprc_node_common1(ctx, node, &flag); |
| 1699 | |
| 1700 | LY_ARRAY_FOR(list->musts, u) { |
| 1701 | yprc_must(ctx, &list->musts[u], NULL); |
| 1702 | } |
| 1703 | if (list->keys) { |
| 1704 | ypr_open(ctx->out, &flag); |
| 1705 | ly_print(ctx->out, "%*skey \"", INDENT); |
| 1706 | LY_ARRAY_FOR(list->keys, u) { |
| 1707 | ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name); |
| 1708 | } |
| 1709 | ypr_close(ctx, 0); |
| 1710 | } |
| 1711 | LY_ARRAY_FOR(list->uniques, u) { |
| 1712 | ypr_open(ctx->out, &flag); |
| 1713 | ly_print(ctx->out, "%*sunique \"", INDENT); |
| 1714 | LY_ARRAY_FOR(list->uniques[u], v) { |
| 1715 | ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name); |
| 1716 | } |
| 1717 | ypr_close(ctx, 0); |
| 1718 | } |
| 1719 | |
| 1720 | ypr_config(ctx, node->flags, node->exts, NULL); |
| 1721 | |
| 1722 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL); |
| 1723 | if (list->max) { |
| 1724 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL); |
| 1725 | } else { |
| 1726 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts); |
| 1727 | } |
| 1728 | |
| 1729 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts); |
| 1730 | |
| 1731 | ypr_status(ctx, node->flags, node->exts, NULL); |
| 1732 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1733 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1734 | |
| 1735 | LY_LIST_FOR(list->child, child) { |
| 1736 | ypr_open(ctx->out, &flag); |
| 1737 | yprc_node(ctx, child); |
| 1738 | } |
| 1739 | |
| 1740 | LY_ARRAY_FOR(list->actions, u) { |
| 1741 | ypr_open(ctx->out, &flag); |
| 1742 | yprc_action(ctx, &list->actions[u]); |
| 1743 | } |
| 1744 | |
| 1745 | LY_ARRAY_FOR(list->notifs, u) { |
| 1746 | ypr_open(ctx->out, &flag); |
| 1747 | yprc_notification(ctx, &list->notifs[u]); |
| 1748 | } |
| 1749 | |
| 1750 | LEVEL--; |
| 1751 | ypr_close(ctx, flag); |
| 1752 | } |
| 1753 | |
| 1754 | static void |
| 1755 | yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1756 | { |
| 1757 | unsigned int u; |
| 1758 | int flag = 0; |
| 1759 | |
| 1760 | ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid); |
| 1761 | LEVEL++; |
| 1762 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1763 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0); |
| 1764 | yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1765 | |
| 1766 | LY_ARRAY_FOR(refine->musts, u) { |
| 1767 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1768 | yprp_restr(ctx, &refine->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | if (refine->presence) { |
| 1772 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1773 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | LY_ARRAY_FOR(refine->dflts, u) { |
| 1777 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1778 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1781 | ypr_config(ctx, refine->flags, refine->exts, &flag); |
| 1782 | ypr_mandatory(ctx, refine->flags, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1783 | |
| 1784 | if (refine->flags & LYS_SET_MIN) { |
| 1785 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1786 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1787 | } |
| 1788 | if (refine->flags & LYS_SET_MAX) { |
| 1789 | ypr_open(ctx->out, &flag); |
| 1790 | if (refine->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1791 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1792 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1793 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | ypr_description(ctx, refine->dsc, refine->exts, &flag); |
| 1798 | ypr_reference(ctx, refine->ref, refine->exts, &flag); |
| 1799 | |
| 1800 | LEVEL--; |
| 1801 | ypr_close(ctx, flag); |
| 1802 | } |
| 1803 | |
| 1804 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1805 | yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1806 | { |
| 1807 | unsigned int u; |
| 1808 | struct lysp_node *child; |
| 1809 | |
| 1810 | ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid); |
| 1811 | LEVEL++; |
| 1812 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1813 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0); |
| 1814 | yprp_when(ctx, aug->when, NULL); |
| 1815 | yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL); |
| 1816 | ypr_status(ctx, aug->flags, aug->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1817 | ypr_description(ctx, aug->dsc, aug->exts, NULL); |
| 1818 | ypr_reference(ctx, aug->ref, aug->exts, NULL); |
| 1819 | |
| 1820 | LY_LIST_FOR(aug->child, child) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1821 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | LY_ARRAY_FOR(aug->actions, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1825 | yprp_action(ctx, &aug->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | LY_ARRAY_FOR(aug->notifs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1829 | yprp_notification(ctx, &aug->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | LEVEL--; |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1833 | ypr_close(ctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | |
| 1837 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1838 | yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1839 | { |
| 1840 | unsigned int u; |
| 1841 | int flag = 0; |
| 1842 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
| 1843 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1844 | yprp_node_common1(ctx, node, &flag); |
| 1845 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1846 | |
| 1847 | LY_ARRAY_FOR(uses->refines, u) { |
| 1848 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1849 | yprp_refine(ctx, &uses->refines[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | LY_ARRAY_FOR(uses->augments, u) { |
| 1853 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1854 | yprp_augment(ctx, &uses->augments[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | LEVEL--; |
| 1858 | ypr_close(ctx, flag); |
| 1859 | } |
| 1860 | |
| 1861 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1862 | yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1863 | { |
| 1864 | unsigned int u; |
| 1865 | int flag = 0; |
| 1866 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
| 1867 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1868 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1869 | |
| 1870 | LY_ARRAY_FOR(any->musts, u) { |
| 1871 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1872 | yprp_restr(ctx, &any->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1875 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1876 | |
| 1877 | LEVEL--; |
| 1878 | ypr_close(ctx, flag); |
| 1879 | } |
| 1880 | |
| 1881 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1882 | yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1883 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1884 | unsigned int u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1885 | int flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1886 | struct lysc_node_anydata *any = (struct lysc_node_anydata *)node; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1887 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1888 | yprc_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1889 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1890 | LY_ARRAY_FOR(any->musts, u) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1891 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1892 | yprc_must(ctx, &any->musts[u], NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1895 | yprc_node_common2(ctx, node, &flag); |
| 1896 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1897 | LEVEL--; |
| 1898 | ypr_close(ctx, flag); |
| 1899 | } |
| 1900 | |
| 1901 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1902 | yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1903 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1904 | LYOUT_CHECK(ctx->out); |
| 1905 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1906 | switch (node->nodetype) { |
| 1907 | case LYS_CONTAINER: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1908 | yprp_container(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1909 | break; |
| 1910 | case LYS_CHOICE: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1911 | yprp_choice(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1912 | break; |
| 1913 | case LYS_LEAF: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1914 | yprp_leaf(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1915 | break; |
| 1916 | case LYS_LEAFLIST: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1917 | yprp_leaflist(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1918 | break; |
| 1919 | case LYS_LIST: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1920 | yprp_list(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1921 | break; |
| 1922 | case LYS_USES: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1923 | yprp_uses(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1924 | break; |
| 1925 | case LYS_ANYXML: |
| 1926 | case LYS_ANYDATA: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1927 | yprp_anydata(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1928 | break; |
| 1929 | case LYS_CASE: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1930 | yprp_case(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1931 | break; |
| 1932 | default: |
| 1933 | break; |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1938 | yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1939 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1940 | LYOUT_CHECK(ctx->out); |
| 1941 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1942 | switch (node->nodetype) { |
| 1943 | case LYS_CONTAINER: |
| 1944 | yprc_container(ctx, node); |
| 1945 | break; |
| 1946 | case LYS_CHOICE: |
| 1947 | yprc_choice(ctx, node); |
| 1948 | break; |
| 1949 | case LYS_LEAF: |
| 1950 | yprc_leaf(ctx, node); |
| 1951 | break; |
| 1952 | case LYS_LEAFLIST: |
| 1953 | yprc_leaflist(ctx, node); |
| 1954 | break; |
| 1955 | case LYS_LIST: |
| 1956 | yprc_list(ctx, node); |
| 1957 | break; |
| 1958 | case LYS_ANYXML: |
| 1959 | case LYS_ANYDATA: |
| 1960 | yprc_anydata(ctx, node); |
| 1961 | break; |
| 1962 | default: |
| 1963 | break; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | static void |
| 1968 | yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1969 | { |
| 1970 | unsigned int u, v; |
| 1971 | struct lysp_deviate_add *add; |
| 1972 | struct lysp_deviate_rpl *rpl; |
| 1973 | struct lysp_deviate_del *del; |
| 1974 | |
| 1975 | ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid); |
| 1976 | LEVEL++; |
| 1977 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1978 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1979 | ypr_description(ctx, deviation->dsc, deviation->exts, NULL); |
| 1980 | ypr_reference(ctx, deviation->ref, deviation->exts, NULL); |
| 1981 | |
| 1982 | LY_ARRAY_FOR(deviation->deviates, u) { |
| 1983 | ly_print(ctx->out, "%*sdeviate ", INDENT); |
| 1984 | if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) { |
| 1985 | if (deviation->deviates[u].exts) { |
| 1986 | ly_print(ctx->out, "not-supported {\n"); |
| 1987 | LEVEL++; |
| 1988 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1989 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1990 | } else { |
| 1991 | ly_print(ctx->out, "not-supported;\n"); |
| 1992 | continue; |
| 1993 | } |
| 1994 | } else if (deviation->deviates[u].mod == LYS_DEV_ADD) { |
| 1995 | add = (struct lysp_deviate_add*)&deviation->deviates[u]; |
| 1996 | ly_print(ctx->out, "add {\n"); |
| 1997 | LEVEL++; |
| 1998 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1999 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0); |
| 2000 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2001 | LY_ARRAY_FOR(add->musts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2002 | yprp_restr(ctx, &add->musts[v], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2003 | } |
| 2004 | LY_ARRAY_FOR(add->uniques, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2005 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2006 | } |
| 2007 | LY_ARRAY_FOR(add->dflts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2008 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2009 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2010 | ypr_config(ctx, add->flags, add->exts, NULL); |
| 2011 | ypr_mandatory(ctx, add->flags, add->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2012 | if (add->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2013 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2014 | } |
| 2015 | if (add->flags & LYS_SET_MAX) { |
| 2016 | if (add->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2017 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2018 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2019 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) { |
| 2023 | rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u]; |
| 2024 | ly_print(ctx->out, "replace {\n"); |
| 2025 | LEVEL++; |
| 2026 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2027 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2028 | if (rpl->type) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2029 | yprp_type(ctx, rpl->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2030 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2031 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts); |
| 2032 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts); |
| 2033 | ypr_config(ctx, rpl->flags, rpl->exts, NULL); |
| 2034 | ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2035 | if (rpl->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2036 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2037 | } |
| 2038 | if (rpl->flags & LYS_SET_MAX) { |
| 2039 | if (rpl->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2040 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2041 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2042 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) { |
| 2046 | del = (struct lysp_deviate_del*)&deviation->deviates[u]; |
| 2047 | ly_print(ctx->out, "delete {\n"); |
| 2048 | LEVEL++; |
| 2049 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2050 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0); |
| 2051 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2052 | LY_ARRAY_FOR(del->musts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2053 | yprp_restr(ctx, &del->musts[v], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2054 | } |
| 2055 | LY_ARRAY_FOR(del->uniques, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2056 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2057 | } |
| 2058 | LY_ARRAY_FOR(del->dflts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2059 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | LEVEL--; |
| 2064 | ypr_close(ctx, 1); |
| 2065 | } |
| 2066 | |
| 2067 | LEVEL--; |
| 2068 | ypr_close(ctx, 1); |
| 2069 | } |
| 2070 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2071 | /** |
| 2072 | * @brief Minimal print of a schema. |
| 2073 | * |
| 2074 | * To print |
| 2075 | * a) compiled schema when it is not compiled or |
| 2076 | * b) parsed when the parsed form was already removed |
| 2077 | */ |
| 2078 | static LY_ERR |
| 2079 | ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module) |
| 2080 | { |
| 2081 | /* module-header-stmts */ |
| 2082 | if (module->version) { |
| 2083 | if (module->version) { |
| 2084 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL); |
| 2085 | } |
| 2086 | } |
| 2087 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL); |
| 2088 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL); |
| 2089 | |
| 2090 | /* meta-stmts */ |
| 2091 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2092 | ly_print(ctx->out, "\n"); |
| 2093 | } |
| 2094 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL); |
| 2095 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL); |
| 2096 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL); |
| 2097 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL); |
| 2098 | |
| 2099 | /* revision-stmts */ |
| 2100 | if (module->revision) { |
| 2101 | ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision); |
| 2102 | } |
| 2103 | |
| 2104 | LEVEL--; |
| 2105 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 2106 | ly_print_flush(ctx->out); |
| 2107 | |
| 2108 | return LY_SUCCESS; |
| 2109 | } |
| 2110 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2111 | LY_ERR |
| 2112 | yang_print_parsed(struct lyout *out, const struct lys_module *module) |
| 2113 | { |
| 2114 | unsigned int u; |
| 2115 | struct lysp_node *data; |
| 2116 | struct lysp_module *modp = module->parsed; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2117 | struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2118 | |
| 2119 | ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name); |
| 2120 | LEVEL++; |
| 2121 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2122 | if (!modp) { |
| 2123 | ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT); |
| 2124 | return ypr_missing_format(ctx, module); |
| 2125 | } |
| 2126 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2127 | /* module-header-stmts */ |
| 2128 | if (module->version) { |
| 2129 | if (module->version) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2130 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2131 | } |
| 2132 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2133 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts); |
| 2134 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2135 | |
| 2136 | /* linkage-stmts */ |
| 2137 | LY_ARRAY_FOR(modp->imports, u) { |
| 2138 | ly_print(out, "\n%*simport %s {\n", INDENT, modp->imports[u].module->name); |
| 2139 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2140 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0); |
| 2141 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2142 | if (modp->imports[u].rev[0]) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2143 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2144 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2145 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts); |
| 2146 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2147 | LEVEL--; |
| 2148 | ly_print(out, "%*s}\n", INDENT); |
| 2149 | } |
| 2150 | LY_ARRAY_FOR(modp->includes, u) { |
| 2151 | if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) { |
| 2152 | ly_print(out, "\n%*sinclude %s {\n", INDENT, modp->includes[u].submodule->name); |
| 2153 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2154 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2155 | if (modp->includes[u].rev[0]) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2156 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2157 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2158 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts); |
| 2159 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2160 | LEVEL--; |
| 2161 | ly_print(out, "%*s}\n", INDENT); |
| 2162 | } else { |
| 2163 | ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name); |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | /* meta-stmts */ |
| 2168 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2169 | ly_print(out, "\n"); |
| 2170 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2171 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts); |
| 2172 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts); |
| 2173 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts); |
| 2174 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2175 | |
| 2176 | /* revision-stmts */ |
| 2177 | if (modp->revs) { |
| 2178 | ly_print(out, "\n"); |
| 2179 | } |
| 2180 | LY_ARRAY_FOR(modp->revs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2181 | yprp_revision(ctx, &modp->revs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2182 | } |
| 2183 | /* body-stmts */ |
| 2184 | LY_ARRAY_FOR(modp->extensions, u) { |
| 2185 | ly_print(out, "\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2186 | yprp_extension(ctx, &modp->extensions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2187 | } |
| 2188 | if (modp->exts) { |
| 2189 | ly_print(out, "\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2190 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | LY_ARRAY_FOR(modp->features, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2194 | yprp_feature(ctx, &modp->features[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | LY_ARRAY_FOR(modp->identities, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2198 | yprp_identity(ctx, &modp->identities[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | LY_ARRAY_FOR(modp->typedefs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2202 | yprp_typedef(ctx, &modp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | LY_ARRAY_FOR(modp->groupings, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2206 | yprp_grouping(ctx, &modp->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | LY_LIST_FOR(modp->data, data) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2210 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | LY_ARRAY_FOR(modp->augments, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2214 | yprp_augment(ctx, &modp->augments[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | LY_ARRAY_FOR(modp->rpcs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2218 | yprp_action(ctx, &modp->rpcs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | LY_ARRAY_FOR(modp->notifs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2222 | yprp_notification(ctx, &modp->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | LY_ARRAY_FOR(modp->deviations, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2226 | yprp_deviation(ctx, &modp->deviations[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | LEVEL--; |
| 2230 | ly_print(out, "%*s}\n", INDENT); |
| 2231 | ly_print_flush(out); |
| 2232 | |
| 2233 | return LY_SUCCESS; |
| 2234 | } |
| 2235 | |
| 2236 | LY_ERR |
| 2237 | yang_print_compiled(struct lyout *out, const struct lys_module *module) |
| 2238 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2239 | unsigned int u; |
| 2240 | struct lysc_node *data; |
| 2241 | struct lysc_module *modc = module->compiled; |
| 2242 | struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_; |
| 2243 | |
| 2244 | ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name); |
| 2245 | LEVEL++; |
| 2246 | |
| 2247 | if (!modc) { |
| 2248 | ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT); |
| 2249 | return ypr_missing_format(ctx, module); |
| 2250 | } |
| 2251 | |
| 2252 | /* module-header-stmts */ |
| 2253 | if (module->version) { |
| 2254 | if (module->version) { |
| 2255 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts); |
| 2256 | } |
| 2257 | } |
| 2258 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts); |
| 2259 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts); |
| 2260 | |
| 2261 | /* linkage-stmts */ |
| 2262 | LY_ARRAY_FOR(modc->imports, u) { |
| 2263 | ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name); |
| 2264 | LEVEL++; |
| 2265 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0); |
| 2266 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts); |
| 2267 | if (modc->imports[u].module->revision) { |
| 2268 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts); |
| 2269 | } |
| 2270 | LEVEL--; |
| 2271 | ly_print(out, "%*s}\n", INDENT); |
| 2272 | } |
| 2273 | |
| 2274 | /* meta-stmts */ |
| 2275 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2276 | ly_print(out, "\n"); |
| 2277 | } |
| 2278 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts); |
| 2279 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts); |
| 2280 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts); |
| 2281 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts); |
| 2282 | |
| 2283 | /* revision-stmts */ |
| 2284 | if (module->revision) { |
| 2285 | ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision); |
| 2286 | } |
| 2287 | |
| 2288 | /* body-stmts */ |
| 2289 | if (modc->exts) { |
| 2290 | ly_print(out, "\n"); |
| 2291 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0); |
| 2292 | } |
| 2293 | |
| 2294 | LY_ARRAY_FOR(modc->features, u) { |
| 2295 | yprc_feature(ctx, &modc->features[u]); |
| 2296 | } |
| 2297 | |
| 2298 | LY_ARRAY_FOR(modc->identities, u) { |
| 2299 | yprc_identity(ctx, &modc->identities[u]); |
| 2300 | } |
| 2301 | |
| 2302 | LY_LIST_FOR(modc->data, data) { |
| 2303 | yprc_node(ctx, data); |
| 2304 | } |
| 2305 | |
| 2306 | LY_ARRAY_FOR(modc->rpcs, u) { |
| 2307 | yprc_action(ctx, &modc->rpcs[u]); |
| 2308 | } |
| 2309 | |
| 2310 | LY_ARRAY_FOR(modc->notifs, u) { |
| 2311 | yprc_notification(ctx, &modc->notifs[u]); |
| 2312 | } |
| 2313 | |
| 2314 | LEVEL--; |
| 2315 | ly_print(out, "%*s}\n", INDENT); |
| 2316 | ly_print_flush(out); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2317 | |
| 2318 | return LY_SUCCESS; |
| 2319 | } |