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