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