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