FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1 | /** |
| 2 | * @file printer_yin.c |
| 3 | * @author Fred Gan <ganshaolong@vip.qq.com> |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 5 | * @brief YIN printer |
| 6 | * |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [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 |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 17 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 21 | |
Radek Krejci | aa45bda | 2020-07-20 07:43:38 +0200 | [diff] [blame] | 22 | #include "compat.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 23 | #include "log.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 24 | #include "ly_common.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 25 | #include "out.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 26 | #include "out_internal.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 27 | #include "printer_internal.h" |
| 28 | #include "tree.h" |
| 29 | #include "tree_schema.h" |
| 30 | #include "tree_schema_internal.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 31 | #include "xml.h" |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 32 | #include "xpath.h" |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * @brief YIN printer context. |
| 36 | */ |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 37 | struct lys_ypr_ctx { |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 38 | union { |
| 39 | struct { |
| 40 | struct ly_out *out; /**< output specification */ |
| 41 | uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
| 42 | uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */ |
| 43 | const struct lys_module *module; /**< schema to print */ |
| 44 | }; |
| 45 | struct lyspr_ctx printer_ctx; |
| 46 | }; |
| 47 | |
| 48 | /* YIN printer specific members */ |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 51 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 52 | ypr_open(struct lys_ypr_ctx *pctx, const char *elem_name, const char *attr_name, const char *attr_value, int8_t flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 53 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 54 | ly_print_(pctx->out, "%*s<%s", INDENT, elem_name); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 55 | |
| 56 | if (attr_name) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 57 | ly_print_(pctx->out, " %s=\"", attr_name); |
| 58 | lyxml_dump_text(pctx->out, attr_value, 1); |
| 59 | ly_print_(pctx->out, "\"%s", flag == -1 ? "/>\n" : flag == 1 ? ">\n" : ""); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 60 | } else if (flag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 61 | ly_print_(pctx->out, flag == -1 ? "/>\n" : ">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 66 | ypr_close(struct lys_ypr_ctx *pctx, const char *elem_name, int8_t flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 67 | { |
| 68 | if (flag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 69 | ly_print_(pctx->out, "%*s</%s>\n", INDENT, elem_name); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 70 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 71 | ly_print_(pctx->out, "/>\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * par_close_flag |
| 77 | * 0 - parent not yet closed, printing >\n, setting flag to 1 |
| 78 | * 1 or NULL - parent already closed, do nothing |
| 79 | */ |
| 80 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 81 | ypr_close_parent(struct lys_ypr_ctx *pctx, int8_t *par_close_flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 82 | { |
| 83 | if (par_close_flag && !(*par_close_flag)) { |
| 84 | (*par_close_flag) = 1; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 85 | ly_print_(pctx->out, ">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 90 | ypr_yin_arg(struct lys_ypr_ctx *pctx, const char *arg, const char *text) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 91 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 92 | ly_print_(pctx->out, "%*s<%s>", INDENT, arg); |
| 93 | lyxml_dump_text(pctx->out, text, 0); |
| 94 | ly_print_(pctx->out, "</%s>\n", arg); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 95 | } |
| 96 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 97 | static void |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 98 | yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt) |
| 99 | { |
| 100 | struct lysp_stmt *childstmt; |
| 101 | int8_t flag = stmt->child ? 1 : -1; |
| 102 | |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 103 | if (lys_stmt_str(stmt->kw)) { |
| 104 | if (lys_stmt_flags(stmt->kw) & LY_STMT_FLAG_YIN) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 105 | ypr_open(pctx, stmt->stmt, NULL, NULL, flag); |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 106 | ypr_yin_arg(pctx, lys_stmt_arg(stmt->kw), stmt->arg); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 107 | } else { |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 108 | ypr_open(pctx, stmt->stmt, lys_stmt_arg(stmt->kw), stmt->arg, flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 109 | } |
zhangtaog | a6c2b2c | 2024-02-21 15:26:15 +0800 | [diff] [blame] | 110 | } else if (stmt->kw == LY_STMT_EXTENSION_INSTANCE) { |
| 111 | ypr_open(pctx, stmt->stmt, (stmt->arg && stmt->arg[0]) ? lys_stmt_arg(LY_STMT_VALUE) : NULL, stmt->arg, flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | if (stmt->child) { |
| 115 | LEVEL++; |
| 116 | LY_LIST_FOR(stmt->child, childstmt) { |
| 117 | yprp_stmt(pctx, childstmt); |
| 118 | } |
| 119 | LEVEL--; |
| 120 | ypr_close(pctx, stmt->stmt, flag); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | static void |
| 125 | yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 126 | struct lysp_ext_instance *ext, int8_t *flag) |
| 127 | { |
| 128 | struct lysp_stmt *stmt; |
| 129 | int8_t inner_flag; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 130 | |
| 131 | if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) { |
| 132 | return; |
| 133 | } |
| 134 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 135 | ypr_close_parent(pctx, flag); |
| 136 | inner_flag = 0; |
| 137 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 138 | ypr_open(pctx, ext->name, (ext->def->flags & LYS_YINELEM_TRUE) ? NULL : ext->def->argname, ext->argument, inner_flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 139 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 140 | if (ext->def->flags & LYS_YINELEM_TRUE) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 141 | const char *prefix, *name, *id; |
| 142 | size_t prefix_len, name_len; |
| 143 | |
| 144 | ypr_close_parent(pctx, &inner_flag); |
| 145 | |
| 146 | /* we need to use the same namespace as for the extension instance element */ |
| 147 | id = ext->name; |
| 148 | ly_parse_nodeid(&id, &prefix, &prefix_len, &name, &name_len); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 149 | ly_print_(pctx->out, "%*s<%.*s:%s>", INDENT, (int)prefix_len, prefix, ext->def->argname); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 150 | lyxml_dump_text(pctx->out, ext->argument, 0); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 151 | ly_print_(pctx->out, "</%.*s:%s>\n", (int)prefix_len, prefix, ext->def->argname); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 152 | } |
| 153 | LY_LIST_FOR(ext->child, stmt) { |
| 154 | if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) { |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | ypr_close_parent(pctx, &inner_flag); |
| 159 | yprp_stmt(pctx, stmt); |
| 160 | } |
| 161 | LEVEL--; |
| 162 | ypr_close(pctx, ext->name, inner_flag); |
| 163 | } |
| 164 | |
| 165 | static void |
| 166 | yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 167 | struct lysp_ext_instance *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 168 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 169 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 170 | |
| 171 | LY_ARRAY_FOR(exts, u) { |
| 172 | yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | static void |
| 177 | ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *exts) |
| 178 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 179 | int8_t extflag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 180 | |
| 181 | if (!text) { |
| 182 | /* nothing to print */ |
| 183 | return; |
| 184 | } |
| 185 | |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 186 | if (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) { |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 187 | extflag = 1; |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 188 | ypr_open(pctx, lys_stmt_str(substmt), NULL, NULL, extflag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 189 | } else { |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 190 | ypr_open(pctx, lys_stmt_str(substmt), lys_stmt_arg(substmt), text, extflag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 194 | yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 195 | |
| 196 | /* argument as yin-element */ |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 197 | if (lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN) { |
| 198 | ypr_yin_arg(pctx, lys_stmt_arg(substmt), text); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | LEVEL--; |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 202 | ypr_close(pctx, lys_stmt_str(substmt), extflag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 206 | ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, unsigned long attr_value) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 207 | { |
| 208 | char *str; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 209 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 210 | if (asprintf(&str, "%lu", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 211 | LOGMEM(pctx->module->ctx); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 212 | return; |
| 213 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 214 | ypr_substmt(pctx, substmt, substmt_index, str, exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 215 | free(str); |
| 216 | } |
| 217 | |
| 218 | static void |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 219 | ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 220 | { |
| 221 | char *str; |
| 222 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 223 | if (asprintf(&str, "%ld", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 224 | LOGMEM(pctx->module->ctx); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 225 | return; |
| 226 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 227 | ypr_substmt(pctx, substmt, substmt_index, str, exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 228 | free(str); |
| 229 | } |
| 230 | |
| 231 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 232 | yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 233 | { |
| 234 | if (rev->dsc || rev->ref || rev->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 235 | ypr_open(pctx, "revision", "date", rev->date, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 236 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 237 | yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 238 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts); |
| 239 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 240 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 241 | ypr_close(pctx, "revision", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 242 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 243 | ypr_open(pctx, "revision", "date", rev->date, -1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 248 | ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 249 | { |
| 250 | if (flags & LYS_MAND_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 251 | ypr_close_parent(pctx, flag); |
| 252 | ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 257 | ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 258 | { |
| 259 | if (flags & LYS_CONFIG_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 260 | ypr_close_parent(pctx, flag); |
| 261 | ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 266 | ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 267 | { |
| 268 | const char *status = NULL; |
| 269 | |
| 270 | if (flags & LYS_STATUS_CURR) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 271 | ypr_close_parent(pctx, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 272 | status = "current"; |
| 273 | } else if (flags & LYS_STATUS_DEPRC) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 274 | ypr_close_parent(pctx, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 275 | status = "deprecated"; |
| 276 | } else if (flags & LYS_STATUS_OBSLT) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 277 | ypr_close_parent(pctx, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 278 | status = "obsolete"; |
| 279 | } |
| 280 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 281 | ypr_substmt(pctx, LY_STMT_STATUS, 0, status, exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 285 | ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 286 | { |
| 287 | if (dsc) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 288 | ypr_close_parent(pctx, flag); |
| 289 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 294 | ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 295 | { |
| 296 | if (ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 297 | ypr_close_parent(pctx, flag); |
| 298 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 303 | yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 304 | { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 305 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 306 | int8_t extflag; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 307 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 308 | LY_ARRAY_FOR(iffs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 309 | ypr_close_parent(pctx, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 310 | extflag = 0; |
| 311 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 312 | ly_print_(pctx->out, "%*s<if-feature name=\"%s", INDENT, iffs[u].str); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 313 | |
| 314 | /* extensions */ |
| 315 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 316 | yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 317 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 318 | ly_print_(pctx->out, "\"/>\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 323 | yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 324 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 325 | int8_t flag = 0, flag2 = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 326 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 327 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 328 | ypr_open(pctx, "extension", "name", ext->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 329 | LEVEL++; |
| 330 | |
| 331 | if (ext->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 332 | ypr_close_parent(pctx, &flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 333 | yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 334 | } |
| 335 | |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 336 | if (ext->argname) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 337 | ypr_close_parent(pctx, &flag); |
| 338 | ypr_open(pctx, "argument", "name", ext->argname, flag2); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 339 | |
| 340 | LEVEL++; |
| 341 | if (ext->exts) { |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 342 | u = -1; |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 343 | while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 344 | ypr_close_parent(pctx, &flag2); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 345 | yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | if ((ext->flags & LYS_YINELEM_MASK) || |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 349 | (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] | 350 | ypr_close_parent(pctx, &flag2); |
| 351 | ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 352 | } |
| 353 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 354 | ypr_close(pctx, "argument", flag2); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 355 | } |
| 356 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 357 | ypr_status(pctx, ext->flags, ext->exts, &flag); |
| 358 | ypr_description(pctx, ext->dsc, ext->exts, &flag); |
| 359 | ypr_reference(pctx, ext->ref, ext->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 360 | |
| 361 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 362 | ypr_close(pctx, "extension", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 366 | yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 367 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 368 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 369 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 370 | ypr_open(pctx, "feature", "name", feat->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 371 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 372 | yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 373 | yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag); |
| 374 | ypr_status(pctx, feat->flags, feat->exts, &flag); |
| 375 | ypr_description(pctx, feat->dsc, feat->exts, &flag); |
| 376 | ypr_reference(pctx, feat->ref, feat->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 377 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 378 | ypr_close(pctx, "feature", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 382 | yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 383 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 384 | int8_t flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 385 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 386 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 387 | ypr_open(pctx, "identity", "name", ident->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 388 | LEVEL++; |
| 389 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 390 | yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 391 | yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 392 | |
| 393 | LY_ARRAY_FOR(ident->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 394 | ypr_close_parent(pctx, &flag); |
| 395 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], ident->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 396 | } |
| 397 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 398 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
| 399 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
| 400 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 401 | |
| 402 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 403 | ypr_close(pctx, "identity", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 407 | yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, const char *attr, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 408 | { |
| 409 | (void)flag; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 410 | int8_t inner_flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 411 | |
| 412 | if (!restr) { |
| 413 | return; |
| 414 | } |
| 415 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 416 | ly_print_(pctx->out, "%*s<%s %s=\"", INDENT, lyplg_ext_stmt2str(stmt), attr); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 417 | lyxml_dump_text(pctx->out, |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 418 | (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ? |
| 419 | restr->arg.str : &restr->arg.str[1], 1); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 420 | ly_print_(pctx->out, "\""); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 421 | |
| 422 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 423 | yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 424 | if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 425 | ypr_close_parent(pctx, &inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 426 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 427 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 428 | } |
| 429 | if (restr->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 430 | ypr_close_parent(pctx, &inner_flag); |
| 431 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 432 | } |
| 433 | if (restr->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 434 | ypr_close_parent(pctx, &inner_flag); |
| 435 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 436 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 437 | ypr_description(pctx, restr->dsc, restr->exts, &inner_flag); |
| 438 | ypr_reference(pctx, restr->ref, restr->exts, &inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 439 | |
| 440 | LEVEL--; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 441 | ypr_close(pctx, lyplg_ext_stmt2str(stmt), inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 445 | yprp_when(struct lys_ypr_ctx *pctx, struct lysp_when *when, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 446 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 447 | int8_t inner_flag = 0; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 448 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 449 | if (!when) { |
| 450 | return; |
| 451 | } |
| 452 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 453 | ypr_close_parent(pctx, flag); |
| 454 | ly_print_(pctx->out, "%*s<when condition=\"", INDENT); |
| 455 | lyxml_dump_text(pctx->out, when->cond, 1); |
| 456 | ly_print_(pctx->out, "\""); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 457 | |
| 458 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 459 | yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 460 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
| 461 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 462 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 463 | ypr_close(pctx, "when", inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 467 | yprp_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 468 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 469 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 470 | int8_t inner_flag; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 471 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 472 | (void)flag; |
| 473 | |
| 474 | LY_ARRAY_FOR(items, u) { |
| 475 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 476 | ly_print_(pctx->out, "%*s<bit name=\"", INDENT); |
| 477 | lyxml_dump_text(pctx->out, items[u].name, 1); |
| 478 | ly_print_(pctx->out, "\""); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 479 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 480 | ly_print_(pctx->out, "%*s<enum name=\"", INDENT); |
| 481 | lyxml_dump_text(pctx->out, items[u].name, 1); |
| 482 | ly_print_(pctx->out, "\""); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 483 | } |
| 484 | inner_flag = 0; |
| 485 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 486 | 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] | 487 | yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 488 | if (items[u].flags & LYS_SET_VALUE) { |
| 489 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 490 | ypr_close_parent(pctx, &inner_flag); |
| 491 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 492 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 493 | ypr_close_parent(pctx, &inner_flag); |
| 494 | ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 495 | } |
| 496 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 497 | ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag); |
| 498 | ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag); |
| 499 | ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 500 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 501 | ypr_close(pctx, type == LY_TYPE_BITS ? "bit" : "enum", inner_flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 506 | yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 507 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 508 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 509 | int8_t flag = 0; |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 510 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 511 | if (!pctx || !type) { |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 515 | ypr_open(pctx, "type", "name", type->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 516 | LEVEL++; |
| 517 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 518 | yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 519 | |
| 520 | if (type->range || type->length || type->patterns || type->bits || type->enums) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 521 | ypr_close_parent(pctx, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 522 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 523 | yprp_restr(pctx, type->range, LY_STMT_RANGE, "value", &flag); |
| 524 | yprp_restr(pctx, type->length, LY_STMT_LENGTH, "value", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 525 | LY_ARRAY_FOR(type->patterns, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 526 | yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, "value", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 527 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 528 | yprp_enum(pctx, type->bits, LY_TYPE_BITS, &flag); |
| 529 | yprp_enum(pctx, type->enums, LY_TYPE_ENUM, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 530 | |
| 531 | if (type->path) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 532 | ypr_close_parent(pctx, &flag); |
| 533 | ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, type->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 534 | } |
| 535 | if (type->flags & LYS_SET_REQINST) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 536 | ypr_close_parent(pctx, &flag); |
| 537 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 538 | } |
| 539 | if (type->flags & LYS_SET_FRDIGITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 540 | ypr_close_parent(pctx, &flag); |
| 541 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 542 | } |
| 543 | LY_ARRAY_FOR(type->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 544 | ypr_close_parent(pctx, &flag); |
| 545 | ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], type->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 546 | } |
| 547 | LY_ARRAY_FOR(type->types, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 548 | ypr_close_parent(pctx, &flag); |
| 549 | yprp_type(pctx, &type->types[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 553 | ypr_close(pctx, "type", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 557 | yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 558 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 559 | ypr_open(pctx, "typedef", "name", tpdf->name, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 560 | LEVEL++; |
| 561 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 562 | yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 563 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 564 | yprp_type(pctx, &tpdf->type); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 565 | |
| 566 | if (tpdf->units) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 567 | ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 568 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 569 | if (tpdf->dflt.str) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 570 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 573 | ypr_status(pctx, tpdf->flags, tpdf->exts, NULL); |
| 574 | ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL); |
| 575 | ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 576 | |
| 577 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 578 | ypr_close(pctx, "typedef", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 579 | } |
| 580 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 581 | static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node); |
| 582 | static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action); |
| 583 | static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 584 | |
| 585 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 586 | yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 587 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 588 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 589 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 590 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 591 | struct lysp_node_action *action; |
| 592 | struct lysp_node_notif *notif; |
| 593 | struct lysp_node_grp *subgrp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 594 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 595 | ypr_open(pctx, "grouping", "name", grp->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 596 | LEVEL++; |
| 597 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 598 | yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 599 | ypr_status(pctx, grp->flags, grp->exts, &flag); |
| 600 | ypr_description(pctx, grp->dsc, grp->exts, &flag); |
| 601 | ypr_reference(pctx, grp->ref, grp->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 602 | |
| 603 | LY_ARRAY_FOR(grp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 604 | ypr_close_parent(pctx, &flag); |
| 605 | yprp_typedef(pctx, &grp->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 608 | LY_LIST_FOR(grp->groupings, subgrp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 609 | ypr_close_parent(pctx, &flag); |
| 610 | yprp_grouping(pctx, subgrp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 611 | } |
| 612 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 613 | LY_LIST_FOR(grp->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 614 | ypr_close_parent(pctx, &flag); |
| 615 | yprp_node(pctx, data); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 616 | } |
| 617 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 618 | LY_LIST_FOR(grp->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 619 | ypr_close_parent(pctx, &flag); |
| 620 | yprp_action(pctx, action); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | LY_LIST_FOR(grp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 624 | ypr_close_parent(pctx, &flag); |
| 625 | yprp_notification(pctx, notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 629 | ypr_close(pctx, "grouping", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 633 | yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 634 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 635 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 636 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 637 | struct lysp_node_grp *grp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 638 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 639 | if (!inout->child) { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 640 | /* input/output is empty */ |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 641 | return; |
| 642 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 643 | ypr_close_parent(pctx, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 644 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 645 | ypr_open(pctx, inout->name, NULL, NULL, *flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 646 | LEVEL++; |
| 647 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 648 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 649 | LY_ARRAY_FOR(inout->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 650 | yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, "condition", NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 651 | } |
| 652 | LY_ARRAY_FOR(inout->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 653 | yprp_typedef(pctx, &inout->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 654 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 655 | LY_LIST_FOR(inout->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 656 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 657 | } |
| 658 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 659 | LY_LIST_FOR(inout->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 660 | yprp_node(pctx, data); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 664 | ypr_close(pctx, inout->name, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 668 | yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 669 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 670 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 671 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 672 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 673 | struct lysp_node_grp *grp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 674 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 675 | ypr_open(pctx, "notification", "name", notif->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 676 | |
| 677 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 678 | yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 679 | yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 680 | |
| 681 | LY_ARRAY_FOR(notif->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 682 | ypr_close_parent(pctx, &flag); |
| 683 | yprp_restr(pctx, ¬if->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 684 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 685 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
| 686 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
| 687 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 688 | |
| 689 | LY_ARRAY_FOR(notif->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 690 | ypr_close_parent(pctx, &flag); |
| 691 | yprp_typedef(pctx, ¬if->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 692 | } |
| 693 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 694 | LY_LIST_FOR(notif->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 695 | ypr_close_parent(pctx, &flag); |
| 696 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 697 | } |
| 698 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 699 | LY_LIST_FOR(notif->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 700 | ypr_close_parent(pctx, &flag); |
| 701 | yprp_node(pctx, data); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 705 | ypr_close(pctx, "notification", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 709 | yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 710 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 711 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 712 | int8_t flag = 0; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 713 | struct lysp_node_grp *grp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 714 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 715 | ypr_open(pctx, action->parent ? "action" : "rpc", "name", action->name, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 716 | |
| 717 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 718 | 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] | 719 | yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag); |
| 720 | ypr_status(pctx, action->flags, action->exts, &flag); |
| 721 | ypr_description(pctx, action->dsc, action->exts, &flag); |
| 722 | ypr_reference(pctx, action->ref, action->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 723 | |
| 724 | LY_ARRAY_FOR(action->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 725 | ypr_close_parent(pctx, &flag); |
| 726 | yprp_typedef(pctx, &action->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 727 | } |
| 728 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 729 | LY_LIST_FOR(action->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 730 | ypr_close_parent(pctx, &flag); |
| 731 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 732 | } |
| 733 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 734 | yprp_inout(pctx, &action->input, &flag); |
| 735 | yprp_inout(pctx, &action->output, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 736 | |
| 737 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 738 | ypr_close(pctx, action->parent ? "action" : "rpc", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 742 | yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 743 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 744 | ypr_open(pctx, lys_nodetype2str(node->nodetype), "name", node->name, *flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 745 | LEVEL++; |
| 746 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 747 | 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] | 748 | yprp_when(pctx, lysp_node_when(node), flag); |
| 749 | yprp_iffeatures(pctx, node->iffeatures, node->exts, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 753 | yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, int8_t *flag) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 754 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 755 | ypr_config(pctx, node->flags, node->exts, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 756 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 757 | ypr_mandatory(pctx, node->flags, node->exts, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 758 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 759 | ypr_status(pctx, node->flags, node->exts, flag); |
| 760 | ypr_description(pctx, node->dsc, node->exts, flag); |
| 761 | ypr_reference(pctx, node->ref, node->exts, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 765 | yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 766 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 767 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 768 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 769 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 770 | struct lysp_node_action *action; |
| 771 | struct lysp_node_notif *notif; |
| 772 | struct lysp_node_grp *grp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 773 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
| 774 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 775 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 776 | |
| 777 | LY_ARRAY_FOR(cont->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 778 | ypr_close_parent(pctx, &flag); |
| 779 | yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 780 | } |
| 781 | if (cont->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 782 | ypr_close_parent(pctx, &flag); |
| 783 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 784 | } |
| 785 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 786 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 787 | |
| 788 | LY_ARRAY_FOR(cont->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 789 | ypr_close_parent(pctx, &flag); |
| 790 | yprp_typedef(pctx, &cont->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 791 | } |
| 792 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 793 | LY_LIST_FOR(cont->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 794 | ypr_close_parent(pctx, &flag); |
| 795 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | LY_LIST_FOR(cont->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 799 | ypr_close_parent(pctx, &flag); |
| 800 | yprp_node(pctx, child); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 801 | } |
| 802 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 803 | LY_LIST_FOR(cont->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 804 | ypr_close_parent(pctx, &flag); |
| 805 | yprp_action(pctx, action); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 806 | } |
| 807 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 808 | LY_LIST_FOR(cont->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 809 | ypr_close_parent(pctx, &flag); |
| 810 | yprp_notification(pctx, notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 814 | ypr_close(pctx, "container", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 818 | yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 819 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 820 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 821 | struct lysp_node *child; |
| 822 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
| 823 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 824 | yprp_node_common1(pctx, node, &flag); |
| 825 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 826 | |
| 827 | LY_LIST_FOR(cas->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 828 | ypr_close_parent(pctx, &flag); |
| 829 | yprp_node(pctx, child); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 833 | ypr_close(pctx, "case", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 837 | yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 838 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 839 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 840 | struct lysp_node *child; |
| 841 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
| 842 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 843 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 844 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 845 | if (choice->dflt.str) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 846 | ypr_close_parent(pctx, &flag); |
| 847 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 848 | } |
| 849 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 850 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 851 | |
| 852 | LY_LIST_FOR(choice->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 853 | ypr_close_parent(pctx, &flag); |
| 854 | yprp_node(pctx, child); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 858 | ypr_close(pctx, "choice", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 862 | yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 863 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 864 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 865 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
| 866 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 867 | int8_t flag = 1; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 868 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 869 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 870 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 871 | yprp_type(pctx, &leaf->type); |
| 872 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 873 | LY_ARRAY_FOR(leaf->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 874 | yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 875 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 876 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 877 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 878 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 879 | |
| 880 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 881 | ypr_close(pctx, "leaf", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 885 | yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 886 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 887 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 888 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 889 | int8_t flag = 1; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 890 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 891 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 892 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 893 | yprp_type(pctx, &llist->type); |
| 894 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, llist->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 895 | LY_ARRAY_FOR(llist->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 896 | yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, "condition", NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 897 | } |
| 898 | LY_ARRAY_FOR(llist->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 899 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 900 | } |
| 901 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 902 | ypr_config(pctx, node->flags, node->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 903 | |
| 904 | if (llist->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 905 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 906 | } |
| 907 | if (llist->flags & LYS_SET_MAX) { |
| 908 | if (llist->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 909 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 910 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 911 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
| 915 | if (llist->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 916 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 917 | } |
| 918 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 919 | ypr_status(pctx, node->flags, node->exts, &flag); |
| 920 | ypr_description(pctx, node->dsc, node->exts, &flag); |
| 921 | ypr_reference(pctx, node->ref, node->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 922 | |
| 923 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 924 | ypr_close(pctx, "leaf-list", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 928 | yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 929 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 930 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 931 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 932 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 933 | struct lysp_node_action *action; |
| 934 | struct lysp_node_notif *notif; |
| 935 | struct lysp_node_grp *grp; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 936 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
| 937 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 938 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 939 | |
| 940 | LY_ARRAY_FOR(list->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 941 | ypr_close_parent(pctx, &flag); |
| 942 | yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 943 | } |
| 944 | if (list->key) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 945 | ypr_close_parent(pctx, &flag); |
| 946 | ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, list->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 947 | } |
| 948 | LY_ARRAY_FOR(list->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 949 | ypr_close_parent(pctx, &flag); |
| 950 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 951 | } |
| 952 | |
Michal Vasko | 846e3ab | 2022-03-01 09:54:27 +0100 | [diff] [blame] | 953 | ypr_config(pctx, node->flags, node->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 954 | |
| 955 | if (list->flags & LYS_SET_MIN) { |
Michal Vasko | 07937f0 | 2022-11-29 08:24:05 +0100 | [diff] [blame] | 956 | ypr_close_parent(pctx, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 957 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 958 | } |
| 959 | if (list->flags & LYS_SET_MAX) { |
Michal Vasko | 07937f0 | 2022-11-29 08:24:05 +0100 | [diff] [blame] | 960 | ypr_close_parent(pctx, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 961 | if (list->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 962 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 963 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 964 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
| 968 | if (list->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 969 | ypr_close_parent(pctx, &flag); |
| 970 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 971 | } |
| 972 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 973 | ypr_status(pctx, node->flags, node->exts, &flag); |
| 974 | ypr_description(pctx, node->dsc, node->exts, &flag); |
| 975 | ypr_reference(pctx, node->ref, node->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 976 | |
| 977 | LY_ARRAY_FOR(list->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 978 | ypr_close_parent(pctx, &flag); |
| 979 | yprp_typedef(pctx, &list->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 980 | } |
| 981 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 982 | LY_LIST_FOR(list->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 983 | ypr_close_parent(pctx, &flag); |
| 984 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | LY_LIST_FOR(list->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 988 | ypr_close_parent(pctx, &flag); |
| 989 | yprp_node(pctx, child); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 990 | } |
| 991 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 992 | LY_LIST_FOR(list->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 993 | ypr_close_parent(pctx, &flag); |
| 994 | yprp_action(pctx, action); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 995 | } |
| 996 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 997 | LY_LIST_FOR(list->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 998 | ypr_close_parent(pctx, &flag); |
| 999 | yprp_notification(pctx, notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1003 | ypr_close(pctx, "list", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1007 | yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1008 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1009 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 1010 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1011 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1012 | ypr_open(pctx, "refine", "target-node", refine->nodeid, flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1013 | LEVEL++; |
| 1014 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1015 | yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1016 | yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1017 | |
| 1018 | LY_ARRAY_FOR(refine->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1019 | ypr_close_parent(pctx, &flag); |
| 1020 | yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | if (refine->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1024 | ypr_close_parent(pctx, &flag); |
| 1025 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | LY_ARRAY_FOR(refine->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1029 | ypr_close_parent(pctx, &flag); |
| 1030 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1033 | ypr_config(pctx, refine->flags, refine->exts, &flag); |
| 1034 | ypr_mandatory(pctx, refine->flags, refine->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1035 | |
| 1036 | if (refine->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1037 | ypr_close_parent(pctx, &flag); |
| 1038 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1039 | } |
| 1040 | if (refine->flags & LYS_SET_MAX) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1041 | ypr_close_parent(pctx, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1042 | if (refine->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1043 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1044 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1045 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1049 | ypr_description(pctx, refine->dsc, refine->exts, &flag); |
| 1050 | ypr_reference(pctx, refine->ref, refine->exts, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1051 | |
| 1052 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1053 | ypr_close(pctx, "refine", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1057 | yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1058 | { |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1059 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1060 | struct lysp_node_action *action; |
| 1061 | struct lysp_node_notif *notif; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1062 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1063 | ypr_open(pctx, "augment", "target-node", aug->nodeid, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1064 | LEVEL++; |
| 1065 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1066 | yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1067 | yprp_when(pctx, aug->when, NULL); |
| 1068 | yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL); |
| 1069 | ypr_status(pctx, aug->flags, aug->exts, NULL); |
| 1070 | ypr_description(pctx, aug->dsc, aug->exts, NULL); |
| 1071 | ypr_reference(pctx, aug->ref, aug->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1072 | |
| 1073 | LY_LIST_FOR(aug->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1074 | yprp_node(pctx, child); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1077 | LY_LIST_FOR(aug->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1078 | yprp_action(pctx, action); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1081 | LY_LIST_FOR(aug->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1082 | yprp_notification(pctx, notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1086 | ypr_close(pctx, "augment", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1087 | } |
| 1088 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1089 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1090 | yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1091 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1092 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 1093 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1094 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1095 | struct lysp_node_augment *aug; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1096 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1097 | yprp_node_common1(pctx, node, &flag); |
| 1098 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1099 | |
| 1100 | LY_ARRAY_FOR(uses->refines, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1101 | ypr_close_parent(pctx, &flag); |
| 1102 | yprp_refine(pctx, &uses->refines[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1103 | } |
| 1104 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1105 | LY_LIST_FOR(uses->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1106 | ypr_close_parent(pctx, &flag); |
| 1107 | yprp_augment(pctx, aug); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1111 | ypr_close(pctx, "uses", flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1115 | yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1116 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1117 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 1118 | int8_t flag = 0; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1119 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
| 1120 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1121 | yprp_node_common1(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1122 | |
| 1123 | LY_ARRAY_FOR(any->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1124 | ypr_close_parent(pctx, &flag); |
| 1125 | yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, "condition", &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1126 | } |
| 1127 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1128 | yprp_node_common2(pctx, node, &flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1129 | |
| 1130 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1131 | ypr_close(pctx, lys_nodetype2str(node->nodetype), flag); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1135 | yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1136 | { |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1137 | switch (node->nodetype) { |
| 1138 | case LYS_CONTAINER: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1139 | yprp_container(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1140 | break; |
| 1141 | case LYS_CHOICE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1142 | yprp_choice(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1143 | break; |
| 1144 | case LYS_LEAF: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1145 | yprp_leaf(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1146 | break; |
| 1147 | case LYS_LEAFLIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1148 | yprp_leaflist(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1149 | break; |
| 1150 | case LYS_LIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1151 | yprp_list(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1152 | break; |
| 1153 | case LYS_USES: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1154 | yprp_uses(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1155 | break; |
| 1156 | case LYS_ANYXML: |
| 1157 | case LYS_ANYDATA: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1158 | yprp_anydata(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1159 | break; |
| 1160 | case LYS_CASE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1161 | yprp_case(pctx, node); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1162 | break; |
| 1163 | default: |
| 1164 | break; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1169 | yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1170 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1171 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1172 | struct lysp_deviate_add *add; |
| 1173 | struct lysp_deviate_rpl *rpl; |
| 1174 | struct lysp_deviate_del *del; |
| 1175 | struct lysp_deviate *elem; |
| 1176 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1177 | ypr_open(pctx, "deviation", "target-node", deviation->nodeid, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1178 | LEVEL++; |
| 1179 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1180 | yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1181 | ypr_description(pctx, deviation->dsc, deviation->exts, NULL); |
| 1182 | ypr_reference(pctx, deviation->ref, deviation->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1183 | |
| 1184 | LY_LIST_FOR(deviation->deviates, elem) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1185 | ly_print_(pctx->out, "%*s<deviate value=\"", INDENT); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1186 | if (elem->mod == LYS_DEV_NOT_SUPPORTED) { |
| 1187 | if (elem->exts) { |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 1188 | ly_print_(pctx->out, "not-supported\">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1189 | LEVEL++; |
| 1190 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1191 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1192 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1193 | ly_print_(pctx->out, "not-supported\"/>\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1194 | continue; |
| 1195 | } |
| 1196 | } else if (elem->mod == LYS_DEV_ADD) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1197 | add = (struct lysp_deviate_add *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1198 | ly_print_(pctx->out, "add\">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1199 | LEVEL++; |
| 1200 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1201 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1202 | ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, add->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1203 | LY_ARRAY_FOR(add->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1204 | yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, "condition", NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1205 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1206 | LY_ARRAY_FOR(add->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1207 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1208 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1209 | LY_ARRAY_FOR(add->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1210 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1211 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1212 | ypr_config(pctx, add->flags, add->exts, NULL); |
| 1213 | ypr_mandatory(pctx, add->flags, add->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1214 | if (add->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1215 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1216 | } |
| 1217 | if (add->flags & LYS_SET_MAX) { |
| 1218 | if (add->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1219 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1220 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1221 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | } else if (elem->mod == LYS_DEV_REPLACE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1225 | rpl = (struct lysp_deviate_rpl *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1226 | ly_print_(pctx->out, "replace\">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1227 | LEVEL++; |
| 1228 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1229 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1230 | if (rpl->type) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1231 | yprp_type(pctx, rpl->type); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1232 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1233 | ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts); |
| 1234 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts); |
| 1235 | ypr_config(pctx, rpl->flags, rpl->exts, NULL); |
| 1236 | ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1237 | if (rpl->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1238 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1239 | } |
| 1240 | if (rpl->flags & LYS_SET_MAX) { |
| 1241 | if (rpl->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1242 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1243 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1244 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | } else if (elem->mod == LYS_DEV_DELETE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1248 | del = (struct lysp_deviate_del *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1249 | ly_print_(pctx->out, "delete\">\n"); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1250 | LEVEL++; |
| 1251 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1252 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1253 | ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, del->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1254 | LY_ARRAY_FOR(del->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1255 | yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, "condition", NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1256 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1257 | LY_ARRAY_FOR(del->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1258 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1259 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 1260 | LY_ARRAY_FOR(del->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1261 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1266 | ypr_close(pctx, "deviate", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1270 | ypr_close(pctx, "deviation", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1271 | } |
| 1272 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1273 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1274 | ypr_xmlns(struct lys_ypr_ctx *pctx, const struct lys_module *module, uint16_t indent) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1275 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1276 | ly_print_(pctx->out, "%*sxmlns=\"%s\"", indent + INDENT, YIN_NS_URI); |
| 1277 | ly_print_(pctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, module->prefix, module->ns); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1278 | } |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1279 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1280 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1281 | ypr_import_xmlns(struct lys_ypr_ctx *pctx, const struct lysp_module *modp, uint16_t indent) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1282 | { |
| 1283 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1284 | |
| 1285 | LY_ARRAY_FOR(modp->imports, u){ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1286 | ly_print_(pctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, modp->imports[u].prefix, modp->imports[u].module->ns); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1290 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1291 | yin_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1292 | { |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1293 | LY_ARRAY_COUNT_TYPE u; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1294 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1295 | LY_ARRAY_FOR(modp->imports, u) { |
Michal Vasko | 3e9bc2f | 2020-11-04 17:13:56 +0100 | [diff] [blame] | 1296 | if (modp->imports[u].flags & LYS_INTERNAL) { |
| 1297 | continue; |
| 1298 | } |
| 1299 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1300 | ypr_open(pctx, "import", "module", modp->imports[u].name, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1301 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1302 | 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] | 1303 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1304 | if (modp->imports[u].rev[0]) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1305 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1306 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1307 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts); |
| 1308 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1309 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1310 | ypr_close(pctx, "import", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1311 | } |
| 1312 | LY_ARRAY_FOR(modp->includes, u) { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 1313 | if (modp->includes[u].injected) { |
| 1314 | /* do not print the includes injected from submodules */ |
| 1315 | continue; |
| 1316 | } |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1317 | 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] | 1318 | ypr_open(pctx, "include", "module", modp->includes[u].name, 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1319 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1320 | yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1321 | if (modp->includes[u].rev[0]) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1322 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1323 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1324 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts); |
| 1325 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1326 | LEVEL--; |
NextLitete | b34bd8a | 2024-02-08 15:37:49 +0800 | [diff] [blame] | 1327 | ypr_close(pctx, "include", 1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1328 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1329 | ypr_open(pctx, "include", "module", modp->includes[u].name, -1); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1330 | } |
| 1331 | } |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1332 | } |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1333 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1334 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1335 | yin_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] | 1336 | { |
| 1337 | LY_ARRAY_COUNT_TYPE u; |
| 1338 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1339 | struct lysp_node_action *action; |
| 1340 | struct lysp_node_notif *notif; |
| 1341 | struct lysp_node_grp *grp; |
| 1342 | struct lysp_node_augment *aug; |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1343 | |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1344 | LY_ARRAY_FOR(modp->extensions, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1345 | yprp_extension(pctx, &modp->extensions[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1346 | } |
| 1347 | if (modp->exts) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1348 | yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | LY_ARRAY_FOR(modp->features, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1352 | yprp_feature(pctx, &modp->features[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | LY_ARRAY_FOR(modp->identities, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1356 | yprp_identity(pctx, &modp->identities[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | LY_ARRAY_FOR(modp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1360 | yprp_typedef(pctx, &modp->typedefs[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1361 | } |
| 1362 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1363 | LY_LIST_FOR(modp->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1364 | yprp_grouping(pctx, grp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | LY_LIST_FOR(modp->data, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1368 | yprp_node(pctx, data); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1371 | LY_LIST_FOR(modp->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1372 | yprp_augment(pctx, aug); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1375 | LY_LIST_FOR(modp->rpcs, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1376 | yprp_action(pctx, action); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1377 | } |
| 1378 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1379 | LY_LIST_FOR(modp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1380 | yprp_notification(pctx, notif); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | LY_ARRAY_FOR(modp->deviations, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1384 | yprp_deviation(pctx, &modp->deviations[u]); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1385 | } |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 1389 | yin_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] | 1390 | { |
| 1391 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 1392 | const struct lys_module *module = modp->mod; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1393 | struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = module, .options = options}, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1394 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1395 | ly_print_(pctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 1396 | ly_print_(pctx->out, "%*s<module name=\"%s\"\n", INDENT, module->name); |
| 1397 | ypr_xmlns(pctx, module, XML_NS_INDENT); |
| 1398 | ypr_import_xmlns(pctx, modp, XML_NS_INDENT); |
| 1399 | ly_print_(pctx->out, ">\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1400 | |
| 1401 | LEVEL++; |
| 1402 | |
| 1403 | /* module-header-stmts */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1404 | if (modp->version) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1405 | 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] | 1406 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1407 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts); |
| 1408 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1409 | |
| 1410 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1411 | yin_print_parsed_linkage(pctx, modp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1412 | |
| 1413 | /* meta-stmts */ |
| 1414 | if (module->org || module->contact || module->dsc || module->ref) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1415 | ly_print_(out, "\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1416 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1417 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts); |
| 1418 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, modp->exts); |
| 1419 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts); |
| 1420 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1421 | |
| 1422 | /* revision-stmts */ |
| 1423 | if (modp->revs) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1424 | ly_print_(out, "\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1425 | } |
| 1426 | LY_ARRAY_FOR(modp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1427 | yprp_revision(pctx, &modp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1431 | yin_print_parsed_body(pctx, modp); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1432 | |
| 1433 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1434 | ly_print_(out, "%*s</module>\n", INDENT); |
FredGan | d944bdc | 2019-11-05 21:57:07 +0800 | [diff] [blame] | 1435 | ly_print_flush(out); |
| 1436 | |
| 1437 | return LY_SUCCESS; |
| 1438 | } |
| 1439 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1440 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1441 | yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1442 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1443 | ypr_open(pctx, "belongs-to", "module", submodp->mod->name, 1); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1444 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1445 | yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1446 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1447 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1448 | ypr_close(pctx, "belongs-to", 1); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 1452 | yin_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] | 1453 | { |
| 1454 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1455 | struct lys_ypr_ctx pctx_ = {.out = out, .level = 0, .module = submodp->mod, .options = options}, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1456 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1457 | ly_print_(pctx->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 1458 | ly_print_(pctx->out, "%*s<submodule name=\"%s\"\n", INDENT, submodp->name); |
| 1459 | ypr_xmlns(pctx, submodp->mod, XML_NS_INDENT); |
| 1460 | ypr_import_xmlns(pctx, (struct lysp_module *)submodp, XML_NS_INDENT); |
| 1461 | ly_print_(pctx->out, ">\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1462 | |
| 1463 | LEVEL++; |
| 1464 | |
| 1465 | /* submodule-header-stmts */ |
| 1466 | if (submodp->version) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1467 | 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] | 1468 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1469 | yprp_belongsto(pctx, submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1470 | |
| 1471 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1472 | yin_print_parsed_linkage(pctx, (struct lysp_module *)submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1473 | |
| 1474 | /* meta-stmts */ |
| 1475 | if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1476 | ly_print_(out, "\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1477 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1478 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts); |
| 1479 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts); |
| 1480 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts); |
| 1481 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1482 | |
| 1483 | /* revision-stmts */ |
| 1484 | if (submodp->revs) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1485 | ly_print_(out, "\n"); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1486 | } |
| 1487 | LY_ARRAY_FOR(submodp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1488 | yprp_revision(pctx, &submodp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1492 | yin_print_parsed_body(pctx, (struct lysp_module *)submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1493 | |
| 1494 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 1495 | ly_print_(out, "%*s</submodule>\n", INDENT); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 1496 | ly_print_flush(out); |
| 1497 | |
| 1498 | return LY_SUCCESS; |
| 1499 | } |