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