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