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