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