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