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