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