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