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