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