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