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