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