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