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