David Sedlák | f824ad5 | 2018-10-14 23:58:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_yin.c |
| 3 | * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz> |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 5 | * @brief YIN parser. |
| 6 | * |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
David Sedlák | f824ad5 | 2018-10-14 23:58:15 +0200 | [diff] [blame] | 14 | */ |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 15 | #define _GNU_SOURCE |
| 16 | |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 17 | #include <assert.h> |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 18 | #include <ctype.h> |
| 19 | #include <errno.h> |
| 20 | #include <stdarg.h> |
| 21 | #include <stdbool.h> |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 22 | #include <stdint.h> |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 25 | #include <string.h> |
David Sedlák | f824ad5 | 2018-10-14 23:58:15 +0200 | [diff] [blame] | 26 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 27 | #include "common.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 28 | #include "compat.h" |
David Sedlák | f824ad5 | 2018-10-14 23:58:15 +0200 | [diff] [blame] | 29 | #include "context.h" |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 30 | #include "dict.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 31 | #include "in.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 32 | #include "in_internal.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 33 | #include "log.h" |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 34 | #include "parser_internal.h" |
Radek Krejci | ca376bd | 2020-06-11 16:04:06 +0200 | [diff] [blame] | 35 | #include "parser_schema.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 36 | #include "path.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 37 | #include "set.h" |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 38 | #include "tree.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 39 | #include "tree_data_internal.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 40 | #include "tree_edit.h" |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 41 | #include "tree_schema.h" |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 42 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 43 | #include "xml.h" |
David Sedlák | 0025034 | 2019-06-21 14:19:39 +0200 | [diff] [blame] | 44 | |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 45 | struct lys_glob_unres; |
| 46 | |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 47 | /** |
| 48 | * @brief check if given string is URI of yin namespace. |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 49 | * |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 50 | * @param ns Namespace URI to check. |
| 51 | * |
| 52 | * @return true if ns equals YIN_NS_URI false otherwise. |
| 53 | */ |
| 54 | #define IS_YIN_NS(ns) (strcmp(ns, YIN_NS_URI) == 0) |
| 55 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 56 | enum yin_argument { |
| 57 | YIN_ARG_UNKNOWN = 0, /**< parsed argument can not be matched with any supported yin argument keyword */ |
| 58 | YIN_ARG_NAME, /**< argument name */ |
| 59 | YIN_ARG_TARGET_NODE, /**< argument target-node */ |
| 60 | YIN_ARG_MODULE, /**< argument module */ |
| 61 | YIN_ARG_VALUE, /**< argument value */ |
| 62 | YIN_ARG_TEXT, /**< argument text */ |
| 63 | YIN_ARG_CONDITION, /**< argument condition */ |
| 64 | YIN_ARG_URI, /**< argument uri */ |
| 65 | YIN_ARG_DATE, /**< argument data */ |
| 66 | YIN_ARG_TAG, /**< argument tag */ |
| 67 | YIN_ARG_NONE /**< empty (special value) */ |
| 68 | }; |
| 69 | |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 70 | const char * const yin_attr_list[] = { |
David Sedlák | f625118 | 2019-06-06 10:22:13 +0200 | [diff] [blame] | 71 | [YIN_ARG_NAME] = "name", |
| 72 | [YIN_ARG_TARGET_NODE] = "target-node", |
| 73 | [YIN_ARG_MODULE] = "module", |
| 74 | [YIN_ARG_VALUE] = "value", |
| 75 | [YIN_ARG_TEXT] = "text", |
| 76 | [YIN_ARG_CONDITION] = "condition", |
| 77 | [YIN_ARG_URI] = "uri", |
| 78 | [YIN_ARG_DATE] = "date", |
| 79 | [YIN_ARG_TAG] = "tag", |
David Sedlák | 071f766 | 2019-09-12 02:02:51 +0200 | [diff] [blame] | 80 | [YIN_ARG_NONE] = "none", |
David Sedlák | f625118 | 2019-06-06 10:22:13 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 83 | #define yin_attr2str(STMT) yin_attr_list[STMT] |
| 84 | |
| 85 | #define VALID_VALS1 " Only valid value is \"%s\"." |
| 86 | #define VALID_VALS2 " Valid values are \"%s\" and \"%s\"." |
| 87 | #define VALID_VALS3 " Valid values are \"%s\", \"%s\" and \"%s\"." |
| 88 | #define VALID_VALS4 " Valid values are \"%s\", \"%s\", \"%s\" and \"%s\"." |
| 89 | |
| 90 | /* shortcut to determin if keyword can in general be subelement of deviation regardles of it's type */ |
| 91 | #define isdevsub(kw) (kw == LY_STMT_CONFIG || kw == LY_STMT_DEFAULT || kw == LY_STMT_MANDATORY || \ |
| 92 | kw == LY_STMT_MAX_ELEMENTS || kw == LY_STMT_MIN_ELEMENTS || \ |
| 93 | kw == LY_STMT_MUST || kw == LY_STMT_TYPE || kw == LY_STMT_UNIQUE || \ |
| 94 | kw == LY_STMT_UNITS || kw == LY_STMT_EXTENSION_INSTANCE) |
| 95 | |
| 96 | /* flags to set constraints of subelements */ |
| 97 | #define YIN_SUBELEM_MANDATORY 0x01 /**< is set when subelement is mandatory */ |
| 98 | #define YIN_SUBELEM_UNIQUE 0x02 /**< is set when subelement is unique */ |
| 99 | #define YIN_SUBELEM_FIRST 0x04 /**< is set when subelement is actually yang argument mapped to yin element */ |
| 100 | #define YIN_SUBELEM_VER2 0x08 /**< subelemnt is allowed only in modules with version at least 2 (YANG 1.1) */ |
| 101 | |
| 102 | #define YIN_SUBELEM_PARSED 0x80 /**< is set during parsing when given subelement is encountered for the first |
| 103 | time to simply check validity of given constraints */ |
| 104 | |
| 105 | struct yin_subelement { |
| 106 | enum ly_stmt type; /**< type of keyword */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 107 | void *dest; /**< meta infromation passed to responsible function (mostly information about where parsed |
| 108 | subelement should be stored) */ |
| 109 | uint16_t flags; /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, |
| 110 | YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST, YIN_SUBELEM_VER2, and YIN_SUBELEM_DEFAULT_TEXT */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* Meta information passed to yin_parse_argument function, |
| 114 | holds information about where content of argument element will be stored. */ |
| 115 | struct yin_argument_meta { |
| 116 | uint16_t *flags; /**< Argument flags */ |
| 117 | const char **argument; /**< Argument value */ |
| 118 | }; |
| 119 | |
| 120 | /** |
| 121 | * @brief Meta information passed to functions working with tree_schema, |
| 122 | * that require additional information about parent node. |
| 123 | */ |
| 124 | struct tree_node_meta { |
| 125 | struct lysp_node *parent; /**< parent node */ |
| 126 | struct lysp_node **nodes; /**< linked list of siblings */ |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * @brief Meta information passed to yin_parse_import function. |
| 131 | */ |
| 132 | struct import_meta { |
| 133 | const char *prefix; /**< module prefix. */ |
| 134 | struct lysp_import **imports; /**< imports to add to. */ |
| 135 | }; |
| 136 | |
| 137 | /** |
| 138 | * @brief Meta information passed to yin_parse_include function. |
| 139 | */ |
| 140 | struct include_meta { |
| 141 | const char *name; /**< Module/submodule name. */ |
| 142 | struct lysp_include **includes; /**< [Sized array](@ref sizedarrays) of parsed includes to add to. */ |
| 143 | }; |
| 144 | |
| 145 | /** |
| 146 | * @brief Meta information passed to yin_parse_inout function. |
| 147 | */ |
| 148 | struct inout_meta { |
| 149 | struct lysp_node *parent; /**< Parent node. */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 150 | struct lysp_node_action_inout *inout_p; /**< inout_p Input/output pointer to write to. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * @brief Meta information passed to yin_parse_minmax function. |
| 155 | */ |
| 156 | struct minmax_dev_meta { |
| 157 | uint32_t *lim; /**< min/max value to write to. */ |
| 158 | uint16_t *flags; /**< min/max flags to write to. */ |
| 159 | struct lysp_ext_instance **exts; /**< extension instances to add to. */ |
| 160 | }; |
| 161 | |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 162 | LY_ERR yin_parse_content(struct lysp_yin_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 163 | const void *parent, enum ly_stmt parent_stmt, const char **text_content, struct lysp_ext_instance **exts); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * @brief Match yang keyword from yin data. |
| 167 | * |
| 168 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
| 169 | * @param[in] name Start of keyword name |
| 170 | * @param[in] name_len Lenght of keyword name. |
| 171 | * @param[in] prefix Start of keyword prefix. |
| 172 | * @param[in] prefix_len Lenght of prefix. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 173 | * @param[in] parent Identification of parent element, use LY_STMT_NONE for elements without parent. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 174 | * @return yang_keyword values. |
| 175 | */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 176 | enum ly_stmt |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 177 | yin_match_keyword(struct lysp_yin_ctx *ctx, const char *name, size_t name_len, const char *prefix, size_t prefix_len, |
| 178 | enum ly_stmt parent) |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 179 | { |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 180 | const char *start = NULL; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 181 | enum ly_stmt kw = LY_STMT_NONE; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 182 | const struct lyxml_ns *ns = NULL; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 183 | struct ly_in *in; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 184 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 185 | if (!name || (name_len == 0)) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 186 | return LY_STMT_NONE; |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 189 | ns = lyxml_ns_get(&ctx->xmlctx->ns, prefix, prefix_len); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 190 | if (ns) { |
| 191 | if (!IS_YIN_NS(ns->uri)) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 192 | return LY_STMT_EXTENSION_INSTANCE; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 193 | } |
| 194 | } else { |
| 195 | /* elements without namespace are automatically unknown */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 196 | return LY_STMT_NONE; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 197 | } |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 198 | |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 199 | LY_CHECK_RET(ly_in_new_memory(name, &in), LY_STMT_NONE); |
| 200 | start = in->current; |
Radek Krejci | d54412f | 2020-12-17 20:25:35 +0100 | [diff] [blame] | 201 | kw = lysp_match_kw(in, NULL); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 202 | name = in->current; |
| 203 | ly_in_free(in, 0); |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 204 | |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 205 | if (name - start == (long)name_len) { |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 206 | /* this is done because of collision in yang statement value and yang argument mapped to yin element value */ |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 207 | if ((kw == LY_STMT_VALUE) && (parent == LY_STMT_ERROR_MESSAGE)) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 208 | return LY_STMT_ARG_VALUE; |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 209 | } |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 210 | return kw; |
| 211 | } else { |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 212 | if (strncmp(start, "text", name_len) == 0) { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 213 | return LY_STMT_ARG_TEXT; |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 214 | } else { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 215 | return LY_STMT_NONE; |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 216 | } |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 220 | /** |
| 221 | * @brief Match argument name. |
| 222 | * |
| 223 | * @param[in] name String representing name. |
| 224 | * @param[in] len Lenght of the name. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 225 | * @return yin_argument values. |
| 226 | */ |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 227 | enum yin_argument |
David Sedlák | 060b00e | 2019-06-19 11:12:06 +0200 | [diff] [blame] | 228 | yin_match_argument_name(const char *name, size_t len) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 229 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 230 | enum yin_argument arg = YIN_ARG_UNKNOWN; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 231 | size_t already_read = 0; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 232 | |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 233 | LY_CHECK_RET(len == 0, YIN_ARG_NONE); |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 234 | |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 235 | #define READ_INC(LEN) already_read += LEN |
| 236 | #define ARG_SET(STMT) arg=STMT |
| 237 | #define ARG_CHECK(STR, LEN) (!strncmp((name) + already_read, STR, LEN) && (READ_INC(LEN))) |
David Sedlák | c10e790 | 2018-12-17 02:17:59 +0100 | [diff] [blame] | 238 | |
David Sedlák | 1c8b270 | 2019-02-22 11:03:02 +0100 | [diff] [blame] | 239 | switch (*name) { |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 240 | case 'c': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 241 | READ_INC(1); |
| 242 | if (ARG_CHECK("ondition", 8)) { |
| 243 | ARG_SET(YIN_ARG_CONDITION); |
| 244 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 245 | break; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 246 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 247 | case 'd': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 248 | READ_INC(1); |
| 249 | if (ARG_CHECK("ate", 3)) { |
| 250 | ARG_SET(YIN_ARG_DATE); |
| 251 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 252 | break; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 253 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 254 | case 'm': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 255 | READ_INC(1); |
| 256 | if (ARG_CHECK("odule", 5)) { |
| 257 | ARG_SET(YIN_ARG_MODULE); |
| 258 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 259 | break; |
| 260 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 261 | case 'n': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 262 | READ_INC(1); |
| 263 | if (ARG_CHECK("ame", 3)) { |
| 264 | ARG_SET(YIN_ARG_NAME); |
| 265 | } |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 266 | break; |
| 267 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 268 | case 't': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 269 | READ_INC(1); |
| 270 | if (ARG_CHECK("a", 1)) { |
| 271 | if (ARG_CHECK("g", 1)) { |
| 272 | ARG_SET(YIN_ARG_TAG); |
| 273 | } else if (ARG_CHECK("rget-node", 9)) { |
| 274 | ARG_SET(YIN_ARG_TARGET_NODE); |
| 275 | } |
| 276 | } else if (ARG_CHECK("ext", 3)) { |
| 277 | ARG_SET(YIN_ARG_TEXT); |
| 278 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 279 | break; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 280 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 281 | case 'u': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 282 | READ_INC(1); |
| 283 | if (ARG_CHECK("ri", 2)) { |
| 284 | ARG_SET(YIN_ARG_URI); |
| 285 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 286 | break; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 287 | |
David Sedlák | 94de2aa | 2019-02-15 12:42:11 +0100 | [diff] [blame] | 288 | case 'v': |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 289 | READ_INC(1); |
| 290 | if (ARG_CHECK("alue", 4)) { |
| 291 | ARG_SET(YIN_ARG_VALUE); |
| 292 | } |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 293 | break; |
| 294 | } |
| 295 | |
David Sedlák | c10e790 | 2018-12-17 02:17:59 +0100 | [diff] [blame] | 296 | /* whole argument must be matched */ |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 297 | if (already_read != len) { |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 298 | arg = YIN_ARG_UNKNOWN; |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Radek Krejci | 8bb8d9d | 2020-08-21 14:53:27 +0200 | [diff] [blame] | 301 | #undef ARG_CHECK |
| 302 | #undef ARG_SET |
| 303 | #undef READ_INC |
David Sedlák | 1873013 | 2019-03-15 15:51:34 +0100 | [diff] [blame] | 304 | |
David Sedlák | 872c7b4 | 2018-10-26 13:15:20 +0200 | [diff] [blame] | 305 | return arg; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 308 | #define IS_NODE_ELEM(kw) (kw == LY_STMT_ANYXML || kw == LY_STMT_ANYDATA || kw == LY_STMT_LEAF || kw == LY_STMT_LEAF_LIST || \ |
| 309 | kw == LY_STMT_TYPEDEF || kw == LY_STMT_USES || kw == LY_STMT_LIST || kw == LY_STMT_NOTIFICATION || \ |
| 310 | kw == LY_STMT_GROUPING || kw == LY_STMT_CONTAINER || kw == LY_STMT_CASE || kw == LY_STMT_CHOICE || \ |
| 311 | kw == LY_STMT_ACTION || kw == LY_STMT_RPC || kw == LY_STMT_AUGMENT) |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 312 | |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 313 | #define HAS_META(kw) (IS_NODE_ELEM(kw) || kw == LY_STMT_IMPORT || kw == LY_STMT_INCLUDE || kw == LY_STMT_INPUT || kw == LY_STMT_OUTPUT) |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 314 | |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 315 | /** |
| 316 | * @brief Free subelems information allocated on heap. |
| 317 | * |
| 318 | * @param[in] count Size of subelems array. |
| 319 | * @param[in] subelems Subelems array to free. |
| 320 | */ |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 321 | static void |
| 322 | subelems_deallocator(size_t count, struct yin_subelement *subelems) |
| 323 | { |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 324 | for (size_t i = 0; i < count; ++i) { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 325 | if (HAS_META(subelems[i].type)) { |
| 326 | free(subelems[i].dest); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | free(subelems); |
| 331 | } |
| 332 | |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 333 | /** |
| 334 | * @brief Allocate subelems information on heap. |
| 335 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 336 | * @param[in] ctx YIN parser context, used for logging. |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 337 | * @param[in] count Number of subelements. |
| 338 | * @param[in] parent Parent node if any. |
| 339 | * @param[out] result Allocated subelems array. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 340 | * @return LY_ERR values. |
David Sedlák | 26ea143 | 2019-08-14 13:42:23 +0200 | [diff] [blame] | 341 | */ |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 342 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 343 | subelems_allocator(struct lysp_yin_ctx *ctx, size_t count, struct lysp_node *parent, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 344 | struct yin_subelement **result, ...) |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 345 | { |
| 346 | va_list ap; |
| 347 | |
| 348 | *result = calloc(count, sizeof **result); |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 349 | LY_CHECK_GOTO(!(*result), mem_err); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 350 | |
| 351 | va_start(ap, result); |
| 352 | for (size_t i = 0; i < count; ++i) { |
| 353 | /* TYPE */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 354 | (*result)[i].type = va_arg(ap, enum ly_stmt); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 355 | /* DEST */ |
| 356 | if (IS_NODE_ELEM((*result)[i].type)) { |
| 357 | struct tree_node_meta *node_meta = NULL; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 358 | |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 359 | node_meta = calloc(1, sizeof *node_meta); |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 360 | LY_CHECK_GOTO(!node_meta, mem_err); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 361 | node_meta->parent = parent; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 362 | node_meta->nodes = va_arg(ap, void *); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 363 | (*result)[i].dest = node_meta; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 364 | } else if ((*result)[i].type == LY_STMT_IMPORT) { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 365 | struct import_meta *imp_meta = NULL; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 366 | |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 367 | imp_meta = calloc(1, sizeof *imp_meta); |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 368 | LY_CHECK_GOTO(!imp_meta, mem_err); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 369 | imp_meta->prefix = va_arg(ap, const char *); |
| 370 | imp_meta->imports = va_arg(ap, struct lysp_import **); |
| 371 | (*result)[i].dest = imp_meta; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 372 | } else if ((*result)[i].type == LY_STMT_INCLUDE) { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 373 | struct include_meta *inc_meta = NULL; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 374 | |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 375 | inc_meta = calloc(1, sizeof *inc_meta); |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 376 | LY_CHECK_GOTO(!inc_meta, mem_err); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 377 | inc_meta->name = va_arg(ap, const char *); |
| 378 | inc_meta->includes = va_arg(ap, struct lysp_include **); |
| 379 | (*result)[i].dest = inc_meta; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 380 | } else if (((*result)[i].type == LY_STMT_INPUT) || ((*result)[i].type == LY_STMT_OUTPUT)) { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 381 | struct inout_meta *inout_meta = NULL; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 382 | |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 383 | inout_meta = calloc(1, sizeof *inout_meta); |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 384 | LY_CHECK_GOTO(!inout_meta, mem_err); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 385 | inout_meta->parent = parent; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 386 | inout_meta->inout_p = va_arg(ap, struct lysp_node_action_inout *); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 387 | (*result)[i].dest = inout_meta; |
| 388 | } else { |
| 389 | (*result)[i].dest = va_arg(ap, void *); |
| 390 | } |
| 391 | /* FLAGS */ |
| 392 | (*result)[i].flags = va_arg(ap, int); |
| 393 | } |
| 394 | va_end(ap); |
| 395 | |
| 396 | return LY_SUCCESS; |
| 397 | |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 398 | mem_err: |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 399 | subelems_deallocator(count, *result); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 400 | LOGMEM(ctx->xmlctx->ctx); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 401 | return LY_EMEM; |
| 402 | } |
| 403 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 404 | /** |
| 405 | * @brief Check that val is valid UTF8 character sequence of val_type. |
| 406 | * Doesn't check empty string, only character validity. |
| 407 | * |
| 408 | * @param[in] ctx Yin parser context for logging. |
| 409 | * @param[in] val_type Type of the input string to select method of checking character validity. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 410 | * @return LY_ERR values. |
| 411 | */ |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 412 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 413 | yin_validate_value(struct lysp_yin_ctx *ctx, enum yang_arg val_type) |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 414 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 415 | uint8_t prefix = 0; |
| 416 | uint32_t c; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 417 | size_t utf8_char_len, already_read = 0; |
| 418 | const char *val; |
| 419 | |
| 420 | assert((ctx->xmlctx->status == LYXML_ELEM_CONTENT) || (ctx->xmlctx->status == LYXML_ATTR_CONTENT)); |
| 421 | |
| 422 | val = ctx->xmlctx->value; |
| 423 | while (already_read < ctx->xmlctx->value_len) { |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 424 | LY_CHECK_ERR_RET(ly_getutf8((const char **)&val, &c, &utf8_char_len), |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 425 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INCHAR, (val)[-utf8_char_len]), LY_EVALID); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 426 | |
| 427 | switch (val_type) { |
| 428 | case Y_IDENTIF_ARG: |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 429 | LY_CHECK_RET(lysp_check_identifierchar((struct lysp_ctx *)ctx, c, already_read ? 0 : 1, NULL)); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 430 | break; |
| 431 | case Y_PREF_IDENTIF_ARG: |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 432 | LY_CHECK_RET(lysp_check_identifierchar((struct lysp_ctx *)ctx, c, already_read ? 0 : 1, &prefix)); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 433 | break; |
| 434 | case Y_STR_ARG: |
| 435 | case Y_MAYBE_STR_ARG: |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 436 | LY_CHECK_RET(lysp_check_stringchar((struct lysp_ctx *)ctx, c)); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 437 | break; |
| 438 | } |
Radek Iša | 2eac74c | 2021-03-15 15:53:08 +0100 | [diff] [blame] | 439 | |
| 440 | already_read += utf8_char_len; |
| 441 | LY_CHECK_ERR_RET(already_read > ctx->xmlctx->value_len, LOGINT(ctx->xmlctx->ctx), LY_EINT); |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Radek Iša | 42cc0b7 | 2021-03-15 16:51:31 +0100 | [diff] [blame] | 444 | if ((already_read == 0) && |
| 445 | ((val_type == Y_PREF_IDENTIF_ARG) || (val_type == Y_IDENTIF_ARG))) { |
| 446 | /* Empty identifier or prefix*/ |
| 447 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YIN, "Empty identifier is not allowed."); |
| 448 | return LY_EVALID; |
| 449 | } |
| 450 | |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 451 | return LY_SUCCESS; |
| 452 | } |
| 453 | |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 454 | /** |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 455 | * @brief Parse yin attributes. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 456 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 457 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 458 | * @param[in] arg_type Type of argument that is expected in parsed element (use YIN_ARG_NONE for elements without |
| 459 | * special argument). |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 460 | * @param[out] arg_val Where value of argument should be stored. Can be NULL iff arg_type is specified as YIN_ARG_NONE. |
David Sedlák | 292763b | 2019-07-09 11:10:53 +0200 | [diff] [blame] | 461 | * @param[in] val_type Type of expected value of attribute. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 462 | * @param[in] current_element Identification of current element, used for logging. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 463 | * @return LY_ERR values. |
| 464 | */ |
| 465 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 466 | yin_parse_attribute(struct lysp_yin_ctx *ctx, enum yin_argument arg_type, const char **arg_val, enum yang_arg val_type, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 467 | enum ly_stmt current_element) |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 468 | { |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 469 | enum yin_argument arg = YIN_ARG_UNKNOWN; |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 470 | bool found = false; |
David Sedlák | 8f7a117 | 2019-06-20 14:42:18 +0200 | [diff] [blame] | 471 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 472 | /* validation of attributes */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 473 | while (ctx->xmlctx->status == LYXML_ATTRIBUTE) { |
David Sedlák | 0025034 | 2019-06-21 14:19:39 +0200 | [diff] [blame] | 474 | /* yin arguments represented as attributes have no namespace, which in this case means no prefix */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 475 | if (!ctx->xmlctx->prefix) { |
| 476 | arg = yin_match_argument_name(ctx->xmlctx->name, ctx->xmlctx->name_len); |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 477 | if (arg == YIN_ARG_NONE) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 478 | /* skip it */ |
| 479 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
David Sedlák | 7ff55a9 | 2019-06-17 11:11:41 +0200 | [diff] [blame] | 480 | } else if (arg == arg_type) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 481 | LY_CHECK_ERR_RET(found, LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_DUP_ATTR, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 482 | yin_attr2str(arg), lyplg_ext_stmt2str(current_element)), LY_EVALID); |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 483 | found = true; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 484 | |
| 485 | /* go to value */ |
| 486 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 487 | LY_CHECK_RET(yin_validate_value(ctx, val_type)); |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 488 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, *arg_val); |
David Sedlák | 169cc52 | 2019-08-15 13:23:45 +0200 | [diff] [blame] | 489 | LY_CHECK_RET(!(*arg_val), LY_EMEM); |
David Sedlák | 2b214ac | 2019-06-06 16:11:03 +0200 | [diff] [blame] | 490 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 491 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_UNEXP_ATTR, ctx->xmlctx->name_len, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 492 | ctx->xmlctx->name, lyplg_ext_stmt2str(current_element)); |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 493 | return LY_EVALID; |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 494 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 495 | } else { |
| 496 | /* skip it */ |
| 497 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 498 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 499 | |
| 500 | /* next attribute */ |
| 501 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 502 | } |
| 503 | |
David Sedlák | 292763b | 2019-07-09 11:10:53 +0200 | [diff] [blame] | 504 | /* anything else than Y_MAYBE_STR_ARG is mandatory */ |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 505 | if ((val_type != Y_MAYBE_STR_ARG) && !found) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 506 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LYVE_SYNTAX_YIN, "Missing mandatory attribute %s of %s element.", |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 507 | yin_attr2str(arg_type), lyplg_ext_stmt2str(current_element)); |
David Sedlák | 619db94 | 2019-07-03 14:47:30 +0200 | [diff] [blame] | 508 | return LY_EVALID; |
| 509 | } |
| 510 | |
| 511 | return LY_SUCCESS; |
David Sedlák | a740695 | 2019-04-05 10:33:07 +0200 | [diff] [blame] | 512 | } |
| 513 | |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 514 | /** |
Radek Krejci | 12b1c15 | 2019-09-05 16:20:48 +0200 | [diff] [blame] | 515 | * @brief Get record with given type. |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 516 | * |
| 517 | * @param[in] type Type of wanted record. |
| 518 | * @param[in] array_size Size of array. |
| 519 | * @param[in] array Searched array. |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 520 | * @return Pointer to desired record on success, NULL if element is not in the array. |
| 521 | */ |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 522 | static struct yin_subelement * |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 523 | get_record(enum ly_stmt type, LY_ARRAY_COUNT_TYPE array_size, struct yin_subelement *array) |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 524 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 525 | for (LY_ARRAY_COUNT_TYPE u = 0; u < array_size; ++u) { |
Radek Krejci | 12b1c15 | 2019-09-05 16:20:48 +0200 | [diff] [blame] | 526 | if (array[u].type == type) { |
| 527 | return &array[u]; |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 528 | } |
| 529 | } |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 530 | return NULL; |
| 531 | } |
| 532 | |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 533 | /** |
| 534 | * @brief Helper function to check mandatory constraint of subelement. |
| 535 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 536 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 537 | * @param[in] subelem_info Array of information about subelements. |
| 538 | * @param[in] subelem_info_size Size of subelem_info array. |
| 539 | * @param[in] current_element Identification of element that is currently being parsed, used for logging. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 540 | * @return LY_ERR values. |
| 541 | */ |
| 542 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 543 | yin_check_subelem_mandatory_constraint(struct lysp_yin_ctx *ctx, struct yin_subelement *subelem_info, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 544 | signed char subelem_info_size, enum ly_stmt current_element) |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 545 | { |
David Sedlák | b0faad8 | 2019-07-04 14:28:59 +0200 | [diff] [blame] | 546 | for (signed char i = 0; i < subelem_info_size; ++i) { |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 547 | /* if there is element that is mandatory and isn't parsed log error and return LY_EVALID */ |
Radek Krejci | 12b1c15 | 2019-09-05 16:20:48 +0200 | [diff] [blame] | 548 | if ((subelem_info[i].flags & YIN_SUBELEM_MANDATORY) && !(subelem_info[i].flags & YIN_SUBELEM_PARSED)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 549 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_MAND_SUBELEM, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 550 | lyplg_ext_stmt2str(subelem_info[i].type), lyplg_ext_stmt2str(current_element)); |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 551 | return LY_EVALID; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return LY_SUCCESS; |
| 556 | } |
| 557 | |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 558 | /** |
| 559 | * @brief Helper function to check "first" constraint of subelement. |
| 560 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 561 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 562 | * @param[in] subelem_info Array of information about subelements. |
| 563 | * @param[in] subelem_info_size Size of subelem_info array. |
| 564 | * @param[in] current_element Identification of element that is currently being parsed, used for logging. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 565 | * @param[in] exp_first Record in subelem_info array that is expected to be defined as first subelement, used for logging. |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 566 | * @return LY_ERR values. |
| 567 | */ |
| 568 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 569 | yin_check_subelem_first_constraint(struct lysp_yin_ctx *ctx, struct yin_subelement *subelem_info, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 570 | signed char subelem_info_size, enum ly_stmt current_element, |
| 571 | struct yin_subelement *exp_first) |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 572 | { |
David Sedlák | b0faad8 | 2019-07-04 14:28:59 +0200 | [diff] [blame] | 573 | for (signed char i = 0; i < subelem_info_size; ++i) { |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 574 | if (subelem_info[i].flags & YIN_SUBELEM_PARSED) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 575 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_FIRT_SUBELEM, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 576 | lyplg_ext_stmt2str(exp_first->type), lyplg_ext_stmt2str(current_element)); |
David Sedlák | 21f87cd | 2019-07-03 16:53:23 +0200 | [diff] [blame] | 577 | return LY_EVALID; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | return LY_SUCCESS; |
| 582 | } |
| 583 | |
David Sedlák | bba38e5 | 2019-07-09 15:20:01 +0200 | [diff] [blame] | 584 | /** |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 585 | * @brief Parse simple element without any special constraints and argument mapped to yin attribute, |
| 586 | * for example prefix or namespace element. |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 587 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 588 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 589 | * @param[in] parent Current statement parent. |
| 590 | * @param[in] parent_stmt Type of @p parent statement. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 591 | * @param[out] value Where value of attribute should be stored. |
| 592 | * @param[in] arg_type Expected type of attribute. |
David Sedlák | 292763b | 2019-07-09 11:10:53 +0200 | [diff] [blame] | 593 | * @param[in] arg_val_type Type of expected value of attribute. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 594 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 595 | * @return LY_ERR values. |
| 596 | */ |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 597 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 598 | yin_parse_simple_element(struct lysp_yin_ctx *ctx, const void *parent, enum ly_stmt parent_stmt, const char **value, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 599 | enum yin_argument arg_type, enum yang_arg arg_val_type, struct lysp_ext_instance **exts) |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 600 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 601 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 602 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 603 | }; |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 604 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 605 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 606 | LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, value, arg_val_type, parent_stmt)); |
| 607 | |
| 608 | return yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, parent_stmt, NULL, exts); |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 612 | * @brief Parse path element. |
| 613 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 614 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 615 | * @param[out] type Type structure to store parsed value, flags and extension instances. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 616 | * @return LY_ERR values. |
| 617 | */ |
| 618 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 619 | yin_parse_path(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 620 | { |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 621 | LY_ERR ret; |
| 622 | const char *str_path; |
| 623 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 624 | LY_CHECK_RET(yin_parse_simple_element(ctx, type, LY_STMT_PATH, &str_path, YIN_ARG_VALUE, Y_STR_ARG, &type->exts)); |
| 625 | |
Michal Vasko | ed725d7 | 2021-06-23 12:03:45 +0200 | [diff] [blame] | 626 | ret = ly_path_parse(ctx->xmlctx->ctx, NULL, str_path, 0, 1, LY_PATH_BEGIN_EITHER, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 627 | LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &type->path); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 628 | lydict_remove(ctx->xmlctx->ctx, str_path); |
| 629 | LY_CHECK_RET(ret); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 630 | type->flags |= LYS_SET_PATH; |
| 631 | |
| 632 | return LY_SUCCESS; |
| 633 | } |
| 634 | |
| 635 | /** |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 636 | * @brief Add extension array to context exts instances. |
| 637 | * |
| 638 | * @param[in] ctx YIN parser context. |
| 639 | * @param[in] exts Parsed extension array that is final (no realloc anymore). |
| 640 | * @return LY_ERR value. |
| 641 | */ |
| 642 | static LY_ERR |
| 643 | yin_unres_exts_add(struct lysp_yin_ctx *ctx, struct lysp_ext_instance *exts) |
| 644 | { |
| 645 | if (!exts) { |
| 646 | return LY_SUCCESS; |
| 647 | } |
| 648 | |
Michal Vasko | c8806c8 | 2022-12-06 10:31:24 +0100 | [diff] [blame] | 649 | return ly_set_add(&ctx->main_ctx->ext_inst, exts, 1, NULL); |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /** |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 653 | * @brief Parse pattern element. |
| 654 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 655 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 656 | * @param[in,out] type Type structure to store parsed value, flags and extension instances. |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 657 | * @return LY_ERR values. |
| 658 | */ |
| 659 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 660 | yin_parse_pattern(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 661 | { |
| 662 | const char *real_value = NULL; |
| 663 | char *saved_value = NULL; |
| 664 | struct lysp_restr *restr; |
| 665 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 666 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, type->patterns, restr, LY_EMEM); |
| 667 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 668 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &real_value, Y_STR_ARG, LY_STMT_PATTERN)); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 669 | size_t len = strlen(real_value); |
| 670 | |
| 671 | saved_value = malloc(len + 2); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 672 | LY_CHECK_ERR_RET(!saved_value, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 673 | memmove(saved_value + 1, real_value, len); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 674 | lydict_remove(ctx->xmlctx->ctx, real_value); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 675 | saved_value[0] = LYSP_RESTR_PATTERN_ACK; |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 676 | saved_value[len + 1] = '\0'; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 677 | LY_CHECK_RET(lydict_insert_zc(ctx->xmlctx->ctx, saved_value, &restr->arg.str)); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 678 | restr->arg.mod = PARSER_CUR_PMOD(ctx); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 679 | type->flags |= LYS_SET_PATTERN; |
| 680 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 681 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 682 | {LY_STMT_DESCRIPTION, &restr->dsc, YIN_SUBELEM_UNIQUE}, |
| 683 | {LY_STMT_ERROR_APP_TAG, &restr->eapptag, YIN_SUBELEM_UNIQUE}, |
| 684 | {LY_STMT_ERROR_MESSAGE, &restr->emsg, YIN_SUBELEM_UNIQUE}, |
| 685 | {LY_STMT_MODIFIER, &restr->arg, YIN_SUBELEM_UNIQUE}, |
| 686 | {LY_STMT_REFERENCE, &restr->ref, YIN_SUBELEM_UNIQUE}, |
| 687 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 688 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 689 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 690 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), restr, LY_STMT_PATTERN, NULL, &restr->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 691 | |
| 692 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 693 | LY_CHECK_RET(yin_unres_exts_add(ctx, restr->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 694 | |
| 695 | return LY_SUCCESS; |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 696 | } |
| 697 | |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 698 | /** |
| 699 | * @brief Parse fraction-digits element. |
| 700 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 701 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 702 | * @param[in,out] type Type structure to store value, flags and extension instances. |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 703 | * @return LY_ERR values. |
| 704 | */ |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 705 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 706 | yin_parse_fracdigits(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 707 | { |
| 708 | const char *temp_val = NULL; |
| 709 | char *ptr; |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 710 | unsigned long long num; |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 711 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 712 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 713 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_FRACTION_DIGITS)); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 714 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 715 | if ((temp_val[0] == '\0') || (temp_val[0] == '0') || !isdigit(temp_val[0])) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 716 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "fraction-digits"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 717 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 718 | return LY_EVALID; |
| 719 | } |
| 720 | |
| 721 | errno = 0; |
Michal Vasko | 73d77ab | 2021-07-23 12:45:55 +0200 | [diff] [blame] | 722 | num = strtoull(temp_val, &ptr, LY_BASE_DEC); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 723 | if (*ptr != '\0') { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 724 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "fraction-digits"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 725 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 726 | return LY_EVALID; |
| 727 | } |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 728 | if ((errno == ERANGE) || (num > LY_TYPE_DEC64_FD_MAX)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 729 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "fraction-digits"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 730 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 731 | return LY_EVALID; |
| 732 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 733 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 734 | type->fraction_digits = num; |
| 735 | type->flags |= LYS_SET_FRDIGITS; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 736 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 737 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 738 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 739 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 740 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), type, LY_STMT_FRACTION_DIGITS, NULL, &type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 741 | |
| 742 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 743 | LY_CHECK_RET(yin_unres_exts_add(ctx, type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 744 | |
| 745 | return LY_SUCCESS; |
David Sedlák | f75d55e | 2019-07-12 16:52:50 +0200 | [diff] [blame] | 746 | } |
| 747 | |
David Sedlák | 07869a5 | 2019-07-12 14:28:19 +0200 | [diff] [blame] | 748 | /** |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 749 | * @brief Parse enum element. |
David Sedlák | 07869a5 | 2019-07-12 14:28:19 +0200 | [diff] [blame] | 750 | * |
| 751 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 752 | * @param[in,out] type Type structure to store parsed value, flags and extension instances. |
David Sedlák | 07869a5 | 2019-07-12 14:28:19 +0200 | [diff] [blame] | 753 | * @return LY_ERR values. |
| 754 | */ |
David Sedlák | ca36c42 | 2019-07-12 12:47:55 +0200 | [diff] [blame] | 755 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 756 | yin_parse_enum(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | ca36c42 | 2019-07-12 12:47:55 +0200 | [diff] [blame] | 757 | { |
David Sedlák | 07869a5 | 2019-07-12 14:28:19 +0200 | [diff] [blame] | 758 | struct lysp_type_enum *en; |
David Sedlák | 1e69678 | 2019-07-17 15:06:07 +0200 | [diff] [blame] | 759 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 760 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, type->enums, en, LY_EMEM); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 761 | type->flags |= LYS_SET_ENUM; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 762 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 763 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &en->name, Y_STR_ARG, LY_STMT_ENUM)); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 764 | LY_CHECK_RET(lysp_check_enum_name((struct lysp_ctx *)ctx, en->name, strlen(en->name))); |
| 765 | CHECK_NONEMPTY((struct lysp_ctx *)ctx, strlen(en->name), "enum"); |
| 766 | CHECK_UNIQUENESS((struct lysp_ctx *)ctx, type->enums, name, "enum", en->name); |
David Sedlák | ca36c42 | 2019-07-12 12:47:55 +0200 | [diff] [blame] | 767 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 768 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 769 | {LY_STMT_DESCRIPTION, &en->dsc, YIN_SUBELEM_UNIQUE}, |
| 770 | {LY_STMT_IF_FEATURE, &en->iffeatures, 0}, |
| 771 | {LY_STMT_REFERENCE, &en->ref, YIN_SUBELEM_UNIQUE}, |
| 772 | {LY_STMT_STATUS, &en->flags, YIN_SUBELEM_UNIQUE}, |
| 773 | {LY_STMT_VALUE, en, YIN_SUBELEM_UNIQUE}, |
| 774 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 775 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 776 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 777 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), en, LY_STMT_ENUM, NULL, &en->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 778 | |
| 779 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 780 | LY_CHECK_RET(yin_unres_exts_add(ctx, en->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 781 | |
| 782 | return LY_SUCCESS; |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /** |
| 786 | * @brief Parse bit element. |
| 787 | * |
| 788 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 789 | * @param[in,out] type Type structure to store parsed value, flags and extension instances. |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 790 | * @return LY_ERR values. |
| 791 | */ |
| 792 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 793 | yin_parse_bit(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 794 | { |
| 795 | struct lysp_type_enum *en; |
| 796 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 797 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, type->bits, en, LY_EMEM); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 798 | type->flags |= LYS_SET_BIT; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 799 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 800 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &en->name, Y_IDENTIF_ARG, LY_STMT_BIT)); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 801 | CHECK_UNIQUENESS((struct lysp_ctx *)ctx, type->bits, name, "bit", en->name); |
David Sedlák | 43801c9 | 2019-08-05 15:58:54 +0200 | [diff] [blame] | 802 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 803 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 804 | {LY_STMT_DESCRIPTION, &en->dsc, YIN_SUBELEM_UNIQUE}, |
| 805 | {LY_STMT_IF_FEATURE, &en->iffeatures, 0}, |
| 806 | {LY_STMT_POSITION, en, YIN_SUBELEM_UNIQUE}, |
| 807 | {LY_STMT_REFERENCE, &en->ref, YIN_SUBELEM_UNIQUE}, |
| 808 | {LY_STMT_STATUS, &en->flags, YIN_SUBELEM_UNIQUE}, |
| 809 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 810 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 811 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 812 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), en, LY_STMT_BIT, NULL, &en->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 813 | |
| 814 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 815 | LY_CHECK_RET(yin_unres_exts_add(ctx, en->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 816 | |
| 817 | return LY_SUCCESS; |
David Sedlák | ca36c42 | 2019-07-12 12:47:55 +0200 | [diff] [blame] | 818 | } |
| 819 | |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 820 | /** |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 821 | * @brief Parse simple element without any special constraints and argument mapped to yin attribute, that can have |
| 822 | * more instances, such as base or if-feature. |
| 823 | * |
| 824 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 825 | * @param[in] parent_stmt Type of parent statement. |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 826 | * @param[out] values Parsed values to add to. |
| 827 | * @param[in] arg_type Expected type of attribute. |
David Sedlák | 292763b | 2019-07-09 11:10:53 +0200 | [diff] [blame] | 828 | * @param[in] arg_val_type Type of expected value of attribute. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 829 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 830 | * @return LY_ERR values. |
| 831 | */ |
| 832 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 833 | yin_parse_simple_elements(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, const char ***values, |
| 834 | enum yin_argument arg_type, enum yang_arg arg_val_type, struct lysp_ext_instance **exts) |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 835 | { |
| 836 | const char **value; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 837 | LY_ARRAY_COUNT_TYPE index = LY_ARRAY_COUNT(*values); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 838 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 839 | {LY_STMT_EXTENSION_INSTANCE, &index, 0} |
| 840 | }; |
David Sedlák | 968ac34 | 2019-07-11 15:17:59 +0200 | [diff] [blame] | 841 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 842 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *values, value, LY_EMEM); |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 843 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 844 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 845 | LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, value, arg_val_type, parent_stmt)); |
| 846 | |
| 847 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), *values, parent_stmt, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 848 | |
| 849 | return LY_SUCCESS; |
David Sedlák | 5f8191e | 2019-07-08 16:35:52 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 853 | * @brief Parse simple element without any special constraints and argument mapped to yin attribute. |
| 854 | * |
| 855 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 856 | * @param[in] parent Current statement parent. |
| 857 | * @param[in] parent_stmt Type of @p parent statement. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 858 | * @param[in] subinfo Information about subelement, is used to determin which function should be called and where to store parsed value. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 859 | * @param[in] arg_type Expected type of attribute. |
| 860 | * @param[in] arg_val_type Type of expected value of attribute. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 861 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 862 | * @return LY_ERR values. |
| 863 | */ |
| 864 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 865 | yin_parse_simple_elem(struct lysp_yin_ctx *ctx, const void *parent, enum ly_stmt parent_stmt, struct yin_subelement *subinfo, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 866 | enum yin_argument arg_type, enum yang_arg arg_val_type, struct lysp_ext_instance **exts) |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 867 | { |
| 868 | if (subinfo->flags & YIN_SUBELEM_UNIQUE) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 869 | LY_CHECK_RET(yin_parse_simple_element(ctx, parent, parent_stmt, (const char **)subinfo->dest, arg_type, |
| 870 | arg_val_type, exts)); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 871 | } else { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 872 | LY_CHECK_RET(yin_parse_simple_elements(ctx, parent_stmt, (const char ***)subinfo->dest, arg_type, |
| 873 | arg_val_type, exts)); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | return LY_SUCCESS; |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * @brief Parse base element. |
| 881 | * |
| 882 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 883 | * @param[in] parent_stmt Type of parent statement. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 884 | * @param[out] dest Where parsed values should be stored. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 885 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 886 | * @return LY_ERR values. |
| 887 | */ |
| 888 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 889 | yin_parse_base(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, void *dest, struct lysp_ext_instance **exts) |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 890 | { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 891 | struct lysp_type *type; |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 892 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 893 | if (parent_stmt == LY_STMT_TYPE) { |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 894 | type = (struct lysp_type *)dest; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 895 | LY_CHECK_RET(yin_parse_simple_elements(ctx, LY_STMT_BASE, &type->bases, YIN_ARG_NAME, Y_PREF_IDENTIF_ARG, exts)); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 896 | type->flags |= LYS_SET_BASE; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 897 | } else if (parent_stmt == LY_STMT_IDENTITY) { |
| 898 | LY_CHECK_RET(yin_parse_simple_elements(ctx, LY_STMT_BASE, (const char ***)dest, YIN_ARG_NAME, Y_PREF_IDENTIF_ARG, exts)); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 899 | } else { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 900 | LOGINT(ctx->xmlctx->ctx); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 901 | return LY_EINT; |
| 902 | } |
| 903 | |
| 904 | return LY_SUCCESS; |
| 905 | } |
| 906 | |
| 907 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 908 | * @brief Parse require-instance element. |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 909 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 910 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 911 | * @param[out] type Type structure to store value, flag and extensions. |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 912 | * @return LY_ERR values. |
| 913 | */ |
| 914 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 915 | yin_pasrse_reqinstance(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 916 | { |
| 917 | const char *temp_val = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 918 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 919 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 920 | }; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 921 | |
| 922 | type->flags |= LYS_SET_REQINST; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 923 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 924 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_REQUIRE_INSTANCE)); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 925 | if (strcmp(temp_val, "true") == 0) { |
| 926 | type->require_instance = 1; |
| 927 | } else if (strcmp(temp_val, "false") != 0) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 928 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_val, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 929 | "require-instance", "true", "false"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 930 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 931 | return LY_EVALID; |
| 932 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 933 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 934 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 935 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), type, LY_STMT_REQUIRE_INSTANCE, NULL, &type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 936 | |
| 937 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 938 | LY_CHECK_RET(yin_unres_exts_add(ctx, type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 939 | |
| 940 | return LY_SUCCESS; |
David Sedlák | cf5569a | 2019-07-11 13:31:34 +0200 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /** |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 944 | * @brief Parse modifier element. |
| 945 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 946 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 947 | * @param[in] parent Current statement parent. |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 948 | * @param[in,out] pat Value to write to. |
| 949 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 950 | * @return LY_ERR values. |
| 951 | */ |
| 952 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 953 | yin_parse_modifier(struct lysp_yin_ctx *ctx, const void *parent, const char **pat, struct lysp_ext_instance **exts) |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 954 | { |
| 955 | const char *temp_val; |
| 956 | char *modified_val; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 957 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 958 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 959 | }; |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 960 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 961 | assert(**pat == 0x06); |
| 962 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 963 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 964 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_MODIFIER)); |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 965 | if (strcmp(temp_val, "invert-match") != 0) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 966 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS1, temp_val, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 967 | "modifier", "invert-match"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 968 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 969 | return LY_EVALID; |
| 970 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 971 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 972 | |
| 973 | /* allocate new value */ |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 974 | modified_val = malloc(strlen(*pat) + 1); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 975 | LY_CHECK_ERR_RET(!modified_val, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | d398311 | 2019-07-12 11:20:56 +0200 | [diff] [blame] | 976 | strcpy(modified_val, *pat); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 977 | lydict_remove(ctx->xmlctx->ctx, *pat); |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 978 | |
| 979 | /* modify the new value */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 980 | modified_val[0] = LYSP_RESTR_PATTERN_NACK; |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 981 | LY_CHECK_RET(lydict_insert_zc(ctx->xmlctx->ctx, modified_val, pat)); |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 982 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 983 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_MODIFIER, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 984 | |
| 985 | return LY_SUCCESS; |
David Sedlák | ce77bf5 | 2019-07-11 16:59:31 +0200 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /** |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 989 | * @brief Parse a restriction element (length, range or one instance of must). |
| 990 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 991 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 992 | * @param[in] restr_kw Identificaton of element that is being parsed, can be set to LY_STMT_MUST, LY_STMT_LENGTH or LY_STMT_RANGE. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 993 | * @param[in] restr Value to write to. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 994 | * @return LY_ERR values. |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 995 | */ |
| 996 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 997 | yin_parse_restriction(struct lysp_yin_ctx *ctx, enum ly_stmt restr_kw, struct lysp_restr *restr) |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 998 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 999 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1000 | {LY_STMT_DESCRIPTION, &restr->dsc, YIN_SUBELEM_UNIQUE}, |
| 1001 | {LY_STMT_ERROR_APP_TAG, &restr->eapptag, YIN_SUBELEM_UNIQUE}, |
| 1002 | {LY_STMT_ERROR_MESSAGE, &restr->emsg, YIN_SUBELEM_UNIQUE}, |
| 1003 | {LY_STMT_REFERENCE, &restr->ref, YIN_SUBELEM_UNIQUE}, |
| 1004 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1005 | }; |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 1006 | /* argument of must is called condition, but argument of length and range is called value */ |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1007 | enum yin_argument arg_type = (restr_kw == LY_STMT_MUST) ? YIN_ARG_CONDITION : YIN_ARG_VALUE; |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 1008 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1009 | assert(restr_kw == LY_STMT_MUST || restr_kw == LY_STMT_LENGTH || restr_kw == LY_STMT_RANGE); |
| 1010 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1011 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1012 | LY_CHECK_RET(yin_parse_attribute(ctx, arg_type, &restr->arg.str, Y_STR_ARG, restr_kw)); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1013 | restr->arg.mod = PARSER_CUR_PMOD(ctx); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1014 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1015 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), restr, restr_kw, NULL, &restr->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1016 | |
| 1017 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1018 | LY_CHECK_RET(yin_unres_exts_add(ctx, restr->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1019 | |
| 1020 | return LY_SUCCESS; |
David Sedlák | b7296dd | 2019-07-11 14:58:38 +0200 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /** |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1024 | * @brief Parse range element. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1025 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1026 | * @param[out] type Type structure to store parsed value and flags. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1027 | * @return LY_ERR values. |
| 1028 | */ |
| 1029 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1030 | yin_parse_range(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1031 | { |
| 1032 | type->range = calloc(1, sizeof *type->range); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1033 | LY_CHECK_ERR_RET(!type->range, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
| 1034 | LY_CHECK_RET(yin_parse_restriction(ctx, LY_STMT_RANGE, type->range)); |
Michal Vasko | 44f3d2c | 2020-08-24 09:49:38 +0200 | [diff] [blame] | 1035 | type->flags |= LYS_SET_RANGE; |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1036 | |
| 1037 | return LY_SUCCESS; |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * @brief Parse length element. |
| 1042 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1043 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1044 | * @param[out] type Type structure to store parsed value and flags. |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1045 | * @return LY_ERR values. |
| 1046 | */ |
| 1047 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1048 | yin_parse_length(struct lysp_yin_ctx *ctx, struct lysp_type *type) |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1049 | { |
| 1050 | type->length = calloc(1, sizeof *type->length); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1051 | LY_CHECK_ERR_RET(!type->length, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
| 1052 | LY_CHECK_RET(yin_parse_restriction(ctx, LY_STMT_LENGTH, type->length)); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1053 | type->flags |= LYS_SET_LENGTH; |
| 1054 | |
| 1055 | return LY_SUCCESS; |
| 1056 | } |
| 1057 | |
| 1058 | /** |
David Sedlák | bc9ec9c | 2019-07-11 15:53:55 +0200 | [diff] [blame] | 1059 | * @brief Parse must element. |
| 1060 | * |
| 1061 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bc9ec9c | 2019-07-11 15:53:55 +0200 | [diff] [blame] | 1062 | * @param[in,out] restrs Restrictions to add to. |
David Sedlák | bc9ec9c | 2019-07-11 15:53:55 +0200 | [diff] [blame] | 1063 | * @return LY_ERR values. |
| 1064 | */ |
| 1065 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1066 | yin_parse_must(struct lysp_yin_ctx *ctx, struct lysp_restr **restrs) |
David Sedlák | bc9ec9c | 2019-07-11 15:53:55 +0200 | [diff] [blame] | 1067 | { |
| 1068 | struct lysp_restr *restr; |
| 1069 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1070 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *restrs, restr, LY_EMEM); |
| 1071 | return yin_parse_restriction(ctx, LY_STMT_MUST, restr); |
David Sedlák | bc9ec9c | 2019-07-11 15:53:55 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | /** |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1075 | * @brief Parse a node id into an array. |
| 1076 | * |
| 1077 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1078 | * @param[in] parent_stmt Type of parent statement. |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1079 | * @param[in] subinfo Information about subelement, is used to determin which function should be called and where to store parsed value. |
| 1080 | * @param[in,out] exts Extension instances to add to. |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1081 | * @return LY_ERR values. |
| 1082 | */ |
| 1083 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1084 | yin_parse_qname(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, struct yin_subelement *subinfo, |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1085 | struct lysp_ext_instance **exts) |
| 1086 | { |
| 1087 | struct lysp_qname *qname, **qnames; |
| 1088 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1089 | switch (parent_stmt) { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1090 | case LY_STMT_DEFAULT: |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1091 | if (subinfo->flags & YIN_SUBELEM_UNIQUE) { |
| 1092 | qname = (struct lysp_qname *)subinfo->dest; |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1093 | } else { |
| 1094 | qnames = (struct lysp_qname **)subinfo->dest; |
| 1095 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *qnames, qname, LY_EMEM); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1096 | } |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1097 | qname->mod = PARSER_CUR_PMOD(ctx); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1098 | return yin_parse_simple_element(ctx, qname, parent_stmt, &qname->str, YIN_ARG_VALUE, Y_STR_ARG, exts); |
Radek Iša | be8a653 | 2021-03-29 08:54:22 +0200 | [diff] [blame] | 1099 | case LY_STMT_UNIQUE: |
| 1100 | assert(!(subinfo->flags & YIN_SUBELEM_UNIQUE)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1101 | |
Radek Iša | be8a653 | 2021-03-29 08:54:22 +0200 | [diff] [blame] | 1102 | qnames = (struct lysp_qname **)subinfo->dest; |
| 1103 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *qnames, qname, LY_EMEM); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1104 | qname->mod = PARSER_CUR_PMOD(ctx); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1105 | return yin_parse_simple_element(ctx, *qnames, parent_stmt, &qname->str, YIN_ARG_TAG, Y_STR_ARG, exts); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1106 | case LY_STMT_IF_FEATURE: |
| 1107 | assert(!(subinfo->flags & YIN_SUBELEM_UNIQUE)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1108 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1109 | qnames = (struct lysp_qname **)subinfo->dest; |
| 1110 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *qnames, qname, LY_EMEM); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1111 | qname->mod = PARSER_CUR_PMOD(ctx); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1112 | return yin_parse_simple_element(ctx, *qnames, parent_stmt, &qname->str, YIN_ARG_NAME, Y_STR_ARG, exts); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1113 | default: |
| 1114 | break; |
| 1115 | } |
| 1116 | |
| 1117 | LOGINT(ctx->xmlctx->ctx); |
| 1118 | return LY_EINT; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1122 | * @brief Parse position or value element. |
| 1123 | * |
| 1124 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1125 | * @param[in] parent_stmt Type of parent statement. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1126 | * @param[out] enm Enum structure to save value, flags and extension instances. |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1127 | * @return LY_ERR values. |
| 1128 | */ |
| 1129 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1130 | yin_parse_value_pos(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, struct lysp_type_enum *enm) |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1131 | { |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1132 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1133 | const char *temp_val = NULL; |
| 1134 | char *ptr; |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 1135 | long long num = 0; |
| 1136 | unsigned long long unum = 0; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1137 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1138 | assert(parent_stmt == LY_STMT_POSITION || parent_stmt == LY_STMT_VALUE); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1139 | |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1140 | /* set value flag */ |
| 1141 | enm->flags |= LYS_SET_VALUE; |
| 1142 | |
| 1143 | /* get attribute value */ |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1144 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1145 | LY_CHECK_GOTO(ret = yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, parent_stmt), cleanup); |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1146 | if (!temp_val || (temp_val[0] == '\0') || (temp_val[0] == '+') || |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1147 | ((temp_val[0] == '0') && (temp_val[1] != '\0')) || ((parent_stmt == LY_STMT_POSITION) && !strcmp(temp_val, "-0"))) { |
| 1148 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1149 | ret = LY_EVALID; |
| 1150 | goto cleanup; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | /* convert value */ |
| 1154 | errno = 0; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1155 | if (parent_stmt == LY_STMT_VALUE) { |
Michal Vasko | 73d77ab | 2021-07-23 12:45:55 +0200 | [diff] [blame] | 1156 | num = strtoll(temp_val, &ptr, LY_BASE_DEC); |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1157 | if ((num < INT64_C(-2147483648)) || (num > INT64_C(2147483647))) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1158 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1159 | ret = LY_EVALID; |
| 1160 | goto cleanup; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1161 | } |
| 1162 | } else { |
Michal Vasko | 73d77ab | 2021-07-23 12:45:55 +0200 | [diff] [blame] | 1163 | unum = strtoull(temp_val, &ptr, LY_BASE_DEC); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1164 | if (unum > UINT64_C(4294967295)) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1165 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1166 | ret = LY_EVALID; |
| 1167 | goto cleanup; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | /* check if whole argument value was converted */ |
| 1171 | if (*ptr != '\0') { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1172 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1173 | ret = LY_EVALID; |
| 1174 | goto cleanup; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1175 | } |
| 1176 | if (errno == ERANGE) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1177 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_OOB_YIN, temp_val, "value", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1178 | ret = LY_EVALID; |
| 1179 | goto cleanup; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1180 | } |
| 1181 | /* save correctly ternary operator can't be used because num and unum have different signes */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1182 | if (parent_stmt == LY_STMT_VALUE) { |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1183 | enm->value = num; |
| 1184 | } else { |
| 1185 | enm->value = unum; |
| 1186 | } |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1187 | |
| 1188 | /* parse subelements */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1189 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1190 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1191 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1192 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1193 | LY_CHECK_GOTO(ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), enm, parent_stmt, NULL, &enm->exts), cleanup); |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1194 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1195 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1196 | LY_CHECK_GOTO(ret = yin_unres_exts_add(ctx, enm->exts), cleanup); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1197 | |
| 1198 | cleanup: |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1199 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1200 | return ret; |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1201 | } |
| 1202 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1203 | /** |
| 1204 | * @brief Parse belongs-to element. |
| 1205 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1206 | * @param[in] ctx YIN parser context for logging and to store current state. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1207 | * @param[out] submod Structure of submodule that is being parsed. |
| 1208 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1209 | * @return LY_ERR values |
| 1210 | */ |
| 1211 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1212 | yin_parse_belongs_to(struct lysp_yin_ctx *ctx, struct lysp_submodule *submod, struct lysp_ext_instance **exts) |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1213 | { |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 1214 | const char *belongsto; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1215 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1216 | {LY_STMT_PREFIX, &submod->prefix, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}, |
| 1217 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1218 | }; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1219 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1220 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 1221 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_MODULE, &belongsto, Y_IDENTIF_ARG, LY_STMT_BELONGS_TO)); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1222 | if (PARSER_CUR_PMOD(ctx)->mod->name != belongsto) { |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 1223 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YIN, "Submodule \"belongs-to\" value \"%s\" does not match its module name \"%s\".", |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1224 | belongsto, PARSER_CUR_PMOD(ctx)->mod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 1225 | lydict_remove(ctx->xmlctx->ctx, belongsto); |
| 1226 | return LY_EVALID; |
| 1227 | } |
| 1228 | lydict_remove(ctx->xmlctx->ctx, belongsto); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1229 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1230 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), submod, LY_STMT_BELONGS_TO, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1231 | |
| 1232 | return LY_SUCCESS; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
David Sedlák | 5545f5d | 2019-07-11 11:55:16 +0200 | [diff] [blame] | 1235 | /** |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1236 | * @brief Function to parse meta tags (description, contact, ...) eg. elements with |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1237 | * text element as child. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1238 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1239 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1240 | * @param[in] parent Current statement parent. |
| 1241 | * @param[in] parent_stmt Type of @p parent statement. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1242 | * @param[out] value Where the content of meta element should be stored. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1243 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1244 | * @return LY_ERR values. |
| 1245 | */ |
| 1246 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1247 | yin_parse_meta(struct lysp_yin_ctx *ctx, const void *parent, enum ly_stmt parent_stmt, const char **value, |
| 1248 | struct lysp_ext_instance **exts) |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1249 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1250 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1251 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1252 | {LY_STMT_ARG_TEXT, value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE | YIN_SUBELEM_FIRST} |
| 1253 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1254 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1255 | assert(parent_stmt == LY_STMT_ORGANIZATION || parent_stmt == LY_STMT_CONTACT || parent_stmt == LY_STMT_DESCRIPTION || |
| 1256 | parent_stmt == LY_STMT_REFERENCE); |
| 1257 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1258 | /* check attributes */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1259 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1260 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, parent_stmt)); |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1261 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1262 | /* parse content */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1263 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, parent_stmt, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1264 | |
| 1265 | return LY_SUCCESS; |
David Sedlák | b4e4456 | 2019-07-04 15:42:12 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /** |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1269 | * @brief Parse error-message element. |
| 1270 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1271 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1272 | * @param[in] parent Current statement parent. |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1273 | * @param[out] value Where the content of error-message element should be stored. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1274 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1275 | * @return LY_ERR values. |
| 1276 | */ |
| 1277 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1278 | yin_parse_err_msg(struct lysp_yin_ctx *ctx, const void *parent, const char **value, struct lysp_ext_instance **exts) |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1279 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1280 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1281 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1282 | {LY_STMT_ARG_VALUE, value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE | YIN_SUBELEM_FIRST} |
| 1283 | }; |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1284 | |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1285 | /* check attributes */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1286 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1287 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, LY_STMT_ERROR_MESSAGE)); |
David Sedlák | df2a973 | 2019-08-07 13:23:16 +0200 | [diff] [blame] | 1288 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1289 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_ERROR_MESSAGE, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1290 | |
| 1291 | return LY_SUCCESS; |
David Sedlák | c1771b1 | 2019-07-10 15:55:46 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /** |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1295 | * @brief Parse type element. |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1296 | * |
| 1297 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1298 | * @param[in] parent_stmt Type of parent statement. |
| 1299 | * @param[in,out] subinfo Information about subelement, is used to determin which function should be called and where |
| 1300 | * to store parsed value. |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1301 | * @return LY_ERR values. |
| 1302 | */ |
| 1303 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1304 | yin_parse_type(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, struct yin_subelement *subinfo) |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1305 | { |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1306 | struct lysp_type *type = NULL; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1307 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1308 | if (parent_stmt == LY_STMT_DEVIATE) { |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1309 | *(struct lysp_type **)subinfo->dest = calloc(1, sizeof **(struct lysp_type **)subinfo->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1310 | LY_CHECK_ERR_RET(!(*(struct lysp_type **)subinfo->dest), LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1311 | type = *((struct lysp_type **)subinfo->dest); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1312 | } else { |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1313 | type = (struct lysp_type *)subinfo->dest; |
| 1314 | } |
Michal Vasko | e9c050f | 2020-10-06 14:01:23 +0200 | [diff] [blame] | 1315 | |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1316 | /* type as child of another type */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1317 | if (parent_stmt == LY_STMT_TYPE) { |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1318 | struct lysp_type *nested_type = NULL; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1319 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1320 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, type->types, nested_type, LY_EMEM); |
David Sedlák | 6542aed | 2019-08-14 10:47:43 +0200 | [diff] [blame] | 1321 | type->flags |= LYS_SET_TYPE; |
| 1322 | type = nested_type; |
| 1323 | } |
Michal Vasko | e9c050f | 2020-10-06 14:01:23 +0200 | [diff] [blame] | 1324 | |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1325 | type->pmod = PARSER_CUR_PMOD(ctx); |
Michal Vasko | 5bbcc24 | 2021-02-23 09:29:13 +0100 | [diff] [blame] | 1326 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1327 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1328 | {LY_STMT_BASE, type, 0}, |
| 1329 | {LY_STMT_BIT, type, 0}, |
| 1330 | {LY_STMT_ENUM, type, 0}, |
| 1331 | {LY_STMT_FRACTION_DIGITS, type, YIN_SUBELEM_UNIQUE}, |
| 1332 | {LY_STMT_LENGTH, type, YIN_SUBELEM_UNIQUE}, |
| 1333 | {LY_STMT_PATH, type, YIN_SUBELEM_UNIQUE}, |
| 1334 | {LY_STMT_PATTERN, type, 0}, |
| 1335 | {LY_STMT_RANGE, type, YIN_SUBELEM_UNIQUE}, |
| 1336 | {LY_STMT_REQUIRE_INSTANCE, type, YIN_SUBELEM_UNIQUE}, |
Michal Vasko | 608b0c0 | 2021-09-23 08:26:53 +0200 | [diff] [blame] | 1337 | {LY_STMT_TYPE, type, 0}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1338 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1339 | }; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1340 | |
| 1341 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1342 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &type->name, Y_PREF_IDENTIF_ARG, LY_STMT_TYPE)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1343 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), type, LY_STMT_TYPE, NULL, &type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1344 | |
| 1345 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1346 | LY_CHECK_RET(yin_unres_exts_add(ctx, type->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1347 | |
| 1348 | return LY_SUCCESS; |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1351 | /** |
| 1352 | * @brief Parse max-elements element. |
| 1353 | * |
| 1354 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1355 | * @param[in,out] max Value to write to. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1356 | * @param[in] flags Flags to write to. |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1357 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1358 | * @return LY_ERR values. |
| 1359 | */ |
| 1360 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1361 | yin_parse_maxelements(struct lysp_yin_ctx *ctx, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1362 | { |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1363 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1364 | const char *temp_val = NULL; |
| 1365 | char *ptr; |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 1366 | unsigned long long num; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1367 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1368 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1369 | }; |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1370 | |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1371 | *flags |= LYS_SET_MAX; |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1372 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 1373 | LY_CHECK_GOTO(ret = yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_MAX_ELEMENTS), cleanup); |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1374 | if (!temp_val || (temp_val[0] == '\0') || (temp_val[0] == '0') || ((temp_val[0] != 'u') && !isdigit(temp_val[0]))) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1375 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "max-elements"); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1376 | ret = LY_EVALID; |
| 1377 | goto cleanup; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | if (strcmp(temp_val, "unbounded")) { |
| 1381 | errno = 0; |
Michal Vasko | 73d77ab | 2021-07-23 12:45:55 +0200 | [diff] [blame] | 1382 | num = strtoull(temp_val, &ptr, LY_BASE_DEC); |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1383 | if (*ptr != '\0') { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1384 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "max-elements"); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1385 | ret = LY_EVALID; |
| 1386 | goto cleanup; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1387 | } |
| 1388 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1389 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_OOB_YIN, temp_val, "value", "max-elements"); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1390 | ret = LY_EVALID; |
| 1391 | goto cleanup; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1392 | } |
| 1393 | *max = num; |
| 1394 | } |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1395 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1396 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), max, LY_STMT_MAX_ELEMENTS, NULL, exts); |
| 1397 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1398 | |
| 1399 | cleanup: |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1400 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1401 | return ret; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 1402 | } |
David Sedlák | 374d2b3 | 2019-07-17 15:06:55 +0200 | [diff] [blame] | 1403 | |
| 1404 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1405 | * @brief Parse min-elements element. |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1406 | * |
| 1407 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1408 | * @param[in,out] min Value to write to. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1409 | * @param[in] flags Flags to write to. |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1410 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1411 | * @return LY_ERR values. |
| 1412 | */ |
| 1413 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1414 | yin_parse_minelements(struct lysp_yin_ctx *ctx, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1415 | { |
| 1416 | const char *temp_val = NULL; |
| 1417 | char *ptr; |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 1418 | unsigned long long num; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1419 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1420 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1421 | }; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1422 | |
| 1423 | *flags |= LYS_SET_MIN; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1424 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1425 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_MIN_ELEMENTS)); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1426 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1427 | if (!temp_val || (temp_val[0] == '\0') || ((temp_val[0] == '0') && (temp_val[1] != '\0'))) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1428 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "min-elements"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1429 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1430 | return LY_EVALID; |
| 1431 | } |
| 1432 | |
| 1433 | errno = 0; |
Michal Vasko | 73d77ab | 2021-07-23 12:45:55 +0200 | [diff] [blame] | 1434 | num = strtoull(temp_val, &ptr, LY_BASE_DEC); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1435 | if (ptr[0] != 0) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1436 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN, temp_val, "value", "min-elements"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1437 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1438 | return LY_EVALID; |
| 1439 | } |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1440 | if ((errno == ERANGE) || (num > UINT32_MAX)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1441 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_OOB_YIN, temp_val, "value", "min-elements"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1442 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1443 | return LY_EVALID; |
| 1444 | } |
| 1445 | *min = num; |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1446 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1447 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), min, LY_STMT_MIN_ELEMENTS, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1448 | |
| 1449 | return LY_SUCCESS; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1452 | /** |
| 1453 | * @brief Parse min-elements or max-elements element. |
| 1454 | * |
| 1455 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1456 | * @param[in] parent_stmt Type of parent statement. |
| 1457 | * @param[in] cur_stmt Type of current element. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1458 | * @param[in] dest Where the parsed value and flags should be stored. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1459 | * @return LY_ERR values. |
| 1460 | */ |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1461 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1462 | yin_parse_minmax(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, enum ly_stmt cur_stmt, void *dest) |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1463 | { |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1464 | uint32_t *lim; |
| 1465 | uint16_t *flags; |
| 1466 | struct lysp_ext_instance **exts; |
| 1467 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1468 | assert(cur_stmt == LY_STMT_MAX_ELEMENTS || cur_stmt == LY_STMT_MIN_ELEMENTS); |
| 1469 | assert(parent_stmt == LY_STMT_LEAF_LIST || parent_stmt == LY_STMT_REFINE || parent_stmt == LY_STMT_LIST || |
| 1470 | parent_stmt == LY_STMT_DEVIATE); |
| 1471 | |
| 1472 | if (parent_stmt == LY_STMT_LEAF_LIST) { |
| 1473 | lim = (cur_stmt == LY_STMT_MAX_ELEMENTS) ? &((struct lysp_node_leaflist *)dest)->max : &((struct lysp_node_leaflist *)dest)->min; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1474 | flags = &((struct lysp_node_leaflist *)dest)->flags; |
| 1475 | exts = &((struct lysp_node_leaflist *)dest)->exts; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1476 | } else if (parent_stmt == LY_STMT_REFINE) { |
| 1477 | lim = (cur_stmt == LY_STMT_MAX_ELEMENTS) ? &((struct lysp_refine *)dest)->max : &((struct lysp_refine *)dest)->min; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1478 | flags = &((struct lysp_refine *)dest)->flags; |
| 1479 | exts = &((struct lysp_refine *)dest)->exts; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1480 | } else if (parent_stmt == LY_STMT_LIST) { |
| 1481 | lim = (cur_stmt == LY_STMT_MAX_ELEMENTS) ? &((struct lysp_node_list *)dest)->max : &((struct lysp_node_list *)dest)->min; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1482 | flags = &((struct lysp_node_list *)dest)->flags; |
| 1483 | exts = &((struct lysp_node_list *)dest)->exts; |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 1484 | } else { |
| 1485 | lim = ((struct minmax_dev_meta *)dest)->lim; |
| 1486 | flags = ((struct minmax_dev_meta *)dest)->flags; |
| 1487 | exts = ((struct minmax_dev_meta *)dest)->exts; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1488 | } |
| 1489 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1490 | if (cur_stmt == LY_STMT_MAX_ELEMENTS) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1491 | LY_CHECK_RET(yin_parse_maxelements(ctx, lim, flags, exts)); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1492 | } else { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1493 | LY_CHECK_RET(yin_parse_minelements(ctx, lim, flags, exts)); |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | return LY_SUCCESS; |
| 1497 | } |
| 1498 | |
| 1499 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1500 | * @brief Parse ordered-by element. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1501 | * |
| 1502 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1503 | * @param[in] parent Current statement parent. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1504 | * @param[out] flags Flags to write to. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1505 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1506 | * @return LY_ERR values. |
| 1507 | */ |
| 1508 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1509 | yin_parse_orderedby(struct lysp_yin_ctx *ctx, const void *parent, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1510 | { |
| 1511 | const char *temp_val; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1512 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1513 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1514 | }; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1515 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1516 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1517 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_ORDERED_BY)); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1518 | if (strcmp(temp_val, "system") == 0) { |
| 1519 | *flags |= LYS_ORDBY_SYSTEM; |
| 1520 | } else if (strcmp(temp_val, "user") == 0) { |
| 1521 | *flags |= LYS_ORDBY_USER; |
| 1522 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1523 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_val, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1524 | "ordered-by", "system", "user"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1525 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1526 | return LY_EVALID; |
| 1527 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1528 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1529 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1530 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_ORDERED_BY, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1531 | |
| 1532 | return LY_SUCCESS; |
David Sedlák | a2dad21 | 2019-07-18 12:45:19 +0200 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1536 | * @brief Parse any-data or any-xml element. |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1537 | * |
| 1538 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1539 | * @param[in] any_stmt Type of current statement, can be set to LY_STMT_ANYDATA or LY_STMT_ANYXML |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 1540 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1541 | * @return LY_ERR values. |
| 1542 | */ |
| 1543 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1544 | yin_parse_any(struct lysp_yin_ctx *ctx, enum ly_stmt any_kw, struct tree_node_meta *node_meta) |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1545 | { |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1546 | struct lysp_node_anydata *any; |
| 1547 | |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1548 | /* create new sibling */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1549 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, any, next, LY_EMEM); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 1550 | any->nodetype = (any_kw == LY_STMT_ANYDATA) ? LYS_ANYDATA : LYS_ANYXML; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1551 | any->parent = node_meta->parent; |
| 1552 | |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1553 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1554 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1555 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &any->name, Y_IDENTIF_ARG, any_kw)); |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1556 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1557 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1558 | {LY_STMT_CONFIG, &any->flags, YIN_SUBELEM_UNIQUE}, |
| 1559 | {LY_STMT_DESCRIPTION, &any->dsc, YIN_SUBELEM_UNIQUE}, |
| 1560 | {LY_STMT_IF_FEATURE, &any->iffeatures, 0}, |
| 1561 | {LY_STMT_MANDATORY, &any->flags, YIN_SUBELEM_UNIQUE}, |
| 1562 | {LY_STMT_MUST, &any->musts, 0}, |
| 1563 | {LY_STMT_REFERENCE, &any->ref, YIN_SUBELEM_UNIQUE}, |
| 1564 | {LY_STMT_STATUS, &any->flags, YIN_SUBELEM_UNIQUE}, |
| 1565 | {LY_STMT_WHEN, &any->when, YIN_SUBELEM_UNIQUE}, |
| 1566 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1567 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1568 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1569 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), any, any_kw, NULL, &any->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1570 | |
| 1571 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1572 | LY_CHECK_RET(yin_unres_exts_add(ctx, any->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1573 | |
| 1574 | return LY_SUCCESS; |
David Sedlák | 8a83bbb | 2019-07-18 14:46:00 +0200 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | /** |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1578 | * @brief parse leaf element. |
| 1579 | * |
| 1580 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 1581 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1582 | * @return LY_ERR values. |
| 1583 | */ |
| 1584 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1585 | yin_parse_leaf(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1586 | { |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1587 | struct lysp_node_leaf *leaf; |
| 1588 | |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1589 | /* create structure new leaf */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1590 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, leaf, next, LY_EMEM); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1591 | leaf->nodetype = LYS_LEAF; |
| 1592 | leaf->parent = node_meta->parent; |
| 1593 | |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1594 | /* parser argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1595 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1596 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &leaf->name, Y_IDENTIF_ARG, LY_STMT_LEAF)); |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1597 | |
| 1598 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1599 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1600 | {LY_STMT_CONFIG, &leaf->flags, YIN_SUBELEM_UNIQUE}, |
| 1601 | {LY_STMT_DEFAULT, &leaf->dflt, YIN_SUBELEM_UNIQUE}, |
| 1602 | {LY_STMT_DESCRIPTION, &leaf->dsc, YIN_SUBELEM_UNIQUE}, |
| 1603 | {LY_STMT_IF_FEATURE, &leaf->iffeatures, 0}, |
| 1604 | {LY_STMT_MANDATORY, &leaf->flags, YIN_SUBELEM_UNIQUE}, |
| 1605 | {LY_STMT_MUST, &leaf->musts, 0}, |
| 1606 | {LY_STMT_REFERENCE, &leaf->ref, YIN_SUBELEM_UNIQUE}, |
| 1607 | {LY_STMT_STATUS, &leaf->flags, YIN_SUBELEM_UNIQUE}, |
| 1608 | {LY_STMT_TYPE, &leaf->type, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_MANDATORY}, |
| 1609 | {LY_STMT_UNITS, &leaf->units, YIN_SUBELEM_UNIQUE}, |
| 1610 | {LY_STMT_WHEN, &leaf->when, YIN_SUBELEM_UNIQUE}, |
| 1611 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1612 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1613 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1614 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), leaf, LY_STMT_LEAF, NULL, &leaf->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1615 | |
| 1616 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1617 | LY_CHECK_RET(yin_unres_exts_add(ctx, leaf->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1618 | |
| 1619 | return LY_SUCCESS; |
David Sedlák | 203ca3a | 2019-07-18 15:26:25 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | /** |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1623 | * @brief Parse leaf-list element. |
| 1624 | * |
| 1625 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 1626 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1627 | * @return LY_ERR values. |
| 1628 | */ |
| 1629 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1630 | yin_parse_leaflist(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1631 | { |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1632 | struct lysp_node_leaflist *llist; |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1633 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1634 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, llist, next, LY_EMEM); |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1635 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1636 | llist->nodetype = LYS_LEAFLIST; |
| 1637 | llist->parent = node_meta->parent; |
| 1638 | |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1639 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1640 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1641 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &llist->name, Y_IDENTIF_ARG, LY_STMT_LEAF_LIST)); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1642 | |
| 1643 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1644 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1645 | {LY_STMT_CONFIG, &llist->flags, YIN_SUBELEM_UNIQUE}, |
| 1646 | {LY_STMT_DEFAULT, &llist->dflts, 0}, |
| 1647 | {LY_STMT_DESCRIPTION, &llist->dsc, YIN_SUBELEM_UNIQUE}, |
| 1648 | {LY_STMT_IF_FEATURE, &llist->iffeatures, 0}, |
| 1649 | {LY_STMT_MAX_ELEMENTS, llist, YIN_SUBELEM_UNIQUE}, |
| 1650 | {LY_STMT_MIN_ELEMENTS, llist, YIN_SUBELEM_UNIQUE}, |
| 1651 | {LY_STMT_MUST, &llist->musts, 0}, |
| 1652 | {LY_STMT_ORDERED_BY, &llist->flags, YIN_SUBELEM_UNIQUE}, |
| 1653 | {LY_STMT_REFERENCE, &llist->ref, YIN_SUBELEM_UNIQUE}, |
| 1654 | {LY_STMT_STATUS, &llist->flags, YIN_SUBELEM_UNIQUE}, |
| 1655 | {LY_STMT_TYPE, &llist->type, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_MANDATORY}, |
| 1656 | {LY_STMT_UNITS, &llist->units, YIN_SUBELEM_UNIQUE}, |
| 1657 | {LY_STMT_WHEN, &llist->when, YIN_SUBELEM_UNIQUE}, |
| 1658 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1659 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1660 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1661 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), llist, LY_STMT_LEAF_LIST, NULL, &llist->exts)); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1662 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1663 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1664 | LY_CHECK_RET(yin_unres_exts_add(ctx, llist->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1665 | |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1666 | /* check invalid combination of subelements */ |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1667 | if ((llist->min) && (llist->dflts)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1668 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INCHILDSTMSCOMB_YIN, "min-elements", "default", "leaf-list"); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1669 | return LY_EVALID; |
| 1670 | } |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1671 | if (llist->max && (llist->min > llist->max)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1672 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_MINMAX, llist->min, llist->max); |
David Sedlák | c3da3ef | 2019-07-19 12:56:08 +0200 | [diff] [blame] | 1673 | return LY_EVALID; |
| 1674 | } |
| 1675 | |
| 1676 | return LY_SUCCESS; |
| 1677 | } |
| 1678 | |
| 1679 | /** |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1680 | * @brief Parse typedef element. |
| 1681 | * |
| 1682 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 1683 | * @param[in] typedef_meta Meta information about parent node and typedefs to add to. |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1684 | * @return LY_ERR values. |
| 1685 | */ |
| 1686 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1687 | yin_parse_typedef(struct lysp_yin_ctx *ctx, struct tree_node_meta *typedef_meta) |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1688 | { |
| 1689 | struct lysp_tpdf *tpdf; |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1690 | struct lysp_tpdf **tpdfs = (struct lysp_tpdf **)typedef_meta->nodes; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1691 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1692 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *tpdfs, tpdf, LY_EMEM); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1693 | |
| 1694 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1695 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1696 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &tpdf->name, Y_IDENTIF_ARG, LY_STMT_TYPEDEF)); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1697 | |
| 1698 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1699 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1700 | {LY_STMT_DEFAULT, &tpdf->dflt, YIN_SUBELEM_UNIQUE}, |
| 1701 | {LY_STMT_DESCRIPTION, &tpdf->dsc, YIN_SUBELEM_UNIQUE}, |
| 1702 | {LY_STMT_REFERENCE, &tpdf->ref, YIN_SUBELEM_UNIQUE}, |
| 1703 | {LY_STMT_STATUS, &tpdf->flags, YIN_SUBELEM_UNIQUE}, |
| 1704 | {LY_STMT_TYPE, &tpdf->type, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_MANDATORY}, |
| 1705 | {LY_STMT_UNITS, &tpdf->units, YIN_SUBELEM_UNIQUE}, |
| 1706 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1707 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1708 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1709 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), tpdf, LY_STMT_TYPEDEF, NULL, &tpdf->exts)); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1710 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1711 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1712 | LY_CHECK_RET(yin_unres_exts_add(ctx, tpdf->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1713 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1714 | /* store data for collision check */ |
aPiecek | 75b83a0 | 2021-06-29 10:34:38 +0200 | [diff] [blame] | 1715 | if (typedef_meta->parent) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1716 | assert(ctx->main_ctx); |
| 1717 | LY_CHECK_RET(ly_set_add(&ctx->main_ctx->tpdfs_nodes, typedef_meta->parent, 0, NULL)); |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | return LY_SUCCESS; |
| 1721 | } |
| 1722 | |
| 1723 | /** |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1724 | * @brief Parse refine element. |
| 1725 | * |
| 1726 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1727 | * @param[in,out] refines Refines to add to. |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1728 | * @return LY_ERR values. |
| 1729 | */ |
| 1730 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1731 | yin_parse_refine(struct lysp_yin_ctx *ctx, struct lysp_refine **refines) |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1732 | { |
| 1733 | struct lysp_refine *rf; |
| 1734 | |
| 1735 | /* allocate new refine */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1736 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *refines, rf, LY_EMEM); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1737 | |
| 1738 | /* parse attribute */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1739 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1740 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_TARGET_NODE, &rf->nodeid, Y_STR_ARG, LY_STMT_REFINE)); |
| 1741 | CHECK_NONEMPTY(ctx, strlen(rf->nodeid), "refine"); |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1742 | |
| 1743 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1744 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1745 | {LY_STMT_CONFIG, &rf->flags, YIN_SUBELEM_UNIQUE}, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1746 | {LY_STMT_DEFAULT, &rf->dflts, 0}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1747 | {LY_STMT_DESCRIPTION, &rf->dsc, YIN_SUBELEM_UNIQUE}, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 1748 | {LY_STMT_IF_FEATURE, &rf->iffeatures, 0}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1749 | {LY_STMT_MANDATORY, &rf->flags, YIN_SUBELEM_UNIQUE}, |
| 1750 | {LY_STMT_MAX_ELEMENTS, rf, YIN_SUBELEM_UNIQUE}, |
| 1751 | {LY_STMT_MIN_ELEMENTS, rf, YIN_SUBELEM_UNIQUE}, |
| 1752 | {LY_STMT_MUST, &rf->musts, 0}, |
| 1753 | {LY_STMT_PRESENCE, &rf->presence, YIN_SUBELEM_UNIQUE}, |
| 1754 | {LY_STMT_REFERENCE, &rf->ref, YIN_SUBELEM_UNIQUE}, |
| 1755 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1756 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1757 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1758 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), rf, LY_STMT_REFINE, NULL, &rf->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1759 | |
| 1760 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1761 | LY_CHECK_RET(yin_unres_exts_add(ctx, rf->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1762 | |
| 1763 | return LY_SUCCESS; |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | /** |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1767 | * @brief Parse uses element. |
| 1768 | * |
| 1769 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 1770 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1771 | * @return LY_ERR values. |
| 1772 | */ |
| 1773 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1774 | yin_parse_uses(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1775 | { |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1776 | struct lysp_node_uses *uses; |
| 1777 | |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 1778 | /* create new uses */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1779 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, uses, next, LY_EMEM); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1780 | uses->nodetype = LYS_USES; |
| 1781 | uses->parent = node_meta->parent; |
| 1782 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1783 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1784 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1785 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &uses->name, Y_PREF_IDENTIF_ARG, LY_STMT_USES)); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1786 | |
| 1787 | /* parse content */ |
David Sedlák | 6881b51 | 2019-08-13 12:52:00 +0200 | [diff] [blame] | 1788 | struct tree_node_meta augments = {(struct lysp_node *)uses, (struct lysp_node **)&uses->augments}; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1789 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1790 | {LY_STMT_AUGMENT, &augments, 0}, |
| 1791 | {LY_STMT_DESCRIPTION, &uses->dsc, YIN_SUBELEM_UNIQUE}, |
| 1792 | {LY_STMT_IF_FEATURE, &uses->iffeatures, 0}, |
| 1793 | {LY_STMT_REFERENCE, &uses->ref, YIN_SUBELEM_UNIQUE}, |
| 1794 | {LY_STMT_REFINE, &uses->refines, 0}, |
| 1795 | {LY_STMT_STATUS, &uses->flags, YIN_SUBELEM_UNIQUE}, |
| 1796 | {LY_STMT_WHEN, &uses->when, YIN_SUBELEM_UNIQUE}, |
| 1797 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1798 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1799 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1800 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), uses, LY_STMT_USES, NULL, &uses->exts)); |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1801 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1802 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1803 | LY_CHECK_RET(yin_unres_exts_add(ctx, uses->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1804 | |
David Sedlák | 0d6de5a | 2019-07-22 13:25:44 +0200 | [diff] [blame] | 1805 | return LY_SUCCESS; |
| 1806 | } |
| 1807 | |
| 1808 | /** |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1809 | * @brief Parse revision element. |
| 1810 | * |
| 1811 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1812 | * @param[in,out] revs Parsed revisions to add to. |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1813 | * @return LY_ERR values. |
| 1814 | */ |
| 1815 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1816 | yin_parse_revision(struct lysp_yin_ctx *ctx, struct lysp_revision **revs) |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1817 | { |
| 1818 | struct lysp_revision *rev; |
| 1819 | const char *temp_date = NULL; |
| 1820 | |
| 1821 | /* allocate new reivison */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1822 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *revs, rev, LY_EMEM); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1823 | |
| 1824 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1825 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1826 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_DATE, &temp_date, Y_STR_ARG, LY_STMT_REVISION)); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1827 | /* check value */ |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1828 | if (lysp_check_date((struct lysp_ctx *)ctx, temp_date, strlen(temp_date), "revision")) { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1829 | lydict_remove(ctx->xmlctx->ctx, temp_date); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1830 | return LY_EVALID; |
| 1831 | } |
Radek Krejci | 3664216 | 2021-01-12 16:49:22 +0100 | [diff] [blame] | 1832 | memcpy(rev->date, temp_date, LY_REV_SIZE); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1833 | lydict_remove(ctx->xmlctx->ctx, temp_date); |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1834 | |
| 1835 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1836 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1837 | {LY_STMT_DESCRIPTION, &rev->dsc, YIN_SUBELEM_UNIQUE}, |
| 1838 | {LY_STMT_REFERENCE, &rev->ref, YIN_SUBELEM_UNIQUE}, |
| 1839 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1840 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1841 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1842 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), rev, LY_STMT_REVISION, NULL, &rev->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1843 | |
| 1844 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1845 | LY_CHECK_RET(yin_unres_exts_add(ctx, rev->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1846 | |
| 1847 | return LY_SUCCESS; |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1848 | } |
| 1849 | |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 1850 | /** |
| 1851 | * @brief Parse include element. |
| 1852 | * |
| 1853 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 1854 | * @param[in,out] inc_meta Meta informatinou about module/submodule name and includes to add to. |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 1855 | * @return LY_ERR values. |
| 1856 | */ |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1857 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1858 | yin_parse_include(struct lysp_yin_ctx *ctx, struct include_meta *inc_meta) |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1859 | { |
| 1860 | struct lysp_include *inc; |
| 1861 | |
| 1862 | /* allocate new include */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1863 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *inc_meta->includes, inc, LY_EMEM); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1864 | |
| 1865 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1866 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1867 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_MODULE, &inc->name, Y_IDENTIF_ARG, LY_STMT_INCLUDE)); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1868 | |
| 1869 | /* submodules share the namespace with the module names, so there must not be |
| 1870 | * a module of the same name in the context, no need for revision matching */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1871 | if (!strcmp(inc_meta->name, inc->name) || ly_ctx_get_module_latest(ctx->xmlctx->ctx, inc->name)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1872 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_NAME2_COL, "module", "submodule", inc->name); |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1873 | return LY_EVALID; |
| 1874 | } |
| 1875 | |
| 1876 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1877 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1878 | {LY_STMT_DESCRIPTION, &inc->dsc, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_VER2}, |
| 1879 | {LY_STMT_REFERENCE, &inc->ref, YIN_SUBELEM_UNIQUE | YIN_SUBELEM_VER2}, |
| 1880 | {LY_STMT_REVISION_DATE, &inc->rev, YIN_SUBELEM_UNIQUE}, |
| 1881 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 1882 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1883 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1884 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), inc, LY_STMT_INCLUDE, NULL, &inc->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1885 | |
| 1886 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 1887 | LY_CHECK_RET(yin_unres_exts_add(ctx, inc->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1888 | |
| 1889 | return LY_SUCCESS; |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 1890 | } |
| 1891 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 1892 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1893 | * @brief Parse revision-date element. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1894 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1895 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1896 | * @param[in,out] rev Array to store the parsed value in. |
| 1897 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1898 | * @return LY_ERR values. |
| 1899 | */ |
| 1900 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1901 | yin_parse_revision_date(struct lysp_yin_ctx *ctx, char *rev, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1902 | { |
| 1903 | const char *temp_rev; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1904 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1905 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1906 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1907 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1908 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1909 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_DATE, &temp_rev, Y_STR_ARG, LY_STMT_REVISION_DATE)); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1910 | LY_CHECK_ERR_RET(lysp_check_date((struct lysp_ctx *)ctx, temp_rev, strlen(temp_rev), "revision-date") != LY_SUCCESS, |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1911 | lydict_remove(ctx->xmlctx->ctx, temp_rev), LY_EVALID); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1912 | |
| 1913 | strcpy(rev, temp_rev); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1914 | lydict_remove(ctx->xmlctx->ctx, temp_rev); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1915 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1916 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), rev, LY_STMT_REVISION_DATE, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1917 | |
| 1918 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /** |
| 1922 | * @brief Parse config element. |
| 1923 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1924 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1925 | * @param[in,out] flags Flags to add to. |
| 1926 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1927 | * @return LY_ERR values. |
| 1928 | */ |
| 1929 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1930 | yin_parse_config(struct lysp_yin_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1931 | { |
| 1932 | const char *temp_val = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1933 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1934 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1935 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1936 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1937 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1938 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_CONFIG)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1939 | if (strcmp(temp_val, "true") == 0) { |
| 1940 | *flags |= LYS_CONFIG_W; |
| 1941 | } else if (strcmp(temp_val, "false") == 0) { |
| 1942 | *flags |= LYS_CONFIG_R; |
| 1943 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1944 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_val, "value", "config", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1945 | "true", "false"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1946 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1947 | return LY_EVALID; |
| 1948 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1949 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1950 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1951 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), flags, LY_STMT_CONFIG, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1952 | |
| 1953 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /** |
| 1957 | * @brief Parse yang-version element. |
| 1958 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1959 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1960 | * @param[in] parent Current statement parent. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1961 | * @param[out] version Storage for the parsed information. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1962 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1963 | * @return LY_ERR values. |
| 1964 | */ |
| 1965 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1966 | yin_parse_yangversion(struct lysp_yin_ctx *ctx, const void *parent, uint8_t *version, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1967 | { |
| 1968 | const char *temp_version = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 1969 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1970 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 1971 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1972 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1973 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 1974 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_version, Y_STR_ARG, LY_STMT_YANG_VERSION)); |
Radek Krejci | 96e48da | 2020-09-04 13:18:06 +0200 | [diff] [blame] | 1975 | if (strcmp(temp_version, "1") == 0) { |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1976 | *version = LYS_VERSION_1_0; |
| 1977 | } else if (strcmp(temp_version, "1.1") == 0) { |
| 1978 | *version = LYS_VERSION_1_1; |
| 1979 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1980 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_version, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 1981 | "yang-version", "1", "1.1"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1982 | lydict_remove(ctx->xmlctx->ctx, temp_version); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1983 | return LY_EVALID; |
| 1984 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1985 | lydict_remove(ctx->xmlctx->ctx, temp_version); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1986 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1987 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_YANG_VERSION, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1988 | |
| 1989 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | /** |
| 1993 | * @brief Parse import element. |
| 1994 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 1995 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1996 | * @param[in,out] imp_meta Meta information about prefix and imports to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 1997 | * @return LY_ERR values. |
| 1998 | */ |
| 1999 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2000 | yin_parse_import(struct lysp_yin_ctx *ctx, struct import_meta *imp_meta) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2001 | { |
| 2002 | struct lysp_import *imp; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2003 | |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2004 | /* allocate new element in sized array for import */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2005 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *imp_meta->imports, imp, LY_EMEM); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2006 | |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2007 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2008 | {LY_STMT_DESCRIPTION, &imp->dsc, YIN_SUBELEM_UNIQUE}, |
| 2009 | {LY_STMT_PREFIX, &imp->prefix, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}, |
| 2010 | {LY_STMT_REFERENCE, &imp->ref, YIN_SUBELEM_UNIQUE}, |
| 2011 | {LY_STMT_REVISION_DATE, imp->rev, YIN_SUBELEM_UNIQUE}, |
| 2012 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2013 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2014 | |
| 2015 | /* parse import attributes */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2016 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2017 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_MODULE, &imp->name, Y_IDENTIF_ARG, LY_STMT_IMPORT)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2018 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), imp, LY_STMT_IMPORT, NULL, &imp->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2019 | |
| 2020 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2021 | LY_CHECK_RET(yin_unres_exts_add(ctx, imp->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2022 | |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2023 | /* check prefix validity */ |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2024 | LY_CHECK_RET(lysp_check_prefix((struct lysp_ctx *)ctx, *imp_meta->imports, imp_meta->prefix, &imp->prefix), LY_EVALID); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2025 | |
| 2026 | return LY_SUCCESS; |
| 2027 | } |
| 2028 | |
| 2029 | /** |
| 2030 | * @brief Parse mandatory element. |
| 2031 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2032 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2033 | * @param[in,out] flags Flags to add to. |
| 2034 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2035 | * @return LY_ERR values. |
| 2036 | */ |
| 2037 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2038 | yin_parse_mandatory(struct lysp_yin_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2039 | { |
| 2040 | const char *temp_val = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2041 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2042 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2043 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2044 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2045 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2046 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_MANDATORY)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2047 | if (strcmp(temp_val, "true") == 0) { |
| 2048 | *flags |= LYS_MAND_TRUE; |
| 2049 | } else if (strcmp(temp_val, "false") == 0) { |
| 2050 | *flags |= LYS_MAND_FALSE; |
| 2051 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2052 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_val, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2053 | "mandatory", "true", "false"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2054 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2055 | return LY_EVALID; |
| 2056 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2057 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2058 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2059 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), flags, LY_STMT_MANDATORY, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2060 | |
| 2061 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | /** |
| 2065 | * @brief Parse status element. |
| 2066 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2067 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2068 | * @param[in,out] flags Flags to add to. |
| 2069 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2070 | * @return LY_ERR values. |
| 2071 | */ |
| 2072 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2073 | yin_parse_status(struct lysp_yin_ctx *ctx, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2074 | { |
| 2075 | const char *value = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2076 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2077 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2078 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2079 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2080 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2081 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &value, Y_STR_ARG, LY_STMT_STATUS)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2082 | if (strcmp(value, "current") == 0) { |
| 2083 | *flags |= LYS_STATUS_CURR; |
| 2084 | } else if (strcmp(value, "deprecated") == 0) { |
| 2085 | *flags |= LYS_STATUS_DEPRC; |
| 2086 | } else if (strcmp(value, "obsolete") == 0) { |
| 2087 | *flags |= LYS_STATUS_OBSLT; |
| 2088 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2089 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS3, value, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2090 | "status", "current", "deprecated", "obsolete"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2091 | lydict_remove(ctx->xmlctx->ctx, value); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2092 | return LY_EVALID; |
| 2093 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2094 | lydict_remove(ctx->xmlctx->ctx, value); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2095 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2096 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), flags, LY_STMT_STATUS, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2097 | |
| 2098 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * @brief Parse when element. |
| 2103 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2104 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2105 | * @param[out] when_p When pointer to parse to. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2106 | * @return LY_ERR values. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2107 | */ |
| 2108 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2109 | yin_parse_when(struct lysp_yin_ctx *ctx, struct lysp_when **when_p) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2110 | { |
| 2111 | struct lysp_when *when; |
David Sedlák | a56e001 | 2019-08-15 13:21:25 +0200 | [diff] [blame] | 2112 | LY_ERR ret = LY_SUCCESS; |
| 2113 | |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2114 | when = calloc(1, sizeof *when); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2115 | LY_CHECK_ERR_RET(!when, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
Radek Krejci | f6923e8 | 2020-07-02 16:36:53 +0200 | [diff] [blame] | 2116 | |
| 2117 | ret = lyxml_ctx_next(ctx->xmlctx); |
| 2118 | LY_CHECK_ERR_RET(ret, free(when), ret); |
| 2119 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2120 | ret = yin_parse_attribute(ctx, YIN_ARG_CONDITION, &when->cond, Y_STR_ARG, LY_STMT_WHEN); |
David Sedlák | a56e001 | 2019-08-15 13:21:25 +0200 | [diff] [blame] | 2121 | LY_CHECK_ERR_RET(ret, free(when), ret); |
| 2122 | |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2123 | *when_p = when; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2124 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2125 | {LY_STMT_DESCRIPTION, &when->dsc, YIN_SUBELEM_UNIQUE}, |
| 2126 | {LY_STMT_REFERENCE, &when->ref, YIN_SUBELEM_UNIQUE}, |
| 2127 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2128 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2129 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2130 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), when, LY_STMT_WHEN, NULL, &when->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2131 | |
| 2132 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2133 | LY_CHECK_RET(yin_unres_exts_add(ctx, when->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2134 | |
| 2135 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * @brief Parse yin-elemenet element. |
| 2140 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2141 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2142 | * @param[in] parent Current statement parent. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2143 | * @param[in,out] flags Flags to add to. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2144 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2145 | * @return LY_ERR values. |
| 2146 | */ |
| 2147 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2148 | yin_parse_yin_element(struct lysp_yin_ctx *ctx, const void *parent, uint16_t *flags, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2149 | { |
| 2150 | const char *temp_val = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2151 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2152 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2153 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2154 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2155 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2156 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_YIN_ELEMENT)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2157 | if (strcmp(temp_val, "true") == 0) { |
| 2158 | *flags |= LYS_YINELEM_TRUE; |
| 2159 | } else if (strcmp(temp_val, "false") == 0) { |
| 2160 | *flags |= LYS_YINELEM_FALSE; |
| 2161 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2162 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS2, temp_val, "value", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2163 | "yin-element", "true", "false"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2164 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2165 | return LY_EVALID; |
| 2166 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2167 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2168 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2169 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_YIN_ELEMENT, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2170 | |
| 2171 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * @brief Parse argument element. |
| 2176 | * |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2177 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
| 2178 | * @param[in] parent Current statement parent. |
| 2179 | * @param[in,out] arg_meta Meta information about destination of parsed data. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2180 | * @param[in,out] exts Extension instances to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2181 | * @return LY_ERR values. |
| 2182 | */ |
| 2183 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2184 | yin_parse_argument(struct lysp_yin_ctx *ctx, const void *parent, struct yin_argument_meta *arg_meta, struct lysp_ext_instance **exts) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2185 | { |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2186 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2187 | {LY_STMT_YIN_ELEMENT, arg_meta->flags, YIN_SUBELEM_UNIQUE}, |
| 2188 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2189 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2190 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2191 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2192 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, arg_meta->argument, Y_IDENTIF_ARG, LY_STMT_ARGUMENT)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2193 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2194 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), parent, LY_STMT_ARGUMENT, NULL, exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2195 | |
| 2196 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | /** |
| 2200 | * @brief Parse the extension statement. |
| 2201 | * |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2202 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2203 | * @param[in,out] extensions Extensions to add to. |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2204 | * @return LY_ERR values. |
| 2205 | */ |
| 2206 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2207 | yin_parse_extension(struct lysp_yin_ctx *ctx, struct lysp_ext **extensions) |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2208 | { |
| 2209 | struct lysp_ext *ex; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2210 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2211 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *extensions, ex, LY_EMEM); |
| 2212 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2213 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &ex->name, Y_IDENTIF_ARG, LY_STMT_EXTENSION)); |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2214 | |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 2215 | struct yin_argument_meta arg_info = {&ex->flags, &ex->argname}; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2216 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2217 | {LY_STMT_ARGUMENT, &arg_info, YIN_SUBELEM_UNIQUE}, |
| 2218 | {LY_STMT_DESCRIPTION, &ex->dsc, YIN_SUBELEM_UNIQUE}, |
| 2219 | {LY_STMT_REFERENCE, &ex->ref, YIN_SUBELEM_UNIQUE}, |
| 2220 | {LY_STMT_STATUS, &ex->flags, YIN_SUBELEM_UNIQUE}, |
| 2221 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2222 | }; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2223 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2224 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), ex, LY_STMT_EXTENSION, NULL, &ex->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2225 | |
| 2226 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2227 | LY_CHECK_RET(yin_unres_exts_add(ctx, ex->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2228 | |
| 2229 | return LY_SUCCESS; |
David Sedlák | dfbbb44 | 2019-08-06 16:33:21 +0200 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /** |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2233 | * @brief Parse feature element. |
| 2234 | * |
| 2235 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2236 | * @param[in,out] features Features to add to. |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2237 | * @return LY_ERR values. |
| 2238 | */ |
| 2239 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2240 | yin_parse_feature(struct lysp_yin_ctx *ctx, struct lysp_feature **features) |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2241 | { |
| 2242 | struct lysp_feature *feat; |
| 2243 | |
| 2244 | /* allocate new feature */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2245 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *features, feat, LY_EMEM); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2246 | |
| 2247 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2248 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2249 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &feat->name, Y_IDENTIF_ARG, LY_STMT_FEATURE)); |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2250 | |
| 2251 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2252 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2253 | {LY_STMT_DESCRIPTION, &feat->dsc, YIN_SUBELEM_UNIQUE}, |
| 2254 | {LY_STMT_IF_FEATURE, &feat->iffeatures, 0}, |
| 2255 | {LY_STMT_REFERENCE, &feat->ref, YIN_SUBELEM_UNIQUE}, |
| 2256 | {LY_STMT_STATUS, &feat->flags, YIN_SUBELEM_UNIQUE}, |
| 2257 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2258 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2259 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2260 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), feat, LY_STMT_FEATURE, NULL, &feat->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2261 | |
| 2262 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2263 | LY_CHECK_RET(yin_unres_exts_add(ctx, feat->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2264 | |
| 2265 | return LY_SUCCESS; |
David Sedlák | 5e13dea | 2019-07-22 16:06:45 +0200 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2269 | * @brief Parse identity element. |
| 2270 | * |
| 2271 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2272 | * @param[in,out] identities Identities to add to. |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2273 | * @return LY_ERR values. |
| 2274 | */ |
| 2275 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2276 | yin_parse_identity(struct lysp_yin_ctx *ctx, struct lysp_ident **identities) |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2277 | { |
| 2278 | struct lysp_ident *ident; |
| 2279 | |
| 2280 | /* allocate new identity */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2281 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *identities, ident, LY_EMEM); |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2282 | |
| 2283 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2284 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2285 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &ident->name, Y_IDENTIF_ARG, LY_STMT_IDENTITY)); |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2286 | |
| 2287 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2288 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2289 | {LY_STMT_BASE, &ident->bases, 0}, |
| 2290 | {LY_STMT_DESCRIPTION, &ident->dsc, YIN_SUBELEM_UNIQUE}, |
| 2291 | {LY_STMT_IF_FEATURE, &ident->iffeatures, YIN_SUBELEM_VER2}, |
| 2292 | {LY_STMT_REFERENCE, &ident->ref, YIN_SUBELEM_UNIQUE}, |
| 2293 | {LY_STMT_STATUS, &ident->flags, YIN_SUBELEM_UNIQUE}, |
| 2294 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2295 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2296 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2297 | LY_CHECK_RET(yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), ident, LY_STMT_IDENTITY, NULL, &ident->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2298 | |
| 2299 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2300 | LY_CHECK_RET(yin_unres_exts_add(ctx, ident->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2301 | |
| 2302 | return LY_SUCCESS; |
David Sedlák | 28794f2 | 2019-07-22 16:45:00 +0200 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | /** |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2306 | * @brief Parse list element. |
| 2307 | * |
| 2308 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 2309 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2310 | * @return LY_ERR values. |
| 2311 | */ |
| 2312 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2313 | yin_parse_list(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2314 | { |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2315 | struct lysp_node_list *list; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2316 | LY_ERR ret = LY_SUCCESS; |
| 2317 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2318 | size_t subelems_size; |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2319 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2320 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, list, next, LY_EMEM); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2321 | list->nodetype = LYS_LIST; |
| 2322 | list->parent = node_meta->parent; |
| 2323 | |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2324 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2325 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2326 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &list->name, Y_IDENTIF_ARG, LY_STMT_LIST)); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2327 | |
| 2328 | /* parse list content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2329 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 25, (struct lysp_node *)list, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2330 | LY_STMT_ACTION, &list->actions, 0, |
| 2331 | LY_STMT_ANYDATA, &list->child, 0, |
| 2332 | LY_STMT_ANYXML, &list->child, 0, |
| 2333 | LY_STMT_CHOICE, &list->child, 0, |
| 2334 | LY_STMT_CONFIG, &list->flags, YIN_SUBELEM_UNIQUE, |
| 2335 | LY_STMT_CONTAINER, &list->child, 0, |
| 2336 | LY_STMT_DESCRIPTION, &list->dsc, YIN_SUBELEM_UNIQUE, |
| 2337 | LY_STMT_GROUPING, &list->groupings, 0, |
| 2338 | LY_STMT_IF_FEATURE, &list->iffeatures, 0, |
| 2339 | LY_STMT_KEY, &list->key, YIN_SUBELEM_UNIQUE, |
| 2340 | LY_STMT_LEAF, &list->child, 0, |
| 2341 | LY_STMT_LEAF_LIST, &list->child, 0, |
| 2342 | LY_STMT_LIST, &list->child, 0, |
| 2343 | LY_STMT_MAX_ELEMENTS, list, YIN_SUBELEM_UNIQUE, |
| 2344 | LY_STMT_MIN_ELEMENTS, list, YIN_SUBELEM_UNIQUE, |
| 2345 | LY_STMT_MUST, &list->musts, 0, |
| 2346 | LY_STMT_NOTIFICATION, &list->notifs, 0, |
| 2347 | LY_STMT_ORDERED_BY, &list->flags, YIN_SUBELEM_UNIQUE, |
| 2348 | LY_STMT_REFERENCE, &list->ref, YIN_SUBELEM_UNIQUE, |
| 2349 | LY_STMT_STATUS, &list->flags, YIN_SUBELEM_UNIQUE, |
| 2350 | LY_STMT_TYPEDEF, &list->typedefs, 0, |
| 2351 | LY_STMT_UNIQUE, &list->uniques, 0, |
| 2352 | LY_STMT_USES, &list->child, 0, |
| 2353 | LY_STMT_WHEN, &list->when, YIN_SUBELEM_UNIQUE, |
| 2354 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2355 | ret = yin_parse_content(ctx, subelems, subelems_size, list, LY_STMT_LIST, NULL, &list->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2356 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2357 | LY_CHECK_RET(ret); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2358 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2359 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2360 | LY_CHECK_RET(yin_unres_exts_add(ctx, list->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2361 | |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2362 | if (list->max && (list->min > list->max)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2363 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_MINMAX, list->min, list->max); |
David Sedlák | af536aa | 2019-07-23 13:42:23 +0200 | [diff] [blame] | 2364 | return LY_EVALID; |
| 2365 | } |
| 2366 | |
| 2367 | return LY_SUCCESS; |
| 2368 | } |
| 2369 | |
| 2370 | /** |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2371 | * @brief Parse notification element. |
| 2372 | * |
| 2373 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2374 | * @param[in,out] notif_meta Meta information about parent node and notifications to add to. |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2375 | * @return LY_ERR values. |
| 2376 | */ |
| 2377 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2378 | yin_parse_notification(struct lysp_yin_ctx *ctx, struct tree_node_meta *notif_meta) |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2379 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2380 | struct lysp_node_notif *notif; |
| 2381 | struct lysp_node_notif **notifs = (struct lysp_node_notif **)notif_meta->nodes; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2382 | LY_ERR ret = LY_SUCCESS; |
| 2383 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2384 | size_t subelems_size; |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2385 | |
| 2386 | /* allocate new notification */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2387 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, notifs, notif, next, LY_EMEM); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2388 | notif->nodetype = LYS_NOTIF; |
| 2389 | notif->parent = notif_meta->parent; |
| 2390 | |
| 2391 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2392 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2393 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, ¬if->name, Y_IDENTIF_ARG, LY_STMT_NOTIFICATION)); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2394 | |
| 2395 | /* parse notification content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2396 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 16, (struct lysp_node *)notif, &subelems, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2397 | LY_STMT_ANYDATA, ¬if->child, 0, |
| 2398 | LY_STMT_ANYXML, ¬if->child, 0, |
| 2399 | LY_STMT_CHOICE, ¬if->child, 0, |
| 2400 | LY_STMT_CONTAINER, ¬if->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2401 | LY_STMT_DESCRIPTION, ¬if->dsc, YIN_SUBELEM_UNIQUE, |
| 2402 | LY_STMT_GROUPING, ¬if->groupings, 0, |
| 2403 | LY_STMT_IF_FEATURE, ¬if->iffeatures, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2404 | LY_STMT_LEAF, ¬if->child, 0, |
| 2405 | LY_STMT_LEAF_LIST, ¬if->child, 0, |
| 2406 | LY_STMT_LIST, ¬if->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2407 | LY_STMT_MUST, ¬if->musts, YIN_SUBELEM_VER2, |
| 2408 | LY_STMT_REFERENCE, ¬if->ref, YIN_SUBELEM_UNIQUE, |
| 2409 | LY_STMT_STATUS, ¬if->flags, YIN_SUBELEM_UNIQUE, |
| 2410 | LY_STMT_TYPEDEF, ¬if->typedefs, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2411 | LY_STMT_USES, ¬if->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2412 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2413 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2414 | ret = yin_parse_content(ctx, subelems, subelems_size, notif, LY_STMT_NOTIFICATION, NULL, ¬if->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2415 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2416 | LY_CHECK_RET(ret); |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2417 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2418 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2419 | LY_CHECK_RET(yin_unres_exts_add(ctx, notif->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2420 | |
David Sedlák | 031b9e7 | 2019-07-23 15:19:37 +0200 | [diff] [blame] | 2421 | return LY_SUCCESS; |
| 2422 | } |
| 2423 | |
| 2424 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2425 | * @brief Parse grouping element. |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2426 | * |
| 2427 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2428 | * @param[in,out] gr_meta Meta information about parent node and groupings to add to. |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2429 | * @return LY_ERR values. |
| 2430 | */ |
| 2431 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2432 | yin_parse_grouping(struct lysp_yin_ctx *ctx, struct tree_node_meta *gr_meta) |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2433 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2434 | struct lysp_node_grp *grp; |
| 2435 | struct lysp_node_grp **grps = (struct lysp_node_grp **)gr_meta->nodes; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2436 | LY_ERR ret = LY_SUCCESS; |
| 2437 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2438 | size_t subelems_size; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2439 | |
| 2440 | /* create new grouping */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2441 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, grps, grp, next, LY_EMEM); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2442 | grp->nodetype = LYS_GROUPING; |
| 2443 | grp->parent = gr_meta->parent; |
| 2444 | |
| 2445 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2446 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2447 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &grp->name, Y_IDENTIF_ARG, LY_STMT_GROUPING)); |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2448 | |
| 2449 | /* parse grouping content */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2450 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 16, &grp->node, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2451 | LY_STMT_ACTION, &grp->actions, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2452 | LY_STMT_ANYDATA, &grp->child, 0, |
| 2453 | LY_STMT_ANYXML, &grp->child, 0, |
| 2454 | LY_STMT_CHOICE, &grp->child, 0, |
| 2455 | LY_STMT_CONTAINER, &grp->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2456 | LY_STMT_DESCRIPTION, &grp->dsc, YIN_SUBELEM_UNIQUE, |
| 2457 | LY_STMT_GROUPING, &grp->groupings, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2458 | LY_STMT_LEAF, &grp->child, 0, |
| 2459 | LY_STMT_LEAF_LIST, &grp->child, 0, |
| 2460 | LY_STMT_LIST, &grp->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2461 | LY_STMT_NOTIFICATION, &grp->notifs, 0, |
| 2462 | LY_STMT_REFERENCE, &grp->ref, YIN_SUBELEM_UNIQUE, |
| 2463 | LY_STMT_STATUS, &grp->flags, YIN_SUBELEM_UNIQUE, |
| 2464 | LY_STMT_TYPEDEF, &grp->typedefs, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2465 | LY_STMT_USES, &grp->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2466 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2467 | ret = yin_parse_content(ctx, subelems, subelems_size, grp, LY_STMT_GROUPING, NULL, &grp->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2468 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2469 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2470 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2471 | LY_CHECK_RET(yin_unres_exts_add(ctx, grp->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2472 | |
aPiecek | 63e080d | 2021-06-29 13:53:28 +0200 | [diff] [blame] | 2473 | /* store data for collision check */ |
| 2474 | if (!ret && grp->parent) { |
| 2475 | assert(ctx->main_ctx); |
| 2476 | LY_CHECK_RET(ly_set_add(&ctx->main_ctx->grps_nodes, grp->parent, 0, NULL)); |
| 2477 | } |
| 2478 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2479 | return ret; |
David Sedlák | e3ce9ef | 2019-07-23 16:34:30 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | /** |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2483 | * @brief Parse container element. |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2484 | * |
| 2485 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 2486 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2487 | * @return LY_ERR values. |
| 2488 | */ |
| 2489 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2490 | yin_parse_container(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2491 | { |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2492 | struct lysp_node_container *cont; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2493 | LY_ERR ret = LY_SUCCESS; |
| 2494 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2495 | size_t subelems_size; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2496 | |
| 2497 | /* create new container */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2498 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, cont, next, LY_EMEM); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2499 | cont->nodetype = LYS_CONTAINER; |
| 2500 | cont->parent = node_meta->parent; |
| 2501 | |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2502 | /* parse aegument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2503 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2504 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &cont->name, Y_IDENTIF_ARG, LY_STMT_CONTAINER)); |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2505 | |
| 2506 | /* parse container content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2507 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 21, (struct lysp_node *)cont, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2508 | LY_STMT_ACTION, &cont->actions, YIN_SUBELEM_VER2, |
| 2509 | LY_STMT_ANYDATA, &cont->child, YIN_SUBELEM_VER2, |
| 2510 | LY_STMT_ANYXML, &cont->child, 0, |
| 2511 | LY_STMT_CHOICE, &cont->child, 0, |
| 2512 | LY_STMT_CONFIG, &cont->flags, YIN_SUBELEM_UNIQUE, |
| 2513 | LY_STMT_CONTAINER, &cont->child, 0, |
| 2514 | LY_STMT_DESCRIPTION, &cont->dsc, YIN_SUBELEM_UNIQUE, |
| 2515 | LY_STMT_GROUPING, &cont->groupings, 0, |
| 2516 | LY_STMT_IF_FEATURE, &cont->iffeatures, 0, |
| 2517 | LY_STMT_LEAF, &cont->child, 0, |
| 2518 | LY_STMT_LEAF_LIST, &cont->child, 0, |
| 2519 | LY_STMT_LIST, &cont->child, 0, |
| 2520 | LY_STMT_MUST, &cont->musts, 0, |
| 2521 | LY_STMT_NOTIFICATION, &cont->notifs, YIN_SUBELEM_VER2, |
| 2522 | LY_STMT_PRESENCE, &cont->presence, YIN_SUBELEM_UNIQUE, |
| 2523 | LY_STMT_REFERENCE, &cont->ref, YIN_SUBELEM_UNIQUE, |
| 2524 | LY_STMT_STATUS, &cont->flags, YIN_SUBELEM_UNIQUE, |
| 2525 | LY_STMT_TYPEDEF, &cont->typedefs, 0, |
| 2526 | LY_STMT_USES, &cont->child, 0, |
| 2527 | LY_STMT_WHEN, &cont->when, YIN_SUBELEM_UNIQUE, |
| 2528 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2529 | ret = yin_parse_content(ctx, subelems, subelems_size, cont, LY_STMT_CONTAINER, NULL, &cont->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2530 | subelems_deallocator(subelems_size, subelems); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2531 | LY_CHECK_RET(ret); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2532 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2533 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2534 | LY_CHECK_RET(yin_unres_exts_add(ctx, cont->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2535 | |
| 2536 | return LY_SUCCESS; |
David Sedlák | f111bcb | 2019-07-23 17:15:51 +0200 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | /** |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2540 | * @brief Parse case element. |
| 2541 | * |
| 2542 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 2543 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2544 | * @return LY_ERR values. |
| 2545 | */ |
| 2546 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2547 | yin_parse_case(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2548 | { |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2549 | struct lysp_node_case *cas; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2550 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2551 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2552 | size_t subelems_size; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2553 | |
| 2554 | /* create new case */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2555 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, cas, next, LY_EMEM); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2556 | cas->nodetype = LYS_CASE; |
| 2557 | cas->parent = node_meta->parent; |
| 2558 | |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2559 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2560 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2561 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &cas->name, Y_IDENTIF_ARG, LY_STMT_CASE)); |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2562 | |
| 2563 | /* parse case content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2564 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 14, (struct lysp_node *)cas, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2565 | LY_STMT_ANYDATA, &cas->child, YIN_SUBELEM_VER2, |
| 2566 | LY_STMT_ANYXML, &cas->child, 0, |
| 2567 | LY_STMT_CHOICE, &cas->child, 0, |
| 2568 | LY_STMT_CONTAINER, &cas->child, 0, |
| 2569 | LY_STMT_DESCRIPTION, &cas->dsc, YIN_SUBELEM_UNIQUE, |
| 2570 | LY_STMT_IF_FEATURE, &cas->iffeatures, 0, |
| 2571 | LY_STMT_LEAF, &cas->child, 0, |
| 2572 | LY_STMT_LEAF_LIST, &cas->child, 0, |
| 2573 | LY_STMT_LIST, &cas->child, 0, |
| 2574 | LY_STMT_REFERENCE, &cas->ref, YIN_SUBELEM_UNIQUE, |
| 2575 | LY_STMT_STATUS, &cas->flags, YIN_SUBELEM_UNIQUE, |
| 2576 | LY_STMT_USES, &cas->child, 0, |
| 2577 | LY_STMT_WHEN, &cas->when, YIN_SUBELEM_UNIQUE, |
| 2578 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2579 | ret = yin_parse_content(ctx, subelems, subelems_size, cas, LY_STMT_CASE, NULL, &cas->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2580 | subelems_deallocator(subelems_size, subelems); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2581 | LY_CHECK_RET(ret); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2582 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2583 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2584 | LY_CHECK_RET(yin_unres_exts_add(ctx, cas->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2585 | |
| 2586 | return LY_SUCCESS; |
David Sedlák | 5379d39 | 2019-07-24 10:42:03 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | /** |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2590 | * @brief Parse choice element. |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2591 | * |
| 2592 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | ad83cf9 | 2019-08-13 12:53:53 +0200 | [diff] [blame] | 2593 | * @param[in] node_meta Meta information about parent node and siblings to add to. |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2594 | * @return LY_ERR values. |
| 2595 | */ |
| 2596 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2597 | yin_parse_choice(struct lysp_yin_ctx *ctx, struct tree_node_meta *node_meta) |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2598 | { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2599 | LY_ERR ret = LY_SUCCESS; |
| 2600 | struct yin_subelement *subelems = NULL; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2601 | struct lysp_node_choice *choice; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2602 | size_t subelems_size; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2603 | |
| 2604 | /* create new choice */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2605 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, node_meta->nodes, choice, next, LY_EMEM); |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 2606 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2607 | choice->nodetype = LYS_CHOICE; |
| 2608 | choice->parent = node_meta->parent; |
| 2609 | |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2610 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2611 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2612 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &choice->name, Y_IDENTIF_ARG, LY_STMT_CHOICE)); |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2613 | |
| 2614 | /* parse choice content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2615 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 17, (struct lysp_node *)choice, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2616 | LY_STMT_ANYDATA, &choice->child, YIN_SUBELEM_VER2, |
| 2617 | LY_STMT_ANYXML, &choice->child, 0, |
| 2618 | LY_STMT_CASE, &choice->child, 0, |
| 2619 | LY_STMT_CHOICE, &choice->child, YIN_SUBELEM_VER2, |
| 2620 | LY_STMT_CONFIG, &choice->flags, YIN_SUBELEM_UNIQUE, |
| 2621 | LY_STMT_CONTAINER, &choice->child, 0, |
| 2622 | LY_STMT_DEFAULT, &choice->dflt, YIN_SUBELEM_UNIQUE, |
| 2623 | LY_STMT_DESCRIPTION, &choice->dsc, YIN_SUBELEM_UNIQUE, |
| 2624 | LY_STMT_IF_FEATURE, &choice->iffeatures, 0, |
| 2625 | LY_STMT_LEAF, &choice->child, 0, |
| 2626 | LY_STMT_LEAF_LIST, &choice->child, 0, |
| 2627 | LY_STMT_LIST, &choice->child, 0, |
| 2628 | LY_STMT_MANDATORY, &choice->flags, YIN_SUBELEM_UNIQUE, |
| 2629 | LY_STMT_REFERENCE, &choice->ref, YIN_SUBELEM_UNIQUE, |
| 2630 | LY_STMT_STATUS, &choice->flags, YIN_SUBELEM_UNIQUE, |
| 2631 | LY_STMT_WHEN, &choice->when, YIN_SUBELEM_UNIQUE, |
| 2632 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2633 | ret = yin_parse_content(ctx, subelems, subelems_size, choice, LY_STMT_CHOICE, NULL, &choice->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2634 | subelems_deallocator(subelems_size, subelems); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2635 | LY_CHECK_RET(ret); |
| 2636 | |
| 2637 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2638 | LY_CHECK_RET(yin_unres_exts_add(ctx, choice->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2639 | |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2640 | return ret; |
David Sedlák | b7abcfa | 2019-07-24 12:33:35 +0200 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | /** |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2644 | * @brief Parse input or output element. |
| 2645 | * |
| 2646 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 2647 | * @param[in] inout_kw Identification of input/output element. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2648 | * @param[in] inout_meta Meta information about parent node and siblings and input/output pointer to write to. |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2649 | * @return LY_ERR values. |
| 2650 | */ |
| 2651 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2652 | yin_parse_inout(struct lysp_yin_ctx *ctx, enum ly_stmt inout_kw, struct inout_meta *inout_meta) |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2653 | { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2654 | LY_ERR ret = LY_SUCCESS; |
| 2655 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2656 | size_t subelems_size; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2657 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2658 | /* initiate structure */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2659 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), (inout_kw == LY_STMT_INPUT) ? "input" : "output", 0, &inout_meta->inout_p->name)); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 2660 | inout_meta->inout_p->nodetype = (inout_kw == LY_STMT_INPUT) ? LYS_INPUT : LYS_OUTPUT; |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2661 | inout_meta->inout_p->parent = inout_meta->parent; |
| 2662 | |
| 2663 | /* check attributes */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2664 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2665 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, NULL, Y_MAYBE_STR_ARG, inout_kw)); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2666 | |
| 2667 | /* parser input/output content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2668 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 12, (struct lysp_node *)inout_meta->inout_p, &subelems, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2669 | LY_STMT_ANYDATA, &inout_meta->inout_p->child, YIN_SUBELEM_VER2, |
| 2670 | LY_STMT_ANYXML, &inout_meta->inout_p->child, 0, |
| 2671 | LY_STMT_CHOICE, &inout_meta->inout_p->child, 0, |
| 2672 | LY_STMT_CONTAINER, &inout_meta->inout_p->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2673 | LY_STMT_GROUPING, &inout_meta->inout_p->groupings, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2674 | LY_STMT_LEAF, &inout_meta->inout_p->child, 0, |
| 2675 | LY_STMT_LEAF_LIST, &inout_meta->inout_p->child, 0, |
| 2676 | LY_STMT_LIST, &inout_meta->inout_p->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2677 | LY_STMT_MUST, &inout_meta->inout_p->musts, YIN_SUBELEM_VER2, |
| 2678 | LY_STMT_TYPEDEF, &inout_meta->inout_p->typedefs, 0, |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2679 | LY_STMT_USES, &inout_meta->inout_p->child, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2680 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2681 | ret = yin_parse_content(ctx, subelems, subelems_size, inout_meta->inout_p, inout_kw, NULL, &inout_meta->inout_p->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2682 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2683 | LY_CHECK_RET(ret); |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2684 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2685 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2686 | LY_CHECK_RET(yin_unres_exts_add(ctx, inout_meta->inout_p->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2687 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 2688 | if (!inout_meta->inout_p->child) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2689 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_MISSTMT, "data-def-stmt", lyplg_ext_stmt2str(inout_kw)); |
Michal Vasko | b83af8a | 2020-01-06 09:49:22 +0100 | [diff] [blame] | 2690 | return LY_EVALID; |
| 2691 | } |
| 2692 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2693 | return LY_SUCCESS; |
| 2694 | } |
| 2695 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2696 | /** |
| 2697 | * @brief Parse action element. |
| 2698 | * |
| 2699 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2700 | * @param[in] act_meta Meta information about parent node and actions to add to. |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2701 | * @return LY_ERR values. |
| 2702 | */ |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2703 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2704 | yin_parse_action(struct lysp_yin_ctx *ctx, struct tree_node_meta *act_meta) |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2705 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2706 | struct lysp_node_action *act, **acts = (struct lysp_node_action **)act_meta->nodes; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2707 | LY_ERR ret = LY_SUCCESS; |
| 2708 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2709 | size_t subelems_size; |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2710 | enum ly_stmt kw = act_meta->parent ? LY_STMT_ACTION : LY_STMT_RPC; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2711 | |
| 2712 | /* create new action */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2713 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, acts, act, next, LY_EMEM); |
Michal Vasko | 1bf0939 | 2020-03-27 12:38:10 +0100 | [diff] [blame] | 2714 | act->nodetype = act_meta->parent ? LYS_ACTION : LYS_RPC; |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2715 | act->parent = act_meta->parent; |
| 2716 | |
| 2717 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2718 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
Radek Krejci | 39b7fc2 | 2021-02-26 23:29:18 +0100 | [diff] [blame] | 2719 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &act->name, Y_IDENTIF_ARG, kw)); |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2720 | |
| 2721 | /* parse content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2722 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 9, (struct lysp_node *)act, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2723 | LY_STMT_DESCRIPTION, &act->dsc, YIN_SUBELEM_UNIQUE, |
| 2724 | LY_STMT_GROUPING, &act->groupings, 0, |
| 2725 | LY_STMT_IF_FEATURE, &act->iffeatures, 0, |
| 2726 | LY_STMT_INPUT, &act->input, YIN_SUBELEM_UNIQUE, |
| 2727 | LY_STMT_OUTPUT, &act->output, YIN_SUBELEM_UNIQUE, |
| 2728 | LY_STMT_REFERENCE, &act->ref, YIN_SUBELEM_UNIQUE, |
| 2729 | LY_STMT_STATUS, &act->flags, YIN_SUBELEM_UNIQUE, |
| 2730 | LY_STMT_TYPEDEF, &act->typedefs, 0, |
| 2731 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2732 | ret = (yin_parse_content(ctx, subelems, subelems_size, act, kw, NULL, &act->exts)); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2733 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2734 | LY_CHECK_RET(ret); |
| 2735 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2736 | /* always initialize inout, they are technically present (needed for later deviations/refines) */ |
| 2737 | if (!act->input.nodetype) { |
| 2738 | act->input.nodetype = LYS_INPUT; |
| 2739 | act->input.parent = (struct lysp_node *)act; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2740 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), "input", 0, &act->input.name)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2741 | } |
| 2742 | if (!act->output.nodetype) { |
| 2743 | act->output.nodetype = LYS_OUTPUT; |
| 2744 | act->output.parent = (struct lysp_node *)act; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2745 | LY_CHECK_RET(lydict_insert(PARSER_CTX(ctx), "output", 0, &act->output.name)); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 2746 | } |
| 2747 | |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2748 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
| 2749 | LY_CHECK_RET(yin_unres_exts_add(ctx, act->exts)); |
| 2750 | |
David Sedlák | 85d0eca | 2019-07-24 15:15:21 +0200 | [diff] [blame] | 2751 | return LY_SUCCESS; |
| 2752 | } |
| 2753 | |
David Sedlák | 05404f6 | 2019-07-24 14:11:53 +0200 | [diff] [blame] | 2754 | /** |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2755 | * @brief Parse augment element. |
| 2756 | * |
| 2757 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2758 | * @param[in] aug_meta Meta information about parent node and augments to add to. |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2759 | * @return LY_ERR values. |
| 2760 | */ |
| 2761 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2762 | yin_parse_augment(struct lysp_yin_ctx *ctx, struct tree_node_meta *aug_meta) |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2763 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2764 | struct lysp_node_augment *aug; |
| 2765 | struct lysp_node_augment **augs = (struct lysp_node_augment **)aug_meta->nodes; |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 2766 | LY_ERR ret = LY_SUCCESS; |
| 2767 | struct yin_subelement *subelems = NULL; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2768 | size_t subelems_size; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2769 | |
| 2770 | /* create new augment */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2771 | LY_LIST_NEW_RET(ctx->xmlctx->ctx, augs, aug, next, LY_EMEM); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2772 | aug->nodetype = LYS_AUGMENT; |
| 2773 | aug->parent = aug_meta->parent; |
| 2774 | |
| 2775 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2776 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2777 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_TARGET_NODE, &aug->nodeid, Y_STR_ARG, LY_STMT_AUGMENT)); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2778 | CHECK_NONEMPTY((struct lysp_ctx *)ctx, strlen(aug->nodeid), "augment"); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2779 | |
| 2780 | /* parser augment content */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2781 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 17, (struct lysp_node *)aug, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2782 | LY_STMT_ACTION, &aug->actions, YIN_SUBELEM_VER2, |
| 2783 | LY_STMT_ANYDATA, &aug->child, YIN_SUBELEM_VER2, |
| 2784 | LY_STMT_ANYXML, &aug->child, 0, |
| 2785 | LY_STMT_CASE, &aug->child, 0, |
| 2786 | LY_STMT_CHOICE, &aug->child, 0, |
| 2787 | LY_STMT_CONTAINER, &aug->child, 0, |
| 2788 | LY_STMT_DESCRIPTION, &aug->dsc, YIN_SUBELEM_UNIQUE, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2789 | LY_STMT_IF_FEATURE, &aug->iffeatures, 0, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2790 | LY_STMT_LEAF, &aug->child, 0, |
| 2791 | LY_STMT_LEAF_LIST, &aug->child, 0, |
| 2792 | LY_STMT_LIST, &aug->child, 0, |
| 2793 | LY_STMT_NOTIFICATION, &aug->notifs, YIN_SUBELEM_VER2, |
| 2794 | LY_STMT_REFERENCE, &aug->ref, YIN_SUBELEM_UNIQUE, |
| 2795 | LY_STMT_STATUS, &aug->flags, YIN_SUBELEM_UNIQUE, |
| 2796 | LY_STMT_USES, &aug->child, 0, |
| 2797 | LY_STMT_WHEN, &aug->when, YIN_SUBELEM_UNIQUE, |
| 2798 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2799 | ret = yin_parse_content(ctx, subelems, subelems_size, aug, LY_STMT_AUGMENT, NULL, &aug->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2800 | subelems_deallocator(subelems_size, subelems); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2801 | LY_CHECK_RET(ret); |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2802 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2803 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2804 | LY_CHECK_RET(yin_unres_exts_add(ctx, aug->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2805 | |
| 2806 | return LY_SUCCESS; |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2807 | } |
| 2808 | |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2809 | /** |
| 2810 | * @brief Parse deviate element. |
| 2811 | * |
| 2812 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2813 | * @param[in] deviates Deviates to add to. |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2814 | * @return LY_ERR values. |
| 2815 | */ |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2816 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2817 | yin_parse_deviate(struct lysp_yin_ctx *ctx, struct lysp_deviate **deviates) |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2818 | { |
| 2819 | LY_ERR ret = LY_SUCCESS; |
| 2820 | uint8_t dev_mod; |
| 2821 | const char *temp_val; |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 2822 | struct lysp_deviate *d; |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2823 | struct lysp_deviate_add *d_add = NULL; |
| 2824 | struct lysp_deviate_rpl *d_rpl = NULL; |
| 2825 | struct lysp_deviate_del *d_del = NULL; |
| 2826 | |
| 2827 | /* parse argument */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2828 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 2829 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, &temp_val, Y_STR_ARG, LY_STMT_DEVIATE)); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2830 | |
| 2831 | if (strcmp(temp_val, "not-supported") == 0) { |
| 2832 | dev_mod = LYS_DEV_NOT_SUPPORTED; |
| 2833 | } else if (strcmp(temp_val, "add") == 0) { |
| 2834 | dev_mod = LYS_DEV_ADD; |
| 2835 | } else if (strcmp(temp_val, "replace") == 0) { |
| 2836 | dev_mod = LYS_DEV_REPLACE; |
| 2837 | } else if (strcmp(temp_val, "delete") == 0) { |
| 2838 | dev_mod = LYS_DEV_DELETE; |
| 2839 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2840 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INVAL_YIN VALID_VALS4, temp_val, "value", "deviate", |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2841 | "not-supported", "add", "replace", "delete"); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2842 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2843 | return LY_EVALID; |
| 2844 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 2845 | lydict_remove(ctx->xmlctx->ctx, temp_val); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2846 | |
| 2847 | if (dev_mod == LYS_DEV_NOT_SUPPORTED) { |
| 2848 | d = calloc(1, sizeof *d); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2849 | LY_CHECK_ERR_RET(!d, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2850 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2851 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0} |
| 2852 | }; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 2853 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2854 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), d, LY_STMT_DEVIATE, NULL, &d->exts); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2855 | |
| 2856 | } else if (dev_mod == LYS_DEV_ADD) { |
| 2857 | d_add = calloc(1, sizeof *d_add); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2858 | LY_CHECK_ERR_RET(!d_add, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2859 | d = (struct lysp_deviate *)d_add; |
| 2860 | struct minmax_dev_meta min = {&d_add->min, &d_add->flags, &d_add->exts}; |
| 2861 | struct minmax_dev_meta max = {&d_add->max, &d_add->flags, &d_add->exts}; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2862 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2863 | {LY_STMT_CONFIG, &d_add->flags, YIN_SUBELEM_UNIQUE}, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2864 | {LY_STMT_DEFAULT, &d_add->dflts, 0}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2865 | {LY_STMT_MANDATORY, &d_add->flags, YIN_SUBELEM_UNIQUE}, |
| 2866 | {LY_STMT_MAX_ELEMENTS, &max, YIN_SUBELEM_UNIQUE}, |
| 2867 | {LY_STMT_MIN_ELEMENTS, &min, YIN_SUBELEM_UNIQUE}, |
| 2868 | {LY_STMT_MUST, &d_add->musts, 0}, |
| 2869 | {LY_STMT_UNIQUE, &d_add->uniques, 0}, |
| 2870 | {LY_STMT_UNITS, &d_add->units, YIN_SUBELEM_UNIQUE}, |
| 2871 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2872 | }; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 2873 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2874 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), d, LY_STMT_DEVIATE, NULL, &d->exts); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2875 | |
| 2876 | } else if (dev_mod == LYS_DEV_REPLACE) { |
| 2877 | d_rpl = calloc(1, sizeof *d_rpl); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2878 | LY_CHECK_ERR_RET(!d_rpl, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2879 | d = (struct lysp_deviate *)d_rpl; |
| 2880 | struct minmax_dev_meta min = {&d_rpl->min, &d_rpl->flags, &d_rpl->exts}; |
| 2881 | struct minmax_dev_meta max = {&d_rpl->max, &d_rpl->flags, &d_rpl->exts}; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2882 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2883 | {LY_STMT_CONFIG, &d_rpl->flags, YIN_SUBELEM_UNIQUE}, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2884 | {LY_STMT_DEFAULT, &d_rpl->dflt, YIN_SUBELEM_UNIQUE}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2885 | {LY_STMT_MANDATORY, &d_rpl->flags, YIN_SUBELEM_UNIQUE}, |
| 2886 | {LY_STMT_MAX_ELEMENTS, &max, YIN_SUBELEM_UNIQUE}, |
| 2887 | {LY_STMT_MIN_ELEMENTS, &min, YIN_SUBELEM_UNIQUE}, |
| 2888 | {LY_STMT_TYPE, &d_rpl->type, YIN_SUBELEM_UNIQUE}, |
| 2889 | {LY_STMT_UNITS, &d_rpl->units, YIN_SUBELEM_UNIQUE}, |
| 2890 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2891 | }; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 2892 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2893 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), d, LY_STMT_DEVIATE, NULL, &d->exts); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2894 | |
| 2895 | } else { |
| 2896 | d_del = calloc(1, sizeof *d_del); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2897 | LY_CHECK_ERR_RET(!d_del, LOGMEM(ctx->xmlctx->ctx), LY_EMEM); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2898 | d = (struct lysp_deviate *)d_del; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2899 | struct yin_subelement subelems[] = { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2900 | {LY_STMT_DEFAULT, &d_del->dflts, 0}, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2901 | {LY_STMT_MUST, &d_del->musts, 0}, |
| 2902 | {LY_STMT_UNIQUE, &d_del->uniques, 0}, |
| 2903 | {LY_STMT_UNITS, &d_del->units, YIN_SUBELEM_UNIQUE}, |
| 2904 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2905 | }; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 2906 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2907 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), d, LY_STMT_DEVIATE, NULL, &d->exts); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2908 | } |
| 2909 | LY_CHECK_GOTO(ret, cleanup); |
| 2910 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2911 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2912 | LY_CHECK_GOTO(ret = yin_unres_exts_add(ctx, d->exts), cleanup); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2913 | |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2914 | d->mod = dev_mod; |
| 2915 | /* insert into siblings */ |
David Sedlák | 8d552d6 | 2019-08-06 15:29:05 +0200 | [diff] [blame] | 2916 | LY_LIST_INSERT(deviates, d, next); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2917 | |
| 2918 | return ret; |
| 2919 | |
| 2920 | cleanup: |
| 2921 | free(d); |
David Sedlák | 4ffcec8 | 2019-07-25 15:10:21 +0200 | [diff] [blame] | 2922 | return ret; |
| 2923 | } |
| 2924 | |
David Sedlák | 992fb7c | 2019-07-24 16:51:01 +0200 | [diff] [blame] | 2925 | /** |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2926 | * @brief Parse deviation element. |
| 2927 | * |
| 2928 | * @param[in,out] ctx YIN parser context for logging and to store current state. |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2929 | * @param[in] deviations Deviations to add to. |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2930 | * @return LY_ERR values. |
| 2931 | */ |
| 2932 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2933 | yin_parse_deviation(struct lysp_yin_ctx *ctx, struct lysp_deviation **deviations) |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2934 | { |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2935 | LY_ERR ret = LY_SUCCESS; |
| 2936 | struct lysp_deviation *dev = NULL; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2937 | struct lysf_ctx fctx = {.ctx = PARSER_CTX(ctx)}; |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2938 | |
| 2939 | /* create new deviation */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 2940 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *deviations, dev, LY_EMEM); |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2941 | |
| 2942 | /* parse argument */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2943 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 2944 | LY_CHECK_GOTO(ret = yin_parse_attribute(ctx, YIN_ARG_TARGET_NODE, &dev->nodeid, Y_STR_ARG, LY_STMT_DEVIATION), cleanup); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2945 | CHECK_NONEMPTY((struct lysp_ctx *)ctx, strlen(dev->nodeid), "deviation"); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 2946 | struct yin_subelement subelems[] = { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2947 | {LY_STMT_DESCRIPTION, &dev->dsc, YIN_SUBELEM_UNIQUE}, |
| 2948 | {LY_STMT_DEVIATE, &dev->deviates, YIN_SUBELEM_MANDATORY}, |
| 2949 | {LY_STMT_REFERENCE, &dev->ref, YIN_SUBELEM_UNIQUE}, |
| 2950 | {LY_STMT_EXTENSION_INSTANCE, NULL, 0}, |
| 2951 | }; |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 2952 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 2953 | ret = yin_parse_content(ctx, subelems, ly_sizeofarray(subelems), dev, LY_STMT_DEVIATION, NULL, &dev->exts); |
| 2954 | LY_CHECK_GOTO(ret, cleanup); |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2955 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2956 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 2957 | LY_CHECK_GOTO(ret = yin_unres_exts_add(ctx, dev->exts), cleanup); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 2958 | |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2959 | cleanup: |
| 2960 | if (ret) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 2961 | lysp_deviation_free(&fctx, dev); |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 2962 | LY_ARRAY_DECREMENT_FREE(*deviations); |
| 2963 | } |
| 2964 | return ret; |
David Sedlák | 8b75446 | 2019-07-25 16:22:13 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | /** |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 2968 | * @brief map keyword to keyword-group. |
| 2969 | * |
| 2970 | * @param[in] ctx YIN parser context used for logging. |
| 2971 | * @param[in] kw Keyword that is child of module or submodule. |
| 2972 | * @param[out] group Group of keyword. |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 2973 | * @return LY_SUCCESS on success LY_EINT if kw can't be mapped to kw_group, should not happen if called correctly. |
| 2974 | */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 2975 | static LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 2976 | kw2kw_group(struct lysp_yin_ctx *ctx, enum ly_stmt kw, enum yang_module_stmt *group) |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 2977 | { |
| 2978 | switch (kw) { |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 2979 | /* module header */ |
| 2980 | case LY_STMT_NONE: |
| 2981 | case LY_STMT_NAMESPACE: |
| 2982 | case LY_STMT_PREFIX: |
| 2983 | case LY_STMT_BELONGS_TO: |
| 2984 | case LY_STMT_YANG_VERSION: |
| 2985 | *group = Y_MOD_MODULE_HEADER; |
| 2986 | break; |
| 2987 | /* linkage */ |
| 2988 | case LY_STMT_INCLUDE: |
| 2989 | case LY_STMT_IMPORT: |
| 2990 | *group = Y_MOD_LINKAGE; |
| 2991 | break; |
| 2992 | /* meta */ |
| 2993 | case LY_STMT_ORGANIZATION: |
| 2994 | case LY_STMT_CONTACT: |
| 2995 | case LY_STMT_DESCRIPTION: |
| 2996 | case LY_STMT_REFERENCE: |
| 2997 | *group = Y_MOD_META; |
| 2998 | break; |
| 2999 | /* revision */ |
| 3000 | case LY_STMT_REVISION: |
| 3001 | *group = Y_MOD_REVISION; |
| 3002 | break; |
| 3003 | /* body */ |
| 3004 | case LY_STMT_ANYDATA: |
| 3005 | case LY_STMT_ANYXML: |
| 3006 | case LY_STMT_AUGMENT: |
| 3007 | case LY_STMT_CHOICE: |
| 3008 | case LY_STMT_CONTAINER: |
| 3009 | case LY_STMT_DEVIATION: |
| 3010 | case LY_STMT_EXTENSION: |
| 3011 | case LY_STMT_FEATURE: |
| 3012 | case LY_STMT_GROUPING: |
| 3013 | case LY_STMT_IDENTITY: |
| 3014 | case LY_STMT_LEAF: |
| 3015 | case LY_STMT_LEAF_LIST: |
| 3016 | case LY_STMT_LIST: |
| 3017 | case LY_STMT_NOTIFICATION: |
| 3018 | case LY_STMT_RPC: |
| 3019 | case LY_STMT_TYPEDEF: |
| 3020 | case LY_STMT_USES: |
| 3021 | case LY_STMT_EXTENSION_INSTANCE: |
| 3022 | *group = Y_MOD_BODY; |
| 3023 | break; |
| 3024 | default: |
| 3025 | LOGINT(ctx->xmlctx->ctx); |
| 3026 | return LY_EINT; |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | return LY_SUCCESS; |
| 3030 | } |
| 3031 | |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 3032 | /** |
| 3033 | * @brief Check if relative order of two keywords is valid. |
| 3034 | * |
| 3035 | * @param[in] ctx YIN parser context used for logging. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3036 | * @param[in] cur_stmt Type of current statement. |
| 3037 | * @param[in] next_stmt Type of next statement. |
| 3038 | * @param[in] parent_stmt Type of parent statement, can be se to to LY_STMT_MODULE of LY_STMT_SUBMODULE, |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 3039 | * because relative order is required only in module and submodule sub-elements, used for logging. |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 3040 | * @return LY_SUCCESS on success and LY_EVALID if relative order is invalid. |
David Sedlák | c5b2084 | 2019-08-13 10:18:31 +0200 | [diff] [blame] | 3041 | */ |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3042 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3043 | yin_check_relative_order(struct lysp_yin_ctx *ctx, enum ly_stmt cur_stmt, enum ly_stmt next_stmt, enum ly_stmt parent_stmt) |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3044 | { |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3045 | enum yang_module_stmt gr, next_gr; |
| 3046 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3047 | assert(parent_stmt == LY_STMT_MODULE || parent_stmt == LY_STMT_SUBMODULE); |
| 3048 | |
| 3049 | if (cur_stmt == LY_STMT_EXTENSION_INSTANCE) { |
Michal Vasko | c78293f | 2021-12-16 15:40:33 +0100 | [diff] [blame] | 3050 | /* no order defined */ |
| 3051 | return LY_SUCCESS; |
| 3052 | } |
| 3053 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3054 | LY_CHECK_RET(kw2kw_group(ctx, cur_stmt, &gr)); |
| 3055 | LY_CHECK_RET(kw2kw_group(ctx, next_stmt, &next_gr)); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3056 | |
| 3057 | if (gr > next_gr) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3058 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INORDER_YIN, lyplg_ext_stmt2str(parent_stmt), lyplg_ext_stmt2str(next_stmt), |
| 3059 | lyplg_ext_stmt2str(cur_stmt)); |
David Sedlák | e6cd89e | 2019-08-07 12:46:02 +0200 | [diff] [blame] | 3060 | return LY_EVALID; |
| 3061 | } |
| 3062 | |
| 3063 | return LY_SUCCESS; |
| 3064 | } |
| 3065 | |
David Sedlák | c5dd094 | 2019-09-13 10:23:59 +0200 | [diff] [blame] | 3066 | /** |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3067 | * @brief Parse argument of extension subelement that is classic yang keyword and not another instance of extension. |
| 3068 | * |
| 3069 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3070 | * @param[in] parent_stmt Type of parent statement. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3071 | * @param[out] arg Value to write to. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3072 | * @return LY_ERR values. |
| 3073 | */ |
| 3074 | static LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3075 | yin_parse_extension_instance_arg(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, const char **arg) |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3076 | { |
| 3077 | enum ly_stmt child; |
| 3078 | |
| 3079 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3080 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3081 | switch (parent_stmt) { |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3082 | case LY_STMT_ACTION: |
| 3083 | case LY_STMT_ANYDATA: |
| 3084 | case LY_STMT_ANYXML: |
| 3085 | case LY_STMT_ARGUMENT: |
| 3086 | case LY_STMT_BASE: |
| 3087 | case LY_STMT_BIT: |
| 3088 | case LY_STMT_CASE: |
| 3089 | case LY_STMT_CHOICE: |
| 3090 | case LY_STMT_CONTAINER: |
| 3091 | case LY_STMT_ENUM: |
| 3092 | case LY_STMT_EXTENSION: |
| 3093 | case LY_STMT_FEATURE: |
| 3094 | case LY_STMT_GROUPING: |
| 3095 | case LY_STMT_IDENTITY: |
| 3096 | case LY_STMT_IF_FEATURE: |
| 3097 | case LY_STMT_LEAF: |
| 3098 | case LY_STMT_LEAF_LIST: |
| 3099 | case LY_STMT_LIST: |
| 3100 | case LY_STMT_MODULE: |
| 3101 | case LY_STMT_NOTIFICATION: |
| 3102 | case LY_STMT_RPC: |
| 3103 | case LY_STMT_SUBMODULE: |
| 3104 | case LY_STMT_TYPE: |
| 3105 | case LY_STMT_TYPEDEF: |
| 3106 | case LY_STMT_UNITS: |
| 3107 | case LY_STMT_USES: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3108 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3109 | break; |
| 3110 | case LY_STMT_AUGMENT: |
| 3111 | case LY_STMT_DEVIATION: |
| 3112 | case LY_STMT_REFINE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3113 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_TARGET_NODE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3114 | break; |
| 3115 | case LY_STMT_CONFIG: |
| 3116 | case LY_STMT_DEFAULT: |
| 3117 | case LY_STMT_DEVIATE: |
| 3118 | case LY_STMT_ERROR_APP_TAG: |
| 3119 | case LY_STMT_FRACTION_DIGITS: |
| 3120 | case LY_STMT_KEY: |
| 3121 | case LY_STMT_LENGTH: |
| 3122 | case LY_STMT_MANDATORY: |
| 3123 | case LY_STMT_MAX_ELEMENTS: |
| 3124 | case LY_STMT_MIN_ELEMENTS: |
| 3125 | case LY_STMT_MODIFIER: |
| 3126 | case LY_STMT_ORDERED_BY: |
| 3127 | case LY_STMT_PATH: |
| 3128 | case LY_STMT_PATTERN: |
| 3129 | case LY_STMT_POSITION: |
| 3130 | case LY_STMT_PREFIX: |
| 3131 | case LY_STMT_PRESENCE: |
| 3132 | case LY_STMT_RANGE: |
| 3133 | case LY_STMT_REQUIRE_INSTANCE: |
| 3134 | case LY_STMT_STATUS: |
| 3135 | case LY_STMT_VALUE: |
| 3136 | case LY_STMT_YANG_VERSION: |
| 3137 | case LY_STMT_YIN_ELEMENT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3138 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_VALUE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3139 | break; |
| 3140 | case LY_STMT_IMPORT: |
| 3141 | case LY_STMT_INCLUDE: |
| 3142 | case LY_STMT_BELONGS_TO: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3143 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_MODULE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3144 | break; |
| 3145 | case LY_STMT_INPUT: |
| 3146 | case LY_STMT_OUTPUT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3147 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3148 | break; |
| 3149 | case LY_STMT_MUST: |
| 3150 | case LY_STMT_WHEN: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3151 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_CONDITION, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3152 | break; |
| 3153 | case LY_STMT_NAMESPACE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3154 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_URI, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3155 | break; |
| 3156 | case LY_STMT_REVISION: |
| 3157 | case LY_STMT_REVISION_DATE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3158 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_DATE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3159 | break; |
| 3160 | case LY_STMT_UNIQUE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3161 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_TAG, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3162 | break; |
| 3163 | /* argument is mapped to yin element */ |
| 3164 | case LY_STMT_CONTACT: |
| 3165 | case LY_STMT_DESCRIPTION: |
| 3166 | case LY_STMT_ORGANIZATION: |
| 3167 | case LY_STMT_REFERENCE: |
| 3168 | case LY_STMT_ERROR_MESSAGE: |
| 3169 | /* there shouldn't be any attribute, argument is supposed to be first subelement */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3170 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NONE, arg, Y_MAYBE_STR_ARG, parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3171 | |
| 3172 | /* no content */ |
| 3173 | assert(ctx->xmlctx->status == LYXML_ELEM_CONTENT); |
| 3174 | if (ctx->xmlctx->ws_only) { |
| 3175 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3176 | } |
| 3177 | if (((ctx->xmlctx->status == LYXML_ELEM_CONTENT) && !ctx->xmlctx->ws_only) || (ctx->xmlctx->status != LYXML_ELEMENT)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3178 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_FIRT_SUBELEM, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3179 | parent_stmt == LY_STMT_ERROR_MESSAGE ? "value" : "text", lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3180 | return LY_EVALID; |
| 3181 | } |
| 3182 | |
| 3183 | /* parse child element */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3184 | child = yin_match_keyword(ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, ctx->xmlctx->prefix, |
| 3185 | ctx->xmlctx->prefix_len, parent_stmt); |
| 3186 | if (((parent_stmt == LY_STMT_ERROR_MESSAGE) && (child != LY_STMT_ARG_VALUE)) || |
| 3187 | ((parent_stmt != LY_STMT_ERROR_MESSAGE) && (child != LY_STMT_ARG_TEXT))) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3188 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_UNEXP_SUBELEM, ctx->xmlctx->name_len, ctx->xmlctx->name, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3189 | lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3190 | return LY_EVALID; |
| 3191 | } |
| 3192 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3193 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3194 | /* no attributes expected */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3195 | while (ctx->xmlctx->status == LYXML_ATTRIBUTE) { |
| 3196 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3197 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3198 | } |
| 3199 | |
| 3200 | /* load and save content */ |
| 3201 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, *arg); |
| 3202 | LY_CHECK_RET(!*arg, LY_EMEM); |
| 3203 | |
| 3204 | /* load closing tag of subelement */ |
| 3205 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3206 | break; |
| 3207 | default: |
| 3208 | LOGINT(ctx->xmlctx->ctx); |
| 3209 | return LY_EINT; |
| 3210 | } |
| 3211 | |
| 3212 | return LY_SUCCESS; |
| 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * @brief Parse yin element into generic structure. |
| 3217 | * |
| 3218 | * @param[in,out] ctx Yin parser context for XML context, logging, and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3219 | * @param[in] parent_stmt Type of parent statement. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3220 | * @param[out] element Where the element structure should be stored. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3221 | * @return LY_ERR values. |
| 3222 | */ |
| 3223 | LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3224 | yin_parse_element_generic(struct lysp_yin_ctx *ctx, enum ly_stmt parent_stmt, struct lysp_stmt **element) |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3225 | { |
| 3226 | LY_ERR ret = LY_SUCCESS; |
| 3227 | struct lysp_stmt *last = NULL, *new = NULL; |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3228 | char *id; |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3229 | |
| 3230 | assert(ctx->xmlctx->status == LYXML_ELEMENT); |
| 3231 | |
| 3232 | /* allocate new structure for element */ |
| 3233 | *element = calloc(1, sizeof(**element)); |
| 3234 | LY_CHECK_ERR_GOTO(!(*element), LOGMEM(ctx->xmlctx->ctx); ret = LY_EMEM, cleanup); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3235 | |
| 3236 | /* store identifier */ |
| 3237 | if (ctx->xmlctx->prefix_len) { |
| 3238 | if (asprintf(&id, "%.*s:%.*s", (int)ctx->xmlctx->prefix_len, ctx->xmlctx->prefix, (int)ctx->xmlctx->name_len, |
| 3239 | ctx->xmlctx->name) == -1) { |
| 3240 | LOGMEM(ctx->xmlctx->ctx); |
| 3241 | ret = LY_EMEM; |
| 3242 | goto cleanup; |
| 3243 | } |
| 3244 | LY_CHECK_GOTO(ret = lydict_insert_zc(ctx->xmlctx->ctx, id, &(*element)->stmt), cleanup); |
| 3245 | |
| 3246 | /* store prefix data for the statement */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 3247 | LY_CHECK_GOTO(ret = ly_store_prefix_data(ctx->xmlctx->ctx, (*element)->stmt, strlen((*element)->stmt), LY_VALUE_XML, |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3248 | &ctx->xmlctx->ns, &(*element)->format, &(*element)->prefix_data), cleanup); |
| 3249 | } else { |
| 3250 | LY_CHECK_GOTO(ret = lydict_insert(ctx->xmlctx->ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, &(*element)->stmt), cleanup); |
| 3251 | } |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3252 | |
| 3253 | (*element)->kw = yin_match_keyword(ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, ctx->xmlctx->prefix, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3254 | ctx->xmlctx->prefix_len, parent_stmt); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3255 | |
| 3256 | last = (*element)->child; |
| 3257 | if ((*element)->kw == LY_STMT_NONE) { |
| 3258 | /* unrecognized element */ |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3259 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_UNEXP_SUBELEM, ctx->xmlctx->name_len, ctx->xmlctx->name, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3260 | lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3261 | ret = LY_EVALID; |
| 3262 | goto cleanup; |
| 3263 | } else if ((*element)->kw != LY_STMT_EXTENSION_INSTANCE) { |
| 3264 | /* element is known yang keyword, which means argument can be parsed correctly. */ |
| 3265 | ret = yin_parse_extension_instance_arg(ctx, (*element)->kw, &(*element)->arg); |
| 3266 | LY_CHECK_GOTO(ret, cleanup); |
| 3267 | } else { |
| 3268 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3269 | |
| 3270 | /* load attributes in generic way, save all attributes in linked list */ |
| 3271 | while (ctx->xmlctx->status == LYXML_ATTRIBUTE) { |
| 3272 | new = calloc(1, sizeof(*last)); |
| 3273 | LY_CHECK_ERR_GOTO(!new, LOGMEM(ctx->xmlctx->ctx); ret = LY_EMEM, cleanup); |
| 3274 | if (!(*element)->child) { |
| 3275 | /* save first */ |
| 3276 | (*element)->child = new; |
| 3277 | } else { |
| 3278 | last->next = new; |
| 3279 | } |
| 3280 | last = new; |
| 3281 | |
| 3282 | last->flags |= LYS_YIN_ATTR; |
| 3283 | LY_CHECK_GOTO(ret = lydict_insert(ctx->xmlctx->ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, &last->stmt), cleanup); |
| 3284 | last->kw = LY_STMT_NONE; |
| 3285 | /* attributes with prefix are ignored */ |
| 3286 | if (!ctx->xmlctx->prefix) { |
| 3287 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3288 | |
| 3289 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, last->arg); |
| 3290 | LY_CHECK_ERR_GOTO(!last->arg, ret = LY_EMEM, cleanup); |
| 3291 | } else { |
| 3292 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3293 | } |
| 3294 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | if ((ctx->xmlctx->status != LYXML_ELEM_CONTENT) || ctx->xmlctx->ws_only) { |
| 3299 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3300 | while (ctx->xmlctx->status == LYXML_ELEMENT) { |
| 3301 | /* parse subelements */ |
| 3302 | ret = yin_parse_element_generic(ctx, (*element)->kw, &new); |
| 3303 | LY_CHECK_GOTO(ret, cleanup); |
| 3304 | if (!(*element)->child) { |
| 3305 | /* save first */ |
| 3306 | (*element)->child = new; |
| 3307 | } else { |
| 3308 | last->next = new; |
| 3309 | } |
| 3310 | last = new; |
| 3311 | |
| 3312 | assert(ctx->xmlctx->status == LYXML_ELEM_CLOSE); |
| 3313 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3314 | } |
| 3315 | } else { |
| 3316 | /* save element content */ |
| 3317 | if (ctx->xmlctx->value_len) { |
| 3318 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, (*element)->arg); |
| 3319 | LY_CHECK_ERR_GOTO(!(*element)->arg, ret = LY_EMEM, cleanup); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3320 | |
| 3321 | /* store prefix data for the argument as well */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 3322 | LY_CHECK_GOTO(ret = ly_store_prefix_data(ctx->xmlctx->ctx, (*element)->arg, strlen((*element)->arg), LY_VALUE_XML, |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3323 | &ctx->xmlctx->ns, &(*element)->format, &(*element)->prefix_data), cleanup); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | /* read closing tag */ |
| 3327 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3328 | } |
| 3329 | |
| 3330 | cleanup: |
| 3331 | return ret; |
| 3332 | } |
| 3333 | |
| 3334 | /** |
| 3335 | * @brief Parse instance of extension. |
| 3336 | * |
| 3337 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3338 | * @param[in] parent Current statement parent. |
| 3339 | * @param[in] parent_stmt Type of @p parent statement. |
| 3340 | * @param[in] parent_stmt_index In case of several @p parent_stmt, index of the relevant @p parent statement. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3341 | * @param[in,out] exts Extension instance to add to. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3342 | * @return LY_ERR values. |
| 3343 | */ |
| 3344 | LY_ERR |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3345 | yin_parse_extension_instance(struct lysp_yin_ctx *ctx, const void *parent, enum ly_stmt parent_stmt, |
| 3346 | LY_ARRAY_COUNT_TYPE parent_stmt_index, struct lysp_ext_instance **exts) |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3347 | { |
| 3348 | struct lysp_ext_instance *e; |
| 3349 | struct lysp_stmt *last_subelem = NULL, *new_subelem = NULL; |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3350 | char *ext_name; |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3351 | |
| 3352 | assert(ctx->xmlctx->status == LYXML_ELEMENT); |
Radek Krejci | 3aac9a7 | 2020-12-01 12:24:26 +0100 | [diff] [blame] | 3353 | assert(exts); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3354 | |
| 3355 | LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *exts, e, LY_EMEM); |
| 3356 | |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3357 | if (!ctx->xmlctx->prefix_len) { |
| 3358 | LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Extension instance \"%*.s\" without the mandatory prefix.", |
| 3359 | (int)ctx->xmlctx->name_len, ctx->xmlctx->name); |
| 3360 | return LY_EVALID; |
| 3361 | } |
| 3362 | |
| 3363 | /* store prefixed name */ |
| 3364 | if (asprintf(&ext_name, "%.*s:%.*s", (int)ctx->xmlctx->prefix_len, ctx->xmlctx->prefix, (int)ctx->xmlctx->name_len, |
| 3365 | ctx->xmlctx->name) == -1) { |
| 3366 | LOGMEM(ctx->xmlctx->ctx); |
| 3367 | return LY_EMEM; |
| 3368 | } |
| 3369 | LY_CHECK_RET(lydict_insert_zc(ctx->xmlctx->ctx, ext_name, &e->name)); |
| 3370 | |
| 3371 | /* store prefix data for the name */ |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 3372 | LY_CHECK_RET(ly_store_prefix_data(ctx->xmlctx->ctx, e->name, strlen(e->name), LY_VALUE_XML, &ctx->xmlctx->ns, |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3373 | &e->format, &e->prefix_data)); |
| 3374 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3375 | e->parent = (void *)parent; |
| 3376 | e->parent_stmt = parent_stmt; |
| 3377 | e->parent_stmt_index = parent_stmt_index; |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3378 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3379 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3380 | |
| 3381 | /* store attributes as subelements */ |
| 3382 | while (ctx->xmlctx->status == LYXML_ATTRIBUTE) { |
| 3383 | if (!ctx->xmlctx->prefix) { |
| 3384 | new_subelem = calloc(1, sizeof(*new_subelem)); |
| 3385 | if (!e->child) { |
| 3386 | e->child = new_subelem; |
| 3387 | } else { |
| 3388 | last_subelem->next = new_subelem; |
| 3389 | } |
| 3390 | last_subelem = new_subelem; |
| 3391 | |
| 3392 | last_subelem->flags |= LYS_YIN_ATTR; |
| 3393 | LY_CHECK_RET(lydict_insert(ctx->xmlctx->ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, &last_subelem->stmt)); |
| 3394 | LY_CHECK_RET(!last_subelem->stmt, LY_EMEM); |
| 3395 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3396 | |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 3397 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, |
| 3398 | last_subelem->arg); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3399 | LY_CHECK_RET(!last_subelem->arg, LY_EMEM); |
| 3400 | } else { |
| 3401 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3402 | } |
| 3403 | |
| 3404 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3405 | } |
| 3406 | |
| 3407 | /* parse subelements */ |
| 3408 | assert(ctx->xmlctx->status == LYXML_ELEM_CONTENT); |
| 3409 | if (ctx->xmlctx->ws_only) { |
| 3410 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3411 | while (ctx->xmlctx->status == LYXML_ELEMENT) { |
| 3412 | LY_CHECK_RET(yin_parse_element_generic(ctx, LY_STMT_EXTENSION_INSTANCE, &new_subelem)); |
| 3413 | if (!e->child) { |
| 3414 | e->child = new_subelem; |
| 3415 | } else { |
| 3416 | last_subelem->next = new_subelem; |
| 3417 | } |
| 3418 | last_subelem = new_subelem; |
| 3419 | |
| 3420 | assert(ctx->xmlctx->status == LYXML_ELEM_CLOSE); |
| 3421 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3422 | } |
| 3423 | } else if (ctx->xmlctx->value_len) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3424 | /* invalid text content */ |
| 3425 | LOGVAL_PARSER(ctx, LYVE_SYNTAX, "Extension instance \"%s\" with unexpected text content \".*s\".", ext_name, |
| 3426 | (int)ctx->xmlctx->value_len, ctx->xmlctx->value); |
| 3427 | return LY_EVALID; |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3428 | } |
| 3429 | |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 3430 | e->parsed = NULL; |
| 3431 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3432 | return LY_SUCCESS; |
| 3433 | } |
| 3434 | |
| 3435 | /** |
| 3436 | * @brief Generic function for content parsing |
| 3437 | * |
| 3438 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
| 3439 | * @param[in] subelem_info array of valid subelement types and meta information |
| 3440 | * @param[in] subelem_info_size Size of subelem_info array. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3441 | * @param[in] parent Current statement parent. |
| 3442 | * @param[in] parent_stmt Type of @p parent statement. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3443 | * @param[out] text_content Where the text content of element should be stored if any. Text content is ignored if set to NULL. |
| 3444 | * @param[in,out] exts Extension instance to add to. Can be set to null if element cannot have extension as subelements. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3445 | * @return LY_ERR values. |
| 3446 | */ |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3447 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3448 | yin_parse_content(struct lysp_yin_ctx *ctx, struct yin_subelement *subelem_info, size_t subelem_info_size, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3449 | const void *parent, enum ly_stmt parent_stmt, const char **text_content, struct lysp_ext_instance **exts) |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3450 | { |
| 3451 | LY_ERR ret = LY_SUCCESS; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3452 | enum LYXML_PARSER_STATUS next_status; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3453 | enum ly_stmt cur_stmt = LY_STMT_NONE, last_stmt = LY_STMT_NONE; |
David Sedlák | 1af868e | 2019-07-17 17:03:14 +0200 | [diff] [blame] | 3454 | struct yin_subelement *subelem = NULL; |
David Sedlák | 09e18c9 | 2019-07-18 11:17:11 +0200 | [diff] [blame] | 3455 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3456 | assert(ctx->xmlctx->status == LYXML_ELEM_CONTENT); |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3457 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3458 | if (ctx->xmlctx->ws_only) { |
| 3459 | /* check whether there are any children */ |
| 3460 | LY_CHECK_GOTO(ret = lyxml_ctx_peek(ctx->xmlctx, &next_status), cleanup); |
| 3461 | } else { |
| 3462 | /* we want to parse the value */ |
| 3463 | next_status = LYXML_ELEM_CLOSE; |
| 3464 | } |
| 3465 | |
| 3466 | if (next_status == LYXML_ELEMENT) { |
| 3467 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3468 | |
| 3469 | /* current element has subelements as content */ |
| 3470 | while (ctx->xmlctx->status == LYXML_ELEMENT) { |
| 3471 | /* match keyword */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3472 | last_stmt = cur_stmt; |
| 3473 | cur_stmt = yin_match_keyword(ctx, ctx->xmlctx->name, ctx->xmlctx->name_len, ctx->xmlctx->prefix, |
| 3474 | ctx->xmlctx->prefix_len, parent_stmt); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3475 | |
| 3476 | /* check if this element can be child of current element */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3477 | subelem = get_record(cur_stmt, subelem_info_size, subelem_info); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3478 | if (!subelem) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3479 | if ((parent_stmt == LY_STMT_DEVIATE) && isdevsub(cur_stmt)) { |
| 3480 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INDEV_YIN, lyplg_ext_stmt2str(cur_stmt)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3481 | } else { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3482 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_UNEXP_SUBELEM, ctx->xmlctx->name_len, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3483 | ctx->xmlctx->name, lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3484 | } |
| 3485 | ret = LY_EVALID; |
| 3486 | goto cleanup; |
| 3487 | } |
| 3488 | |
| 3489 | /* relative order is required only in module and submodule sub-elements */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3490 | if ((parent_stmt == LY_STMT_MODULE) || (parent_stmt == LY_STMT_SUBMODULE)) { |
| 3491 | ret = yin_check_relative_order(ctx, last_stmt, cur_stmt, parent_stmt); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3492 | LY_CHECK_GOTO(ret, cleanup); |
| 3493 | } |
| 3494 | |
| 3495 | /* flag check */ |
| 3496 | if ((subelem->flags & YIN_SUBELEM_UNIQUE) && (subelem->flags & YIN_SUBELEM_PARSED)) { |
| 3497 | /* subelement uniquenes */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3498 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_SUBELEM_REDEF, lyplg_ext_stmt2str(cur_stmt), lyplg_ext_stmt2str(parent_stmt)); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3499 | return LY_EVALID; |
| 3500 | } |
| 3501 | if (subelem->flags & YIN_SUBELEM_FIRST) { |
| 3502 | /* subelement is supposed to be defined as first subelement */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3503 | ret = yin_check_subelem_first_constraint(ctx, subelem_info, subelem_info_size, parent_stmt, subelem); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3504 | LY_CHECK_GOTO(ret, cleanup); |
| 3505 | } |
| 3506 | if (subelem->flags & YIN_SUBELEM_VER2) { |
| 3507 | /* subelement is supported only in version 1.1 or higher */ |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3508 | if (PARSER_CUR_PMOD(ctx)->version < LYS_VERSION_1_1) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3509 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_INSUBELEM2, lyplg_ext_stmt2str(cur_stmt), lyplg_ext_stmt2str(parent_stmt)); |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3510 | ret = LY_EVALID; |
| 3511 | goto cleanup; |
| 3512 | } |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3513 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3514 | /* note that element was parsed for easy uniqueness check in next iterations */ |
| 3515 | subelem->flags |= YIN_SUBELEM_PARSED; |
| 3516 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3517 | switch (cur_stmt) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3518 | /* call responsible function */ |
| 3519 | case LY_STMT_EXTENSION_INSTANCE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3520 | ret = yin_parse_extension_instance(ctx, parent, parent_stmt, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3521 | (subelem->dest) ? *((LY_ARRAY_COUNT_TYPE *)subelem->dest) : 0, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3522 | break; |
| 3523 | case LY_STMT_ACTION: |
| 3524 | case LY_STMT_RPC: |
| 3525 | ret = yin_parse_action(ctx, (struct tree_node_meta *)subelem->dest); |
| 3526 | break; |
| 3527 | case LY_STMT_ANYDATA: |
| 3528 | case LY_STMT_ANYXML: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3529 | ret = yin_parse_any(ctx, cur_stmt, (struct tree_node_meta *)subelem->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3530 | break; |
| 3531 | case LY_STMT_ARGUMENT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3532 | ret = yin_parse_argument(ctx, parent, (struct yin_argument_meta *)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3533 | break; |
| 3534 | case LY_STMT_AUGMENT: |
| 3535 | ret = yin_parse_augment(ctx, (struct tree_node_meta *)subelem->dest); |
| 3536 | break; |
| 3537 | case LY_STMT_BASE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3538 | ret = yin_parse_base(ctx, parent_stmt, subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3539 | break; |
| 3540 | case LY_STMT_BELONGS_TO: |
| 3541 | ret = yin_parse_belongs_to(ctx, (struct lysp_submodule *)subelem->dest, exts); |
| 3542 | break; |
| 3543 | case LY_STMT_BIT: |
| 3544 | ret = yin_parse_bit(ctx, (struct lysp_type *)subelem->dest); |
| 3545 | break; |
| 3546 | case LY_STMT_CASE: |
| 3547 | ret = yin_parse_case(ctx, (struct tree_node_meta *)subelem->dest); |
| 3548 | break; |
| 3549 | case LY_STMT_CHOICE: |
| 3550 | ret = yin_parse_choice(ctx, (struct tree_node_meta *)subelem->dest); |
| 3551 | break; |
| 3552 | case LY_STMT_CONFIG: |
| 3553 | ret = yin_parse_config(ctx, (uint16_t *)subelem->dest, exts); |
| 3554 | break; |
| 3555 | case LY_STMT_CONTACT: |
| 3556 | case LY_STMT_DESCRIPTION: |
| 3557 | case LY_STMT_ORGANIZATION: |
| 3558 | case LY_STMT_REFERENCE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3559 | ret = yin_parse_meta(ctx, parent, cur_stmt, (const char **)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3560 | break; |
| 3561 | case LY_STMT_CONTAINER: |
| 3562 | ret = yin_parse_container(ctx, (struct tree_node_meta *)subelem->dest); |
| 3563 | break; |
| 3564 | case LY_STMT_DEFAULT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3565 | ret = yin_parse_qname(ctx, cur_stmt, subelem, exts); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3566 | break; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3567 | case LY_STMT_ERROR_APP_TAG: |
| 3568 | case LY_STMT_KEY: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3569 | ret = yin_parse_simple_elem(ctx, parent, cur_stmt, subelem, YIN_ARG_VALUE, Y_STR_ARG, exts); |
| 3570 | break; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3571 | case LY_STMT_PRESENCE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3572 | ret = yin_parse_simple_elem(ctx, *(const char **)subelem->dest, cur_stmt, subelem, YIN_ARG_VALUE, Y_STR_ARG, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3573 | break; |
| 3574 | case LY_STMT_DEVIATE: |
| 3575 | ret = yin_parse_deviate(ctx, (struct lysp_deviate **)subelem->dest); |
| 3576 | break; |
| 3577 | case LY_STMT_DEVIATION: |
| 3578 | ret = yin_parse_deviation(ctx, (struct lysp_deviation **)subelem->dest); |
| 3579 | break; |
| 3580 | case LY_STMT_ENUM: |
| 3581 | ret = yin_parse_enum(ctx, (struct lysp_type *)subelem->dest); |
| 3582 | break; |
| 3583 | case LY_STMT_ERROR_MESSAGE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3584 | ret = yin_parse_err_msg(ctx, parent, (const char **)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3585 | break; |
| 3586 | case LY_STMT_EXTENSION: |
| 3587 | ret = yin_parse_extension(ctx, (struct lysp_ext **)subelem->dest); |
| 3588 | break; |
| 3589 | case LY_STMT_FEATURE: |
| 3590 | ret = yin_parse_feature(ctx, (struct lysp_feature **)subelem->dest); |
| 3591 | break; |
| 3592 | case LY_STMT_FRACTION_DIGITS: |
| 3593 | ret = yin_parse_fracdigits(ctx, (struct lysp_type *)subelem->dest); |
| 3594 | break; |
| 3595 | case LY_STMT_GROUPING: |
| 3596 | ret = yin_parse_grouping(ctx, (struct tree_node_meta *)subelem->dest); |
| 3597 | break; |
| 3598 | case LY_STMT_IDENTITY: |
| 3599 | ret = yin_parse_identity(ctx, (struct lysp_ident **)subelem->dest); |
| 3600 | break; |
Radek Iša | be8a653 | 2021-03-29 08:54:22 +0200 | [diff] [blame] | 3601 | case LY_STMT_UNIQUE: |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3602 | case LY_STMT_IF_FEATURE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3603 | ret = yin_parse_qname(ctx, cur_stmt, subelem, exts); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 3604 | break; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3605 | case LY_STMT_UNITS: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3606 | ret = yin_parse_simple_elem(ctx, *(const char **)subelem->dest, cur_stmt, subelem, YIN_ARG_NAME, Y_STR_ARG, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3607 | break; |
| 3608 | case LY_STMT_IMPORT: |
| 3609 | ret = yin_parse_import(ctx, (struct import_meta *)subelem->dest); |
| 3610 | break; |
| 3611 | case LY_STMT_INCLUDE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3612 | if ((parent_stmt == LY_STMT_SUBMODULE) && (PARSER_CUR_PMOD(ctx)->version == LYS_VERSION_1_1)) { |
| 3613 | LOGWRN(PARSER_CTX(ctx), "YANG version 1.1 expects all includes in main module, includes in " |
| 3614 | "submodules (%s) are not necessary.", ((struct lysp_submodule *)PARSER_CUR_PMOD(ctx))->name); |
Radek Krejci | eeee95c | 2021-01-19 10:57:22 +0100 | [diff] [blame] | 3615 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3616 | ret = yin_parse_include(ctx, (struct include_meta *)subelem->dest); |
| 3617 | break; |
| 3618 | case LY_STMT_INPUT: |
| 3619 | case LY_STMT_OUTPUT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3620 | ret = yin_parse_inout(ctx, cur_stmt, (struct inout_meta *)subelem->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3621 | break; |
| 3622 | case LY_STMT_LEAF: |
| 3623 | ret = yin_parse_leaf(ctx, (struct tree_node_meta *)subelem->dest); |
| 3624 | break; |
| 3625 | case LY_STMT_LEAF_LIST: |
| 3626 | ret = yin_parse_leaflist(ctx, (struct tree_node_meta *)subelem->dest); |
| 3627 | break; |
| 3628 | case LY_STMT_LENGTH: |
| 3629 | ret = yin_parse_length(ctx, (struct lysp_type *)subelem->dest); |
| 3630 | break; |
| 3631 | case LY_STMT_LIST: |
| 3632 | ret = yin_parse_list(ctx, (struct tree_node_meta *)subelem->dest); |
| 3633 | break; |
| 3634 | case LY_STMT_MANDATORY: |
| 3635 | ret = yin_parse_mandatory(ctx, (uint16_t *)subelem->dest, exts); |
| 3636 | break; |
| 3637 | case LY_STMT_MAX_ELEMENTS: |
| 3638 | case LY_STMT_MIN_ELEMENTS: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3639 | ret = yin_parse_minmax(ctx, parent_stmt, cur_stmt, subelem->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3640 | break; |
| 3641 | case LY_STMT_MODIFIER: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3642 | ret = yin_parse_modifier(ctx, parent, (const char **)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3643 | break; |
| 3644 | case LY_STMT_MUST: |
| 3645 | ret = yin_parse_must(ctx, (struct lysp_restr **)subelem->dest); |
| 3646 | break; |
| 3647 | case LY_STMT_NAMESPACE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3648 | ret = yin_parse_simple_elem(ctx, parent, cur_stmt, subelem, YIN_ARG_URI, Y_STR_ARG, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3649 | break; |
| 3650 | case LY_STMT_NOTIFICATION: |
| 3651 | ret = yin_parse_notification(ctx, (struct tree_node_meta *)subelem->dest); |
| 3652 | break; |
| 3653 | case LY_STMT_ORDERED_BY: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3654 | ret = yin_parse_orderedby(ctx, parent, (uint16_t *)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3655 | break; |
| 3656 | case LY_STMT_PATH: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3657 | ret = yin_parse_path(ctx, (struct lysp_type *)subelem->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3658 | break; |
| 3659 | case LY_STMT_PATTERN: |
| 3660 | ret = yin_parse_pattern(ctx, (struct lysp_type *)subelem->dest); |
| 3661 | break; |
| 3662 | case LY_STMT_VALUE: |
| 3663 | case LY_STMT_POSITION: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3664 | ret = yin_parse_value_pos(ctx, cur_stmt, (struct lysp_type_enum *)subelem->dest); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3665 | break; |
| 3666 | case LY_STMT_PREFIX: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3667 | ret = yin_parse_simple_elem(ctx, *(const char **)subelem->dest, cur_stmt, subelem, YIN_ARG_VALUE, |
| 3668 | Y_IDENTIF_ARG, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3669 | break; |
| 3670 | case LY_STMT_RANGE: |
| 3671 | ret = yin_parse_range(ctx, (struct lysp_type *)subelem->dest); |
| 3672 | break; |
| 3673 | case LY_STMT_REFINE: |
| 3674 | ret = yin_parse_refine(ctx, (struct lysp_refine **)subelem->dest); |
| 3675 | break; |
| 3676 | case LY_STMT_REQUIRE_INSTANCE: |
| 3677 | ret = yin_pasrse_reqinstance(ctx, (struct lysp_type *)subelem->dest); |
| 3678 | break; |
| 3679 | case LY_STMT_REVISION: |
| 3680 | ret = yin_parse_revision(ctx, (struct lysp_revision **)subelem->dest); |
| 3681 | break; |
| 3682 | case LY_STMT_REVISION_DATE: |
| 3683 | ret = yin_parse_revision_date(ctx, (char *)subelem->dest, exts); |
| 3684 | break; |
| 3685 | case LY_STMT_STATUS: |
| 3686 | ret = yin_parse_status(ctx, (uint16_t *)subelem->dest, exts); |
| 3687 | break; |
| 3688 | case LY_STMT_TYPE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3689 | ret = yin_parse_type(ctx, parent_stmt, subelem); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3690 | break; |
| 3691 | case LY_STMT_TYPEDEF: |
| 3692 | ret = yin_parse_typedef(ctx, (struct tree_node_meta *)subelem->dest); |
| 3693 | break; |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3694 | case LY_STMT_USES: |
| 3695 | ret = yin_parse_uses(ctx, (struct tree_node_meta *)subelem->dest); |
| 3696 | break; |
| 3697 | case LY_STMT_WHEN: |
| 3698 | ret = yin_parse_when(ctx, (struct lysp_when **)subelem->dest); |
| 3699 | break; |
| 3700 | case LY_STMT_YANG_VERSION: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3701 | ret = yin_parse_yangversion(ctx, parent, (uint8_t *)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3702 | break; |
| 3703 | case LY_STMT_YIN_ELEMENT: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3704 | ret = yin_parse_yin_element(ctx, parent, (uint16_t *)subelem->dest, exts); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3705 | break; |
| 3706 | case LY_STMT_ARG_TEXT: |
| 3707 | case LY_STMT_ARG_VALUE: |
| 3708 | /* TODO what to do with content/attributes? */ |
| 3709 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3710 | while (ctx->xmlctx->status == LYXML_ATTRIBUTE) { |
| 3711 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3712 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
| 3713 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3714 | ret = yin_parse_content(ctx, NULL, 0, parent, cur_stmt, (const char **)subelem->dest, NULL); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3715 | break; |
| 3716 | default: |
| 3717 | LOGINT(ctx->xmlctx->ctx); |
| 3718 | ret = LY_EINT; |
David Sedlák | 3ffbc52 | 2019-07-02 17:49:28 +0200 | [diff] [blame] | 3719 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3720 | LY_CHECK_GOTO(ret, cleanup); |
| 3721 | subelem = NULL; |
| 3722 | |
| 3723 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3724 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3725 | } else { |
| 3726 | LY_CHECK_RET(ret); |
| 3727 | /* elements with text or none content */ |
| 3728 | /* save text content, if text_content isn't set, it's just ignored */ |
| 3729 | /* no resources are allocated in this branch, no need to use cleanup label */ |
| 3730 | LY_CHECK_RET(yin_validate_value(ctx, Y_STR_ARG)); |
| 3731 | if (text_content) { |
Radek Krejci | 011e4aa | 2020-09-04 15:22:31 +0200 | [diff] [blame] | 3732 | INSERT_STRING_RET(ctx->xmlctx->ctx, ctx->xmlctx->value, ctx->xmlctx->value_len, ctx->xmlctx->dynamic, *text_content); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3733 | LY_CHECK_RET(!*text_content, LY_EMEM); |
| 3734 | } |
| 3735 | |
| 3736 | LY_CHECK_GOTO(ret = lyxml_ctx_next(ctx->xmlctx), cleanup); |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3737 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3738 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 3739 | /* mandatory subelements are checked only after whole element was succesfully parsed */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3740 | LY_CHECK_RET(yin_check_subelem_mandatory_constraint(ctx, subelem_info, subelem_info_size, parent_stmt)); |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3741 | |
| 3742 | cleanup: |
David Sedlák | d6e5689 | 2019-07-01 15:40:24 +0200 | [diff] [blame] | 3743 | return ret; |
| 3744 | } |
| 3745 | |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 3746 | /** |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3747 | * @brief Parse module element. |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 3748 | * |
| 3749 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3750 | * @param[out] mod Parsed module structure. |
David Sedlák | aa98bba | 2019-09-12 11:52:14 +0200 | [diff] [blame] | 3751 | * @return LY_ERR values. |
| 3752 | */ |
David Sedlák | 1e2cdd0 | 2019-06-27 14:17:43 +0200 | [diff] [blame] | 3753 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3754 | yin_parse_mod(struct lysp_yin_ctx *ctx, struct lysp_module *mod) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3755 | { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3756 | LY_ERR ret = LY_SUCCESS; |
| 3757 | struct yin_subelement *subelems = NULL; |
Michal Vasko | 8dc3199 | 2021-02-22 10:30:47 +0100 | [diff] [blame] | 3758 | const struct lysp_submodule *dup; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3759 | size_t subelems_size; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3760 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 3761 | mod->is_submod = 0; |
| 3762 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3763 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3764 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &mod->mod->name, Y_IDENTIF_ARG, LY_STMT_MODULE)); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3765 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 28, NULL, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3766 | LY_STMT_ANYDATA, &mod->data, YIN_SUBELEM_VER2, |
| 3767 | LY_STMT_ANYXML, &mod->data, 0, |
| 3768 | LY_STMT_AUGMENT, &mod->augments, 0, |
| 3769 | LY_STMT_CHOICE, &mod->data, 0, |
| 3770 | LY_STMT_CONTACT, &mod->mod->contact, YIN_SUBELEM_UNIQUE, |
| 3771 | LY_STMT_CONTAINER, &mod->data, 0, |
| 3772 | LY_STMT_DESCRIPTION, &mod->mod->dsc, YIN_SUBELEM_UNIQUE, |
| 3773 | LY_STMT_DEVIATION, &mod->deviations, 0, |
| 3774 | LY_STMT_EXTENSION, &mod->extensions, 0, |
| 3775 | LY_STMT_FEATURE, &mod->features, 0, |
| 3776 | LY_STMT_GROUPING, &mod->groupings, 0, |
| 3777 | LY_STMT_IDENTITY, &mod->identities, 0, |
| 3778 | LY_STMT_IMPORT, mod->mod->prefix, &mod->imports, 0, |
| 3779 | LY_STMT_INCLUDE, mod->mod->name, &mod->includes, 0, |
| 3780 | LY_STMT_LEAF, &mod->data, 0, |
| 3781 | LY_STMT_LEAF_LIST, &mod->data, 0, |
| 3782 | LY_STMT_LIST, &mod->data, 0, |
| 3783 | LY_STMT_NAMESPACE, &mod->mod->ns, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE, |
| 3784 | LY_STMT_NOTIFICATION, &mod->notifs, 0, |
| 3785 | LY_STMT_ORGANIZATION, &mod->mod->org, YIN_SUBELEM_UNIQUE, |
| 3786 | LY_STMT_PREFIX, &mod->mod->prefix, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE, |
| 3787 | LY_STMT_REFERENCE, &mod->mod->ref, YIN_SUBELEM_UNIQUE, |
| 3788 | LY_STMT_REVISION, &mod->revs, 0, |
| 3789 | LY_STMT_RPC, &mod->rpcs, 0, |
| 3790 | LY_STMT_TYPEDEF, &mod->typedefs, 0, |
| 3791 | LY_STMT_USES, &mod->data, 0, |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3792 | LY_STMT_YANG_VERSION, &mod->version, YIN_SUBELEM_UNIQUE, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3793 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3794 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3795 | ret = yin_parse_content(ctx, subelems, subelems_size, mod, LY_STMT_MODULE, NULL, &mod->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3796 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3797 | LY_CHECK_RET(ret); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3798 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 3799 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 3800 | LY_CHECK_RET(yin_unres_exts_add(ctx, mod->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 3801 | |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3802 | /* submodules share the namespace with the module names, so there must not be |
| 3803 | * a submodule of the same name in the context, no need for revision matching */ |
Michal Vasko | 8dc3199 | 2021-02-22 10:30:47 +0100 | [diff] [blame] | 3804 | dup = ly_ctx_get_submodule_latest(ctx->xmlctx->ctx, mod->mod->name); |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3805 | if (dup) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3806 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_NAME2_COL, "module", "submodule", mod->mod->name); |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3807 | return LY_EVALID; |
| 3808 | } |
| 3809 | |
| 3810 | return LY_SUCCESS; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3811 | } |
| 3812 | |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3813 | /** |
| 3814 | * @brief Parse submodule element. |
| 3815 | * |
| 3816 | * @param[in,out] ctx Yin parser context for logging and to store current state. |
| 3817 | * @param[in] mod_attrs Attributes of submodule element. |
| 3818 | * @param[out] submod Parsed submodule structure. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 3819 | * @return LY_ERR values. |
| 3820 | */ |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3821 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3822 | yin_parse_submod(struct lysp_yin_ctx *ctx, struct lysp_submodule *submod) |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3823 | { |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3824 | LY_ERR ret = LY_SUCCESS; |
| 3825 | struct yin_subelement *subelems = NULL; |
Michal Vasko | 8dc3199 | 2021-02-22 10:30:47 +0100 | [diff] [blame] | 3826 | const struct lysp_submodule *dup; |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3827 | size_t subelems_size; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3828 | |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 3829 | submod->is_submod = 1; |
| 3830 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3831 | LY_CHECK_RET(lyxml_ctx_next(ctx->xmlctx)); |
| 3832 | LY_CHECK_RET(yin_parse_attribute(ctx, YIN_ARG_NAME, &submod->name, Y_IDENTIF_ARG, LY_STMT_SUBMODULE)); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3833 | LY_CHECK_RET(subelems_allocator(ctx, subelems_size = 27, NULL, &subelems, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3834 | LY_STMT_ANYDATA, &submod->data, YIN_SUBELEM_VER2, |
| 3835 | LY_STMT_ANYXML, &submod->data, 0, |
| 3836 | LY_STMT_AUGMENT, &submod->augments, 0, |
| 3837 | LY_STMT_BELONGS_TO, submod, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE, |
| 3838 | LY_STMT_CHOICE, &submod->data, 0, |
| 3839 | LY_STMT_CONTACT, &submod->contact, YIN_SUBELEM_UNIQUE, |
| 3840 | LY_STMT_CONTAINER, &submod->data, 0, |
| 3841 | LY_STMT_DESCRIPTION, &submod->dsc, YIN_SUBELEM_UNIQUE, |
| 3842 | LY_STMT_DEVIATION, &submod->deviations, 0, |
| 3843 | LY_STMT_EXTENSION, &submod->extensions, 0, |
| 3844 | LY_STMT_FEATURE, &submod->features, 0, |
| 3845 | LY_STMT_GROUPING, &submod->groupings, 0, |
| 3846 | LY_STMT_IDENTITY, &submod->identities, 0, |
| 3847 | LY_STMT_IMPORT, submod->prefix, &submod->imports, 0, |
| 3848 | LY_STMT_INCLUDE, submod->name, &submod->includes, 0, |
| 3849 | LY_STMT_LEAF, &submod->data, 0, |
| 3850 | LY_STMT_LEAF_LIST, &submod->data, 0, |
| 3851 | LY_STMT_LIST, &submod->data, 0, |
| 3852 | LY_STMT_NOTIFICATION, &submod->notifs, 0, |
| 3853 | LY_STMT_ORGANIZATION, &submod->org, YIN_SUBELEM_UNIQUE, |
| 3854 | LY_STMT_REFERENCE, &submod->ref, YIN_SUBELEM_UNIQUE, |
| 3855 | LY_STMT_REVISION, &submod->revs, 0, |
| 3856 | LY_STMT_RPC, &submod->rpcs, 0, |
| 3857 | LY_STMT_TYPEDEF, &submod->typedefs, 0, |
| 3858 | LY_STMT_USES, &submod->data, 0, |
| 3859 | LY_STMT_YANG_VERSION, &submod->version, YIN_SUBELEM_UNIQUE, |
| 3860 | LY_STMT_EXTENSION_INSTANCE, NULL, 0)); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3861 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3862 | ret = yin_parse_content(ctx, subelems, subelems_size, submod, LY_STMT_SUBMODULE, NULL, &submod->exts); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 3863 | subelems_deallocator(subelems_size, subelems); |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3864 | LY_CHECK_RET(ret); |
David Sedlák | 81497a3 | 2019-08-13 16:56:26 +0200 | [diff] [blame] | 3865 | |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 3866 | /* store extension instance array (no realloc anymore) to find the plugin records and finish parsing */ |
Michal Vasko | 4929d5f | 2022-11-08 13:21:02 +0100 | [diff] [blame] | 3867 | LY_CHECK_RET(yin_unres_exts_add(ctx, submod->exts)); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 3868 | |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3869 | /* submodules share the namespace with the module names, so there must not be |
| 3870 | * a submodule of the same name in the context, no need for revision matching */ |
Michal Vasko | 8dc3199 | 2021-02-22 10:30:47 +0100 | [diff] [blame] | 3871 | dup = ly_ctx_get_submodule_latest(ctx->xmlctx->ctx, submod->name); |
Michal Vasko | c3781c3 | 2020-10-06 14:04:08 +0200 | [diff] [blame] | 3872 | if (dup && strcmp(dup->mod->name, submod->mod->name)) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3873 | LOGVAL_PARSER((struct lysp_ctx *)ctx, LY_VCODE_NAME_COL, "submodules", dup->name); |
David Sedlák | ed809f1 | 2019-09-13 10:15:11 +0200 | [diff] [blame] | 3874 | return LY_EVALID; |
| 3875 | } |
| 3876 | |
| 3877 | return LY_SUCCESS; |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3881 | yin_parse_submodule(struct lysp_yin_ctx **yin_ctx, struct ly_ctx *ctx, struct lysp_ctx *main_ctx, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 3882 | struct ly_in *in, struct lysp_submodule **submod) |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3883 | { |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3884 | enum ly_stmt kw = LY_STMT_NONE; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3885 | LY_ERR ret = LY_SUCCESS; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3886 | struct lysp_submodule *mod_p = NULL; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3887 | struct lysf_ctx fctx = {.ctx = ctx}; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3888 | |
aPiecek | 56be92a | 2021-07-01 07:18:10 +0200 | [diff] [blame] | 3889 | assert(yin_ctx && ctx && main_ctx && in && submod); |
| 3890 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3891 | /* create context */ |
| 3892 | *yin_ctx = calloc(1, sizeof **yin_ctx); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 3893 | LY_CHECK_ERR_RET(!(*yin_ctx), LOGMEM(ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3894 | (*yin_ctx)->format = LYS_IN_YIN; |
aPiecek | 56be92a | 2021-07-01 07:18:10 +0200 | [diff] [blame] | 3895 | (*yin_ctx)->main_ctx = main_ctx; |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3896 | LY_CHECK_RET(lyxml_ctx_new(ctx, in, &(*yin_ctx)->xmlctx)); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3897 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3898 | mod_p = calloc(1, sizeof *mod_p); |
| 3899 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM(ctx); ret = LY_EMEM, cleanup); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3900 | mod_p->mod = PARSER_CUR_PMOD(main_ctx)->mod; |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3901 | mod_p->parsing = 1; |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3902 | |
| 3903 | /* use main context parsed mods adding the current one */ |
| 3904 | (*yin_ctx)->parsed_mods = main_ctx->parsed_mods; |
| 3905 | ly_set_add((*yin_ctx)->parsed_mods, mod_p, 1, NULL); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3906 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3907 | /* check submodule */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3908 | kw = yin_match_keyword(*yin_ctx, (*yin_ctx)->xmlctx->name, (*yin_ctx)->xmlctx->name_len, (*yin_ctx)->xmlctx->prefix, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3909 | (*yin_ctx)->xmlctx->prefix_len, LY_STMT_NONE); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3910 | if (kw == LY_STMT_MODULE) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3911 | LOGERR(ctx, LY_EDENIED, "Input data contains module when a submodule is expected."); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3912 | ret = LY_EINVAL; |
| 3913 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3914 | } else if (kw != LY_STMT_SUBMODULE) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3915 | LOGVAL_PARSER((struct lysp_ctx *)*yin_ctx, LY_VCODE_MOD_SUBOMD, lyplg_ext_stmt2str(kw)); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3916 | ret = LY_EVALID; |
| 3917 | goto cleanup; |
| 3918 | } |
| 3919 | |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3920 | ret = yin_parse_submod(*yin_ctx, mod_p); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3921 | LY_CHECK_GOTO(ret, cleanup); |
| 3922 | |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 3923 | /* skip possible trailing whitespaces at end of the input */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3924 | while (isspace(in->current[0])) { |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 3925 | if (in->current[0] == '\n') { |
| 3926 | LY_IN_NEW_LINE(in); |
| 3927 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3928 | ly_in_skip(in, 1); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3929 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3930 | if (in->current[0]) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3931 | LOGVAL_PARSER((struct lysp_ctx *)*yin_ctx, LY_VCODE_TRAILING_SUBMOD, 15, in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3932 | strlen(in->current) > 15 ? "..." : ""); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3933 | ret = LY_EVALID; |
| 3934 | goto cleanup; |
| 3935 | } |
| 3936 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3937 | mod_p->parsing = 0; |
| 3938 | *submod = mod_p; |
| 3939 | |
| 3940 | cleanup: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3941 | LOG_LOCBACK(0, 0, 0, 1); |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3942 | if (ret) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3943 | lysp_module_free(&fctx, (struct lysp_module *)mod_p); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3944 | lysp_yin_ctx_free(*yin_ctx); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 3945 | *yin_ctx = NULL; |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3946 | } |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3947 | return ret; |
| 3948 | } |
| 3949 | |
| 3950 | LY_ERR |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3951 | yin_parse_module(struct lysp_yin_ctx **yin_ctx, struct ly_in *in, struct lys_module *mod) |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3952 | { |
David Sedlák | e488991 | 2018-11-02 09:52:40 +0100 | [diff] [blame] | 3953 | LY_ERR ret = LY_SUCCESS; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3954 | enum ly_stmt kw = LY_STMT_NONE; |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 3955 | struct lysp_module *mod_p = NULL; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 3956 | struct lysf_ctx fctx = {.ctx = mod->ctx}; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 3957 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3958 | /* create context */ |
| 3959 | *yin_ctx = calloc(1, sizeof **yin_ctx); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 3960 | LY_CHECK_ERR_RET(!(*yin_ctx), LOGMEM(mod->ctx), LY_EMEM); |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3961 | (*yin_ctx)->format = LYS_IN_YIN; |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3962 | LY_CHECK_ERR_RET(ly_set_new(&(*yin_ctx)->parsed_mods), free(*yin_ctx); LOGMEM(mod->ctx), LY_EMEM); |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3963 | LY_CHECK_RET(lyxml_ctx_new(mod->ctx, in, &(*yin_ctx)->xmlctx)); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3964 | (*yin_ctx)->main_ctx = (struct lysp_ctx *)(*yin_ctx); |
David Sedlák | da8ffa3 | 2019-07-08 14:17:10 +0200 | [diff] [blame] | 3965 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3966 | mod_p = calloc(1, sizeof *mod_p); |
| 3967 | LY_CHECK_ERR_GOTO(!mod_p, LOGMEM(mod->ctx), cleanup); |
| 3968 | mod_p->mod = mod; |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 3969 | ly_set_add((*yin_ctx)->parsed_mods, mod_p, 1, NULL); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 3970 | |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3971 | /* check module */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3972 | kw = yin_match_keyword(*yin_ctx, (*yin_ctx)->xmlctx->name, (*yin_ctx)->xmlctx->name_len, (*yin_ctx)->xmlctx->prefix, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3973 | (*yin_ctx)->xmlctx->prefix_len, LY_STMT_NONE); |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3974 | if (kw == LY_STMT_SUBMODULE) { |
David Sedlák | 8985a14 | 2019-07-31 16:43:06 +0200 | [diff] [blame] | 3975 | LOGERR(mod->ctx, LY_EDENIED, "Input data contains submodule which cannot be parsed directly without its main module."); |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 3976 | ret = LY_EINVAL; |
| 3977 | goto cleanup; |
Radek Krejci | d6b7645 | 2019-09-03 17:03:03 +0200 | [diff] [blame] | 3978 | } else if (kw != LY_STMT_MODULE) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 3979 | LOGVAL_PARSER((struct lysp_ctx *)*yin_ctx, LY_VCODE_MOD_SUBOMD, lyplg_ext_stmt2str(kw)); |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 3980 | ret = LY_EVALID; |
| 3981 | goto cleanup; |
David Sedlák | e488991 | 2018-11-02 09:52:40 +0100 | [diff] [blame] | 3982 | } |
| 3983 | |
David Sedlák | 0025034 | 2019-06-21 14:19:39 +0200 | [diff] [blame] | 3984 | /* parse module substatements */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 3985 | ret = yin_parse_mod(*yin_ctx, mod_p); |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 3986 | LY_CHECK_GOTO(ret, cleanup); |
David Sedlák | 2e41142 | 2018-12-17 02:35:39 +0100 | [diff] [blame] | 3987 | |
David Sedlák | bf8a2b7 | 2019-08-14 16:48:10 +0200 | [diff] [blame] | 3988 | /* skip possible trailing whitespaces at end of the input */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3989 | while (isspace(in->current[0])) { |
Radek Krejci | dd713ce | 2021-01-04 23:12:12 +0100 | [diff] [blame] | 3990 | if (in->current[0] == '\n') { |
| 3991 | LY_IN_NEW_LINE(in); |
| 3992 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3993 | ly_in_skip(in, 1); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3994 | } |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 3995 | if (in->current[0]) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 3996 | LOGVAL_PARSER((struct lysp_ctx *)*yin_ctx, LY_VCODE_TRAILING_MOD, 15, in->current, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 3997 | strlen(in->current) > 15 ? "..." : ""); |
David Sedlák | 6d781b6 | 2019-08-02 15:22:52 +0200 | [diff] [blame] | 3998 | ret = LY_EVALID; |
| 3999 | goto cleanup; |
| 4000 | } |
| 4001 | |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 4002 | mod->parsed = mod_p; |
| 4003 | |
| 4004 | cleanup: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 4005 | LOG_LOCBACK(0, 0, 0, 1); |
| 4006 | if (ret) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 4007 | lysp_module_free(&fctx, mod_p); |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 4008 | lysp_yin_ctx_free(*yin_ctx); |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 4009 | *yin_ctx = NULL; |
David Sedlák | 3017da4 | 2019-02-15 09:48:04 +0100 | [diff] [blame] | 4010 | } |
David Sedlák | 2e41142 | 2018-12-17 02:35:39 +0100 | [diff] [blame] | 4011 | return ret; |
David Sedlák | 3b4db24 | 2018-10-19 16:11:01 +0200 | [diff] [blame] | 4012 | } |