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