Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file yin.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief YIN parser for libyang |
| 5 | * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6 | * Copyright (c) 2015 - 2018 CESNET, z.s.p.o. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 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 |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 15 | #include <assert.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 16 | #include <ctype.h> |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 17 | #include <errno.h> |
| 18 | #include <limits.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 19 | #include <stdint.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 22 | #include <stddef.h> |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 23 | #include <sys/types.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 24 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 25 | #include "libyang.h" |
| 26 | #include "common.h" |
| 27 | #include "context.h" |
Michal Vasko | 6c81070 | 2018-03-14 16:23:21 +0100 | [diff] [blame] | 28 | #include "hash_table.h" |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 29 | #include "xpath.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 30 | #include "parser.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 31 | #include "resolve.h" |
| 32 | #include "tree_internal.h" |
Michal Vasko | fc5744d | 2015-10-22 12:09:34 +0200 | [diff] [blame] | 33 | #include "xml_internal.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 34 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 35 | #define GETVAL(ctx, value, node, arg) \ |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 36 | value = lyxml_get_attr(node, arg, NULL); \ |
| 37 | if (!value) { \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 38 | LOGVAL(ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, arg, node->name); \ |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 39 | goto error; \ |
Michal Vasko | 2d710f3 | 2016-02-05 12:29:21 +0100 | [diff] [blame] | 40 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 41 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 42 | #define YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, counter, storage, name, parent, code) \ |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 43 | if ((counter) == LY_ARRAY_MAX(storage)) { \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 44 | LOGERR(ctx, LY_EINT, "Reached limit (%"PRIu64") for storing %s in %s statement.", \ |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 45 | LY_ARRAY_MAX(storage), name, parent); \ |
| 46 | code; \ |
| 47 | } |
| 48 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 49 | #define YIN_CHECK_ARRAY_OVERFLOW_RETURN(ctx, counter, storage, name, parent, retval) \ |
| 50 | YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, counter, storage, name, parent, return retval) |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 51 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 52 | #define YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, counter, storage, name, parent, target) \ |
| 53 | YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, counter, storage, name, parent, goto target) |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 54 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 55 | #define OPT_IDENT 0x01 |
| 56 | #define OPT_CFG_PARSE 0x02 |
| 57 | #define OPT_CFG_INHERIT 0x04 |
| 58 | #define OPT_CFG_IGNORE 0x08 |
| 59 | #define OPT_MODULE 0x10 |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 60 | static int read_yin_common(struct lys_module *, struct lys_node *, void *, LYEXT_PAR, struct lyxml_elem *, int, |
| 61 | struct unres_schema *); |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 62 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 63 | static struct lys_node *read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 64 | int options, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 65 | static struct lys_node *read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 66 | int options, struct unres_schema *unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 67 | static struct lys_node *read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 68 | LYS_NODE type, int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 69 | static struct lys_node *read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 70 | int options, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 71 | static struct lys_node *read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 72 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 73 | static struct lys_node *read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 74 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 75 | static struct lys_node *read_yin_list(struct lys_module *module,struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 76 | int options, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 77 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 78 | int options, struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 79 | static struct lys_node *read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 80 | int options, struct unres_schema *unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 81 | static struct lys_node *read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 82 | int options, struct unres_schema *unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 83 | static struct lys_node *read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 84 | int options, struct unres_schema *unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 85 | static struct lys_when *read_yin_when(struct lys_module *module, struct lyxml_elem *yin, struct unres_schema *unres); |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 86 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 87 | /* |
| 88 | * yin - the provided XML subtree is unlinked |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 89 | * ext - pointer to the storage in the parent structure to be able to update its location after realloc |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 90 | */ |
| 91 | int |
| 92 | lyp_yin_fill_ext(void *parent, LYEXT_PAR parent_type, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 93 | struct lys_module *module, struct lyxml_elem *yin, struct lys_ext_instance ***ext, |
Michal Vasko | a310a45 | 2018-11-21 12:34:29 +0100 | [diff] [blame] | 94 | uint8_t ext_index, struct unres_schema *unres) |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 95 | { |
| 96 | struct unres_ext *info; |
| 97 | |
| 98 | info = malloc(sizeof *info); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 99 | LY_CHECK_ERR_RETURN(!info, LOGMEM(module->ctx), EXIT_FAILURE); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 100 | lyxml_unlink(module->ctx, yin); |
| 101 | info->data.yin = yin; |
| 102 | info->datatype = LYS_IN_YIN; |
| 103 | info->parent = parent; |
Radek Krejci | a7db970 | 2017-01-20 12:55:14 +0100 | [diff] [blame] | 104 | info->mod = module; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 105 | info->parent_type = parent_type; |
| 106 | info->substmt = substmt; |
| 107 | info->substmt_index = substmt_index; |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 108 | info->ext_index = ext_index; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 109 | |
| 110 | if (unres_schema_add_node(module, unres, ext, UNRES_EXT, (struct lys_node *)info) == -1) { |
| 111 | return EXIT_FAILURE; |
| 112 | } |
| 113 | |
| 114 | return EXIT_SUCCESS; |
| 115 | } |
| 116 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 117 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 118 | static const char * |
| 119 | read_yin_subnode(struct ly_ctx *ctx, struct lyxml_elem *node, const char *name) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 120 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 121 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 122 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 123 | /* there should be <text> child */ |
| 124 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 125 | LOGERR(ctx, LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 126 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 127 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 128 | } else if (node->child->content) { |
| 129 | len = strlen(node->child->content); |
| 130 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 131 | } else { |
| 132 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 133 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 136 | int |
| 137 | lyp_yin_parse_subnode_ext(struct lys_module *mod, void *elem, LYEXT_PAR elem_type, |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 138 | struct lyxml_elem *yin, LYEXT_SUBSTMT type, uint8_t i, struct unres_schema *unres) |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 139 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 140 | void *reallocated; |
| 141 | struct lyxml_elem *next, *child; |
| 142 | int r; |
| 143 | struct lys_ext_instance ***ext; |
Michal Vasko | a310a45 | 2018-11-21 12:34:29 +0100 | [diff] [blame] | 144 | uint8_t *ext_size; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 145 | const char *statement; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 146 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 147 | switch (elem_type) { |
| 148 | case LYEXT_PAR_MODULE: |
| 149 | ext_size = &((struct lys_module *)elem)->ext_size; |
| 150 | ext = &((struct lys_module *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 151 | statement = ((struct lys_module *)elem)->type ? "submodule" : "module"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 152 | break; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 153 | case LYEXT_PAR_IMPORT: |
| 154 | ext_size = &((struct lys_import *)elem)->ext_size; |
| 155 | ext = &((struct lys_import *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 156 | statement = "import"; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 157 | break; |
| 158 | case LYEXT_PAR_INCLUDE: |
| 159 | ext_size = &((struct lys_include *)elem)->ext_size; |
| 160 | ext = &((struct lys_include *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 161 | statement = "include"; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 162 | break; |
| 163 | case LYEXT_PAR_REVISION: |
| 164 | ext_size = &((struct lys_revision *)elem)->ext_size; |
| 165 | ext = &((struct lys_revision *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 166 | statement = "revision"; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 167 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 168 | case LYEXT_PAR_NODE: |
| 169 | ext_size = &((struct lys_node *)elem)->ext_size; |
| 170 | ext = &((struct lys_node *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 171 | statement = strnodetype(((struct lys_node *)elem)->nodetype); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 172 | break; |
| 173 | case LYEXT_PAR_IDENT: |
| 174 | ext_size = &((struct lys_ident *)elem)->ext_size; |
| 175 | ext = &((struct lys_ident *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 176 | statement = "identity"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 177 | break; |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 178 | case LYEXT_PAR_TYPE: |
| 179 | ext_size = &((struct lys_type *)elem)->ext_size; |
| 180 | ext = &((struct lys_type *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 181 | statement = "type"; |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 182 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 183 | case LYEXT_PAR_TYPE_BIT: |
| 184 | ext_size = &((struct lys_type_bit *)elem)->ext_size; |
| 185 | ext = &((struct lys_type_bit *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 186 | statement = "bit"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 187 | break; |
| 188 | case LYEXT_PAR_TYPE_ENUM: |
| 189 | ext_size = &((struct lys_type_enum *)elem)->ext_size; |
| 190 | ext = &((struct lys_type_enum *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 191 | statement = "enum"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 192 | break; |
| 193 | case LYEXT_PAR_TPDF: |
| 194 | ext_size = &((struct lys_tpdf *)elem)->ext_size; |
| 195 | ext = &((struct lys_tpdf *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 196 | statement = " typedef"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 197 | break; |
| 198 | case LYEXT_PAR_EXT: |
| 199 | ext_size = &((struct lys_ext *)elem)->ext_size; |
| 200 | ext = &((struct lys_ext *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 201 | statement = "extension"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 202 | break; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 203 | case LYEXT_PAR_EXTINST: |
| 204 | ext_size = &((struct lys_ext_instance *)elem)->ext_size; |
| 205 | ext = &((struct lys_ext_instance *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 206 | statement = "extension instance"; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 207 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 208 | case LYEXT_PAR_FEATURE: |
| 209 | ext_size = &((struct lys_feature *)elem)->ext_size; |
| 210 | ext = &((struct lys_feature *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 211 | statement = "feature"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 212 | break; |
| 213 | case LYEXT_PAR_REFINE: |
| 214 | ext_size = &((struct lys_refine *)elem)->ext_size; |
| 215 | ext = &((struct lys_refine *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 216 | statement = "refine"; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 217 | break; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 218 | case LYEXT_PAR_RESTR: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 219 | ext_size = &((struct lys_restr *)elem)->ext_size; |
| 220 | ext = &((struct lys_restr *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 221 | statement = "YANG restriction"; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 222 | break; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 223 | case LYEXT_PAR_WHEN: |
| 224 | ext_size = &((struct lys_when *)elem)->ext_size; |
| 225 | ext = &((struct lys_when *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 226 | statement = "when"; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 227 | break; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 228 | case LYEXT_PAR_DEVIATE: |
| 229 | ext_size = &((struct lys_deviate *)elem)->ext_size; |
| 230 | ext = &((struct lys_deviate *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 231 | statement = "deviate"; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 232 | break; |
| 233 | case LYEXT_PAR_DEVIATION: |
| 234 | ext_size = &((struct lys_deviation *)elem)->ext_size; |
| 235 | ext = &((struct lys_deviation *)elem)->ext; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 236 | statement = "deviation"; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 237 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 238 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 239 | LOGERR(mod->ctx, LY_EINT, "parent type %d", elem_type); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 240 | return EXIT_FAILURE; |
| 241 | } |
| 242 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 243 | if (type == LYEXT_SUBSTMT_SELF) { |
| 244 | /* parse for the statement self, not for the substatement */ |
| 245 | child = yin; |
| 246 | next = NULL; |
| 247 | goto parseext; |
| 248 | } |
| 249 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 250 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Michal Vasko | c440572 | 2019-03-14 09:17:34 +0100 | [diff] [blame^] | 251 | if (!child->ns) { |
| 252 | LOGVAL(mod->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Extension instance \"%s\" is missing namespace.", child->name); |
| 253 | return EXIT_FAILURE; |
| 254 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 255 | if (!strcmp(child->ns->value, LY_NSYIN)) { |
| 256 | /* skip the regular YIN nodes */ |
| 257 | continue; |
| 258 | } |
| 259 | |
| 260 | /* parse it as extension */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 261 | parseext: |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 262 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 263 | YIN_CHECK_ARRAY_OVERFLOW_RETURN(mod->ctx, *ext_size, *ext_size, "extension", statement, EXIT_FAILURE); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 264 | /* first, allocate a space for the extension instance in the parent elem */ |
| 265 | reallocated = realloc(*ext, (1 + (*ext_size)) * sizeof **ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 266 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(mod->ctx), EXIT_FAILURE); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 267 | (*ext) = reallocated; |
| 268 | |
| 269 | /* init memory */ |
| 270 | (*ext)[(*ext_size)] = NULL; |
| 271 | |
| 272 | /* parse YIN data */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 273 | r = lyp_yin_fill_ext(elem, elem_type, type, i, mod, child, &(*ext), (*ext_size), unres); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 274 | (*ext_size)++; |
| 275 | if (r) { |
| 276 | return EXIT_FAILURE; |
| 277 | } |
| 278 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 279 | /* done - do not free the child, it is unlinked in lyp_yin_fill_ext */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 282 | return EXIT_SUCCESS; |
| 283 | } |
| 284 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 285 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 286 | static int |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 287 | fill_yin_iffeature(struct lys_node *parent, int parent_is_feature, struct lyxml_elem *yin, struct lys_iffeature *iffeat, |
| 288 | struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 289 | { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 290 | int r, c_ext = 0; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 291 | const char *value; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 292 | struct lyxml_elem *node, *next; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 293 | struct ly_ctx *ctx = parent->module->ctx; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 294 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 295 | GETVAL(ctx, value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 296 | |
| 297 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 298 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 299 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 300 | return EXIT_FAILURE; |
| 301 | } |
| 302 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 303 | if (!(value = transform_iffeat_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 304 | return EXIT_FAILURE; |
| 305 | } |
| 306 | |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 307 | r = resolve_iffeature_compile(iffeat, value, parent, parent_is_feature, unres); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 308 | lydict_remove(ctx, value); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 309 | if (r) { |
| 310 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 313 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 314 | if (!node->ns) { |
| 315 | /* garbage */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 316 | lyxml_free(ctx, node); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 317 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 318 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 319 | YIN_CHECK_ARRAY_OVERFLOW_RETURN(ctx, c_ext, iffeat->ext_size, "extensions", "if-feature", EXIT_FAILURE); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 320 | c_ext++; |
| 321 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 322 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "if-feature"); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 323 | return EXIT_FAILURE; |
| 324 | } |
| 325 | } |
| 326 | if (c_ext) { |
| 327 | iffeat->ext = calloc(c_ext, sizeof *iffeat->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 328 | LY_CHECK_ERR_RETURN(!iffeat->ext, LOGMEM(ctx), EXIT_FAILURE); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 329 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 330 | /* extensions */ |
| 331 | r = lyp_yin_fill_ext(iffeat, LYEXT_PAR_IDENT, 0, 0, parent->module, node, |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 332 | &iffeat->ext, iffeat->ext_size, unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 333 | iffeat->ext_size++; |
| 334 | if (r) { |
| 335 | return EXIT_FAILURE; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 340 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* logs directly */ |
| 344 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 345 | fill_yin_identity(struct lys_module *module, struct lyxml_elem *yin, struct lys_ident *ident, struct unres_schema *unres) |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 346 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 347 | struct lyxml_elem *node, *next; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 348 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 349 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 350 | int rc; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 351 | int c_ftrs = 0, c_base = 0, c_ext = 0; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 352 | void *reallocated; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 353 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 354 | GETVAL(ctx, value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 355 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 356 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 357 | if (read_yin_common(module, NULL, ident, LYEXT_PAR_IDENT, yin, OPT_IDENT | OPT_MODULE, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 358 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 359 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 360 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 361 | if (dup_identities_check(ident->name, module)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 362 | goto error; |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 365 | LY_TREE_FOR(yin->child, node) { |
| 366 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 367 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 368 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, ident->ext_size, "extensions", "identity", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 369 | c_ext++; |
| 370 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 371 | if (c_base && (module->version < 2)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 372 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 373 | goto error; |
| 374 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 375 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_base, ident->base_size, "bases", "identity", error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 376 | if (lyp_yin_parse_subnode_ext(module, ident, LYEXT_PAR_IDENT, node, LYEXT_SUBSTMT_BASE, c_base, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 377 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 378 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 379 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 380 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 381 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 382 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, ident->iffeature_size, "if-features", "identity", error); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 383 | c_ftrs++; |
| 384 | |
| 385 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 386 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 387 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
| 391 | if (c_base) { |
| 392 | ident->base_size = 0; |
| 393 | ident->base = calloc(c_base, sizeof *ident->base); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 394 | LY_CHECK_ERR_GOTO(!ident->base, LOGMEM(ctx), error); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 395 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 396 | if (c_ftrs) { |
| 397 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 398 | LY_CHECK_ERR_GOTO(!ident->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 399 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 400 | if (c_ext) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 401 | /* some extensions may be already present from the substatements */ |
| 402 | reallocated = realloc(ident->ext, (c_ext + ident->ext_size) * sizeof *ident->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 403 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 404 | ident->ext = reallocated; |
| 405 | |
| 406 | /* init memory */ |
| 407 | memset(&ident->ext[ident->ext_size], 0, c_ext * sizeof *ident->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 408 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 409 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 410 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 411 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 412 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 413 | rc = lyp_yin_fill_ext(ident, LYEXT_PAR_IDENT, 0, 0, module, node, &ident->ext, ident->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 414 | ident->ext_size++; |
| 415 | if (rc) { |
| 416 | goto error; |
| 417 | } |
| 418 | } else if (!strcmp(node->name, "base")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 419 | GETVAL(ctx, value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 420 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 421 | if (!value) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 422 | goto error; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 423 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 424 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 425 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 426 | lydict_remove(ctx, value); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 427 | goto error; |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 428 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 429 | lydict_remove(ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 430 | } else if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 431 | rc = fill_yin_iffeature((struct lys_node *)ident, 0, node, &ident->iffeature[ident->iffeature_size], unres); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 432 | ident->iffeature_size++; |
| 433 | if (rc) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 434 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 435 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 436 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 437 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 438 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 439 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 440 | |
| 441 | error: |
| 442 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 445 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 446 | static int |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 447 | read_restr_substmt(struct lys_module *module, struct lys_restr *restr, struct lyxml_elem *yin, |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 448 | struct unres_schema *unres) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 449 | { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 450 | struct lyxml_elem *child, *next; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 451 | const char *value; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 452 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 453 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 454 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 455 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 456 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 457 | continue; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 458 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 459 | /* extension */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 460 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 461 | return EXIT_FAILURE; |
| 462 | } |
| 463 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 464 | if (restr->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 465 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 466 | return EXIT_FAILURE; |
| 467 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 468 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 469 | return EXIT_FAILURE; |
| 470 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 471 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 472 | if (!restr->dsc) { |
| 473 | return EXIT_FAILURE; |
| 474 | } |
| 475 | } else if (!strcmp(child->name, "reference")) { |
| 476 | if (restr->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 477 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 478 | return EXIT_FAILURE; |
| 479 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 480 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 481 | return EXIT_FAILURE; |
| 482 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 483 | restr->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 484 | if (!restr->ref) { |
| 485 | return EXIT_FAILURE; |
| 486 | } |
| 487 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 488 | if (restr->eapptag) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 489 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 490 | return EXIT_FAILURE; |
| 491 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 492 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_ERRTAG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 493 | return EXIT_FAILURE; |
| 494 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 495 | GETVAL(ctx, value, child, "value"); |
| 496 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 497 | } else if (!strcmp(child->name, "error-message")) { |
| 498 | if (restr->emsg) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 499 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 500 | return EXIT_FAILURE; |
| 501 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 502 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_ERRMSG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 503 | return EXIT_FAILURE; |
| 504 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 505 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 506 | if (!restr->emsg) { |
| 507 | return EXIT_FAILURE; |
| 508 | } |
| 509 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 510 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 511 | return EXIT_FAILURE; |
| 512 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 516 | |
| 517 | error: |
| 518 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 521 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 522 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 523 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 524 | int parenttype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 525 | { |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 526 | const char *value, *name, *module_name = NULL; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 527 | struct lys_node *siter; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 528 | struct lyxml_elem *next, *next2, *node, *child, exts; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 529 | struct lys_restr **restrs, *restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 530 | struct lys_type_bit bit, *bits_sc = NULL; |
| 531 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 532 | struct lys_type *dertype; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 533 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 534 | int rc, val_set, c_ftrs, c_ext = 0; |
| 535 | unsigned int i, j; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 536 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 537 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 538 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 539 | size_t len; |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 540 | int in_grp = 0; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 541 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 542 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 543 | /* init */ |
| 544 | memset(&exts, 0, sizeof exts); |
| 545 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 546 | GETVAL(ctx, value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 547 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 548 | if (!value) { |
| 549 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 550 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 551 | |
| 552 | i = parse_identifier(value); |
| 553 | if (i < 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 554 | LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
| 555 | lydict_remove(ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 556 | goto error; |
| 557 | } |
| 558 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 559 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 560 | if (value[i]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 561 | module_name = lydict_insert(ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 562 | name += i; |
| 563 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 564 | LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
| 565 | lydict_remove(ctx, module_name); |
| 566 | lydict_remove(ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 567 | goto error; |
| 568 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 569 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 570 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 571 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 572 | |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 573 | rc = resolve_superior_type(name, module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 574 | if (rc == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 575 | LOGVAL(ctx, LYE_INMOD, LY_VLOG_NONE, NULL, module_name); |
| 576 | lydict_remove(ctx, module_name); |
| 577 | lydict_remove(ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 578 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 579 | |
| 580 | /* the type could not be resolved or it was resolved to an unresolved typedef */ |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 581 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 582 | LOGVAL(ctx, LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
| 583 | lydict_remove(ctx, module_name); |
| 584 | lydict_remove(ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 585 | ret = EXIT_FAILURE; |
| 586 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 587 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 588 | lydict_remove(ctx, module_name); |
| 589 | lydict_remove(ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 590 | |
Michal Vasko | 101658e | 2018-06-05 15:05:54 +0200 | [diff] [blame] | 591 | if (type->value_flags & LY_VALUE_UNRESGRP) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 592 | /* resolved type in grouping, decrease the grouping's nacm number to indicate that one less |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 593 | * unresolved item left inside the grouping, LYTYPE_GRP used as a flag for types inside a grouping. */ |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 594 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 595 | if (siter) { |
Radek Krejci | 93def38 | 2017-05-24 15:33:48 +0200 | [diff] [blame] | 596 | assert(((struct lys_node_grp *)siter)->unres_count); |
| 597 | ((struct lys_node_grp *)siter)->unres_count--; |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 598 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 599 | LOGINT(ctx); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 600 | goto error; |
| 601 | } |
Michal Vasko | 101658e | 2018-06-05 15:05:54 +0200 | [diff] [blame] | 602 | type->value_flags &= ~LY_VALUE_UNRESGRP; |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 603 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 604 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 605 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 606 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 607 | if (lyp_check_status(type->parent->flags, type->parent->module, type->parent->name, |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 608 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 609 | return -1; |
| 610 | } |
| 611 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 612 | /* parse extension instances */ |
| 613 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 614 | if (!node->ns) { |
| 615 | /* garbage */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 616 | lyxml_free(ctx, node); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 617 | continue; |
| 618 | } else if (!strcmp(node->ns->value, LY_NSYIN)) { |
| 619 | /* YANG (YIN) statements - process later */ |
| 620 | continue; |
| 621 | } |
| 622 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 623 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, type->ext_size, "extensions", "type", error); |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 624 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 625 | lyxml_unlink_elem(ctx, node, 2); |
| 626 | lyxml_add_child(ctx, &exts, node); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 627 | c_ext++; |
| 628 | } |
| 629 | if (c_ext) { |
| 630 | type->ext = calloc(c_ext, sizeof *type->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 631 | LY_CHECK_ERR_GOTO(!type->ext, LOGMEM(ctx), error); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 632 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 633 | LY_TREE_FOR_SAFE(exts.child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 634 | rc = lyp_yin_fill_ext(type, LYEXT_PAR_TYPE, 0, 0, module, node, &type->ext, type->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 635 | type->ext_size++; |
| 636 | if (rc) { |
| 637 | goto error; |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 642 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 643 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 644 | /* RFC 6020 9.7.4 - bit */ |
| 645 | |
| 646 | /* get bit specifications, at least one must be present */ |
| 647 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 648 | if (!strcmp(node->name, "bit")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 649 | YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, type->info.bits.count, type->info.bits.count, "bits", "type", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 650 | type->info.bits.count = 0; goto error); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 651 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 652 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 653 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 654 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 655 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 656 | } |
| 657 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 658 | dertype = &type->der->type; |
| 659 | if (!dertype->der) { |
| 660 | if (!type->info.bits.count) { |
| 661 | /* type is derived directly from buit-in bits type and bit statement is required */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 662 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 663 | goto error; |
| 664 | } |
| 665 | } else { |
| 666 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 667 | if (module->version < 2 && type->info.bits.count) { |
| 668 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 669 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 670 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 671 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 672 | goto error; |
| 673 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 674 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 675 | |
| 676 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 677 | LY_CHECK_ERR_GOTO(!type->info.bits.bit, LOGMEM(ctx), error); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 678 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 679 | p = 0; |
Michal Vasko | c643f71 | 2018-09-14 08:26:13 +0200 | [diff] [blame] | 680 | i = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 681 | LY_TREE_FOR(yin->child, next) { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 682 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 683 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 684 | GETVAL(ctx, value, next, "name"); |
| 685 | if (lyp_check_identifier(ctx, value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 686 | goto error; |
| 687 | } |
| 688 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 689 | type->info.bits.bit[i].name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 690 | if (read_yin_common(module, NULL, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, next, 0, unres)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 691 | type->info.bits.count = i + 1; |
| 692 | goto error; |
| 693 | } |
| 694 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 695 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 696 | /* check the name uniqueness */ |
| 697 | for (j = 0; j < i; j++) { |
| 698 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 699 | LOGVAL(ctx, LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 700 | type->info.bits.count = i + 1; |
| 701 | goto error; |
| 702 | } |
| 703 | } |
| 704 | } else { |
| 705 | /* restricted bits type - the name MUST be used in the base type */ |
| 706 | bits_sc = dertype->info.bits.bit; |
| 707 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 708 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 709 | break; |
| 710 | } |
| 711 | } |
| 712 | if (j == dertype->info.bits.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 713 | LOGVAL(ctx, LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 714 | type->info.bits.count = i + 1; |
| 715 | goto error; |
| 716 | } |
| 717 | } |
| 718 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 719 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 720 | p_ = -1; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 721 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 722 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 723 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 724 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 725 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 726 | /* extension */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 727 | if (lyp_yin_parse_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 728 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 729 | goto error; |
| 730 | } |
| 731 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 732 | if (p_ != -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 733 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 734 | type->info.bits.count = i + 1; |
| 735 | goto error; |
| 736 | } |
| 737 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 738 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 739 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 740 | |
| 741 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 742 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 743 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 744 | type->info.bits.count = i + 1; |
| 745 | goto error; |
| 746 | } |
| 747 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 748 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 749 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 750 | /* keep the highest enum value for automatic increment */ |
| 751 | if (type->info.bits.bit[i].pos >= p) { |
| 752 | p = type->info.bits.bit[i].pos; |
| 753 | p++; |
| 754 | } else { |
| 755 | /* check that the value is unique */ |
| 756 | for (j = 0; j < i; j++) { |
| 757 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 758 | LOGVAL(ctx, LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 759 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 760 | type->info.bits.bit[j].name); |
| 761 | type->info.bits.count = i + 1; |
| 762 | goto error; |
| 763 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 764 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 765 | } |
| 766 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 767 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 768 | if (lyp_yin_parse_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 769 | LYEXT_SUBSTMT_POSITION, 0, unres)) { |
| 770 | goto error; |
| 771 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 772 | |
PavolVican | 0144fae | 2018-02-05 15:54:17 +0100 | [diff] [blame] | 773 | for (j = 0; j < type->info.bits.bit[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 774 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 775 | if (type->info.bits.bit[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 776 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 777 | break; |
| 778 | } |
| 779 | } |
| 780 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 781 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 782 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, type->info.bits.bit[i].iffeature_size, "if-features", "bit", error); |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 783 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 784 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 785 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 786 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 787 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 788 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 789 | |
| 790 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 791 | if (p_ == -1) { |
| 792 | /* assign value automatically */ |
| 793 | if (p > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 794 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 795 | type->info.bits.count = i + 1; |
| 796 | goto error; |
| 797 | } |
| 798 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 799 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 800 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 801 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 802 | } else { /* restricted bits type */ |
| 803 | if (p_ == -1) { |
| 804 | /* automatically assign position from base type */ |
| 805 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 806 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 807 | } else { |
| 808 | /* check that the assigned position corresponds to the original |
| 809 | * position of the bit in the base type */ |
| 810 | if (p_ != bits_sc[j].pos) { |
| 811 | /* p_ - assigned position in restricted bits |
| 812 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 813 | LOGVAL(ctx, LYE_BITS_INVAL, LY_VLOG_NONE, NULL, type->info.bits.bit[i].pos, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 814 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 815 | type->info.bits.count = i + 1; |
| 816 | goto error; |
| 817 | } |
| 818 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 819 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 820 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 821 | /* if-features */ |
| 822 | if (c_ftrs) { |
| 823 | bits_sc = &type->info.bits.bit[i]; |
| 824 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 825 | if (!bits_sc->iffeature) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 826 | LOGMEM(ctx); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 827 | type->info.bits.count = i + 1; |
| 828 | goto error; |
| 829 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 830 | |
| 831 | LY_TREE_FOR(next->child, node) { |
| 832 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 833 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 834 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 835 | bits_sc->iffeature_size++; |
| 836 | if (rc) { |
| 837 | type->info.bits.count = i + 1; |
| 838 | goto error; |
| 839 | } |
| 840 | } |
| 841 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 842 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 843 | |
| 844 | /* keep them ordered by position */ |
| 845 | j = i; |
| 846 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 847 | /* switch them */ |
| 848 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 849 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 850 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 851 | j--; |
| 852 | } |
Michal Vasko | c643f71 | 2018-09-14 08:26:13 +0200 | [diff] [blame] | 853 | |
| 854 | ++i; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 855 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 856 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 857 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 858 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 859 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 860 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 861 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 862 | if (!strcmp(node->name, "range")) { |
| 863 | if (type->info.dec64.range) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 864 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 865 | goto error; |
| 866 | } |
| 867 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 868 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 869 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 870 | LY_CHECK_ERR_GOTO(!type->info.dec64.range, LOGMEM(ctx), error); |
| 871 | type->info.dec64.range->expr = lydict_insert(ctx, value, 0); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 872 | |
| 873 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 874 | if (read_restr_substmt(module, type->info.dec64.range, node, unres)) { |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 875 | goto error; |
| 876 | } |
PavolVican | 0144fae | 2018-02-05 15:54:17 +0100 | [diff] [blame] | 877 | for (j = 0; j < type->info.dec64.range->ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 878 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 879 | if (type->info.dec64.range->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 880 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 884 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 885 | if (type->info.dec64.dig) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 886 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 887 | goto error; |
| 888 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 889 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 890 | v = strtol(value, NULL, 10); |
| 891 | |
| 892 | /* range check */ |
| 893 | if (v < 1 || v > 18) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 894 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 895 | goto error; |
| 896 | } |
| 897 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 898 | type->info.dec64.div = 10; |
| 899 | for (i = 1; i < v; i++) { |
| 900 | type->info.dec64.div *= 10; |
| 901 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 902 | |
| 903 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 904 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_DIGITS, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 905 | goto error; |
| 906 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 907 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 908 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 909 | goto error; |
| 910 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* mandatory sub-statement(s) check */ |
| 914 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 915 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 916 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 917 | goto error; |
| 918 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 919 | if (type->info.dec64.dig && type->der->type.der) { |
| 920 | /* type is not directly derived from buit-in type and fraction-digits statement is prohibited */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 921 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 922 | goto error; |
| 923 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 924 | |
| 925 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 926 | if (type->der->type.der) { |
| 927 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 928 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 929 | } |
| 930 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 931 | if (type->info.dec64.range && lyp_check_length_range(ctx, type->info.dec64.range->expr, type)) { |
| 932 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 933 | goto error; |
| 934 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 935 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 936 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 937 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 938 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 939 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 940 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 941 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 942 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 943 | if (!strcmp(node->name, "enum")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 944 | YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, type->info.enums.count, type->info.enums.count, "enums", "type", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 945 | type->info.enums.count = 0; goto error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 946 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 947 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 948 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 949 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 950 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 951 | } |
| 952 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 953 | dertype = &type->der->type; |
| 954 | if (!dertype->der) { |
| 955 | if (!type->info.enums.count) { |
| 956 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 957 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 958 | goto error; |
| 959 | } |
| 960 | } else { |
| 961 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 962 | if (module->version < 2 && type->info.enums.count) { |
| 963 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 964 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 965 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 966 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 967 | goto error; |
| 968 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 969 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 970 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 971 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 972 | LY_CHECK_ERR_GOTO(!type->info.enums.enm, LOGMEM(ctx), error); |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 973 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 974 | v = 0; |
Michal Vasko | c643f71 | 2018-09-14 08:26:13 +0200 | [diff] [blame] | 975 | i = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 976 | LY_TREE_FOR(yin->child, next) { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 977 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 978 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 979 | GETVAL(ctx, value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 980 | if (!value[0]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 981 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 982 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty."); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 983 | goto error; |
| 984 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 985 | type->info.enums.enm[i].name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 986 | if (read_yin_common(module, NULL, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, next, 0, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 987 | type->info.enums.count = i + 1; |
| 988 | goto error; |
| 989 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 990 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 991 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 992 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 993 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 994 | LOGVAL(ctx, LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 995 | type->info.enums.count = i + 1; |
| 996 | goto error; |
| 997 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 998 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 999 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 1000 | /* check the name uniqueness */ |
| 1001 | for (j = 0; j < i; j++) { |
| 1002 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1003 | LOGVAL(ctx, LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1004 | type->info.enums.count = i + 1; |
| 1005 | goto error; |
| 1006 | } |
| 1007 | } |
| 1008 | } else { |
| 1009 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 1010 | enms_sc = dertype->info.enums.enm; |
| 1011 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 1012 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 1013 | break; |
| 1014 | } |
| 1015 | } |
| 1016 | if (j == dertype->info.enums.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1017 | LOGVAL(ctx, LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1018 | type->info.enums.count = i + 1; |
| 1019 | goto error; |
| 1020 | } |
| 1021 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 1022 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1023 | val_set = 0; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1024 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 1025 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1026 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1027 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1028 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1029 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1030 | if (lyp_yin_parse_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1031 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 1032 | goto error; |
| 1033 | } |
| 1034 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1035 | if (val_set) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1036 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1037 | type->info.enums.count = i + 1; |
| 1038 | goto error; |
| 1039 | } |
| 1040 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1041 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 1042 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1043 | |
| 1044 | /* range check */ |
| 1045 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1046 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1047 | type->info.enums.count = i + 1; |
| 1048 | goto error; |
| 1049 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1050 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1051 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1052 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1053 | if (!i) { |
| 1054 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1055 | v = type->info.enums.enm[i].value; |
| 1056 | v++; |
| 1057 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1058 | /* keep the highest enum value for automatic increment */ |
| 1059 | if (type->info.enums.enm[i].value >= v) { |
| 1060 | v = type->info.enums.enm[i].value; |
| 1061 | v++; |
| 1062 | } else { |
| 1063 | /* check that the value is unique */ |
| 1064 | for (j = 0; j < i; j++) { |
| 1065 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1066 | LOGVAL(ctx, LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1067 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 1068 | type->info.enums.enm[j].name); |
| 1069 | type->info.enums.count = i + 1; |
| 1070 | goto error; |
| 1071 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1072 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1073 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1074 | } |
| 1075 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 1076 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1077 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1078 | if (lyp_yin_parse_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1079 | LYEXT_SUBSTMT_VALUE, 0, unres)) { |
| 1080 | goto error; |
| 1081 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1082 | |
PavolVican | 0144fae | 2018-02-05 15:54:17 +0100 | [diff] [blame] | 1083 | for (j = 0; j < type->info.enums.enm[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1084 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1085 | if (type->info.enums.enm[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1086 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1087 | break; |
| 1088 | } |
| 1089 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1090 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1091 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, type->info.enums.enm[i].iffeature_size, "if-features", "enum", error); |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1092 | c_ftrs++; |
| 1093 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1094 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1095 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1096 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1097 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1098 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1099 | |
| 1100 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 1101 | if (!val_set) { |
| 1102 | /* assign value automatically */ |
| 1103 | if (v > INT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1104 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1105 | type->info.enums.count = i + 1; |
| 1106 | goto error; |
| 1107 | } |
| 1108 | type->info.enums.enm[i].value = v; |
| 1109 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1110 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1111 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1112 | } else { /* restricted enum type */ |
| 1113 | if (!val_set) { |
| 1114 | /* automatically assign value from base type */ |
| 1115 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 1116 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1117 | } else { |
| 1118 | /* check that the assigned value corresponds to the original |
| 1119 | * value of the enum in the base type */ |
| 1120 | if (v_ != enms_sc[j].value) { |
| 1121 | /* v_ - assigned value in restricted enum |
| 1122 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1123 | LOGVAL(ctx, LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 1124 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, enms_sc[j].value); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1125 | type->info.enums.count = i + 1; |
| 1126 | goto error; |
| 1127 | } |
| 1128 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1129 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1130 | |
| 1131 | /* if-features */ |
| 1132 | if (c_ftrs) { |
| 1133 | enms_sc = &type->info.enums.enm[i]; |
| 1134 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 1135 | if (!enms_sc->iffeature) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1136 | LOGMEM(ctx); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1137 | type->info.enums.count = i + 1; |
| 1138 | goto error; |
| 1139 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1140 | |
| 1141 | LY_TREE_FOR(next->child, node) { |
| 1142 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 1143 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1144 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 1145 | enms_sc->iffeature_size++; |
| 1146 | if (rc) { |
| 1147 | type->info.enums.count = i + 1; |
| 1148 | goto error; |
| 1149 | } |
| 1150 | } |
| 1151 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1152 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1153 | |
Michal Vasko | c643f71 | 2018-09-14 08:26:13 +0200 | [diff] [blame] | 1154 | ++i; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1155 | } |
| 1156 | break; |
| 1157 | |
| 1158 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 1159 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1160 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1161 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1162 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1163 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 1164 | if (strcmp(node->name, "base")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1165 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1166 | goto error; |
| 1167 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1168 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1169 | GETVAL(ctx, value, yin->child, "name"); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1170 | /* store in the JSON format */ |
| 1171 | value = transform_schema2json(module, value); |
| 1172 | if (!value) { |
| 1173 | goto error; |
| 1174 | } |
| 1175 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1176 | lydict_remove(ctx, value); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1177 | if (rc == -1) { |
| 1178 | goto error; |
| 1179 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1180 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1181 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_BASE, 0, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1182 | goto error; |
| 1183 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1186 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1187 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1188 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1189 | break; |
| 1190 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1191 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1192 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1193 | } else { |
| 1194 | if (type->der->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1195 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1196 | goto error; |
| 1197 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1198 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1199 | if (yin->child->next) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1200 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, yin->child->next->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1201 | goto error; |
| 1202 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1203 | break; |
| 1204 | |
| 1205 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1206 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1207 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1208 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1209 | if (!strcmp(node->name, "require-instance")) { |
| 1210 | if (type->info.inst.req) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1211 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1212 | goto error; |
| 1213 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1214 | GETVAL(ctx, value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1215 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1216 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1217 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1218 | type->info.inst.req = -1; |
| 1219 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1220 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1221 | goto error; |
| 1222 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1223 | |
| 1224 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1225 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINSTANCE, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1226 | goto error; |
| 1227 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1228 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1229 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1230 | goto error; |
| 1231 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1232 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1233 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1234 | break; |
| 1235 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1236 | case LY_TYPE_BINARY: |
| 1237 | /* RFC 6020 9.8.1, 9.4.4 - length, number of octets it contains */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1238 | case LY_TYPE_INT8: |
| 1239 | case LY_TYPE_INT16: |
| 1240 | case LY_TYPE_INT32: |
| 1241 | case LY_TYPE_INT64: |
| 1242 | case LY_TYPE_UINT8: |
| 1243 | case LY_TYPE_UINT16: |
| 1244 | case LY_TYPE_UINT32: |
| 1245 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1246 | /* RFC 6020 9.2.4 - range */ |
| 1247 | |
| 1248 | /* length and range are actually the same restriction, so process |
| 1249 | * them by this common code, we just need to differ the name and |
| 1250 | * structure where the information will be stored |
| 1251 | */ |
| 1252 | if (type->base == LY_TYPE_BINARY) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1253 | restrs = &type->info.binary.length; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1254 | name = "length"; |
| 1255 | } else { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1256 | restrs = &type->info.num.range; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1257 | name = "range"; |
| 1258 | } |
| 1259 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1260 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1261 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1262 | if (!strcmp(node->name, name)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1263 | if (*restrs) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1264 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1265 | goto error; |
| 1266 | } |
| 1267 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1268 | GETVAL(ctx, value, node, "value"); |
| 1269 | if (lyp_check_length_range(ctx, value, type)) { |
| 1270 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1271 | goto error; |
| 1272 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1273 | *restrs = calloc(1, sizeof **restrs); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1274 | LY_CHECK_ERR_GOTO(!(*restrs), LOGMEM(ctx), error); |
| 1275 | (*restrs)->expr = lydict_insert(ctx, value, 0); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1276 | |
| 1277 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1278 | if (read_restr_substmt(module, *restrs, node, unres)) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1279 | goto error; |
| 1280 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1281 | |
| 1282 | for (j = 0; j < (*restrs)->ext_size; ++j) { |
| 1283 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1284 | if ((*restrs)->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1285 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1286 | break; |
| 1287 | } |
| 1288 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1289 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1290 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1291 | goto error; |
| 1292 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1293 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1294 | break; |
| 1295 | |
| 1296 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1297 | /* flag resolving for later use */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1298 | if (!parenttype) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1299 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 1300 | if (siter) { |
| 1301 | /* just a flag - do not resolve */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1302 | parenttype = 1; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1306 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1307 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1308 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1309 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1310 | if (type->info.lref.path) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1311 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1312 | goto error; |
| 1313 | } |
| 1314 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1315 | GETVAL(ctx, value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1316 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1317 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1318 | if (!type->info.lref.path) { |
| 1319 | goto error; |
| 1320 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1321 | |
| 1322 | /* try to resolve leafref path only when this is instantiated |
| 1323 | * leaf, so it is not: |
| 1324 | * - typedef's type, |
| 1325 | * - in grouping definition, |
| 1326 | * - just instantiated in a grouping definition, |
| 1327 | * because in those cases the nodes referenced in path might not be present |
| 1328 | * and it is not a bug. */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1329 | if (!parenttype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1330 | goto error; |
| 1331 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1332 | |
| 1333 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1334 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_PATH, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1335 | goto error; |
| 1336 | } |
Radek Krejci | d6353ed | 2016-09-15 13:30:45 +0200 | [diff] [blame] | 1337 | } else if (module->version >= 2 && !strcmp(node->name, "require-instance")) { |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1338 | if (type->info.lref.req) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1339 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1340 | goto error; |
| 1341 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1342 | GETVAL(ctx, value, node, "value"); |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1343 | if (!strcmp(value, "true")) { |
| 1344 | type->info.lref.req = 1; |
| 1345 | } else if (!strcmp(value, "false")) { |
| 1346 | type->info.lref.req = -1; |
| 1347 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1348 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1349 | goto error; |
| 1350 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1351 | |
| 1352 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1353 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINSTANCE, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1354 | goto error; |
| 1355 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1356 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1357 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1358 | goto error; |
| 1359 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1360 | } |
| 1361 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1362 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1363 | if (!type->der->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1364 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1365 | goto error; |
| 1366 | } else { |
| 1367 | /* copy leafref definition into the derived type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1368 | type->info.lref.path = lydict_insert(ctx, type->der->type.info.lref.path, 0); |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1369 | /* and resolve the path at the place we are (if not in grouping/typedef) */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1370 | if (!parenttype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1371 | goto error; |
| 1372 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1373 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1376 | break; |
| 1377 | |
| 1378 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1379 | /* RFC 6020 9.4.4 - length */ |
| 1380 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1381 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1382 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1383 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1384 | if (!strcmp(node->name, "length")) { |
| 1385 | if (type->info.str.length) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1386 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1387 | goto error; |
| 1388 | } |
| 1389 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1390 | GETVAL(ctx, value, node, "value"); |
| 1391 | if (lyp_check_length_range(ctx, value, type)) { |
| 1392 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1393 | goto error; |
| 1394 | } |
| 1395 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1396 | LY_CHECK_ERR_GOTO(!type->info.str.length, LOGMEM(ctx), error); |
| 1397 | type->info.str.length->expr = lydict_insert(ctx, value, 0); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1398 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1399 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1400 | if (read_restr_substmt(module, type->info.str.length, node, unres)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1401 | goto error; |
| 1402 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1403 | |
| 1404 | for (j = 0; j < type->info.str.length->ext_size; ++j) { |
| 1405 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1406 | if (type->info.str.length->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1407 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1408 | break; |
| 1409 | } |
| 1410 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1411 | lyxml_free(ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1412 | } else if (!strcmp(node->name, "pattern")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1413 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, i, type->info.str.pat_count, "patterns", "type", error); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1414 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1415 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1416 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1417 | goto error; |
| 1418 | } |
| 1419 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1420 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1421 | if (i) { |
Radek Krejci | f15cc7c | 2017-07-19 12:00:02 +0200 | [diff] [blame] | 1422 | if (!parenttype && parent && lys_ingrouping(parent)) { |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1423 | in_grp = 1; |
| 1424 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1425 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1426 | LY_CHECK_ERR_GOTO(!type->info.str.patterns, LOGMEM(ctx), error); |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1427 | #ifdef LY_ENABLED_CACHE |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1428 | if (!in_grp) { |
| 1429 | /* do not compile patterns in groupings */ |
Michal Vasko | 95ed90b | 2017-10-31 14:28:07 +0100 | [diff] [blame] | 1430 | type->info.str.patterns_pcre = calloc(2 * i, sizeof *type->info.str.patterns_pcre); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1431 | LY_CHECK_ERR_GOTO(!type->info.str.patterns_pcre, LOGMEM(ctx), error); |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1432 | } |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1433 | #endif |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1434 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1435 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1436 | |
Michal Vasko | 9c7dee3 | 2018-07-09 09:12:59 +0200 | [diff] [blame] | 1437 | if (in_grp) { |
| 1438 | /* in grouping, just check the pattern syntax */ |
| 1439 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && lyp_check_pattern(ctx, value, NULL)) { |
| 1440 | goto error; |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1441 | } |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1442 | } |
Michal Vasko | 9c7dee3 | 2018-07-09 09:12:59 +0200 | [diff] [blame] | 1443 | #ifdef LY_ENABLED_CACHE |
| 1444 | else { |
| 1445 | /* outside grouping, check syntax and precompile pattern for later use by libpcre */ |
| 1446 | if (lyp_precompile_pattern(ctx, value, |
| 1447 | (pcre **)&type->info.str.patterns_pcre[type->info.str.pat_count * 2], |
| 1448 | (pcre_extra **)&type->info.str.patterns_pcre[type->info.str.pat_count * 2 + 1])) { |
| 1449 | goto error; |
| 1450 | } |
| 1451 | } |
| 1452 | #endif |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1453 | restr = &type->info.str.patterns[type->info.str.pat_count]; /* shortcut */ |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1454 | type->info.str.pat_count++; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1455 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1456 | modifier = 0x06; /* ACK */ |
| 1457 | name = NULL; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1458 | if (module->version >= 2) { |
| 1459 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1460 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 1461 | if (name) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1462 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1463 | goto error; |
| 1464 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1465 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1466 | GETVAL(ctx, name, child, "value"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1467 | if (!strcmp(name, "invert-match")) { |
| 1468 | modifier = 0x15; /* NACK */ |
| 1469 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1470 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1471 | goto error; |
| 1472 | } |
| 1473 | /* get extensions of the modifier */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1474 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1475 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 1476 | goto error; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1477 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1478 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1479 | lyxml_free(ctx, child); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1480 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | len = strlen(value); |
| 1485 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1486 | LY_CHECK_ERR_GOTO(!buf, LOGMEM(ctx), error); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1487 | buf[0] = modifier; |
| 1488 | strcpy(&buf[1], value); |
| 1489 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1490 | restr->expr = lydict_insert_zc(ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1491 | |
| 1492 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1493 | if (read_restr_substmt(module, restr, node, unres)) { |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1494 | goto error; |
| 1495 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1496 | |
| 1497 | for (j = 0; j < restr->ext_size; ++j) { |
| 1498 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1499 | if (restr->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1500 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1501 | break; |
| 1502 | } |
| 1503 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1504 | } |
| 1505 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1506 | break; |
| 1507 | |
| 1508 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1509 | /* RFC 6020 7.4 - type */ |
| 1510 | /* count number of types in union */ |
| 1511 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1512 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1513 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1514 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1515 | if (type->der->type.der) { |
| 1516 | /* type can be a substatement only in "union" type, not in derived types */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1517 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1518 | goto error; |
| 1519 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1520 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, i, type->info.uni.count, "types", "type", error); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1521 | i++; |
| 1522 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1523 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1524 | goto error; |
| 1525 | } |
| 1526 | } |
| 1527 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1528 | if (!i && !type->der->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1529 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1530 | goto error; |
| 1531 | } |
| 1532 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1533 | /* inherit instid presence information */ |
| 1534 | if ((type->der->type.base == LY_TYPE_UNION) && type->der->type.info.uni.has_ptr_type) { |
| 1535 | type->info.uni.has_ptr_type = 1; |
| 1536 | } |
| 1537 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1538 | /* allocate array for union's types ... */ |
Michal Vasko | adeddfc | 2017-06-30 13:12:42 +0200 | [diff] [blame] | 1539 | if (i) { |
| 1540 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1541 | LY_CHECK_ERR_GOTO(!type->info.uni.types, LOGMEM(ctx), error); |
Michal Vasko | adeddfc | 2017-06-30 13:12:42 +0200 | [diff] [blame] | 1542 | } |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1543 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1544 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1545 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1546 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1547 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], parenttype, unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1548 | if (!rc) { |
| 1549 | type->info.uni.count++; |
| 1550 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1551 | if (module->version < 2) { |
| 1552 | /* union's type cannot be empty or leafref */ |
| 1553 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1554 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1555 | rc = -1; |
| 1556 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1557 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1558 | rc = -1; |
| 1559 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1560 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1561 | |
| 1562 | if ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_INST) |
Michal Vasko | b6ab50c | 2018-03-08 13:46:10 +0100 | [diff] [blame] | 1563 | || (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) |
| 1564 | || ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_UNION) |
| 1565 | && type->info.uni.types[type->info.uni.count - 1].info.uni.has_ptr_type)) { |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1566 | type->info.uni.has_ptr_type = 1; |
| 1567 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1568 | } |
| 1569 | if (rc) { |
| 1570 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1571 | for (i = 0; i < type->info.uni.count; ++i) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1572 | lys_type_free(ctx, &type->info.uni.types[i], NULL); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1573 | } |
| 1574 | free(type->info.uni.types); |
| 1575 | type->info.uni.types = NULL; |
| 1576 | type->info.uni.count = 0; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1577 | type->info.uni.has_ptr_type = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1578 | type->der = NULL; |
| 1579 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1580 | |
| 1581 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1582 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1583 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1584 | goto error; |
| 1585 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1586 | } |
| 1587 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1588 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1589 | case LY_TYPE_BOOL: |
| 1590 | case LY_TYPE_EMPTY: |
| 1591 | /* no sub-statement allowed */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1592 | if (yin->child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1593 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, yin->child->name); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1594 | goto error; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1595 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1596 | break; |
| 1597 | |
| 1598 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1599 | LOGINT(ctx); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1600 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1603 | for(j = 0; j < type->ext_size; ++j) { |
| 1604 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1605 | if (type->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1606 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1607 | break; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | /* if derived type has extension, which need validate data */ |
| 1612 | dertype = &type->der->type; |
| 1613 | while (dertype->der) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1614 | if (dertype->parent->flags & LYS_VALID_EXT) { |
| 1615 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1616 | } |
| 1617 | dertype = &dertype->der->type; |
| 1618 | } |
| 1619 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1620 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1621 | |
| 1622 | error: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1623 | lyxml_free_withsiblings(ctx, exts.child); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1624 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1625 | } |
| 1626 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1627 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1628 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1629 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, |
| 1630 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1631 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1632 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1633 | struct lyxml_elem *node, *next; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1634 | struct ly_ctx *ctx = module->ctx; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1635 | int rc, has_type = 0, c_ext = 0, i; |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1636 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1637 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1638 | GETVAL(ctx, value, yin, "name"); |
| 1639 | if (lyp_check_identifier(ctx, value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1640 | goto error; |
| 1641 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1642 | tpdf->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1643 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1644 | /* generic part - status, description, reference */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1645 | if (read_yin_common(module, NULL, tpdf, LYEXT_PAR_TPDF, yin, OPT_MODULE, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1646 | goto error; |
| 1647 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1648 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1649 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1650 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1651 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1652 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, tpdf->ext_size, "extensions", "typedef", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1653 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1654 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1655 | } else if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1656 | if (has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1657 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1658 | goto error; |
| 1659 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1660 | /* HACK for unres */ |
| 1661 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1662 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1663 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DER_TPDF, parent) == -1) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1664 | goto error; |
| 1665 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1666 | has_type = 1; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1667 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1668 | /* skip lyxml_free() at the end of the loop, node was freed or at least unlinked in unres processing */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1669 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1670 | } else if (!strcmp(node->name, "default")) { |
| 1671 | if (tpdf->dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1672 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1673 | goto error; |
| 1674 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1675 | GETVAL(ctx, value, node, "value"); |
| 1676 | tpdf->dflt = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1677 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1678 | if (lyp_yin_parse_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1679 | goto error; |
| 1680 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1681 | } else if (!strcmp(node->name, "units")) { |
| 1682 | if (tpdf->units) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1683 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1684 | goto error; |
| 1685 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1686 | GETVAL(ctx, value, node, "name"); |
| 1687 | tpdf->units = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1688 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1689 | if (lyp_yin_parse_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1690 | goto error; |
| 1691 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1692 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1693 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1694 | goto error; |
| 1695 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1696 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1697 | lyxml_free(ctx, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1698 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1699 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1700 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1701 | if (!has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1702 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1703 | goto error; |
| 1704 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1705 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1706 | /* check default value (if not defined, there still could be some restrictions |
| 1707 | * that need to be checked against a default value from a derived type) */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1708 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 1709 | unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPEDEF_DFLT, (struct lys_node *)(&tpdf->dflt)) == -1) { |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1710 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1711 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1712 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1713 | /* finish extensions parsing */ |
| 1714 | if (c_ext) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1715 | /* some extensions may be already present from the substatements */ |
| 1716 | reallocated = realloc(tpdf->ext, (c_ext + tpdf->ext_size) * sizeof *tpdf->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1717 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1718 | tpdf->ext = reallocated; |
| 1719 | |
| 1720 | /* init memory */ |
| 1721 | memset(&tpdf->ext[tpdf->ext_size], 0, c_ext * sizeof *tpdf->ext); |
| 1722 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1723 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1724 | rc = lyp_yin_fill_ext(tpdf, LYEXT_PAR_TYPE, 0, 0, module, node, &tpdf->ext, tpdf->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1725 | tpdf->ext_size++; |
| 1726 | if (rc) { |
| 1727 | goto error; |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1732 | for (i = 0; i < tpdf->ext_size; ++i) { |
| 1733 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 1734 | if (tpdf->ext[i]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1735 | tpdf->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1736 | break; |
| 1737 | } |
| 1738 | } |
| 1739 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1740 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1741 | |
| 1742 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1743 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1744 | } |
| 1745 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1746 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1747 | fill_yin_extension(struct lys_module *module, struct lyxml_elem *yin, struct lys_ext *ext, struct unres_schema *unres) |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1748 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1749 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1750 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1751 | struct lyxml_elem *child, *node, *next, *next2; |
| 1752 | int c_ext = 0, rc; |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1753 | void *reallocated; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1754 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1755 | GETVAL(ctx, value, yin, "name"); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1756 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1757 | if (lyp_check_identifier(ctx, value, LY_IDENT_EXTENSION, module, NULL)) { |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1758 | goto error; |
| 1759 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1760 | ext->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1761 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1762 | if (read_yin_common(module, NULL, ext, LYEXT_PAR_EXT, yin, OPT_MODULE, unres)) { |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1763 | goto error; |
| 1764 | } |
| 1765 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1766 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1767 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1768 | /* possible extension instance */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1769 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, ext->ext_size, "extensions", "extension", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1770 | c_ext++; |
| 1771 | } else if (!strcmp(node->name, "argument")) { |
| 1772 | /* argument */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1773 | GETVAL(ctx, value, node, "name"); |
| 1774 | ext->argument = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1775 | if (lyp_yin_parse_subnode_ext(module, ext, LYEXT_PAR_EXT, node, LYEXT_SUBSTMT_ARGUMENT, 0, unres)) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1776 | goto error; |
| 1777 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1778 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1779 | /* yin-element */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1780 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1781 | if (child->ns == node->ns && !strcmp(child->name, "yin-element")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1782 | GETVAL(ctx, value, child, "value"); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1783 | if (ly_strequal(value, "true", 0)) { |
| 1784 | ext->flags |= LYS_YINELEM; |
| 1785 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1786 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1787 | if (lyp_yin_parse_subnode_ext(module, ext, LYEXT_PAR_EXT, child, LYEXT_SUBSTMT_YINELEM, 0, unres)) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1788 | goto error; |
| 1789 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1790 | } else if (child->ns) { |
| 1791 | /* unexpected YANG statement */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1792 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1793 | goto error; |
| 1794 | } /* else garbage, but save resource needed for unlinking */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1795 | } |
| 1796 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1797 | lyxml_free(ctx, node); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1798 | } else { |
| 1799 | /* unexpected YANG statement */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1800 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->name); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1801 | goto error; |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | if (c_ext) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1806 | /* some extensions may be already present from the substatements */ |
| 1807 | reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1808 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1809 | ext->ext = reallocated; |
| 1810 | |
| 1811 | /* init memory */ |
| 1812 | memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext); |
| 1813 | |
| 1814 | /* process the extension instances of the extension itself */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1815 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1816 | rc = lyp_yin_fill_ext(ext, LYEXT_PAR_EXT, 0, 0, module, node, &ext->ext, ext->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1817 | ext->ext_size++; |
| 1818 | if (rc) { |
| 1819 | goto error; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 1824 | /* search for plugin */ |
| 1825 | ext->plugin = ext_get_plugin(ext->name, ext->module->name, ext->module->rev ? ext->module->rev[0].date : NULL); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1826 | |
| 1827 | return EXIT_SUCCESS; |
| 1828 | |
| 1829 | error: |
| 1830 | return EXIT_FAILURE; |
| 1831 | } |
| 1832 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1833 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1834 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1835 | fill_yin_feature(struct lys_module *module, struct lyxml_elem *yin, struct lys_feature *f, struct unres_schema *unres) |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1836 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1837 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1838 | const char *value; |
| 1839 | struct lyxml_elem *child, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1840 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1841 | void *reallocated; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1842 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1843 | GETVAL(ctx, value, yin, "name"); |
| 1844 | if (lyp_check_identifier(ctx, value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1845 | goto error; |
| 1846 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1847 | f->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1848 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1849 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1850 | if (read_yin_common(module, NULL, f, LYEXT_PAR_FEATURE, yin, 0, unres)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1851 | goto error; |
| 1852 | } |
| 1853 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1854 | LY_TREE_FOR(yin->child, child) { |
| 1855 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1856 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1857 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, f->ext_size, "extensions", "feature", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1858 | c_ext++; |
| 1859 | } else if (!strcmp(child->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1860 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, f->iffeature_size, "if-feature", "feature", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1861 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1862 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1863 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1864 | goto error; |
| 1865 | } |
| 1866 | } |
| 1867 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1868 | if (c_ftrs) { |
| 1869 | f->iffeature = calloc(c_ftrs, sizeof *f->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1870 | LY_CHECK_ERR_GOTO(!f->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1871 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1872 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1873 | /* some extensions may be already present from the substatements */ |
| 1874 | reallocated = realloc(f->ext, (c_ext + f->ext_size) * sizeof *f->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1875 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1876 | f->ext = reallocated; |
| 1877 | |
| 1878 | /* init memory */ |
| 1879 | memset(&f->ext[f->ext_size], 0, c_ext * sizeof *f->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1880 | } |
| 1881 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1882 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1883 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1884 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1885 | ret = lyp_yin_fill_ext(f, LYEXT_PAR_FEATURE, 0, 0, module, child, &f->ext, f->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1886 | f->ext_size++; |
| 1887 | if (ret) { |
| 1888 | goto error; |
| 1889 | } |
| 1890 | } else { /* if-feature */ |
| 1891 | ret = fill_yin_iffeature((struct lys_node *)f, 1, child, &f->iffeature[f->iffeature_size], unres); |
| 1892 | f->iffeature_size++; |
| 1893 | if (ret) { |
| 1894 | goto error; |
| 1895 | } |
| 1896 | } |
| 1897 | } |
| 1898 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1899 | /* check for circular dependencies */ |
| 1900 | if (f->iffeature_size) { |
| 1901 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1902 | goto error; |
| 1903 | } |
| 1904 | } |
| 1905 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1906 | return EXIT_SUCCESS; |
| 1907 | |
| 1908 | error: |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1909 | return EXIT_FAILURE; |
| 1910 | } |
| 1911 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1912 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1913 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1914 | fill_yin_must(struct lys_module *module, struct lyxml_elem *yin, struct lys_restr *must, struct unres_schema *unres) |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1915 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1916 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1917 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1918 | GETVAL(module->ctx, value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1919 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1920 | if (!must->expr) { |
| 1921 | goto error; |
| 1922 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1923 | |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1924 | return read_restr_substmt(module, must, yin, unres); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1925 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1926 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1927 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1928 | } |
| 1929 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1930 | static int |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1931 | fill_yin_revision(struct lys_module *module, struct lyxml_elem *yin, struct lys_revision *rev, |
| 1932 | struct unres_schema *unres) |
| 1933 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1934 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1935 | struct lyxml_elem *next, *child; |
| 1936 | const char *value; |
| 1937 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1938 | GETVAL(ctx, value, yin, "date"); |
| 1939 | if (lyp_check_date(ctx, value)) { |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1940 | goto error; |
| 1941 | } |
| 1942 | memcpy(rev->date, value, LY_REV_SIZE - 1); |
| 1943 | |
| 1944 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1945 | if (!child->ns) { |
| 1946 | /* garbage */ |
| 1947 | continue; |
| 1948 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1949 | /* possible extension instance */ |
| 1950 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1951 | child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 1952 | goto error; |
| 1953 | } |
| 1954 | } else if (!strcmp(child->name, "description")) { |
| 1955 | if (rev->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1956 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1957 | goto error; |
| 1958 | } |
| 1959 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1960 | child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 1961 | goto error; |
| 1962 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1963 | rev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1964 | if (!rev->dsc) { |
| 1965 | goto error; |
| 1966 | } |
| 1967 | } else if (!strcmp(child->name, "reference")) { |
| 1968 | if (rev->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1969 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1970 | goto error; |
| 1971 | } |
| 1972 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1973 | child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 1974 | goto error; |
| 1975 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1976 | rev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1977 | if (!rev->ref) { |
| 1978 | goto error; |
| 1979 | } |
| 1980 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1981 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1982 | goto error; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | return EXIT_SUCCESS; |
| 1987 | |
| 1988 | error: |
| 1989 | return EXIT_FAILURE; |
| 1990 | } |
| 1991 | |
| 1992 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1993 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1994 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1995 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1996 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1997 | int i, j, ret = EXIT_FAILURE; |
| 1998 | const char *orig; |
Radek Krejci | 2449b39 | 2017-04-25 09:37:16 +0200 | [diff] [blame] | 1999 | char *value, *vaux, *start = NULL, c; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 2000 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2001 | |
| 2002 | /* get unique value (list of leafs supposed to be unique */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2003 | GETVAL(ctx, orig, yin, "tag"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2004 | |
| 2005 | /* count the number of unique leafs in the value */ |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 2006 | start = value = vaux = strdup(orig); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2007 | LY_CHECK_ERR_GOTO(!vaux, LOGMEM(ctx), error); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2008 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2009 | YIN_CHECK_ARRAY_OVERFLOW_CODE(ctx, unique->expr_size, unique->expr_size, "referenced items", "unique", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 2010 | unique->expr_size = 0; goto error); |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 2011 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2012 | while (isspace(*vaux)) { |
| 2013 | vaux++; |
| 2014 | } |
| 2015 | } |
| 2016 | unique->expr_size++; |
| 2017 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2018 | LY_CHECK_ERR_GOTO(!unique->expr, LOGMEM(ctx), error); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2019 | |
| 2020 | for (i = 0; i < unique->expr_size; i++) { |
| 2021 | vaux = strpbrk(value, " \t\n"); |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 2022 | if (vaux) { |
| 2023 | c = *vaux; |
| 2024 | *vaux = '\0'; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | /* store token into unique structure */ |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 2028 | unique->expr[i] = transform_schema2json(module, value); |
| 2029 | if (vaux) { |
| 2030 | *vaux = c; |
| 2031 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2032 | |
| 2033 | /* check that the expression does not repeat */ |
| 2034 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2035 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2036 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 2037 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2038 | goto error; |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | /* try to resolve leaf */ |
| 2043 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 2044 | unique_info = malloc(sizeof *unique_info); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2045 | LY_CHECK_ERR_GOTO(!unique_info, LOGMEM(ctx), error); |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 2046 | unique_info->list = parent; |
| 2047 | unique_info->expr = unique->expr[i]; |
| 2048 | unique_info->trg_type = &unique->trg_type; |
| 2049 | if (unres_schema_add_node(module, unres, unique_info, UNRES_LIST_UNIQ, NULL) == -1){ |
Pavol Vican | 18b1021 | 2016-04-11 15:41:52 +0200 | [diff] [blame] | 2050 | goto error; |
| 2051 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2052 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 2053 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2054 | goto error; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | /* move to next token */ |
| 2059 | value = vaux; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2060 | while (value && isspace(*value)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2061 | value++; |
| 2062 | } |
| 2063 | } |
| 2064 | |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 2065 | ret = EXIT_SUCCESS; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2066 | |
| 2067 | error: |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 2068 | free(start); |
| 2069 | return ret; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2070 | } |
| 2071 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2072 | /* logs directly |
| 2073 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2074 | * type: 0 - min, 1 - max |
| 2075 | */ |
| 2076 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2077 | deviate_minmax(struct lys_node *target, struct lyxml_elem *node, struct lys_deviate *d, int type) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2078 | { |
| 2079 | const char *value; |
| 2080 | char *endptr; |
| 2081 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2082 | uint32_t *ui32val, *min, *max; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2083 | struct ly_ctx *ctx = target->module->ctx; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2084 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2085 | /* del min/max is forbidden */ |
| 2086 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2087 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, (type ? "max-elements" : "min-elements"), "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2088 | goto error; |
| 2089 | } |
| 2090 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2091 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2092 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2093 | max = &((struct lys_node_leaflist *)target)->max; |
| 2094 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2095 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2096 | max = &((struct lys_node_list *)target)->max; |
| 2097 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2098 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2099 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 2100 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2101 | goto error; |
| 2102 | } |
| 2103 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2104 | GETVAL(ctx, value, node, "value"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2105 | while (isspace(value[0])) { |
| 2106 | value++; |
| 2107 | } |
| 2108 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2109 | if (type && !strcmp(value, "unbounded")) { |
| 2110 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 2111 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2112 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2113 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2114 | /* convert it to uint32_t */ |
| 2115 | errno = 0; |
| 2116 | endptr = NULL; |
| 2117 | val = strtoul(value, &endptr, 10); |
| 2118 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2119 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2120 | goto error; |
| 2121 | } |
| 2122 | if (type) { |
| 2123 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 2124 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2125 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2126 | } else { |
| 2127 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 2128 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2129 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2130 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | if (d->mod == LY_DEVIATE_ADD) { |
| 2134 | /* check that there is no current value */ |
| 2135 | if (*ui32val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2136 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 2137 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2138 | goto error; |
| 2139 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2140 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2141 | /* unfortunately, there is no way to check reliably that there |
| 2142 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2143 | } |
| 2144 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2145 | /* add (already checked) and replace */ |
| 2146 | /* set new value specified in deviation */ |
| 2147 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2148 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2149 | /* check min-elements is smaller than max-elements */ |
| 2150 | if (*max && *min > *max) { |
| 2151 | if (type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2152 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "max-elements"); |
| 2153 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2154 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2155 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "min-elements"); |
| 2156 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2157 | } |
| 2158 | goto error; |
| 2159 | } |
| 2160 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2161 | return EXIT_SUCCESS; |
| 2162 | |
| 2163 | error: |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2164 | return EXIT_FAILURE; |
| 2165 | } |
| 2166 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2167 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2168 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2169 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 2170 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2171 | { |
| 2172 | const char *value, **stritem; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2173 | struct lyxml_elem *next, *next2, *child, *develem; |
| 2174 | int c_dev = 0, c_must, c_uniq, c_dflt, c_ext = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2175 | int f_min = 0, f_max = 0; /* flags */ |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2176 | int i, j, k, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2177 | unsigned int u; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2178 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2179 | struct lys_deviate *d = NULL; |
Michal Vasko | 5df038e | 2018-08-02 09:41:26 +0200 | [diff] [blame] | 2180 | struct lys_node *node, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2181 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2182 | struct lys_node_leaf *leaf = NULL; |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2183 | struct ly_set *dflt_check = ly_set_new(), *set; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2184 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2185 | struct lys_node_leaflist *llist = NULL; |
Michal Vasko | 5df038e | 2018-08-02 09:41:26 +0200 | [diff] [blame] | 2186 | struct lys_node_inout *inout; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2187 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2188 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2189 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2190 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2191 | struct lys_module *mod; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2192 | void *reallocated; |
Andrew Langefeld | f976324 | 2018-09-16 22:23:50 -0500 | [diff] [blame] | 2193 | size_t deviate_must_index; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2194 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2195 | GETVAL(ctx, value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2196 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2197 | if (!dev->target_name) { |
| 2198 | goto error; |
| 2199 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2200 | |
| 2201 | /* resolve target node */ |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2202 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, &set, 0, 1); |
| 2203 | if (rc == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2204 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2205 | ly_set_free(set); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2206 | goto error; |
| 2207 | } |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2208 | dev_target = set->set.s[0]; |
| 2209 | ly_set_free(set); |
| 2210 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2211 | if (dev_target->module == lys_main_module(module)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2212 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 2213 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2214 | goto error; |
| 2215 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2216 | |
| 2217 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2218 | if (!child->ns ) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2219 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2220 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2221 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2222 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2223 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2224 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, dev->ext_size, "extensions", "deviation", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2225 | c_ext++; |
| 2226 | continue; |
| 2227 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2228 | if (dev->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2229 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2230 | goto error; |
| 2231 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2232 | if (lyp_yin_parse_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2233 | goto error; |
| 2234 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2235 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2236 | if (!dev->dsc) { |
| 2237 | goto error; |
| 2238 | } |
| 2239 | } else if (!strcmp(child->name, "reference")) { |
| 2240 | if (dev->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2241 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2242 | goto error; |
| 2243 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2244 | if (lyp_yin_parse_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2245 | goto error; |
| 2246 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2247 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2248 | if (!dev->ref) { |
| 2249 | goto error; |
| 2250 | } |
| 2251 | } else if (!strcmp(child->name, "deviate")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2252 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_dev, dev->deviate_size, "deviates", "deviation", error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2253 | c_dev++; |
| 2254 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2255 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2256 | * further processed later |
| 2257 | */ |
| 2258 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2259 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2260 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2261 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2262 | goto error; |
| 2263 | } |
| 2264 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2265 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | if (c_dev) { |
| 2269 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2270 | LY_CHECK_ERR_GOTO(!dev->deviate, LOGMEM(ctx), error); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2271 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2272 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2273 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2274 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2275 | if (c_ext) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2276 | /* some extensions may be already present from the substatements */ |
| 2277 | reallocated = realloc(dev->ext, (c_ext + dev->ext_size) * sizeof *dev->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2278 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2279 | dev->ext = reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2280 | |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2281 | /* init memory */ |
| 2282 | memset(&dev->ext[dev->ext_size], 0, c_ext * sizeof *dev->ext); |
| 2283 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2284 | |
| 2285 | LY_TREE_FOR_SAFE(yin->child, next, develem) { |
| 2286 | if (strcmp(develem->ns->value, LY_NSYIN)) { |
| 2287 | /* deviation's extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 2288 | rc = lyp_yin_fill_ext(dev, LYEXT_PAR_DEVIATION, 0, 0, module, develem, &dev->ext, dev->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2289 | dev->ext_size++; |
| 2290 | if (rc) { |
| 2291 | goto error; |
| 2292 | } |
| 2293 | continue; |
| 2294 | } |
| 2295 | |
| 2296 | /* deviate */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2297 | /* init */ |
| 2298 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2299 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2300 | c_must = 0; |
| 2301 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2302 | c_dflt = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2303 | c_ext = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2304 | |
| 2305 | /* get deviation type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2306 | GETVAL(ctx, value, develem, "value"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2307 | if (!strcmp(value, "not-supported")) { |
| 2308 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2309 | /* no other deviate statement is expected, |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2310 | * not-supported deviation must be the only deviation of the target |
| 2311 | */ |
| 2312 | if (dev->deviate_size || develem->next) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2313 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2314 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation."); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2315 | goto error; |
| 2316 | } |
| 2317 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2318 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 2319 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 2320 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 2321 | if (((struct lys_node_list *)lys_parent(dev_target))->keys[i] == (struct lys_node_leaf *)dev_target) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2322 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2323 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot remove a list key."); |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2324 | goto error; |
| 2325 | } |
| 2326 | } |
| 2327 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2328 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2329 | /* unlink and store the original node */ |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2330 | parent = dev_target->parent; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2331 | lys_node_unlink(dev_target); |
Michal Vasko | 5df038e | 2018-08-02 09:41:26 +0200 | [diff] [blame] | 2332 | if (parent) { |
| 2333 | if (parent->nodetype & (LYS_AUGMENT | LYS_USES)) { |
| 2334 | /* hack for augment, because when the original will be sometime reconnected back, we actually need |
| 2335 | * to reconnect it to both - the augment and its target (which is deduced from the deviations target |
| 2336 | * path), so we need to remember the augment as an addition */ |
| 2337 | /* remember uses parent so we can reconnect to it */ |
| 2338 | dev_target->parent = parent; |
| 2339 | } else if (parent->nodetype & (LYS_RPC | LYS_ACTION)) { |
| 2340 | /* re-create implicit node */ |
| 2341 | inout = calloc(1, sizeof *inout); |
| 2342 | LY_CHECK_ERR_GOTO(!inout, LOGMEM(ctx), error); |
| 2343 | |
| 2344 | inout->nodetype = dev_target->nodetype; |
| 2345 | inout->name = lydict_insert(ctx, (inout->nodetype == LYS_INPUT) ? "input" : "output", 0); |
| 2346 | inout->module = dev_target->module; |
| 2347 | inout->flags = LYS_IMPLICIT; |
| 2348 | |
| 2349 | /* insert it manually */ |
| 2350 | assert(parent->child && !parent->child->next |
| 2351 | && (parent->child->nodetype == (inout->nodetype == LYS_INPUT ? LYS_OUTPUT : LYS_INPUT))); |
| 2352 | parent->child->next = (struct lys_node *)inout; |
| 2353 | inout->prev = parent->child; |
| 2354 | parent->child->prev = (struct lys_node *)inout; |
| 2355 | inout->parent = parent; |
| 2356 | } |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2357 | } |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2358 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2359 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2360 | } else if (!strcmp(value, "add")) { |
| 2361 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 2362 | } else if (!strcmp(value, "replace")) { |
| 2363 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 2364 | } else if (!strcmp(value, "delete")) { |
| 2365 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 2366 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2367 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2368 | goto error; |
| 2369 | } |
| 2370 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 2371 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2372 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2373 | /* store a shallow copy of the original node */ |
| 2374 | if (!dev->orig_node) { |
| 2375 | memset(&tmp_unres, 0, sizeof tmp_unres); |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 2376 | dev->orig_node = lys_node_dup(dev_target->module, NULL, dev_target, &tmp_unres, 1); |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2377 | /* just to be safe */ |
| 2378 | if (tmp_unres.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2379 | LOGINT(ctx); |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2380 | goto error; |
| 2381 | } |
| 2382 | } |
| 2383 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2384 | /* process deviation properties */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2385 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2386 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2387 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2388 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2389 | continue; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2390 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2391 | /* extensions */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2392 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, d->ext_size, "extensions", "deviate", error); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2393 | c_ext++; |
| 2394 | } else if (d->mod == LY_DEVIATE_NO) { |
| 2395 | /* no YIN substatement expected in this case */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2396 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2397 | goto error; |
| 2398 | } else if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2399 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2400 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2401 | goto error; |
| 2402 | } |
| 2403 | |
| 2404 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 2405 | * specified in the target explicitly since config property inherits. So we expect |
| 2406 | * that config is specified in every node. But for delete, we check that the value |
| 2407 | * is the same as here in deviation |
| 2408 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2409 | GETVAL(ctx, value, child, "value"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2410 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2411 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2412 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2413 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2414 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2415 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2416 | goto error; |
| 2417 | } |
| 2418 | |
| 2419 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2420 | /* del config is forbidden */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2421 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2422 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2423 | } else { /* add and replace are the same in this case */ |
| 2424 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2425 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2426 | |
| 2427 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2428 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2429 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2430 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2431 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2432 | goto error; |
| 2433 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2434 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2435 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2436 | goto error; |
| 2437 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2438 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_dflt, d->dflt_size, "defaults", "deviate", error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2439 | c_dflt++; |
| 2440 | |
| 2441 | /* check target node type */ |
| 2442 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2443 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2444 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2445 | goto error; |
| 2446 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2447 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2448 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2449 | goto error; |
| 2450 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2451 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2452 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2453 | goto error; |
| 2454 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2455 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2456 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 2457 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2458 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2459 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2460 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2461 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2462 | goto error; |
| 2463 | } |
| 2464 | |
| 2465 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2466 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2467 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2468 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2469 | goto error; |
| 2470 | } |
| 2471 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2472 | GETVAL(ctx, value, child, "value"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2473 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2474 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2475 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2476 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2477 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2478 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2479 | goto error; |
| 2480 | } |
| 2481 | |
| 2482 | if (d->mod == LY_DEVIATE_ADD) { |
| 2483 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2484 | if (dev_target->flags & LYS_MAND_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2485 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2486 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2487 | goto error; |
| 2488 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2489 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2490 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2491 | if (d->flags & LYS_MAND_TRUE) { |
| 2492 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2493 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2494 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2495 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2496 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 2497 | goto error; |
| 2498 | } |
| 2499 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2500 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2501 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2502 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2503 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 2504 | goto error; |
| 2505 | } |
| 2506 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2507 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2508 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2509 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 2510 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2511 | /* check that there was a value before */ |
| 2512 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2513 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2514 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2515 | goto error; |
| 2516 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2517 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2518 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2519 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2520 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2521 | /* del mandatory is forbidden */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2522 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2523 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2524 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2525 | |
| 2526 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 2527 | for (parent = dev_target->parent; |
| 2528 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 2529 | parent = parent->parent) { |
| 2530 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 2531 | /* stop also on presence containers */ |
| 2532 | break; |
| 2533 | } |
| 2534 | } |
| 2535 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 2536 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 2537 | if (lyp_check_mandatory_choice(parent)) { |
| 2538 | goto error; |
| 2539 | } |
| 2540 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2541 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2542 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2543 | goto error; |
| 2544 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2545 | } else if (!strcmp(child->name, "min-elements")) { |
| 2546 | if (f_min) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2547 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2548 | goto error; |
| 2549 | } |
| 2550 | f_min = 1; |
| 2551 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2552 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2553 | goto error; |
| 2554 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2555 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2556 | goto error; |
| 2557 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2558 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2559 | if (f_max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2560 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2561 | goto error; |
| 2562 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2563 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2564 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2565 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2566 | goto error; |
| 2567 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2568 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2569 | goto error; |
| 2570 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2571 | } else if (!strcmp(child->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2572 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, d->must_size, "musts", "deviate", error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2573 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2574 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2575 | continue; |
| 2576 | } else if (!strcmp(child->name, "type")) { |
| 2577 | if (d->type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2578 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2579 | goto error; |
| 2580 | } |
| 2581 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2582 | /* add, del type is forbidden */ |
| 2583 | if (d->mod == LY_DEVIATE_ADD) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2584 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2585 | goto error; |
| 2586 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2587 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2588 | goto error; |
| 2589 | } |
| 2590 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2591 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2592 | if (dev_target->nodetype == LYS_LEAF) { |
| 2593 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2594 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 2595 | ly_set_add(dflt_check, dev_target, 0); |
| 2596 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2597 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2598 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2599 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 2600 | ly_set_add(dflt_check, dev_target, 0); |
| 2601 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2602 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2603 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2604 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2605 | goto error; |
| 2606 | } |
| 2607 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2608 | /* replace */ |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2609 | lys_type_free(ctx, t, NULL); |
Radek Krejci | 0ec2cc5 | 2017-11-09 16:30:12 +0100 | [diff] [blame] | 2610 | memset(t, 0, sizeof (struct lys_type)); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2611 | /* HACK for unres */ |
| 2612 | t->der = (struct lys_tpdf *)child; |
Radek Krejci | 0ec2cc5 | 2017-11-09 16:30:12 +0100 | [diff] [blame] | 2613 | t->parent = (struct lys_tpdf *)dev_target; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 2614 | if (unres_schema_add_node(module, unres, t, UNRES_TYPE_DER, dev_target) == -1) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2615 | goto error; |
| 2616 | } |
| 2617 | d->type = t; |
| 2618 | } else if (!strcmp(child->name, "unique")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2619 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNIQUE, c_uniq, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2620 | goto error; |
| 2621 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2622 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_uniq, d->unique_size, "uniques", "deviate", error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2623 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2624 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2625 | continue; |
| 2626 | } else if (!strcmp(child->name, "units")) { |
| 2627 | if (d->units) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2628 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2629 | goto error; |
| 2630 | } |
| 2631 | |
| 2632 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2633 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2634 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 2635 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2636 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2637 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2638 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2639 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2640 | goto error; |
| 2641 | } |
| 2642 | |
| 2643 | /* get units value */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2644 | GETVAL(ctx, value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2645 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2646 | |
| 2647 | /* apply to target */ |
| 2648 | if (d->mod == LY_DEVIATE_ADD) { |
| 2649 | /* check that there is no current value */ |
| 2650 | if (*stritem) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2651 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2652 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2653 | goto error; |
| 2654 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2655 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2656 | *stritem = lydict_insert(ctx, value, 0); |
| 2657 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2658 | /* check that there was a value before */ |
| 2659 | if (!*stritem) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2660 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2661 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2662 | goto error; |
| 2663 | } |
| 2664 | |
| 2665 | lydict_remove(ctx, *stritem); |
| 2666 | *stritem = lydict_insert(ctx, value, 0); |
| 2667 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2668 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2669 | if (!ly_strequal(*stritem, d->units, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2670 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2671 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2672 | goto error; |
| 2673 | } |
| 2674 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2675 | lydict_remove(ctx, *stritem); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2676 | (*stritem) = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2677 | |
| 2678 | /* remove its extensions */ |
| 2679 | j = -1; |
| 2680 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNITS)) != -1) { |
| 2681 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2682 | --j; |
| 2683 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2684 | } |
| 2685 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2686 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2687 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2688 | } |
| 2689 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2690 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2691 | goto error; |
| 2692 | } |
| 2693 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2694 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | if (c_must) { |
| 2698 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2699 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2700 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2701 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2702 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2703 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2704 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2705 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2706 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2707 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2708 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2709 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2710 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2711 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2712 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2713 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2714 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2715 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2716 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2717 | case LYS_ANYDATA: |
| 2718 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2719 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2720 | break; |
| 2721 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2722 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2723 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"must\" property."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2724 | goto error; |
| 2725 | } |
| 2726 | |
Michal Vasko | c04173b | 2018-03-09 10:43:22 +0100 | [diff] [blame] | 2727 | dev_target->flags &= ~(LYS_XPCONF_DEP | LYS_XPSTATE_DEP); |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2728 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2729 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2730 | /* replace must is forbidden */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2731 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2732 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2733 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2734 | /* reallocate the must array of the target */ |
Andrew Langefeld | f976324 | 2018-09-16 22:23:50 -0500 | [diff] [blame] | 2735 | struct lys_restr *must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
| 2736 | LY_CHECK_ERR_GOTO(!must, LOGMEM(ctx), error); |
| 2737 | *trg_must = must; |
| 2738 | d->must = calloc(c_must, sizeof *d->must); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2739 | d->must_size = c_must; |
| 2740 | } else { /* LY_DEVIATE_DEL */ |
| 2741 | d->must = calloc(c_must, sizeof *d->must); |
| 2742 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2743 | LY_CHECK_ERR_GOTO(!d->must, LOGMEM(ctx), error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2744 | } |
| 2745 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2746 | /* replace unique is forbidden */ |
| 2747 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2748 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2749 | goto error; |
| 2750 | } |
| 2751 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2752 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2753 | if (dev_target->nodetype != LYS_LIST) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2754 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2755 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"unique\" property."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2756 | goto error; |
| 2757 | } |
| 2758 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2759 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2760 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2761 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2762 | d->unique = ly_realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2763 | LY_CHECK_ERR_GOTO(!d->unique, LOGMEM(ctx), error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2764 | list->unique = d->unique; |
| 2765 | d->unique = &list->unique[list->unique_size]; |
| 2766 | d->unique_size = c_uniq; |
| 2767 | } else { /* LY_DEVIATE_DEL */ |
| 2768 | d->unique = calloc(c_uniq, sizeof *d->unique); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2769 | LY_CHECK_ERR_GOTO(!d->unique, LOGMEM(ctx), error); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2770 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2771 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2772 | if (c_dflt) { |
| 2773 | if (d->mod == LY_DEVIATE_ADD) { |
| 2774 | /* check that there is no current value */ |
| 2775 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2776 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2777 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2778 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2779 | goto error; |
| 2780 | } |
| 2781 | |
| 2782 | /* check collision with mandatory/min-elements */ |
| 2783 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2784 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2785 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2786 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2787 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2788 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2789 | goto error; |
| 2790 | } |
| 2791 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2792 | /* check that there was a value before */ |
| 2793 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2794 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2795 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2796 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2797 | goto error; |
| 2798 | } |
| 2799 | } |
| 2800 | |
| 2801 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2802 | /* reallocate default list in the target */ |
| 2803 | llist = (struct lys_node_leaflist *)dev_target; |
| 2804 | if (d->mod == LY_DEVIATE_ADD) { |
| 2805 | /* reallocate (enlarge) the unique array of the target */ |
| 2806 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2807 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM(ctx), error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2808 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2809 | /* reallocate (replace) the unique array of the target */ |
| 2810 | for (i = 0; i < llist->dflt_size; i++) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2811 | lydict_remove(ctx, llist->dflt[i]); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2812 | } |
| 2813 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2814 | llist->dflt_size = 0; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2815 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM(ctx), error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2819 | LY_CHECK_ERR_GOTO(!d->dflt, LOGMEM(ctx), error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2820 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2821 | if (c_ext) { |
| 2822 | /* some extensions may be already present from the substatements */ |
| 2823 | reallocated = realloc(d->ext, (c_ext + d->ext_size) * sizeof *d->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2824 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2825 | d->ext = reallocated; |
| 2826 | |
| 2827 | /* init memory */ |
| 2828 | memset(&d->ext[d->ext_size], 0, c_ext * sizeof *d->ext); |
| 2829 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2830 | |
| 2831 | /* process deviation properties with 0..n cardinality */ |
Andrew Langefeld | f976324 | 2018-09-16 22:23:50 -0500 | [diff] [blame] | 2832 | deviate_must_index = 0; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2833 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
| 2834 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2835 | /* extension */ |
| 2836 | if (lyp_yin_fill_ext(d, LYEXT_PAR_DEVIATE, 0, 0, module, child, &d->ext, d->ext_size, unres)) { |
| 2837 | goto error; |
| 2838 | } |
| 2839 | d->ext_size++; |
| 2840 | } else if (!strcmp(child->name, "must")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2841 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2842 | if (fill_yin_must(module, child, &d->must[d->must_size], unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2843 | goto error; |
| 2844 | } |
| 2845 | |
| 2846 | /* find must to delete, we are ok with just matching conditions */ |
| 2847 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2848 | if (ly_strequal(d->must[d->must_size].expr, (*trg_must)[i].expr, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2849 | /* we have a match, free the must structure ... */ |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2850 | lys_restr_free(ctx, &((*trg_must)[i]), NULL); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2851 | /* ... and maintain the array */ |
| 2852 | (*trg_must_size)--; |
| 2853 | if (i != *trg_must_size) { |
| 2854 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2855 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2856 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2857 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2858 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2859 | } |
| 2860 | if (!(*trg_must_size)) { |
| 2861 | free(*trg_must); |
| 2862 | *trg_must = NULL; |
| 2863 | } else { |
| 2864 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2865 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2866 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2867 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2868 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2869 | } |
| 2870 | |
| 2871 | i = -1; /* set match flag */ |
| 2872 | break; |
| 2873 | } |
| 2874 | } |
| 2875 | d->must_size++; |
| 2876 | if (i != -1) { |
| 2877 | /* no match found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2878 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2879 | d->must[d->must_size - 1].expr, child->name); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2880 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value does not match any must from the target."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2881 | goto error; |
| 2882 | } |
| 2883 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2884 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2885 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]), unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2886 | goto error; |
| 2887 | } |
Andrew Langefeld | f976324 | 2018-09-16 22:23:50 -0500 | [diff] [blame] | 2888 | memcpy(d->must + deviate_must_index, &((*trg_must)[*trg_must_size]), sizeof *d->must); |
| 2889 | ++deviate_must_index; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2890 | (*trg_must_size)++; |
| 2891 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2892 | |
| 2893 | /* check XPath dependencies again */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 2894 | if (*trg_must_size && !(ctx->models.flags & LY_CTX_TRUSTED) && |
| 2895 | (unres_schema_add_node(module, unres, dev_target, UNRES_XPATH, NULL) == -1)) { |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2896 | goto error; |
| 2897 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2898 | } else if (!strcmp(child->name, "unique")) { |
| 2899 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2900 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2901 | if (fill_yin_unique(module, dev_target, child, &d->unique[d->unique_size], NULL)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2902 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2903 | goto error; |
| 2904 | } |
| 2905 | |
| 2906 | /* find unique structures to delete */ |
| 2907 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2908 | if (list->unique[i].expr_size != d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2909 | continue; |
| 2910 | } |
| 2911 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2912 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2913 | if (!ly_strequal(list->unique[i].expr[j], d->unique[d->unique_size].expr[j], 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2914 | break; |
| 2915 | } |
| 2916 | } |
| 2917 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2918 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2919 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2920 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2921 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2922 | } |
| 2923 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2924 | /* ... and maintain the array */ |
| 2925 | list->unique_size--; |
| 2926 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2927 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2928 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | if (!list->unique_size) { |
| 2932 | free(list->unique); |
| 2933 | list->unique = NULL; |
| 2934 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2935 | list->unique[list->unique_size].expr_size = 0; |
| 2936 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2937 | } |
| 2938 | |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2939 | k = i; /* remember index for removing extensions */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2940 | i = -1; /* set match flag */ |
| 2941 | break; |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | d->unique_size++; |
| 2946 | if (i != -1) { |
| 2947 | /* no match found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2948 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2949 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2950 | goto error; |
| 2951 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2952 | |
| 2953 | /* remove extensions of this unique instance from the target node */ |
| 2954 | j = -1; |
| 2955 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNIQUE)) != -1) { |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2956 | if (dev_target->ext[j]->insubstmt_index == k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2957 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2958 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2959 | } else if (dev_target->ext[j]->insubstmt_index > k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2960 | /* decrease the substatement index of the extension because of the changed array of uniques */ |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2961 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2962 | } |
| 2963 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2964 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2965 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2966 | i = fill_yin_unique(module, dev_target, child, &list->unique[list->unique_size], NULL); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2967 | list->unique_size++; |
| 2968 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2969 | goto error; |
| 2970 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2971 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2972 | } else if (!strcmp(child->name, "default")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2973 | GETVAL(ctx, value, child, "value"); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2974 | u = strlen(value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2975 | d->dflt[d->dflt_size++] = lydict_insert(ctx, value, u); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2976 | |
| 2977 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2978 | choice = (struct lys_node_choice *)dev_target; |
| 2979 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2980 | if (rc || !node) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2981 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2982 | goto error; |
| 2983 | } |
| 2984 | if (d->mod == LY_DEVIATE_DEL) { |
| 2985 | if (!choice->dflt || (choice->dflt != node)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2986 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2987 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2988 | goto error; |
| 2989 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2990 | choice->dflt = NULL; |
| 2991 | /* remove extensions of this default instance from the target node */ |
| 2992 | j = -1; |
| 2993 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2994 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2995 | --j; |
| 2996 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2997 | } else { /* add or replace */ |
| 2998 | choice->dflt = node; |
| 2999 | if (!choice->dflt) { |
| 3000 | /* default branch not found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3001 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3002 | goto error; |
| 3003 | } |
| 3004 | } |
| 3005 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 3006 | leaf = (struct lys_node_leaf *)dev_target; |
| 3007 | if (d->mod == LY_DEVIATE_DEL) { |
| 3008 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3009 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3010 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3011 | goto error; |
| 3012 | } |
| 3013 | /* remove value */ |
| 3014 | lydict_remove(ctx, leaf->dflt); |
| 3015 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 3016 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 3017 | |
| 3018 | /* remove extensions of this default instance from the target node */ |
| 3019 | j = -1; |
| 3020 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 3021 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 3022 | --j; |
| 3023 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3024 | } else { /* add (already checked) and replace */ |
| 3025 | /* remove value */ |
| 3026 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 3027 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3028 | |
| 3029 | /* set new value */ |
| 3030 | leaf->dflt = lydict_insert(ctx, value, u); |
| 3031 | |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 3032 | /* remember to check it later (it may not fit now, because the type can be deviated too) */ |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3033 | ly_set_add(dflt_check, dev_target, 0); |
| 3034 | } |
| 3035 | } else { /* LYS_LEAFLIST */ |
| 3036 | llist = (struct lys_node_leaflist *)dev_target; |
| 3037 | if (d->mod == LY_DEVIATE_DEL) { |
| 3038 | /* find and remove the value in target list */ |
| 3039 | for (i = 0; i < llist->dflt_size; i++) { |
| 3040 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 3041 | /* match, remove the value */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3042 | lydict_remove(ctx, llist->dflt[i]); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3043 | llist->dflt[i] = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 3044 | |
| 3045 | /* remove extensions of this default instance from the target node */ |
| 3046 | j = -1; |
| 3047 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 3048 | if (dev_target->ext[j]->insubstmt_index == i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 3049 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 3050 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 3051 | } else if (dev_target->ext[j]->insubstmt_index > i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 3052 | /* decrease the substatement index of the extension because of the changed array of defaults */ |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 3053 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 3054 | } |
| 3055 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3056 | break; |
| 3057 | } |
| 3058 | } |
| 3059 | if (i == llist->dflt_size) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3060 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3061 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3062 | goto error; |
| 3063 | } |
| 3064 | } else { |
| 3065 | /* add or replace, anyway we place items into the deviate's list |
| 3066 | which propagates to the target */ |
| 3067 | /* we just want to check that the value isn't already in the list */ |
| 3068 | for (i = 0; i < llist->dflt_size; i++) { |
| 3069 | if (ly_strequal(llist->dflt[i], value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3070 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3071 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3072 | goto error; |
| 3073 | } |
| 3074 | } |
| 3075 | /* store it in target node */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3076 | llist->dflt[llist->dflt_size++] = lydict_insert(ctx, value, u); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3077 | |
| 3078 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 3079 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 3080 | llist->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3081 | } |
| 3082 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3083 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3084 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3085 | |
| 3086 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 3087 | /* consolidate the final list in the target after removing items from it */ |
| 3088 | llist = (struct lys_node_leaflist *)dev_target; |
| 3089 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 3090 | llist->dflt[i] = llist->dflt[j]; |
| 3091 | if (llist->dflt[i]) { |
| 3092 | i++; |
| 3093 | } |
| 3094 | } |
| 3095 | llist->dflt_size = i + 1; |
| 3096 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 3099 | /* now check whether default value, if any, matches the type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3100 | if (!(ctx->models.flags & LY_CTX_TRUSTED)) { |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3101 | for (u = 0; u < dflt_check->number; ++u) { |
| 3102 | value = NULL; |
| 3103 | rc = EXIT_SUCCESS; |
| 3104 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 3105 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
| 3106 | value = leaf->dflt; |
| 3107 | rc = unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt)); |
| 3108 | } else { /* LYS_LEAFLIST */ |
| 3109 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 3110 | for (j = 0; j < llist->dflt_size; j++) { |
| 3111 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 3112 | (struct lys_node *)(&llist->dflt[j])); |
| 3113 | if (rc == -1) { |
| 3114 | value = llist->dflt[j]; |
| 3115 | break; |
| 3116 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3117 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3118 | |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3119 | } |
| 3120 | if (rc == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3121 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3122 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3123 | "The default value \"%s\" of the deviated node \"%s\" no longer matches its type.", |
| 3124 | dev->target_name); |
| 3125 | goto error; |
| 3126 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 3127 | } |
| 3128 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 3129 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3130 | /* mark all the affected modules as deviated and implemented */ |
| 3131 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 3132 | mod = lys_node_module(parent); |
| 3133 | if (module != mod) { |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 3134 | mod->deviated = 1; /* main module */ |
| 3135 | parent->module->deviated = 1; /* possible submodule */ |
Michal Vasko | 0f43706 | 2018-06-08 15:52:39 +0200 | [diff] [blame] | 3136 | if (!mod->implemented) { |
| 3137 | mod->implemented = 1; |
| 3138 | if (unres_schema_add_node(mod, unres, NULL, UNRES_MOD_IMPLEMENT, NULL) == -1) { |
| 3139 | goto error; |
| 3140 | } |
Radek Krejci | 2bb5be7 | 2017-02-27 13:07:25 +0100 | [diff] [blame] | 3141 | } |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3145 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3146 | return EXIT_SUCCESS; |
| 3147 | |
| 3148 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3149 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3150 | return EXIT_FAILURE; |
| 3151 | } |
| 3152 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3153 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3154 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3155 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3156 | int options, struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3157 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3158 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3159 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3160 | struct lyxml_elem *sub, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3161 | struct lys_node *node; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3162 | int ret, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3163 | void *reallocated; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3164 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 3165 | aug->nodetype = LYS_AUGMENT; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3166 | GETVAL(ctx, value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3167 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 3168 | if (!aug->target_name) { |
| 3169 | goto error; |
| 3170 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3171 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3172 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3173 | if (read_yin_common(module, NULL, aug, LYEXT_PAR_NODE, yin, OPT_MODULE, unres)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3174 | goto error; |
| 3175 | } |
| 3176 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3177 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3178 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3179 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3180 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, aug->ext_size, "extensions", "augment", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3181 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3182 | continue; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3183 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3184 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, aug->iffeature_size, "if-features", "augment", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3185 | c_ftrs++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3186 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3187 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3188 | if (aug->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3189 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3190 | goto error; |
| 3191 | } |
| 3192 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3193 | aug->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3194 | if (!aug->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3195 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3196 | goto error; |
| 3197 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3198 | lyxml_free(ctx, sub); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3199 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3200 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3201 | /* check allowed data sub-statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3202 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3203 | node = read_yin_container(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3204 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3205 | node = read_yin_leaflist(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3206 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3207 | node = read_yin_leaf(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3208 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3209 | node = read_yin_list(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3210 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3211 | node = read_yin_uses(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3212 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3213 | node = read_yin_choice(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3214 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3215 | node = read_yin_case(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3216 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3217 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYXML, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3218 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3219 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYDATA, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3220 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3221 | node = read_yin_rpc_action(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3222 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3223 | node = read_yin_notif(module, (struct lys_node *)aug, sub, options, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3224 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3225 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3226 | goto error; |
| 3227 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3228 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3229 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3230 | goto error; |
| 3231 | } |
| 3232 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3233 | node = NULL; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3234 | lyxml_free(ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3235 | } |
| 3236 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3237 | if (c_ftrs) { |
| 3238 | aug->iffeature = calloc(c_ftrs, sizeof *aug->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3239 | LY_CHECK_ERR_GOTO(!aug->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3240 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3241 | if (c_ext) { |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3242 | /* some extensions may be already present from the substatements */ |
| 3243 | reallocated = realloc(aug->ext, (c_ext + aug->ext_size) * sizeof *aug->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3244 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3245 | aug->ext = reallocated; |
| 3246 | |
| 3247 | /* init memory */ |
| 3248 | memset(&aug->ext[aug->ext_size], 0, c_ext * sizeof *aug->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3249 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3250 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3251 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3252 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3253 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3254 | ret = lyp_yin_fill_ext(aug, LYEXT_PAR_NODE, 0, 0, module, sub, &aug->ext, aug->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3255 | aug->ext_size++; |
| 3256 | if (ret) { |
| 3257 | goto error; |
| 3258 | } |
| 3259 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3260 | ret = fill_yin_iffeature((struct lys_node *)aug, 0, sub, &aug->iffeature[aug->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3261 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3262 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3263 | goto error; |
| 3264 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3265 | lyxml_free(ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3266 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3267 | } |
| 3268 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3269 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3270 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3271 | * However, if this is augment in a uses (parent is NULL), it gets resolved |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3272 | * when the uses does and cannot be resolved now for sure |
| 3273 | * (the grouping was not yet copied into uses). |
| 3274 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3275 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3276 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 3277 | goto error; |
| 3278 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3279 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3280 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3281 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3282 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && aug->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3283 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3284 | if (lyxp_node_check_syntax((struct lys_node *)aug)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3285 | goto error; |
| 3286 | } |
| 3287 | } else { |
| 3288 | if (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1) { |
| 3289 | goto error; |
| 3290 | } |
| 3291 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3294 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3295 | |
| 3296 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3297 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3298 | } |
| 3299 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3300 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3301 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3302 | fill_yin_refine(struct lys_node *uses, struct lyxml_elem *yin, struct lys_refine *rfn, struct unres_schema *unres) |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3303 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3304 | struct ly_ctx *ctx = uses->module->ctx; |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3305 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3306 | struct lyxml_elem *sub, *next; |
| 3307 | const char *value; |
| 3308 | char *endptr; |
| 3309 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3310 | int c_must = 0, c_ftrs = 0, c_dflt = 0, c_ext = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3311 | int r; |
| 3312 | unsigned long int val; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3313 | void *reallocated; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3314 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3315 | assert(uses); |
| 3316 | module = uses->module; /* shorthand */ |
| 3317 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3318 | GETVAL(ctx, value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3319 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 3320 | if (!rfn->target_name) { |
| 3321 | goto error; |
| 3322 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3323 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3324 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3325 | if (!sub->ns) { |
| 3326 | /* garbage */ |
| 3327 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3328 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3329 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, rfn->ext_size, "extensions", "refine", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3330 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3331 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3332 | |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3333 | } else if (!strcmp(sub->name, "description")) { |
| 3334 | if (rfn->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3335 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3336 | goto error; |
| 3337 | } |
| 3338 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3339 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3340 | goto error; |
| 3341 | } |
| 3342 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3343 | rfn->dsc = read_yin_subnode(ctx, sub, "text"); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3344 | if (!rfn->dsc) { |
| 3345 | goto error; |
| 3346 | } |
| 3347 | } else if (!strcmp(sub->name, "reference")) { |
| 3348 | if (rfn->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3349 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3350 | goto error; |
| 3351 | } |
| 3352 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3353 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3354 | goto error; |
| 3355 | } |
| 3356 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3357 | rfn->ref = read_yin_subnode(ctx, sub, "text"); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3358 | if (!rfn->ref) { |
| 3359 | goto error; |
| 3360 | } |
| 3361 | } else if (!strcmp(sub->name, "config")) { |
| 3362 | if (rfn->flags & LYS_CONFIG_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3363 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3364 | goto error; |
| 3365 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3366 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3367 | if (!strcmp(value, "false")) { |
| 3368 | rfn->flags |= LYS_CONFIG_R; |
| 3369 | } else if (!strcmp(value, "true")) { |
| 3370 | rfn->flags |= LYS_CONFIG_W; |
| 3371 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3372 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3373 | goto error; |
| 3374 | } |
| 3375 | rfn->flags |= LYS_CONFIG_SET; |
| 3376 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3377 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3378 | goto error; |
| 3379 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3380 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3381 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3382 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3383 | /* check possibility of statements combination */ |
| 3384 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3385 | if (c_dflt) { |
| 3386 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3387 | if (module->version < 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3388 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3389 | goto error; |
| 3390 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3391 | rfn->target_type &= LYS_LEAFLIST; |
| 3392 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3393 | if (module->version < 2) { |
| 3394 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 3395 | } else { |
| 3396 | /* YANG 1.1 */ |
| 3397 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 3398 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3399 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3400 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3401 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3402 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3403 | goto error; |
| 3404 | } |
| 3405 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3406 | if (module->version < 2) { |
| 3407 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 3408 | } else { |
| 3409 | /* YANG 1.1 */ |
| 3410 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 3411 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3412 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3413 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3414 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_dflt, rfn->dflt_size, "defaults", "refine", error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3415 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3416 | goto error; |
| 3417 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3418 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3419 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3420 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3421 | /* leaf, choice or anyxml */ |
| 3422 | if (f_mand) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3423 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3424 | goto error; |
| 3425 | } |
| 3426 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3427 | * multiple mandatory statements with the "false" value |
| 3428 | */ |
| 3429 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3430 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3431 | /* check possibility of statements combination */ |
| 3432 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3433 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3434 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3435 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3436 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3437 | goto error; |
| 3438 | } |
| 3439 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3440 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3441 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3442 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3443 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3444 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3445 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3446 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3447 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3448 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3449 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3450 | goto error; |
| 3451 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3452 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3453 | goto error; |
| 3454 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3455 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3456 | /* list or leaf-list */ |
| 3457 | if (f_min) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3458 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3459 | goto error; |
| 3460 | } |
| 3461 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3462 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3463 | /* check possibility of statements combination */ |
| 3464 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3465 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3466 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3467 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3468 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3469 | goto error; |
| 3470 | } |
| 3471 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3472 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3473 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3474 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3475 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3476 | while (isspace(value[0])) { |
| 3477 | value++; |
| 3478 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3480 | /* convert it to uint32_t */ |
| 3481 | errno = 0; |
| 3482 | endptr = NULL; |
| 3483 | val = strtoul(value, &endptr, 10); |
| 3484 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3485 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3486 | goto error; |
| 3487 | } |
| 3488 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3489 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3490 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3491 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3492 | goto error; |
| 3493 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3494 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3495 | /* list or leaf-list */ |
| 3496 | if (f_max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3497 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3498 | goto error; |
| 3499 | } |
| 3500 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3501 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3502 | /* check possibility of statements combination */ |
| 3503 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3504 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3505 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3506 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3507 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3508 | goto error; |
| 3509 | } |
| 3510 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3511 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3512 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3513 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3514 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3515 | while (isspace(value[0])) { |
| 3516 | value++; |
| 3517 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3518 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3519 | if (!strcmp(value, "unbounded")) { |
| 3520 | rfn->mod.list.max = 0; |
| 3521 | } else { |
| 3522 | /* convert it to uint32_t */ |
| 3523 | errno = 0; |
| 3524 | endptr = NULL; |
| 3525 | val = strtoul(value, &endptr, 10); |
| 3526 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3527 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3528 | goto error; |
| 3529 | } |
| 3530 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3531 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3532 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3533 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3534 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3535 | goto error; |
| 3536 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3537 | } else if (!strcmp(sub->name, "presence")) { |
| 3538 | /* container */ |
| 3539 | if (rfn->mod.presence) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3540 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3541 | goto error; |
| 3542 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3543 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3544 | /* check possibility of statements combination */ |
| 3545 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3546 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3547 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3548 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3549 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3550 | goto error; |
| 3551 | } |
| 3552 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3553 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3554 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3555 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3556 | GETVAL(ctx, value, sub, "value"); |
| 3557 | rfn->mod.presence = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3558 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3559 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_PRESENCE, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3560 | goto error; |
| 3561 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3562 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3563 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | /* check possibility of statements combination */ |
| 3565 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3566 | rfn->target_type &= (LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3567 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3568 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3569 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3570 | goto error; |
| 3571 | } |
| 3572 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3573 | rfn->target_type = LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3574 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3575 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3576 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, rfn->must_size, "musts", "refine", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3577 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3578 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3579 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3580 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 3581 | /* leaf, leaf-list, list, container or anyxml */ |
| 3582 | /* check possibility of statements combination */ |
| 3583 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3584 | rfn->target_type &= (LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYDATA); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3585 | if (!rfn->target_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3586 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3587 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3588 | goto error; |
| 3589 | } |
| 3590 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3591 | rfn->target_type = LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYDATA; |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3592 | } |
| 3593 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3594 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, rfn->iffeature_size, "if-feature", "refine", error); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3595 | c_ftrs++; |
| 3596 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3597 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3598 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3599 | goto error; |
| 3600 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3601 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3602 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3603 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3604 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3605 | /* process nodes with cardinality of 0..n */ |
| 3606 | if (c_must) { |
| 3607 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3608 | LY_CHECK_ERR_GOTO(!rfn->must, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3609 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3610 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 3611 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3612 | LY_CHECK_ERR_GOTO(!rfn->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3613 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3614 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3615 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3616 | LY_CHECK_ERR_GOTO(!rfn->dflt, LOGMEM(ctx), error); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3617 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3618 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3619 | /* some extensions may be already present from the substatements */ |
| 3620 | reallocated = realloc(rfn->ext, (c_ext + rfn->ext_size) * sizeof *rfn->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3621 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3622 | rfn->ext = reallocated; |
| 3623 | |
| 3624 | /* init memory */ |
| 3625 | memset(&rfn->ext[rfn->ext_size], 0, c_ext * sizeof *rfn->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3626 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3627 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3628 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3629 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3630 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3631 | r = lyp_yin_fill_ext(rfn, LYEXT_PAR_REFINE, 0, 0, module, sub, &rfn->ext, rfn->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3632 | rfn->ext_size++; |
| 3633 | if (r) { |
| 3634 | goto error; |
| 3635 | } |
| 3636 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 3637 | r = fill_yin_iffeature(uses, 0, sub, &rfn->iffeature[rfn->iffeature_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3638 | rfn->iffeature_size++; |
| 3639 | if (r) { |
| 3640 | goto error; |
| 3641 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3642 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 3643 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3644 | rfn->must_size++; |
| 3645 | if (r) { |
| 3646 | goto error; |
| 3647 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3648 | } else { /* default */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3649 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3650 | |
| 3651 | /* check for duplicity */ |
| 3652 | for (r = 0; r < rfn->dflt_size; r++) { |
| 3653 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3654 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3655 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3656 | goto error; |
| 3657 | } |
| 3658 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3659 | rfn->dflt[rfn->dflt_size++] = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3660 | } |
| 3661 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3662 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3663 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3664 | |
| 3665 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3666 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3667 | } |
| 3668 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3669 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3670 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3671 | fill_yin_import(struct lys_module *module, struct lyxml_elem *yin, struct lys_import *imp, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3672 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3673 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3674 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3675 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3676 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3677 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3678 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3679 | /* init */ |
| 3680 | memset(&exts, 0, sizeof exts); |
| 3681 | |
| 3682 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3683 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3684 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3685 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3686 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3687 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3688 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, imp->ext_size, "extensions", "import", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3689 | c_ext++; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3690 | lyxml_unlink_elem(ctx, child, 2); |
| 3691 | lyxml_add_child(ctx, &exts, child); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3692 | } else if (!strcmp(child->name, "prefix")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3693 | GETVAL(ctx, value, child, "value"); |
| 3694 | if (lyp_check_identifier(ctx, value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3695 | goto error; |
| 3696 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3697 | imp->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3698 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3699 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3700 | goto error; |
| 3701 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3702 | } else if (!strcmp(child->name, "revision-date")) { |
| 3703 | if (imp->rev[0]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3704 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 3705 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3706 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3707 | GETVAL(ctx, value, child, "date"); |
| 3708 | if (lyp_check_date(ctx, value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3709 | goto error; |
| 3710 | } |
| 3711 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3712 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3713 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3714 | goto error; |
| 3715 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3716 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3717 | if (imp->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3718 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3719 | goto error; |
| 3720 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3721 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3722 | goto error; |
| 3723 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3724 | imp->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3725 | if (!imp->dsc) { |
| 3726 | goto error; |
| 3727 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3728 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3729 | if (imp->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3730 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3731 | goto error; |
| 3732 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3733 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3734 | goto error; |
| 3735 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3736 | imp->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3737 | if (!imp->ref) { |
| 3738 | goto error; |
| 3739 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3740 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3741 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3742 | goto error; |
| 3743 | } |
| 3744 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3745 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3746 | /* check mandatory information */ |
| 3747 | if (!imp->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3748 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3749 | goto error; |
| 3750 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3751 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3752 | /* process extensions */ |
| 3753 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3754 | /* some extensions may be already present from the substatements */ |
| 3755 | reallocated = realloc(imp->ext, (c_ext + imp->ext_size) * sizeof *imp->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3756 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3757 | imp->ext = reallocated; |
| 3758 | |
| 3759 | /* init memory */ |
| 3760 | memset(&imp->ext[imp->ext_size], 0, c_ext * sizeof *imp->ext); |
| 3761 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3762 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3763 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3764 | r = lyp_yin_fill_ext(imp, LYEXT_PAR_IMPORT, 0, 0, module, child, &imp->ext, imp->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3765 | imp->ext_size++; |
| 3766 | if (r) { |
| 3767 | goto error; |
| 3768 | } |
| 3769 | } |
| 3770 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3771 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3772 | GETVAL(ctx, value, yin, "module"); |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 3773 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3774 | |
| 3775 | error: |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3776 | while (exts.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3777 | lyxml_free(ctx, exts.child); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3778 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3779 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3780 | } |
| 3781 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3782 | /* logs directly |
| 3783 | * returns: |
| 3784 | * 0 - inc successfully filled |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3785 | * -1 - error |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3786 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3787 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 3788 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 3789 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3790 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3791 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3792 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3793 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3794 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3795 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3796 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3797 | /* init */ |
| 3798 | memset(&exts, 0, sizeof exts); |
| 3799 | |
| 3800 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3801 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3802 | /* garbage */ |
| 3803 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3804 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3805 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3806 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, inc->ext_size, "extensions", "include", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3807 | c_ext++; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3808 | lyxml_unlink_elem(ctx, child, 2); |
| 3809 | lyxml_add_child(ctx, &exts, child); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3810 | } else if (!strcmp(child->name, "revision-date")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3811 | if (inc->rev[0]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3812 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3813 | goto error; |
| 3814 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3815 | GETVAL(ctx, value, child, "date"); |
| 3816 | if (lyp_check_date(ctx, value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3817 | goto error; |
| 3818 | } |
| 3819 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3820 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3821 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3822 | goto error; |
| 3823 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3824 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3825 | if (inc->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3826 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3827 | goto error; |
| 3828 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3829 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3830 | goto error; |
| 3831 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3832 | inc->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3833 | if (!inc->dsc) { |
| 3834 | goto error; |
| 3835 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3836 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3837 | if (inc->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3838 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3839 | goto error; |
| 3840 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3841 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3842 | goto error; |
| 3843 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3844 | inc->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3845 | if (!inc->ref) { |
| 3846 | goto error; |
| 3847 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3848 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3849 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3850 | goto error; |
| 3851 | } |
| 3852 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3853 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3854 | /* process extensions */ |
| 3855 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3856 | /* some extensions may be already present from the substatements */ |
| 3857 | reallocated = realloc(inc->ext, (c_ext + inc->ext_size) * sizeof *inc->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3858 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3859 | inc->ext = reallocated; |
| 3860 | |
| 3861 | /* init memory */ |
| 3862 | memset(&inc->ext[inc->ext_size], 0, c_ext * sizeof *inc->ext); |
| 3863 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3864 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3865 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3866 | r = lyp_yin_fill_ext(inc, LYEXT_PAR_INCLUDE, 0, 0, module, child, &inc->ext, inc->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3867 | inc->ext_size++; |
| 3868 | if (r) { |
| 3869 | goto error; |
| 3870 | } |
| 3871 | } |
| 3872 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3873 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3874 | GETVAL(ctx, value, yin, "module"); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3875 | return lyp_check_include(submodule ? (struct lys_module *)submodule : module, value, inc, unres); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3876 | |
| 3877 | error: |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 3878 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3879 | } |
| 3880 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3881 | /* logs directly |
| 3882 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3883 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3884 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3885 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3886 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3887 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3888 | read_yin_common(struct lys_module *module, struct lys_node *parent, void *stmt, LYEXT_PAR stmt_type, |
| 3889 | struct lyxml_elem *xmlnode, int opt, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3890 | { |
Radek Krejci | e4dce29 | 2017-10-30 11:16:47 +0100 | [diff] [blame] | 3891 | struct lys_node *node = stmt, *p; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3892 | const char *value; |
| 3893 | struct lyxml_elem *sub, *next; |
| 3894 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 2cc2532 | 2017-09-06 16:32:02 +0200 | [diff] [blame] | 3895 | char *str; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3896 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3897 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3898 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3899 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3900 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3901 | if (opt & OPT_IDENT) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3902 | GETVAL(ctx, value, xmlnode, "name"); |
| 3903 | if (lyp_check_identifier(ctx, value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3904 | goto error; |
| 3905 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3906 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3907 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3908 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3909 | /* process local parameters */ |
| 3910 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3911 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3912 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3913 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3914 | continue; |
| 3915 | } |
| 3916 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 3917 | /* possibly an extension, keep the node for later processing, so skipping lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3918 | continue; |
| 3919 | } |
| 3920 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3921 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3922 | if (node->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3923 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3924 | goto error; |
| 3925 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3926 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3927 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3928 | goto error; |
| 3929 | } |
| 3930 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3931 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3932 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3933 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3934 | } |
| 3935 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3936 | if (node->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3937 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3938 | goto error; |
| 3939 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3940 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3941 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3942 | goto error; |
| 3943 | } |
| 3944 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3945 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3946 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3947 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3948 | } |
| 3949 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3950 | if (node->flags & LYS_STATUS_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3951 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3952 | goto error; |
| 3953 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3954 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3955 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3956 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3957 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3958 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3959 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3960 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3961 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3962 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3963 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3964 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3965 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3966 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3967 | goto error; |
| 3968 | } |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3969 | } else if ((opt & (OPT_CFG_PARSE | OPT_CFG_IGNORE)) && !strcmp(sub->name, "config")) { |
| 3970 | if (opt & OPT_CFG_PARSE) { |
| 3971 | if (node->flags & LYS_CONFIG_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3972 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3973 | goto error; |
| 3974 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3975 | GETVAL(ctx, value, sub, "value"); |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3976 | if (!strcmp(value, "false")) { |
| 3977 | node->flags |= LYS_CONFIG_R; |
| 3978 | } else if (!strcmp(value, "true")) { |
| 3979 | node->flags |= LYS_CONFIG_W; |
| 3980 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3981 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3982 | goto error; |
| 3983 | } |
| 3984 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3985 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3986 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3987 | goto error; |
| 3988 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3989 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3990 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3991 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3992 | continue; |
| 3993 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3994 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3995 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3996 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3997 | if ((opt & OPT_CFG_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3998 | /* get config flag from parent */ |
Radek Krejci | f71f48f | 2016-10-25 16:37:24 +0200 | [diff] [blame] | 3999 | if (parent) { |
| 4000 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
| 4001 | } else if (!parent) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4002 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4003 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4004 | } |
| 4005 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4006 | |
Radek Krejci | 2cc2532 | 2017-09-06 16:32:02 +0200 | [diff] [blame] | 4007 | if (parent && (parent->flags & (LYS_STATUS_DEPRC | LYS_STATUS_OBSLT))) { |
| 4008 | /* status is not inherited by specification, but it not make sense to have |
| 4009 | * current in deprecated or deprecated in obsolete, so we print warning |
| 4010 | * and fix the schema by inheriting */ |
| 4011 | if (!(node->flags & (LYS_STATUS_MASK))) { |
| 4012 | /* status not explicitely specified on the current node -> inherit */ |
Radek Krejci | e4dce29 | 2017-10-30 11:16:47 +0100 | [diff] [blame] | 4013 | if (stmt_type == LYEXT_PAR_NODE) { |
| 4014 | p = node->parent; |
| 4015 | node->parent = parent; |
Michal Vasko | 395b0a0 | 2018-01-22 09:36:20 +0100 | [diff] [blame] | 4016 | str = lys_path(node, LYS_PATH_FIRST_PREFIX); |
Radek Krejci | e4dce29 | 2017-10-30 11:16:47 +0100 | [diff] [blame] | 4017 | node->parent = p; |
| 4018 | } else { |
Michal Vasko | 395b0a0 | 2018-01-22 09:36:20 +0100 | [diff] [blame] | 4019 | str = lys_path(parent, LYS_PATH_FIRST_PREFIX); |
Radek Krejci | e4dce29 | 2017-10-30 11:16:47 +0100 | [diff] [blame] | 4020 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4021 | LOGWRN(ctx, "Missing status in %s subtree (%s), inheriting.", |
| 4022 | parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", str); |
Radek Krejci | 2cc2532 | 2017-09-06 16:32:02 +0200 | [diff] [blame] | 4023 | free(str); |
| 4024 | node->flags |= parent->flags & LYS_STATUS_MASK; |
| 4025 | } else if ((parent->flags & LYS_STATUS_MASK) > (node->flags & LYS_STATUS_MASK)) { |
| 4026 | /* invalid combination of statuses */ |
| 4027 | switch (node->flags & LYS_STATUS_MASK) { |
| 4028 | case 0: |
| 4029 | case LYS_STATUS_CURR: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4030 | LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "current", xmlnode->name, "is child of", |
Radek Krejci | 2cc2532 | 2017-09-06 16:32:02 +0200 | [diff] [blame] | 4031 | parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", parent->name); |
| 4032 | break; |
| 4033 | case LYS_STATUS_DEPRC: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4034 | LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "deprecated", xmlnode->name, "is child of", |
Radek Krejci | 2cc2532 | 2017-09-06 16:32:02 +0200 | [diff] [blame] | 4035 | "obsolete", parent->name); |
| 4036 | break; |
| 4037 | } |
| 4038 | goto error; |
| 4039 | } |
| 4040 | } |
| 4041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4042 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 4043 | |
| 4044 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4045 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4046 | } |
| 4047 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4048 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4049 | static struct lys_when * |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4050 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin, struct unres_schema *unres) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4051 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4052 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4053 | struct lys_when *retval = NULL; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4054 | struct lyxml_elem *child, *next; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4055 | const char *value; |
| 4056 | |
| 4057 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4058 | LY_CHECK_ERR_RETURN(!retval, LOGMEM(ctx), NULL); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4059 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4060 | GETVAL(ctx, value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4061 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 4062 | if (!retval->cond) { |
| 4063 | goto error; |
| 4064 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4065 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4066 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4067 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4068 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4069 | continue; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4070 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 4071 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4072 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4073 | goto error; |
| 4074 | } |
| 4075 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4076 | if (retval->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4077 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4078 | goto error; |
| 4079 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4080 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4081 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4082 | goto error; |
| 4083 | } |
| 4084 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4085 | retval->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4086 | if (!retval->dsc) { |
| 4087 | goto error; |
| 4088 | } |
| 4089 | } else if (!strcmp(child->name, "reference")) { |
| 4090 | if (retval->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4091 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4092 | goto error; |
| 4093 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4094 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4095 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4096 | goto error; |
| 4097 | } |
| 4098 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4099 | retval->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4100 | if (!retval->ref) { |
| 4101 | goto error; |
| 4102 | } |
| 4103 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4104 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4105 | goto error; |
| 4106 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | return retval; |
| 4110 | |
| 4111 | error: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4112 | lys_when_free(ctx, retval, NULL); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4113 | return NULL; |
| 4114 | } |
| 4115 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4116 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4117 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4118 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4119 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4120 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4121 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4122 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4123 | struct lys_node_case *cs; |
| 4124 | struct lys_node *retval, *node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4125 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4126 | void *reallocated; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4127 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 4128 | /* init */ |
| 4129 | memset(&root, 0, sizeof root); |
| 4130 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4131 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4132 | LY_CHECK_ERR_RETURN(!cs, LOGMEM(ctx), NULL); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4133 | cs->nodetype = LYS_CASE; |
| 4134 | cs->prev = (struct lys_node *)cs; |
| 4135 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4136 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4137 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4138 | OPT_IDENT | OPT_MODULE | (!(options & LYS_PARSE_OPT_CFG_MASK) ? OPT_CFG_INHERIT : 0), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4139 | goto error; |
| 4140 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4141 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4142 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4143 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4144 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 4145 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4146 | goto error; |
| 4147 | } |
| 4148 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4149 | /* process choice's specific children */ |
| 4150 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4151 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4152 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4153 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "case", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4154 | c_ext++; |
| 4155 | } else if (!strcmp(sub->name, "container") || |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4156 | !strcmp(sub->name, "leaf-list") || |
| 4157 | !strcmp(sub->name, "leaf") || |
| 4158 | !strcmp(sub->name, "list") || |
| 4159 | !strcmp(sub->name, "uses") || |
| 4160 | !strcmp(sub->name, "choice") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 4161 | !strcmp(sub->name, "anyxml") || |
| 4162 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4163 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4164 | lyxml_unlink_elem(ctx, sub, 2); |
| 4165 | lyxml_add_child(ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4166 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4167 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "case", error); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4168 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4169 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4170 | if (cs->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4171 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4172 | goto error; |
| 4173 | } |
| 4174 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4175 | cs->when = read_yin_when(module, sub, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4176 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4177 | goto error; |
| 4178 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4179 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4180 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4181 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4182 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4183 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4184 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4185 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4186 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4187 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4188 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4189 | LY_CHECK_ERR_GOTO(!cs->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4190 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4191 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4192 | /* some extensions may be already present from the substatements */ |
| 4193 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4194 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4195 | retval->ext = reallocated; |
| 4196 | |
| 4197 | /* init memory */ |
| 4198 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4199 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4200 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4201 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4202 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4203 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4204 | ret = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4205 | retval->ext_size++; |
| 4206 | if (ret) { |
| 4207 | goto error; |
| 4208 | } |
| 4209 | } else { |
| 4210 | /* if-feature */ |
| 4211 | ret = fill_yin_iffeature(retval, 0, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 4212 | cs->iffeature_size++; |
| 4213 | if (ret) { |
| 4214 | goto error; |
| 4215 | } |
| 4216 | } |
| 4217 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4218 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4219 | /* last part - process data nodes */ |
| 4220 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4221 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4222 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4223 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4224 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4225 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4226 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4227 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4228 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4229 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4230 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4231 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4232 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4233 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4234 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4235 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4236 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4237 | } |
| 4238 | if (!node) { |
| 4239 | goto error; |
| 4240 | } |
| 4241 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4242 | lyxml_free(ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4243 | } |
| 4244 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4245 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4246 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && cs->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4247 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4248 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4249 | goto error; |
| 4250 | } |
| 4251 | } else { |
| 4252 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4253 | goto error; |
| 4254 | } |
| 4255 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4256 | } |
| 4257 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4258 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4259 | |
| 4260 | error: |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4261 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4262 | lyxml_free(ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4263 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4264 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4266 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4267 | } |
| 4268 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4269 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4270 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4271 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4272 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4273 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4274 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4275 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4276 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4277 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4278 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4279 | int f_mand = 0, c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4280 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4282 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4283 | LY_CHECK_ERR_RETURN(!choice, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4284 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4285 | choice->nodetype = LYS_CHOICE; |
| 4286 | choice->prev = (struct lys_node *)choice; |
| 4287 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4288 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4289 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4290 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4291 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4292 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4293 | goto error; |
| 4294 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4295 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4296 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4297 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4298 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 4299 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4300 | goto error; |
| 4301 | } |
| 4302 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4303 | /* process choice's specific children */ |
| 4304 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4305 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4306 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4307 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "choice", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4308 | c_ext++; |
| 4309 | /* keep it for later processing, skip lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4310 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4311 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4312 | if (!(node = read_yin_container(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4313 | goto error; |
| 4314 | } |
| 4315 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4316 | if (!(node = read_yin_leaflist(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4317 | goto error; |
| 4318 | } |
| 4319 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4320 | if (!(node = read_yin_leaf(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4321 | goto error; |
| 4322 | } |
| 4323 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4324 | if (!(node = read_yin_list(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4325 | goto error; |
| 4326 | } |
| 4327 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4328 | if (!(node = read_yin_case(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4329 | goto error; |
| 4330 | } |
| 4331 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4332 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres))) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4333 | goto error; |
| 4334 | } |
| 4335 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4336 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4337 | goto error; |
| 4338 | } |
| 4339 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4340 | if (dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4341 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4342 | goto error; |
| 4343 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4344 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4345 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4346 | goto error; |
| 4347 | } |
| 4348 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4349 | dflt = sub; |
| 4350 | lyxml_unlink_elem(ctx, dflt, 0); |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 4351 | continue; |
| 4352 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 4353 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4354 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4355 | if (f_mand) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4356 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4357 | goto error; |
| 4358 | } |
| 4359 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4360 | * multiple mandatory statements with the "false" value |
| 4361 | */ |
| 4362 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4363 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4364 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4365 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4366 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4367 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4368 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4369 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4370 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4371 | goto error; |
| 4372 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4373 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4374 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4375 | goto error; |
| 4376 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4377 | } else if (!strcmp(sub->name, "when")) { |
| 4378 | if (choice->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4379 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4380 | goto error; |
| 4381 | } |
| 4382 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4383 | choice->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4384 | if (!choice->when) { |
| 4385 | goto error; |
| 4386 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4387 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4388 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "choice", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4389 | c_ftrs++; |
| 4390 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4391 | /* skip lyxml_free() at the end of the loop, the sub node is processed later */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4392 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4393 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4394 | if (!(node = read_yin_choice(module, retval, sub, options, unres))) { |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4395 | goto error; |
| 4396 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4397 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4398 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4399 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4400 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4401 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4402 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4403 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4404 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4405 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4406 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4407 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4408 | LY_CHECK_ERR_GOTO(!choice->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4409 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4410 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4411 | /* some extensions may be already present from the substatements */ |
| 4412 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4413 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4414 | retval->ext = reallocated; |
| 4415 | |
| 4416 | /* init memory */ |
| 4417 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4418 | } |
| 4419 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4420 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4421 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4422 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4423 | ret = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4424 | retval->ext_size++; |
| 4425 | if (ret) { |
| 4426 | goto error; |
| 4427 | } |
| 4428 | } else { |
| 4429 | ret = fill_yin_iffeature(retval, 0, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 4430 | choice->iffeature_size++; |
| 4431 | if (ret) { |
| 4432 | goto error; |
| 4433 | } |
| 4434 | } |
| 4435 | } |
| 4436 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4437 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4438 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4439 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice"); |
| 4440 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "The \"default\" statement is forbidden on choices with \"mandatory\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4441 | goto error; |
| 4442 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4443 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4444 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4445 | if (dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4446 | GETVAL(ctx, value, dflt, "value"); |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4447 | if (unres_schema_add_str(module, unres, choice, UNRES_CHOICE_DFLT, value) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4448 | goto error; |
| 4449 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4450 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4451 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4452 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4453 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4454 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && choice->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4455 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4456 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4457 | goto error; |
| 4458 | } |
| 4459 | } else { |
| 4460 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4461 | goto error; |
| 4462 | } |
| 4463 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4464 | } |
| 4465 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4466 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4467 | |
| 4468 | error: |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4469 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4470 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4471 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4472 | } |
| 4473 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4474 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4475 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4476 | read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, LYS_NODE type, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4477 | int options, struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4478 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4479 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4480 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4481 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4482 | struct lyxml_elem *sub, *next; |
| 4483 | const char *value; |
| 4484 | int r; |
| 4485 | int f_mand = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4486 | int c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4487 | void *reallocated; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4488 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4489 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4490 | LY_CHECK_ERR_RETURN(!anyxml, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4491 | |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4492 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4493 | anyxml->prev = (struct lys_node *)anyxml; |
| 4494 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4495 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4496 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4497 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4498 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4499 | goto error; |
| 4500 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4501 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4502 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4503 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4504 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 4505 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4506 | goto error; |
| 4507 | } |
| 4508 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4509 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4510 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4511 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4512 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "anydata", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4513 | c_ext++; |
| 4514 | } else if (!strcmp(sub->name, "mandatory")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4515 | if (f_mand) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4516 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4517 | goto error; |
| 4518 | } |
| 4519 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4520 | * multiple mandatory statements with the "false" value |
| 4521 | */ |
| 4522 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4523 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4524 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4525 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4526 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4527 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4528 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4529 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4530 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4531 | goto error; |
| 4532 | } |
| 4533 | /* else false is the default value, so we can ignore it */ |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4534 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4535 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4536 | goto error; |
| 4537 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4538 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4539 | } else if (!strcmp(sub->name, "when")) { |
| 4540 | if (anyxml->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4541 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4542 | goto error; |
| 4543 | } |
| 4544 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4545 | anyxml->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4546 | if (!anyxml->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4547 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4548 | goto error; |
| 4549 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4550 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4551 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4552 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, anyxml->must_size, "musts", "anydata", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4553 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4554 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4555 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "anydata", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4556 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4557 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4558 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4559 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4560 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4561 | } |
| 4562 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4563 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4564 | /* middle part - process nodes with cardinality of 0..n */ |
| 4565 | if (c_must) { |
| 4566 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4567 | LY_CHECK_ERR_GOTO(!anyxml->must, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4568 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4569 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4570 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4571 | LY_CHECK_ERR_GOTO(!anyxml->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4572 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4573 | if (c_ext) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4574 | /* some extensions may be already present from the substatements */ |
| 4575 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4576 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4577 | retval->ext = reallocated; |
| 4578 | |
| 4579 | /* init memory */ |
| 4580 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4581 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4582 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4583 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4584 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4585 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4586 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4587 | retval->ext_size++; |
| 4588 | if (r) { |
| 4589 | goto error; |
| 4590 | } |
| 4591 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4592 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4593 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4594 | if (r) { |
| 4595 | goto error; |
| 4596 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4597 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4598 | r = fill_yin_iffeature(retval, 0, sub, &anyxml->iffeature[anyxml->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4599 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4600 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4601 | goto error; |
| 4602 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4603 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4604 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4605 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4606 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4607 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && (anyxml->when || anyxml->must)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4608 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4609 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4610 | goto error; |
| 4611 | } |
| 4612 | } else { |
| 4613 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4614 | goto error; |
| 4615 | } |
| 4616 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4617 | } |
| 4618 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4619 | for (r = 0; r < retval->ext_size; ++r) { |
| 4620 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 4621 | if (retval->ext[r]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 4622 | retval->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4623 | break; |
| 4624 | } |
| 4625 | } |
| 4626 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4627 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4628 | |
| 4629 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4630 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4631 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4632 | } |
| 4633 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4634 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4635 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4636 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4637 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4638 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4639 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4640 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4641 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | struct lyxml_elem *sub, *next; |
| 4643 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4644 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4645 | int c_must = 0, c_ftrs = 0, f_mand = 0, c_ext = 0; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4646 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4647 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4648 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4649 | LY_CHECK_ERR_RETURN(!leaf, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4650 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4651 | leaf->nodetype = LYS_LEAF; |
| 4652 | leaf->prev = (struct lys_node *)leaf; |
| 4653 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4654 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4655 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4656 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4657 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4658 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4659 | goto error; |
| 4660 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4661 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4662 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4663 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4664 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 4665 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4666 | goto error; |
| 4667 | } |
| 4668 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4669 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4670 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4671 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4672 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "leaf", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4673 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4674 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4675 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4676 | if (has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4677 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4678 | goto error; |
| 4679 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4680 | /* HACK for unres */ |
| 4681 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4682 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4683 | /* postpone type resolution when if-feature parsing is done since we need |
| 4684 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4685 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4686 | } else if (!strcmp(sub->name, "default")) { |
| 4687 | if (leaf->dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4688 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4689 | goto error; |
| 4690 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4691 | GETVAL(ctx, value, sub, "value"); |
| 4692 | leaf->dflt = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4693 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4694 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4695 | goto error; |
| 4696 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4697 | } else if (!strcmp(sub->name, "units")) { |
| 4698 | if (leaf->units) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4699 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4700 | goto error; |
| 4701 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4702 | GETVAL(ctx, value, sub, "name"); |
| 4703 | leaf->units = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4704 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4705 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4706 | goto error; |
| 4707 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4708 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4709 | if (f_mand) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4710 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4711 | goto error; |
| 4712 | } |
| 4713 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4714 | * multiple mandatory statements with the "false" value |
| 4715 | */ |
| 4716 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4717 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4718 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4719 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4720 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4721 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4722 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4723 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4724 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4725 | goto error; |
| 4726 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4727 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4728 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4729 | goto error; |
| 4730 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4731 | } else if (!strcmp(sub->name, "when")) { |
| 4732 | if (leaf->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4733 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4734 | goto error; |
| 4735 | } |
| 4736 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4737 | leaf->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4738 | if (!leaf->when) { |
| 4739 | goto error; |
| 4740 | } |
| 4741 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4742 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4743 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, leaf->must_size, "musts", "leaf", error); |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4744 | c_must++; |
| 4745 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4746 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4747 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "musts", "leaf", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4748 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4749 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4750 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4751 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4752 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4753 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4754 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4755 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4756 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4757 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4758 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4759 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4760 | if (!has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4761 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4762 | goto error; |
| 4763 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4764 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4765 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf"); |
| 4766 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4767 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 4768 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4769 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4770 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4771 | /* middle part - process nodes with cardinality of 0..n */ |
| 4772 | if (c_must) { |
| 4773 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4774 | LY_CHECK_ERR_GOTO(!leaf->must, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4775 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4776 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4777 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4778 | LY_CHECK_ERR_GOTO(!leaf->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4779 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4780 | if (c_ext) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4781 | /* some extensions may be already present from the substatements */ |
| 4782 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4783 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4784 | retval->ext = reallocated; |
| 4785 | |
| 4786 | /* init memory */ |
| 4787 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4788 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4789 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4790 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4791 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4792 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4793 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4794 | retval->ext_size++; |
| 4795 | if (r) { |
| 4796 | goto error; |
| 4797 | } |
| 4798 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4799 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4800 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4801 | if (r) { |
| 4802 | goto error; |
| 4803 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4804 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4805 | r = fill_yin_iffeature(retval, 0, sub, &leaf->iffeature[leaf->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4806 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4807 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4808 | goto error; |
| 4809 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4810 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4811 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4812 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4813 | /* finalize type parsing */ |
| 4814 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
| 4815 | leaf->type.der = NULL; |
| 4816 | goto error; |
| 4817 | } |
| 4818 | |
| 4819 | /* check default value (if not defined, there still could be some restrictions |
| 4820 | * that need to be checked against a default value from a derived type) */ |
Michal Vasko | 6a05778 | 2018-03-09 13:24:33 +0100 | [diff] [blame] | 4821 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 4822 | (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, |
| 4823 | (struct lys_node *)(&leaf->dflt)) == -1)) { |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4824 | goto error; |
| 4825 | } |
| 4826 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4827 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4828 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && (leaf->when || leaf->must)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4829 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4830 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4831 | goto error; |
| 4832 | } |
| 4833 | } else { |
| 4834 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4835 | goto error; |
| 4836 | } |
| 4837 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4840 | for (r = 0; r < retval->ext_size; ++r) { |
| 4841 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 4842 | if (retval->ext[r]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 4843 | retval->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4844 | break; |
| 4845 | } |
| 4846 | } |
| 4847 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4848 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4849 | |
| 4850 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4851 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4852 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4853 | } |
| 4854 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4855 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4856 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4857 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4858 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4859 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4860 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4861 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4862 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4863 | struct lyxml_elem *sub, *next; |
| 4864 | const char *value; |
| 4865 | char *endptr; |
| 4866 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4867 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4868 | int c_must = 0, c_ftrs = 0, c_dflt = 0, c_ext = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4869 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4870 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4871 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4872 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4873 | LY_CHECK_ERR_RETURN(!llist, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4874 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4875 | llist->nodetype = LYS_LEAFLIST; |
| 4876 | llist->prev = (struct lys_node *)llist; |
| 4877 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4878 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4879 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4880 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4881 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4882 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4883 | goto error; |
| 4884 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4885 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4886 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4887 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4888 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 4889 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4890 | goto error; |
| 4891 | } |
| 4892 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4893 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4894 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4895 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4896 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "leaf-list", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4897 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4898 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4899 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4900 | if (has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4901 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4902 | goto error; |
| 4903 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4904 | /* HACK for unres */ |
| 4905 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4906 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4907 | /* postpone type resolution when if-feature parsing is done since we need |
| 4908 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4909 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4910 | } else if (!strcmp(sub->name, "units")) { |
| 4911 | if (llist->units) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4912 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4913 | goto error; |
| 4914 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4915 | GETVAL(ctx, value, sub, "name"); |
| 4916 | llist->units = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4917 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4918 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4919 | goto error; |
| 4920 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4921 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4922 | if (f_ordr) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4923 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4924 | goto error; |
| 4925 | } |
| 4926 | /* just checking the flags in llist is not sufficient, we would |
| 4927 | * allow multiple ordered-by statements with the "system" value |
| 4928 | */ |
| 4929 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4930 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4931 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4932 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4933 | * state data |
| 4934 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4935 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4936 | continue; |
| 4937 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4938 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4939 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4940 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4941 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4942 | } else if (strcmp(value, "system")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4943 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4944 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4945 | } /* else system is the default value, so we can ignore it */ |
| 4946 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4947 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4948 | goto error; |
| 4949 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4950 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4951 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, llist->must_size, "musts", "leaf-list", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4952 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4953 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4954 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4955 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "leaf-list", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4956 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4957 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4958 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4959 | /* read the default's extension instances */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4960 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4961 | goto error; |
| 4962 | } |
| 4963 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4964 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_dflt, llist->dflt_size, "defaults", "leaf-list", error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4965 | c_dflt++; |
| 4966 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4967 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4968 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4969 | if (f_min) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4970 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4971 | goto error; |
| 4972 | } |
| 4973 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4974 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4975 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4976 | while (isspace(value[0])) { |
| 4977 | value++; |
| 4978 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4979 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4980 | /* convert it to uint32_t */ |
| 4981 | errno = 0; |
| 4982 | endptr = NULL; |
| 4983 | val = strtoul(value, &endptr, 10); |
| 4984 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4985 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4986 | goto error; |
| 4987 | } |
| 4988 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4989 | if (llist->max && (llist->min > llist->max)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4990 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
| 4991 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4992 | goto error; |
| 4993 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4994 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4995 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4996 | goto error; |
| 4997 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4998 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4999 | if (f_max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5000 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5001 | goto error; |
| 5002 | } |
| 5003 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5004 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5005 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5006 | while (isspace(value[0])) { |
| 5007 | value++; |
| 5008 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5009 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5010 | if (!strcmp(value, "unbounded")) { |
| 5011 | llist->max = 0; |
| 5012 | } else { |
| 5013 | /* convert it to uint32_t */ |
| 5014 | errno = 0; |
| 5015 | endptr = NULL; |
| 5016 | val = strtoul(value, &endptr, 10); |
| 5017 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5018 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5019 | goto error; |
| 5020 | } |
| 5021 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5022 | if (llist->min > llist->max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5023 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
| 5024 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5025 | goto error; |
| 5026 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5027 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5028 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5029 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5030 | goto error; |
| 5031 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5032 | } else if (!strcmp(sub->name, "when")) { |
| 5033 | if (llist->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5034 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5035 | goto error; |
| 5036 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5037 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5038 | llist->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5039 | if (!llist->when) { |
| 5040 | goto error; |
| 5041 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5042 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5043 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5044 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5045 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5046 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 5047 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5048 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5049 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5050 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 5051 | if (!has_type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5052 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5053 | goto error; |
| 5054 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5055 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5056 | /* middle part - process nodes with cardinality of 0..n */ |
| 5057 | if (c_must) { |
| 5058 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5059 | LY_CHECK_ERR_GOTO(!llist->must, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5060 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5061 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5062 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5063 | LY_CHECK_ERR_GOTO(!llist->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5064 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5065 | if (c_dflt) { |
| 5066 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5067 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM(ctx), error); |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5068 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5069 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5070 | /* some extensions may be already present from the substatements */ |
| 5071 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5072 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5073 | retval->ext = reallocated; |
| 5074 | |
| 5075 | /* init memory */ |
| 5076 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5077 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 5078 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5079 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5080 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5081 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5082 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5083 | retval->ext_size++; |
| 5084 | if (r) { |
| 5085 | goto error; |
| 5086 | } |
| 5087 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5088 | r = fill_yin_must(module, sub, &llist->must[llist->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5089 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5090 | if (r) { |
| 5091 | goto error; |
| 5092 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5093 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5094 | r = fill_yin_iffeature(retval, 0, sub, &llist->iffeature[llist->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5095 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5096 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5097 | goto error; |
| 5098 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5099 | } else if (!strcmp(sub->name, "default")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5100 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5101 | |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 5102 | /* check for duplicity in case of configuration data, |
| 5103 | * in case of status data duplicities are allowed */ |
| 5104 | if (llist->flags & LYS_CONFIG_W) { |
| 5105 | for (r = 0; r < llist->dflt_size; r++) { |
| 5106 | if (ly_strequal(llist->dflt[r], value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5107 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, "default"); |
| 5108 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 5109 | goto error; |
| 5110 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5111 | } |
| 5112 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5113 | llist->dflt[llist->dflt_size++] = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5114 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5115 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5116 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 5117 | /* finalize type parsing */ |
| 5118 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
| 5119 | llist->type.der = NULL; |
| 5120 | goto error; |
| 5121 | } |
| 5122 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5123 | if (llist->dflt_size && llist->min) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5124 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list"); |
| 5125 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5126 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 5127 | goto error; |
| 5128 | } |
| 5129 | |
| 5130 | /* check default value (if not defined, there still could be some restrictions |
| 5131 | * that need to be checked against a default value from a derived type) */ |
| 5132 | for (r = 0; r < llist->dflt_size; r++) { |
Michal Vasko | 6a05778 | 2018-03-09 13:24:33 +0100 | [diff] [blame] | 5133 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 5134 | (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 5135 | (struct lys_node *)(&llist->dflt[r])) == -1)) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5136 | goto error; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 5137 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5138 | } |
| 5139 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5140 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5141 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && (llist->when || llist->must)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5142 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5143 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5144 | goto error; |
| 5145 | } |
| 5146 | } else { |
| 5147 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5148 | goto error; |
| 5149 | } |
| 5150 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5151 | } |
| 5152 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5153 | for (r = 0; r < retval->ext_size; ++r) { |
| 5154 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 5155 | if (retval->ext[r]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 5156 | retval->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5157 | break; |
| 5158 | } |
| 5159 | } |
| 5160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5161 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5162 | |
| 5163 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5164 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5165 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5166 | } |
| 5167 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5168 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5169 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5170 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5171 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5172 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5173 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5174 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5175 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5176 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5177 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5178 | int c_tpdf = 0, c_must = 0, c_uniq = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5179 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5180 | const char *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5181 | char *auxs; |
| 5182 | unsigned long val; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5183 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5184 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5185 | /* init */ |
| 5186 | memset(&root, 0, sizeof root); |
| 5187 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5188 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5189 | list = calloc(1, sizeof *list); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5190 | LY_CHECK_ERR_RETURN(!list, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5191 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5192 | list->nodetype = LYS_LIST; |
| 5193 | list->prev = (struct lys_node *)list; |
| 5194 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5195 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5196 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5197 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 5198 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 5199 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5200 | goto error; |
| 5201 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5202 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5203 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5204 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5205 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 5206 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5207 | goto error; |
| 5208 | } |
| 5209 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5210 | /* process list's specific children */ |
| 5211 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5212 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5213 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5214 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "list", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5215 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5216 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5217 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5218 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5219 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5220 | !strcmp(sub->name, "leaf-list") || |
| 5221 | !strcmp(sub->name, "leaf") || |
| 5222 | !strcmp(sub->name, "list") || |
| 5223 | !strcmp(sub->name, "choice") || |
| 5224 | !strcmp(sub->name, "uses") || |
| 5225 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5226 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5227 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5228 | !strcmp(sub->name, "action") || |
| 5229 | !strcmp(sub->name, "notification")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5230 | lyxml_unlink_elem(ctx, sub, 2); |
| 5231 | lyxml_add_child(ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5232 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5233 | /* array counters */ |
| 5234 | } else if (!strcmp(sub->name, "key")) { |
| 5235 | /* check cardinality 0..1 */ |
| 5236 | if (list->keys_size) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5237 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5238 | goto error; |
| 5239 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5240 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5241 | /* count the number of keys */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5242 | GETVAL(ctx, value, sub, "value"); |
| 5243 | list->keys_str = lydict_insert(ctx, value, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5244 | while ((value = strpbrk(value, " \t\n"))) { |
| 5245 | list->keys_size++; |
| 5246 | while (isspace(*value)) { |
| 5247 | value++; |
| 5248 | } |
| 5249 | } |
| 5250 | list->keys_size++; |
| 5251 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5252 | LY_CHECK_ERR_GOTO(!list->keys, LOGMEM(ctx), error); |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5253 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5254 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_KEY, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5255 | goto error; |
| 5256 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5257 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5258 | } else if (!strcmp(sub->name, "unique")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5259 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_uniq, list->unique_size, "uniques", "list", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5260 | c_uniq++; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5261 | lyxml_unlink_elem(ctx, sub, 2); |
| 5262 | lyxml_add_child(ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5263 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5264 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, list->tpdf_size, "typedefs", "list", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5265 | c_tpdf++; |
| 5266 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5267 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, list->must_size, "musts", "list", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5268 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5269 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5270 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "list", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5271 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5273 | /* optional stetments */ |
| 5274 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 5275 | if (f_ordr) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5276 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5277 | goto error; |
| 5278 | } |
| 5279 | /* just checking the flags in llist is not sufficient, we would |
| 5280 | * allow multiple ordered-by statements with the "system" value |
| 5281 | */ |
| 5282 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5283 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5284 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5285 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 5286 | * state data |
| 5287 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5288 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5289 | continue; |
| 5290 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5291 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5292 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5293 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5294 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5295 | } else if (strcmp(value, "system")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5296 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5297 | goto error; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5298 | } /* else system is the default value, so we can ignore it */ |
| 5299 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5300 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5301 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5302 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5303 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5304 | } else if (!strcmp(sub->name, "min-elements")) { |
| 5305 | if (f_min) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5306 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5307 | goto error; |
| 5308 | } |
| 5309 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5310 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5311 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5312 | while (isspace(value[0])) { |
| 5313 | value++; |
| 5314 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5315 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5316 | /* convert it to uint32_t */ |
| 5317 | errno = 0; |
| 5318 | auxs = NULL; |
| 5319 | val = strtoul(value, &auxs, 10); |
| 5320 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5321 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5322 | goto error; |
| 5323 | } |
| 5324 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5325 | if (list->max && (list->min > list->max)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5326 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
| 5327 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 5328 | lyxml_free(ctx, sub); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5329 | goto error; |
| 5330 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5331 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5332 | goto error; |
| 5333 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5334 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5335 | } else if (!strcmp(sub->name, "max-elements")) { |
| 5336 | if (f_max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5337 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5338 | goto error; |
| 5339 | } |
| 5340 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5341 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5342 | GETVAL(ctx, value, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5343 | while (isspace(value[0])) { |
| 5344 | value++; |
| 5345 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5346 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5347 | if (!strcmp(value, "unbounded")) { |
| 5348 | list->max = 0;; |
| 5349 | } else { |
| 5350 | /* convert it to uint32_t */ |
| 5351 | errno = 0; |
| 5352 | auxs = NULL; |
| 5353 | val = strtoul(value, &auxs, 10); |
| 5354 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5355 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5356 | goto error; |
| 5357 | } |
| 5358 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5359 | if (list->min > list->max) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5360 | LOGVAL(ctx, LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
| 5361 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_PREV, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5362 | goto error; |
| 5363 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5364 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5365 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5366 | goto error; |
| 5367 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5368 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5369 | } else if (!strcmp(sub->name, "when")) { |
| 5370 | if (list->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5371 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5372 | goto error; |
| 5373 | } |
| 5374 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5375 | list->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5376 | if (!list->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5377 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5378 | goto error; |
| 5379 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5380 | lyxml_free(ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5381 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5382 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5383 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5384 | } |
| 5385 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5386 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5387 | /* check - if list is configuration, key statement is mandatory |
| 5388 | * (but only if we are not in a grouping or augment, then the check is deferred) */ |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5389 | for (node = retval; node && !(node->nodetype & (LYS_GROUPING | LYS_AUGMENT | LYS_EXT)); node = node->parent); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5390 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys_str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5391 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5392 | goto error; |
| 5393 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5395 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5396 | if (c_tpdf) { |
| 5397 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5398 | LY_CHECK_ERR_GOTO(!list->tpdf, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5399 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5400 | if (c_must) { |
| 5401 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5402 | LY_CHECK_ERR_GOTO(!list->must, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5403 | } |
| 5404 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5405 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5406 | LY_CHECK_ERR_GOTO(!list->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5407 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5408 | if (c_ext) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5409 | /* some extensions may be already present from the substatements */ |
| 5410 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5411 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5412 | retval->ext = reallocated; |
| 5413 | |
| 5414 | /* init memory */ |
| 5415 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5416 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5417 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5418 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5419 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5420 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5421 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5422 | retval->ext_size++; |
| 5423 | if (r) { |
| 5424 | goto error; |
| 5425 | } |
| 5426 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5427 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 5428 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5429 | if (r) { |
| 5430 | goto error; |
| 5431 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5432 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5433 | r = fill_yin_iffeature(retval, 0, sub, &list->iffeature[list->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5434 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5435 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5436 | goto error; |
| 5437 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5438 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5439 | r = fill_yin_must(module, sub, &list->must[list->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5440 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5441 | if (r) { |
| 5442 | goto error; |
| 5443 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5444 | } |
| 5445 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5446 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5447 | /* last part - process data nodes */ |
| 5448 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5449 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5450 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5451 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5452 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5453 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5454 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5455 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5456 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5457 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5458 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5459 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5460 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5461 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5462 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5463 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5464 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5465 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5466 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5467 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5468 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5469 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5470 | node = read_yin_notif(module, retval, sub, options, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5471 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5472 | LOGINT(ctx); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5473 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5474 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5475 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5476 | goto error; |
| 5477 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5478 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5479 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5480 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5481 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5482 | if (list->keys_str) { |
Radek Krejci | 7a1e607 | 2018-08-13 14:59:16 +0200 | [diff] [blame] | 5483 | if (unres_schema_add_node(module, unres, list, UNRES_LIST_KEYS, NULL) == -1) { |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5484 | goto error; |
| 5485 | } |
| 5486 | } /* else config false list without a key, key_str presence in case of config true is checked earlier */ |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 5487 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5488 | /* process unique statements */ |
| 5489 | if (c_uniq) { |
| 5490 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5491 | LY_CHECK_ERR_GOTO(!list->unique, LOGMEM(ctx), error); |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5492 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5493 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 5494 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 5495 | list->unique_size++; |
| 5496 | if (r) { |
| 5497 | goto error; |
| 5498 | } |
| 5499 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5500 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5501 | LYEXT_SUBSTMT_UNIQUE, list->unique_size - 1, unres)) { |
| 5502 | goto error; |
| 5503 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5504 | lyxml_free(ctx, sub); |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5505 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5506 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5507 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5508 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5509 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && (list->when || list->must)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5510 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5511 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5512 | goto error; |
| 5513 | } |
| 5514 | } else { |
| 5515 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5516 | goto error; |
| 5517 | } |
| 5518 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5519 | } |
| 5520 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5521 | for (r = 0; r < retval->ext_size; ++r) { |
| 5522 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 5523 | if (retval->ext[r]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 5524 | retval->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5525 | break; |
| 5526 | } |
| 5527 | } |
| 5528 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5529 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5530 | |
| 5531 | error: |
| 5532 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5533 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5534 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5535 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5536 | } |
| 5537 | while (uniq.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5538 | lyxml_free(ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5539 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5540 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5541 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5542 | } |
| 5543 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5544 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5545 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5546 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5547 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5548 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5549 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5550 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5551 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5552 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5553 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5554 | const char *value; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5555 | void *reallocated; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5556 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5557 | int c_tpdf = 0, c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5558 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5559 | /* init */ |
| 5560 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5561 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5562 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5563 | LY_CHECK_ERR_RETURN(!cont, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5564 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5565 | cont->nodetype = LYS_CONTAINER; |
| 5566 | cont->prev = (struct lys_node *)cont; |
| 5567 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5568 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5569 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5570 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 5571 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 5572 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5573 | goto error; |
| 5574 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5575 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5576 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5577 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5578 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 5579 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5580 | goto error; |
| 5581 | } |
| 5582 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5583 | /* process container's specific children */ |
| 5584 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5585 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5586 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5587 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "container", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5588 | c_ext++; |
| 5589 | } else if (!strcmp(sub->name, "presence")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5590 | if (cont->presence) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5591 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5592 | goto error; |
| 5593 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5594 | GETVAL(ctx, value, sub, "value"); |
| 5595 | cont->presence = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5596 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5597 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_PRESENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5598 | goto error; |
| 5599 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5600 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5601 | } else if (!strcmp(sub->name, "when")) { |
| 5602 | if (cont->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5603 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5604 | goto error; |
| 5605 | } |
| 5606 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5607 | cont->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5608 | if (!cont->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5609 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5610 | goto error; |
| 5611 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5612 | lyxml_free(ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 5613 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5614 | /* data statements */ |
| 5615 | } else if (!strcmp(sub->name, "container") || |
| 5616 | !strcmp(sub->name, "leaf-list") || |
| 5617 | !strcmp(sub->name, "leaf") || |
| 5618 | !strcmp(sub->name, "list") || |
| 5619 | !strcmp(sub->name, "choice") || |
| 5620 | !strcmp(sub->name, "uses") || |
| 5621 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5622 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5623 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5624 | !strcmp(sub->name, "action") || |
| 5625 | !strcmp(sub->name, "notification")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5626 | lyxml_unlink_elem(ctx, sub, 2); |
| 5627 | lyxml_add_child(ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5628 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5629 | /* array counters */ |
| 5630 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5631 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, cont->tpdf_size, "typedefs", "container", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5632 | c_tpdf++; |
| 5633 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5634 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, cont->must_size, "musts", "container", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5635 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5636 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5637 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "container", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5638 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5639 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5640 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5641 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5642 | } |
| 5643 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5644 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5645 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5646 | if (c_tpdf) { |
| 5647 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5648 | LY_CHECK_ERR_GOTO(!cont->tpdf, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5649 | } |
| 5650 | if (c_must) { |
| 5651 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5652 | LY_CHECK_ERR_GOTO(!cont->must, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5653 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5654 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5655 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5656 | LY_CHECK_ERR_GOTO(!cont->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5657 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5658 | if (c_ext) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5659 | /* some extensions may be already present from the substatements */ |
| 5660 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5661 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5662 | retval->ext = reallocated; |
| 5663 | |
| 5664 | /* init memory */ |
| 5665 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5666 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5667 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5668 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5669 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5670 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5671 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5672 | retval->ext_size++; |
| 5673 | if (r) { |
| 5674 | goto error; |
| 5675 | } |
| 5676 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5677 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 5678 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5679 | if (r) { |
| 5680 | goto error; |
| 5681 | } |
| 5682 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5683 | r = fill_yin_must(module, sub, &cont->must[cont->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5684 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5685 | if (r) { |
| 5686 | goto error; |
| 5687 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5688 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5689 | r = fill_yin_iffeature(retval, 0, sub, &cont->iffeature[cont->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5690 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5691 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5692 | goto error; |
| 5693 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5694 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5695 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5696 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5697 | /* last part - process data nodes */ |
| 5698 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5699 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5700 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5701 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5702 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5703 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5704 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5705 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5706 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5707 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5708 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5709 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5710 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5711 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5712 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5713 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5714 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5715 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5716 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5717 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5718 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5719 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5720 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5721 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5722 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5723 | goto error; |
| 5724 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5725 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5726 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5727 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5728 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5729 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5730 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && (cont->when || cont->must)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5731 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5732 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5733 | goto error; |
| 5734 | } |
| 5735 | } else { |
| 5736 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5737 | goto error; |
| 5738 | } |
| 5739 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5740 | } |
| 5741 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5742 | for (r = 0; r < retval->ext_size; ++r) { |
| 5743 | /* set flag, which represent LYEXT_OPT_VALID */ |
| 5744 | if (retval->ext[r]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 5745 | retval->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 5746 | break; |
| 5747 | } |
| 5748 | } |
| 5749 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5750 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5751 | |
| 5752 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5753 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5754 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5755 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5756 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5757 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5758 | } |
| 5759 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5760 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5761 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5762 | read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5763 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5764 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5765 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5766 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5767 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5768 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5769 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5770 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5771 | int c_tpdf = 0, c_ext = 0; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5772 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5773 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5774 | /* init */ |
| 5775 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5776 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5777 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5778 | LY_CHECK_ERR_RETURN(!grp, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5779 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5780 | grp->nodetype = LYS_GROUPING; |
| 5781 | grp->prev = (struct lys_node *)grp; |
| 5782 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5783 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5784 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, OPT_IDENT | OPT_MODULE , unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5785 | goto error; |
| 5786 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5787 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5788 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5789 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5790 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 5791 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5792 | goto error; |
| 5793 | } |
| 5794 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5795 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5796 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5797 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5798 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "grouping", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5799 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5800 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5801 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5802 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5803 | !strcmp(sub->name, "leaf-list") || |
| 5804 | !strcmp(sub->name, "leaf") || |
| 5805 | !strcmp(sub->name, "list") || |
| 5806 | !strcmp(sub->name, "choice") || |
| 5807 | !strcmp(sub->name, "uses") || |
| 5808 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5809 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5810 | !strcmp(sub->name, "anydata") || |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5811 | !strcmp(sub->name, "action") || |
| 5812 | !strcmp(sub->name, "notification")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5813 | lyxml_unlink_elem(ctx, sub, 2); |
| 5814 | lyxml_add_child(ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5815 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5816 | /* array counters */ |
| 5817 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5818 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, grp->tpdf_size, "typedefs", "grouping", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5819 | c_tpdf++; |
| 5820 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5821 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5822 | goto error; |
| 5823 | } |
| 5824 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5825 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5826 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5827 | if (c_tpdf) { |
| 5828 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5829 | LY_CHECK_ERR_GOTO(!grp->tpdf, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5830 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5831 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5832 | /* some extensions may be already present from the substatements */ |
| 5833 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5834 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5835 | retval->ext = reallocated; |
| 5836 | |
| 5837 | /* init memory */ |
| 5838 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5839 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5840 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5841 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5842 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5843 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5844 | retval->ext_size++; |
| 5845 | if (r) { |
| 5846 | goto error; |
| 5847 | } |
| 5848 | } else { |
| 5849 | /* typedef */ |
| 5850 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 5851 | grp->tpdf_size++; |
| 5852 | if (r) { |
| 5853 | goto error; |
| 5854 | } |
| 5855 | } |
| 5856 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5857 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5858 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5859 | if (!root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5860 | LOGWRN(ctx, "Grouping \"%s\" without children.", retval->name); |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5861 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5862 | options |= LYS_PARSE_OPT_INGRP; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5863 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5864 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5865 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5866 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5867 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5868 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5869 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5870 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5871 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5872 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5873 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5874 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5875 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5876 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5877 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5878 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5879 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5880 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5881 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5882 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5883 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5884 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5885 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5886 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5887 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5888 | goto error; |
| 5889 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5890 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5891 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5892 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5893 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5894 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5895 | |
| 5896 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5897 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5898 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5899 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5900 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5901 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5902 | } |
| 5903 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5904 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5905 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5906 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5907 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5908 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5909 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5910 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5911 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 5912 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5913 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5914 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5915 | int c_tpdf = 0, c_must = 0, c_ext = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5916 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5917 | /* init */ |
| 5918 | memset(&root, 0, sizeof root); |
| 5919 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5920 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5921 | LY_CHECK_ERR_RETURN(!inout, LOGMEM(ctx), NULL); |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5922 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5923 | |
| 5924 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5925 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5926 | inout->name = lydict_insert(ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5927 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5928 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5929 | inout->name = lydict_insert(ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5930 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5931 | LOGINT(ctx); |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5932 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5933 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5934 | } |
| 5935 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5936 | retval = (struct lys_node *)inout; |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5937 | retval->module = module; |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 5938 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5939 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5940 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5941 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 5942 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5943 | goto error; |
| 5944 | } |
| 5945 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5946 | /* data statements */ |
| 5947 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5948 | if (!sub->ns) { |
| 5949 | /* garbage */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5950 | lyxml_free(ctx, sub); |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5951 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5952 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5953 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 5954 | inout->nodetype == LYS_INPUT ? "input" : "output", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5955 | c_ext++; |
| 5956 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5957 | !strcmp(sub->name, "leaf-list") || |
| 5958 | !strcmp(sub->name, "leaf") || |
| 5959 | !strcmp(sub->name, "list") || |
| 5960 | !strcmp(sub->name, "choice") || |
| 5961 | !strcmp(sub->name, "uses") || |
| 5962 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5963 | !strcmp(sub->name, "anyxml") || |
| 5964 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5965 | lyxml_unlink_elem(ctx, sub, 2); |
| 5966 | lyxml_add_child(ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5967 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5968 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5969 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5970 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, inout->tpdf_size, "typedefs", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 5971 | inout->nodetype == LYS_INPUT ? "input" : "output", error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5972 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 5973 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5974 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5975 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, inout->must_size, "musts", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 5976 | inout->nodetype == LYS_INPUT ? "input" : "output", error); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5977 | c_must++; |
| 5978 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5979 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5980 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5981 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5982 | } |
| 5983 | } |
| 5984 | |
| 5985 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5986 | if (c_tpdf) { |
| 5987 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5988 | LY_CHECK_ERR_GOTO(!inout->tpdf, LOGMEM(ctx), error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5989 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5990 | if (c_must) { |
| 5991 | inout->must = calloc(c_must, sizeof *inout->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5992 | LY_CHECK_ERR_GOTO(!inout->must, LOGMEM(ctx), error); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5993 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5994 | if (c_ext) { |
| 5995 | inout->ext = calloc(c_ext, sizeof *inout->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5996 | LY_CHECK_ERR_GOTO(!inout->ext, LOGMEM(ctx), error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5997 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5998 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5999 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6000 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6001 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6002 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6003 | retval->ext_size++; |
| 6004 | if (r) { |
| 6005 | goto error; |
| 6006 | } |
| 6007 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 6008 | r = fill_yin_must(module, sub, &inout->must[inout->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6009 | inout->must_size++; |
| 6010 | if (r) { |
| 6011 | goto error; |
| 6012 | } |
| 6013 | } else { /* typedef */ |
| 6014 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 6015 | inout->tpdf_size++; |
| 6016 | if (r) { |
| 6017 | goto error; |
| 6018 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6019 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6023 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6024 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6025 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6026 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6027 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6028 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6029 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6030 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6031 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6032 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6033 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6034 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6035 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6036 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6037 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6038 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6039 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6040 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6041 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6042 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6043 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6044 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6045 | goto error; |
| 6046 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6047 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6048 | lyxml_free(ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6049 | } |
| 6050 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6051 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6052 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && inout->must) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6053 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 6054 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6055 | goto error; |
| 6056 | } |
| 6057 | } else { |
| 6058 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6059 | goto error; |
| 6060 | } |
| 6061 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6062 | } |
| 6063 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6064 | return retval; |
| 6065 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6066 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6067 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6068 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6069 | lyxml_free(ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6070 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6071 | return NULL; |
| 6072 | } |
| 6073 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6074 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6075 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6076 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6077 | int options, struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6078 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6079 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 6080 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6081 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6082 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6083 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6084 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6085 | int c_tpdf = 0, c_ftrs = 0, c_must = 0, c_ext = 0; |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 6086 | void *reallocated; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6087 | |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 6088 | if (parent && (module->version < 2)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6089 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, parent, "notification"); |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 6090 | return NULL; |
| 6091 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6092 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 6093 | memset(&root, 0, sizeof root); |
| 6094 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6095 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6096 | LY_CHECK_ERR_RETURN(!notif, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6097 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6098 | notif->nodetype = LYS_NOTIF; |
| 6099 | notif->prev = (struct lys_node *)notif; |
| 6100 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6101 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6102 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, OPT_IDENT | OPT_MODULE, unres)) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6103 | goto error; |
| 6104 | } |
| 6105 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6106 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6107 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6108 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 6109 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6110 | goto error; |
| 6111 | } |
| 6112 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6113 | /* process rpc's specific children */ |
| 6114 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6115 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6116 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6117 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "notification", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6118 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6119 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6120 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6121 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6122 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6123 | !strcmp(sub->name, "leaf-list") || |
| 6124 | !strcmp(sub->name, "leaf") || |
| 6125 | !strcmp(sub->name, "list") || |
| 6126 | !strcmp(sub->name, "choice") || |
| 6127 | !strcmp(sub->name, "uses") || |
| 6128 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 6129 | !strcmp(sub->name, "anyxml") || |
| 6130 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6131 | lyxml_unlink_elem(ctx, sub, 2); |
| 6132 | lyxml_add_child(ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6133 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6134 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6135 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6136 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, notif->tpdf_size, "typedefs", "notification", error); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6137 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6138 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6139 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "notification", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6140 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6141 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6142 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_must, notif->must_size, "musts", "notification", error); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6143 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6144 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6145 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6146 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6151 | if (c_tpdf) { |
| 6152 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6153 | LY_CHECK_ERR_GOTO(!notif->tpdf, LOGMEM(ctx), error); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6154 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6155 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6156 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6157 | LY_CHECK_ERR_GOTO(!notif->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6158 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6159 | if (c_must) { |
| 6160 | notif->must = calloc(c_must, sizeof *notif->must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6161 | LY_CHECK_ERR_GOTO(!notif->must, LOGMEM(ctx), error); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6162 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6163 | if (c_ext) { |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 6164 | /* some extensions may be already present from the substatements */ |
| 6165 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6166 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 6167 | retval->ext = reallocated; |
| 6168 | |
| 6169 | /* init memory */ |
| 6170 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6171 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6172 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6173 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6174 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6175 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6176 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6177 | retval->ext_size++; |
| 6178 | if (r) { |
| 6179 | goto error; |
| 6180 | } |
| 6181 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6182 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 6183 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6184 | if (r) { |
| 6185 | goto error; |
| 6186 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 6187 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6188 | r = fill_yin_iffeature(retval, 0, sub, ¬if->iffeature[notif->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6189 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6190 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6191 | goto error; |
| 6192 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6193 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 6194 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6195 | notif->must_size++; |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 6196 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6197 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6198 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6199 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6203 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6204 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6205 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6206 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6207 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6208 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6209 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6210 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6211 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6212 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6213 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6214 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6215 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6216 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6217 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6218 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6219 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6220 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6221 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6222 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6223 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6224 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6225 | goto error; |
| 6226 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6227 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6228 | lyxml_free(ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6229 | } |
| 6230 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6231 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6232 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && notif->must) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6233 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 6234 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6235 | goto error; |
| 6236 | } |
| 6237 | } else { |
| 6238 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6239 | goto error; |
| 6240 | } |
| 6241 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6242 | } |
| 6243 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6244 | return retval; |
| 6245 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6246 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6247 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6248 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6249 | lyxml_free(ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6250 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6251 | return NULL; |
| 6252 | } |
| 6253 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6254 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6255 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6256 | read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6257 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6258 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6259 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6260 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6261 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6262 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 6263 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6264 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6265 | int c_tpdf = 0, c_ftrs = 0, c_input = 0, c_output = 0, c_ext = 0; |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6266 | void *reallocated; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6267 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6268 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6269 | if (module->version < 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6270 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, parent, "action"); |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 6271 | return NULL; |
| 6272 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6273 | for (node = parent; node; node = lys_parent(node)) { |
Radek Krejci | a3b19f7 | 2016-09-30 13:02:45 +0200 | [diff] [blame] | 6274 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6275 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6276 | LOGVAL(ctx, LYE_INPAR, LY_VLOG_LYS, parent, strnodetype(node->nodetype), "action"); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6277 | return NULL; |
| 6278 | } |
| 6279 | } |
| 6280 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6281 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6282 | /* init */ |
| 6283 | memset(&root, 0, sizeof root); |
| 6284 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6285 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6286 | LY_CHECK_ERR_RETURN(!rpc, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6287 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6288 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6289 | rpc->prev = (struct lys_node *)rpc; |
| 6290 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6291 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6292 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, OPT_IDENT | OPT_MODULE, unres)) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6293 | goto error; |
| 6294 | } |
| 6295 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6296 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6297 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6298 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 6299 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6300 | goto error; |
| 6301 | } |
| 6302 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6303 | /* process rpc's specific children */ |
| 6304 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6305 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6306 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6307 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6308 | rpc->nodetype == LYS_RPC ? "rpc" : "action", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6309 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6310 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6311 | } else if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6312 | if (c_input) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6313 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6314 | goto error; |
| 6315 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6316 | c_input++; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6317 | lyxml_unlink_elem(ctx, sub, 2); |
| 6318 | lyxml_add_child(ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6319 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6320 | if (c_output) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6321 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6322 | goto error; |
| 6323 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6324 | c_output++; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6325 | lyxml_unlink_elem(ctx, sub, 2); |
| 6326 | lyxml_add_child(ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6328 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6329 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6330 | lyxml_unlink_elem(ctx, sub, 2); |
| 6331 | lyxml_add_child(ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6332 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6333 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6334 | } else if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6335 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, rpc->tpdf_size, "typedefs", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6336 | rpc->nodetype == LYS_RPC ? "rpc" : "action", error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6337 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6338 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6339 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6340 | rpc->nodetype == LYS_RPC ? "rpc" : "action", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6341 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6342 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6343 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6344 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6349 | if (c_tpdf) { |
| 6350 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6351 | LY_CHECK_ERR_GOTO(!rpc->tpdf, LOGMEM(ctx), error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6352 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6353 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6354 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6355 | LY_CHECK_ERR_GOTO(!rpc->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6356 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6357 | if (c_ext) { |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6358 | /* some extensions may be already present from the substatements */ |
| 6359 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6360 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6361 | retval->ext = reallocated; |
| 6362 | |
| 6363 | /* init memory */ |
| 6364 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6365 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6366 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6367 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6368 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6369 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6370 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6371 | retval->ext_size++; |
| 6372 | if (r) { |
| 6373 | goto error; |
| 6374 | } |
| 6375 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6376 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 6377 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6378 | if (r) { |
| 6379 | goto error; |
| 6380 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6381 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6382 | r = fill_yin_iffeature(retval, 0, sub, &rpc->iffeature[rpc->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6383 | rpc->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6384 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6385 | goto error; |
| 6386 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6387 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | /* last part - process data nodes */ |
| 6391 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6392 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6393 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6394 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6395 | node = read_yin_input_output(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6396 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6397 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6398 | goto error; |
| 6399 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6400 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6401 | lyxml_free(ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6402 | } |
| 6403 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6404 | return retval; |
| 6405 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6406 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6407 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6408 | while (root.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6409 | lyxml_free(ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6410 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6411 | return NULL; |
| 6412 | } |
| 6413 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6414 | /* logs directly |
| 6415 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6416 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 6417 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 6418 | * we just get information but we do not apply augment or refine to it. |
| 6419 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6420 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6421 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 6422 | int options, struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6423 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6424 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6425 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6426 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6427 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6428 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6429 | int c_ref = 0, c_aug = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6430 | int r; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6431 | void *reallocated; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6432 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6433 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6434 | LY_CHECK_ERR_RETURN(!uses, LOGMEM(ctx), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6435 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6436 | uses->nodetype = LYS_USES; |
| 6437 | uses->prev = (struct lys_node *)uses; |
| 6438 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6439 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6440 | GETVAL(ctx, value, yin, "name"); |
| 6441 | uses->name = lydict_insert(ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 6442 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6443 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, OPT_MODULE, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6444 | goto error; |
| 6445 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6446 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6447 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6448 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6449 | /* insert the node into the schema tree */ |
Michal Vasko | 8d30dd8 | 2018-09-10 10:06:12 +0200 | [diff] [blame] | 6450 | if (lys_node_addchild(parent, lys_main_module(module), retval, options)) { |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6451 | goto error; |
| 6452 | } |
| 6453 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6454 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6455 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6456 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6457 | /* extension */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6458 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, retval->ext_size, "extensions", "uses", error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6459 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6460 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6461 | } else if (!strcmp(sub->name, "refine")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6462 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ref, uses->refine_size, "refines", "uses", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6463 | c_ref++; |
| 6464 | } else if (!strcmp(sub->name, "augment")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6465 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_aug, uses->augment_size, "augments", "uses", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6466 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6467 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6468 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, retval->iffeature_size, "if-features", "uses", error); |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 6469 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6470 | } else if (!strcmp(sub->name, "when")) { |
| 6471 | if (uses->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6472 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6473 | goto error; |
| 6474 | } |
| 6475 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 6476 | uses->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6477 | if (!uses->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6478 | lyxml_free(ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6479 | goto error; |
| 6480 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6481 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6482 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6483 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6484 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6485 | } |
| 6486 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6487 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6488 | /* process properties with cardinality 0..n */ |
| 6489 | if (c_ref) { |
| 6490 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6491 | LY_CHECK_ERR_GOTO(!uses->refine, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6492 | } |
| 6493 | if (c_aug) { |
| 6494 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6495 | LY_CHECK_ERR_GOTO(!uses->augment, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6496 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6497 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6498 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6499 | LY_CHECK_ERR_GOTO(!uses->iffeature, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6500 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6501 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6502 | /* some extensions may be already present from the substatements */ |
| 6503 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6504 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6505 | retval->ext = reallocated; |
| 6506 | |
| 6507 | /* init memory */ |
| 6508 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6509 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6510 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6511 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6512 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6513 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6514 | r = lyp_yin_fill_ext(retval, LYEXT_PAR_NODE, 0, 0, module, sub, &retval->ext, retval->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6515 | retval->ext_size++; |
| 6516 | if (r) { |
| 6517 | goto error; |
| 6518 | } |
| 6519 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 6520 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6521 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6522 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6523 | goto error; |
| 6524 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6525 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6526 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], options, unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6527 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6528 | if (r) { |
| 6529 | goto error; |
| 6530 | } |
| 6531 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6532 | r = fill_yin_iffeature(retval, 0, sub, &uses->iffeature[uses->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6533 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6534 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6535 | goto error; |
| 6536 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6537 | } |
| 6538 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6539 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6540 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6541 | goto error; |
| 6542 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6543 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6544 | /* check XPath dependencies */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6545 | if (!(ctx->models.flags & LY_CTX_TRUSTED) && uses->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6546 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 6547 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6548 | goto error; |
| 6549 | } |
| 6550 | } else { |
| 6551 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6552 | goto error; |
| 6553 | } |
| 6554 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6555 | } |
| 6556 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6557 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6558 | |
| 6559 | error: |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6560 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6561 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6562 | } |
| 6563 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6564 | /* logs directly |
| 6565 | * |
| 6566 | * common code for yin_read_module() and yin_read_submodule() |
| 6567 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6568 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6569 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 6570 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6571 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6572 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6573 | struct lyxml_elem *next, *child, root, grps, augs, revs, exts; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6574 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6575 | struct lys_module *trg; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6576 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6577 | int i, r, ret = -1; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6578 | int version_flag = 0; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6579 | /* (sub)module substatements are ordered in groups, increment this value when moving to another group |
| 6580 | * 0 - header-stmts, 1 - linkage-stmts, 2 - meta-stmts, 3 - revision-stmts, 4 - body-stmts */ |
| 6581 | int substmt_group; |
| 6582 | /* just remember last substatement for logging */ |
| 6583 | const char *substmt_prev; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6584 | /* counters */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6585 | int c_imp = 0, c_rev = 0, c_tpdf = 0, c_ident = 0, c_inc = 0, c_aug = 0, c_ftrs = 0, c_dev = 0; |
| 6586 | int c_ext = 0, c_extinst = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6587 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6588 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6589 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 6590 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6591 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6592 | /* init */ |
| 6593 | memset(&root, 0, sizeof root); |
| 6594 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6595 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6596 | memset(&exts, 0, sizeof exts); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6597 | memset(&revs, 0, sizeof revs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6598 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6599 | /* |
| 6600 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 6601 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 6602 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 6603 | * need have all top-level and groupings already prepared at that time. In |
| 6604 | * the middle loop, we process other elements with carinality of 0..n since |
| 6605 | * we need to allocate arrays to store them. |
| 6606 | */ |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6607 | substmt_group = 0; |
| 6608 | substmt_prev = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6609 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6610 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6611 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6612 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6613 | continue; |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6614 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6615 | /* possible extension instance */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6616 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_extinst, trg->ext_size, "extension instances", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6617 | submodule ? "submodule" : "module", error); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6618 | lyxml_unlink_elem(ctx, child, 2); |
| 6619 | lyxml_add_child(ctx, &exts, child); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6620 | c_extinst++; |
| 6621 | } else if (!submodule && !strcmp(child->name, "namespace")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6622 | if (substmt_group > 0) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6623 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6624 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6625 | child->name, substmt_prev); |
| 6626 | goto error; |
| 6627 | } |
| 6628 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6629 | if (trg->ns) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6630 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6631 | goto error; |
| 6632 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6633 | GETVAL(ctx, value, child, "uri"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6634 | trg->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6635 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6636 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_NAMESPACE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6637 | goto error; |
| 6638 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6639 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6640 | |
| 6641 | substmt_prev = "namespace"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6642 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6643 | if (substmt_group > 0) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6644 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6645 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6646 | child->name, substmt_prev); |
| 6647 | goto error; |
| 6648 | } |
| 6649 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6650 | if (trg->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6651 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6652 | goto error; |
| 6653 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6654 | GETVAL(ctx, value, child, "value"); |
| 6655 | if (lyp_check_identifier(ctx, value, LY_IDENT_PREFIX, trg, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6656 | goto error; |
| 6657 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6658 | trg->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6659 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6660 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6661 | goto error; |
| 6662 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6663 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6664 | |
| 6665 | substmt_prev = "prefix"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6666 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6667 | if (substmt_group > 0) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6668 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6669 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6670 | child->name, substmt_prev); |
| 6671 | goto error; |
| 6672 | } |
| 6673 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6674 | if (trg->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6675 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6676 | goto error; |
| 6677 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6678 | GETVAL(ctx, value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 6679 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6680 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6681 | goto error; |
| 6682 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 6683 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6684 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_BELONGSTO, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6685 | goto error; |
| 6686 | } |
| 6687 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6688 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6689 | if (!child->child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6690 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6691 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6692 | } else if (strcmp(child->child->name, "prefix")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6693 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6694 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6695 | } else if (child->child->next) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6696 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6697 | goto error; |
| 6698 | } |
| 6699 | /* and now finally get the value */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6700 | GETVAL(ctx, value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6701 | /* check here differs from a generic prefix check, since this prefix |
| 6702 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6703 | */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6704 | if (lyp_check_identifier(ctx, value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6705 | goto error; |
| 6706 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6707 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 6708 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6709 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child->child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6710 | goto error; |
| 6711 | } |
| 6712 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6713 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6714 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6715 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6716 | substmt_prev = "belongs-to"; |
| 6717 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6718 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6719 | } else if (!strcmp(child->name, "import")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6720 | if (substmt_group > 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6721 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6722 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6723 | child->name, substmt_prev); |
| 6724 | goto error; |
| 6725 | } |
| 6726 | substmt_group = 1; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6727 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_imp, trg->imp_size, "imports", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6728 | submodule ? "submodule" : "module", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6729 | c_imp++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6730 | |
| 6731 | substmt_prev = "import"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6732 | } else if (!strcmp(child->name, "revision")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6733 | if (substmt_group > 3) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6734 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6735 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6736 | child->name, substmt_prev); |
| 6737 | goto error; |
| 6738 | } |
| 6739 | substmt_group = 3; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6740 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_rev, trg->rev_size, "revisions", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6741 | submodule ? "submodule" : "module", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6742 | c_rev++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6743 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6744 | lyxml_unlink_elem(ctx, child, 2); |
| 6745 | lyxml_add_child(ctx, &revs, child); |
| 6746 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6747 | substmt_prev = "revision"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6748 | } else if (!strcmp(child->name, "typedef")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6749 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6750 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_tpdf, trg->tpdf_size, "typedefs", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6751 | submodule ? "submodule" : "module", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6752 | c_tpdf++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6753 | |
| 6754 | substmt_prev = "typedef"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6755 | } else if (!strcmp(child->name, "identity")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6756 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6757 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ident, trg->ident_size, "identities", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6758 | submodule ? "submodule" : "module", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6759 | c_ident++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6760 | |
| 6761 | substmt_prev = "identity"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6762 | } else if (!strcmp(child->name, "include")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6763 | if (substmt_group > 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6764 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6765 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6766 | child->name, substmt_prev); |
| 6767 | goto error; |
| 6768 | } |
| 6769 | substmt_group = 1; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6770 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_inc, trg->inc_size, "includes", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6771 | submodule ? "submodule" : "module", error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6772 | c_inc++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6773 | |
| 6774 | substmt_prev = "include"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6775 | } else if (!strcmp(child->name, "augment")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6776 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6777 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_aug, trg->augment_size, "augments", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6778 | submodule ? "submodule" : "module", error); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6779 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6780 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6781 | lyxml_unlink_elem(ctx, child, 2); |
| 6782 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6783 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6784 | substmt_prev = "augment"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6785 | } else if (!strcmp(child->name, "feature")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6786 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6787 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ftrs, trg->features_size, "features", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6788 | submodule ? "submodule" : "module", error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6789 | c_ftrs++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6790 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6791 | substmt_prev = "feature"; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6792 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6793 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6794 | } else if (!strcmp(child->name, "container") || |
| 6795 | !strcmp(child->name, "leaf-list") || |
| 6796 | !strcmp(child->name, "leaf") || |
| 6797 | !strcmp(child->name, "list") || |
| 6798 | !strcmp(child->name, "choice") || |
| 6799 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6800 | !strcmp(child->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 6801 | !strcmp(child->name, "anydata") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6802 | !strcmp(child->name, "rpc") || |
| 6803 | !strcmp(child->name, "notification")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6804 | substmt_group = 4; |
| 6805 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6806 | lyxml_unlink_elem(ctx, child, 2); |
| 6807 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6808 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6809 | substmt_prev = "data definition"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6810 | } else if (!strcmp(child->name, "grouping")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6811 | substmt_group = 4; |
| 6812 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6813 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6814 | lyxml_unlink_elem(ctx, child, 2); |
| 6815 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6816 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6817 | substmt_prev = "grouping"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6818 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6819 | } else if (!strcmp(child->name, "description")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6820 | if (substmt_group > 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6821 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6822 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6823 | child->name, substmt_prev); |
| 6824 | goto error; |
| 6825 | } |
| 6826 | substmt_group = 2; |
| 6827 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6828 | if (trg->dsc) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6829 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6830 | goto error; |
| 6831 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6832 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6833 | goto error; |
| 6834 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6835 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6836 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6837 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6838 | goto error; |
| 6839 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6840 | |
| 6841 | substmt_prev = "description"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6842 | } else if (!strcmp(child->name, "reference")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6843 | if (substmt_group > 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6844 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6845 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6846 | child->name, substmt_prev); |
| 6847 | goto error; |
| 6848 | } |
| 6849 | substmt_group = 2; |
| 6850 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6851 | if (trg->ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6852 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6853 | goto error; |
| 6854 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6855 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6856 | goto error; |
| 6857 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6858 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6859 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6860 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6861 | goto error; |
| 6862 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6863 | |
| 6864 | substmt_prev = "reference"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6865 | } else if (!strcmp(child->name, "organization")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6866 | if (substmt_group > 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6867 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6868 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6869 | child->name, substmt_prev); |
| 6870 | goto error; |
| 6871 | } |
| 6872 | substmt_group = 2; |
| 6873 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6874 | if (trg->org) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6875 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6876 | goto error; |
| 6877 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6878 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_ORGANIZATION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6879 | goto error; |
| 6880 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6881 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6882 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6883 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6884 | goto error; |
| 6885 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6886 | |
| 6887 | substmt_prev = "organization"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6888 | } else if (!strcmp(child->name, "contact")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6889 | if (substmt_group > 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6890 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6891 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6892 | child->name, substmt_prev); |
| 6893 | goto error; |
| 6894 | } |
| 6895 | substmt_group = 2; |
| 6896 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6897 | if (trg->contact) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6898 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6899 | goto error; |
| 6900 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6901 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_CONTACT, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6902 | goto error; |
| 6903 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6904 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6905 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6906 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6907 | goto error; |
| 6908 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6909 | |
| 6910 | substmt_prev = "contact"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6911 | } else if (!strcmp(child->name, "yang-version")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6912 | if (substmt_group > 0) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6913 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6914 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6915 | child->name, substmt_prev); |
| 6916 | goto error; |
| 6917 | } |
| 6918 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6919 | if (version_flag) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6920 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6921 | goto error; |
| 6922 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6923 | GETVAL(ctx, value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6924 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6925 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6926 | goto error; |
| 6927 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6928 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6929 | if (!strcmp(value, "1")) { |
| 6930 | if (submodule) { |
| 6931 | if (module->version > 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6932 | LOGVAL(ctx, LYE_INVER, LY_VLOG_NONE, NULL); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6933 | goto error; |
| 6934 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 6935 | submodule->version = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6936 | } else { |
| 6937 | module->version = 1; |
| 6938 | } |
| 6939 | } else { |
| 6940 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6941 | if (module->version < 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6942 | LOGVAL(ctx, LYE_INVER, LY_VLOG_NONE, NULL); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6943 | goto error; |
| 6944 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 6945 | submodule->version = 2; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6946 | } else { |
| 6947 | module->version = 2; |
| 6948 | } |
| 6949 | } |
| 6950 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6951 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_VERSION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6952 | goto error; |
| 6953 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6954 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6955 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6956 | substmt_prev = "yang-version"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6957 | } else if (!strcmp(child->name, "extension")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6958 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6959 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_ext, trg->extensions_size, "extensions", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6960 | submodule ? "submodule" : "module", error); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6961 | c_ext++; |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 6962 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6963 | substmt_prev = "extension"; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6964 | } else if (!strcmp(child->name, "deviation")) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6965 | substmt_group = 4; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6966 | YIN_CHECK_ARRAY_OVERFLOW_GOTO(ctx, c_dev, trg->deviation_size, "deviations", |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 6967 | submodule ? "submodule" : "module", error); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6968 | c_dev++; |
| 6969 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6970 | substmt_prev = "deviation"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6971 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6972 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6973 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6974 | } |
| 6975 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6976 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6977 | /* check for mandatory statements */ |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6978 | if (submodule) { |
| 6979 | if (!submodule->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6980 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6981 | goto error; |
| 6982 | } |
| 6983 | if (!version_flag) { |
| 6984 | /* check version compatibility with the main module */ |
| 6985 | if (module->version > 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6986 | LOGVAL(ctx, LYE_INVER, LY_VLOG_NONE, NULL); |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6987 | goto error; |
| 6988 | } |
| 6989 | } |
| 6990 | } else { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6991 | if (!trg->ns) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6992 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6993 | goto error; |
| 6994 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6995 | if (!trg->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 6996 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6997 | goto error; |
| 6998 | } |
| 6999 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 7000 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7001 | /* allocate arrays for elements with cardinality of 0..n */ |
| 7002 | if (c_imp) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7003 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7004 | LY_CHECK_ERR_GOTO(!trg->imp, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7005 | } |
| 7006 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7007 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7008 | LY_CHECK_ERR_GOTO(!trg->rev, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7009 | } |
| 7010 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7011 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7012 | LY_CHECK_ERR_GOTO(!trg->tpdf, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7013 | } |
| 7014 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7015 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7016 | LY_CHECK_ERR_GOTO(!trg->ident, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7017 | } |
| 7018 | if (c_inc) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7019 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7020 | LY_CHECK_ERR_GOTO(!trg->inc, LOGMEM(ctx), error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7021 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7022 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7023 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7024 | LY_CHECK_ERR_GOTO(!trg->augment, LOGMEM(ctx), error); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7025 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 7026 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7027 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7028 | LY_CHECK_ERR_GOTO(!trg->features, LOGMEM(ctx), error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 7029 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 7030 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7031 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7032 | LY_CHECK_ERR_GOTO(!trg->deviation, LOGMEM(ctx), error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 7033 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 7034 | if (c_ext) { |
| 7035 | trg->extensions = calloc(c_ext, sizeof *trg->extensions); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7036 | LY_CHECK_ERR_GOTO(!trg->extensions, LOGMEM(ctx), error); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 7037 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7038 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7039 | /* middle part 1 - process revision and then check whether this (sub)module was not already parsed, add it there */ |
| 7040 | LY_TREE_FOR_SAFE(revs.child, next, child) { |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7041 | r = fill_yin_revision(trg, child, &trg->rev[trg->rev_size], unres); |
| 7042 | trg->rev_size++; |
| 7043 | if (r) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7044 | goto error; |
| 7045 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7046 | |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7047 | /* check uniqueness of the revision date - not required by RFC */ |
| 7048 | for (i = 0; i < (trg->rev_size - 1); i++) { |
| 7049 | if (!strcmp(trg->rev[i].date, trg->rev[trg->rev_size - 1].date)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7050 | LOGWRN(ctx, "Module's revisions are not unique (%s).", trg->rev[trg->rev_size - 1].date); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7051 | break; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7052 | } |
| 7053 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7054 | |
| 7055 | lyxml_free(ctx, child); |
| 7056 | } |
| 7057 | |
| 7058 | /* check the module with respect to the context now */ |
| 7059 | if (!submodule) { |
| 7060 | switch (lyp_ctx_check_module(module)) { |
| 7061 | case -1: |
| 7062 | goto error; |
| 7063 | case 0: |
| 7064 | break; |
| 7065 | case 1: |
| 7066 | /* it's already there */ |
| 7067 | ret = 1; |
| 7068 | goto error; |
| 7069 | } |
| 7070 | } |
| 7071 | |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 7072 | /* check first definition of extensions */ |
| 7073 | if (c_ext) { |
| 7074 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 7075 | if (!strcmp(child->name, "extension")) { |
| 7076 | r = fill_yin_extension(trg, child, &trg->extensions[trg->extensions_size], unres); |
| 7077 | trg->extensions_size++; |
| 7078 | if (r) { |
| 7079 | goto error; |
| 7080 | } |
| 7081 | |
| 7082 | } |
| 7083 | } |
| 7084 | } |
| 7085 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7086 | /* middle part 2 - process nodes with cardinality of 0..n except the data nodes and augments */ |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7087 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7088 | if (!strcmp(child->name, "import")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7089 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size], unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7090 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7091 | if (r) { |
| 7092 | goto error; |
| 7093 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 7094 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7095 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7096 | r = fill_yin_include(module, submodule, child, &trg->inc[trg->inc_size], unres); |
| 7097 | trg->inc_size++; |
| 7098 | if (r) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7099 | goto error; |
| 7100 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 7101 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7102 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7103 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 7104 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7105 | if (r) { |
| 7106 | goto error; |
| 7107 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7108 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7109 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7110 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 7111 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7112 | if (r) { |
| 7113 | goto error; |
| 7114 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7115 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7116 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7117 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 7118 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 7119 | if (r) { |
| 7120 | goto error; |
| 7121 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7122 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7123 | } else if (!strcmp(child->name, "deviation")) { |
Michal Vasko | 0f43706 | 2018-06-08 15:52:39 +0200 | [diff] [blame] | 7124 | /* must be implemented in this case */ |
| 7125 | trg->implemented = 1; |
| 7126 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7127 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 7128 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 7129 | if (r) { |
| 7130 | goto error; |
| 7131 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7132 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7133 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7134 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7135 | /* process extension instances */ |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 7136 | if (c_extinst) { |
| 7137 | /* some extensions may be already present from the substatements */ |
| 7138 | reallocated = realloc(trg->ext, (c_extinst + trg->ext_size) * sizeof *trg->ext); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7139 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(ctx), error); |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 7140 | trg->ext = reallocated; |
| 7141 | |
| 7142 | /* init memory */ |
| 7143 | memset(&trg->ext[trg->ext_size], 0, c_extinst * sizeof *trg->ext); |
| 7144 | |
| 7145 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 7146 | r = lyp_yin_fill_ext(trg, LYEXT_PAR_MODULE, 0, 0, trg, child, &trg->ext, trg->ext_size, unres); |
| 7147 | trg->ext_size++; |
| 7148 | if (r) { |
| 7149 | goto error; |
| 7150 | } |
| 7151 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7152 | } |
| 7153 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7154 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7155 | * refer to them. Submodule's data nodes are stored in the |
| 7156 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7157 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7158 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7159 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7160 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7161 | goto error; |
| 7162 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 7163 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7164 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7165 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 7166 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7167 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7168 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7169 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7170 | if (!strcmp(child->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7171 | node = read_yin_container(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7172 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7173 | node = read_yin_leaflist(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7174 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7175 | node = read_yin_leaf(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7176 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7177 | node = read_yin_list(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7178 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7179 | node = read_yin_choice(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7180 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7181 | node = read_yin_uses(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7182 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7183 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 7184 | } else if (!strcmp(child->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7185 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 7186 | } else if (!strcmp(child->name, "rpc")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7187 | node = read_yin_rpc_action(trg, NULL, child, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 7188 | } else if (!strcmp(child->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7189 | node = read_yin_notif(trg, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7190 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7191 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7192 | goto error; |
| 7193 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 7194 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7195 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7196 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7197 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7198 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 7199 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7200 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], 0, unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7201 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7202 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7203 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7204 | goto error; |
| 7205 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7206 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7207 | } |
| 7208 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7209 | return 0; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7210 | |
| 7211 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7212 | while (root.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7213 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7214 | } |
| 7215 | while (grps.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7216 | lyxml_free(ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7217 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7218 | while (augs.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7219 | lyxml_free(ctx, augs.child); |
| 7220 | } |
| 7221 | while (revs.child) { |
| 7222 | lyxml_free(ctx, revs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 7223 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7224 | while (exts.child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7225 | lyxml_free(ctx, exts.child); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7226 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7227 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7228 | return ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7229 | } |
| 7230 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7231 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7232 | struct lys_submodule * |
| 7233 | yin_read_submodule(struct lys_module *module, const char *data, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7234 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7235 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7236 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7237 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7238 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7239 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7240 | yin = lyxml_parse_mem(ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7241 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7242 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7243 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7244 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7245 | /* check root element */ |
| 7246 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7247 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7248 | goto error; |
| 7249 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7250 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7251 | GETVAL(ctx, value, yin, "name"); |
| 7252 | if (lyp_check_identifier(ctx, value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7253 | goto error; |
| 7254 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7255 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7256 | submodule = calloc(1, sizeof *submodule); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7257 | LY_CHECK_ERR_GOTO(!submodule, LOGMEM(ctx), error); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7258 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7259 | submodule->ctx = ctx; |
| 7260 | submodule->name = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7261 | submodule->type = 1; |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 7262 | submodule->implemented = module->implemented; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7263 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7264 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7265 | /* add into the list of processed modules */ |
| 7266 | if (lyp_check_circmod_add((struct lys_module *)submodule)) { |
| 7267 | goto error; |
| 7268 | } |
| 7269 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7270 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7271 | /* module cannot be changed in this case and 1 cannot be returned */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7272 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7273 | goto error; |
| 7274 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7275 | |
Radek Krejci | 33fc477 | 2017-01-26 16:00:35 +0100 | [diff] [blame] | 7276 | lyp_sort_revisions((struct lys_module *)submodule); |
| 7277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7278 | /* cleanup */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7279 | lyxml_free(ctx, yin); |
| 7280 | lyp_check_circmod_pop(ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7281 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7282 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7283 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7284 | |
| 7285 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7286 | /* cleanup */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7287 | lyxml_free(ctx, yin); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7288 | if (!submodule) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7289 | LOGERR(ctx, ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7290 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7291 | } |
| 7292 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7293 | LOGERR(ctx, ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7294 | |
Michal Vasko | a972812 | 2018-01-16 14:00:13 +0100 | [diff] [blame] | 7295 | unres_schema_free((struct lys_module *)submodule, &unres, 0); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7296 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7297 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 7298 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7299 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7300 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7301 | } |
| 7302 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7303 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 7304 | struct lys_module * |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7305 | yin_read_module_(struct ly_ctx *ctx, struct lyxml_elem *yin, const char *revision, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7306 | { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 7307 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7308 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7309 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7310 | int ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7311 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7312 | unres = calloc(1, sizeof *unres); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7313 | LY_CHECK_ERR_RETURN(!unres, LOGMEM(ctx), NULL); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7314 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7315 | /* check root element */ |
| 7316 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7317 | if (ly_strequal("submodule", yin->name, 0)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7318 | LOGVAL(ctx, LYE_SUBMODULE, LY_VLOG_NONE, NULL); |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7319 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7320 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7321 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7322 | goto error; |
| 7323 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7324 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7325 | GETVAL(ctx, value, yin, "name"); |
| 7326 | if (lyp_check_identifier(ctx, value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7327 | goto error; |
| 7328 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7329 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7330 | module = calloc(1, sizeof *module); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7331 | LY_CHECK_ERR_GOTO(!module, LOGMEM(ctx), error); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7332 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7333 | module->ctx = ctx; |
| 7334 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 7335 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 7336 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7337 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7338 | /* add into the list of processed modules */ |
| 7339 | if (lyp_check_circmod_add(module)) { |
| 7340 | goto error; |
| 7341 | } |
| 7342 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7343 | LOGVRB("Reading module \"%s\".", module->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7344 | ret = read_sub_module(module, NULL, yin, unres); |
| 7345 | if (ret == -1) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7346 | goto error; |
| 7347 | } |
| 7348 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7349 | if (ret == 1) { |
| 7350 | assert(!unres->count); |
| 7351 | } else { |
Michal Vasko | 0f43706 | 2018-06-08 15:52:39 +0200 | [diff] [blame] | 7352 | /* make this module implemented if was not from start */ |
| 7353 | if (!implement && module->implemented && (unres_schema_add_node(module, unres, NULL, UNRES_MOD_IMPLEMENT, NULL) == -1)) { |
| 7354 | goto error; |
| 7355 | } |
| 7356 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7357 | /* resolve rest of unres items */ |
| 7358 | if (unres->count && resolve_unres_schema(module, unres)) { |
| 7359 | goto error; |
| 7360 | } |
| 7361 | |
| 7362 | /* check correctness of includes */ |
| 7363 | if (lyp_check_include_missing(module)) { |
| 7364 | goto error; |
| 7365 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7366 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7367 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7368 | lyp_sort_revisions(module); |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 7369 | |
| 7370 | if (lyp_rfn_apply_ext(module) || lyp_deviation_apply_ext(module)) { |
| 7371 | goto error; |
| 7372 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7373 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7374 | if (revision) { |
| 7375 | /* check revision of the parsed model */ |
| 7376 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 7377 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 7378 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7379 | goto error; |
| 7380 | } |
| 7381 | } |
| 7382 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7383 | /* add into context if not already there */ |
| 7384 | if (!ret) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7385 | if (lyp_ctx_add_module(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 7386 | goto error; |
| 7387 | } |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 7388 | |
| 7389 | /* remove our submodules from the parsed submodules list */ |
| 7390 | lyp_del_includedup(module, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7391 | } else { |
| 7392 | /* free what was parsed */ |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 7393 | lys_free(module, NULL, 0, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7394 | |
| 7395 | /* get the model from the context */ |
Radek Krejci | dfb00d6 | 2017-09-06 09:39:35 +0200 | [diff] [blame] | 7396 | module = (struct lys_module *)ly_ctx_get_module(ctx, value, revision, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7397 | assert(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7398 | } |
| 7399 | |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 7400 | unres_schema_free(NULL, &unres, 0); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7401 | lyp_check_circmod_pop(ctx); |
Michal Vasko | be136f6 | 2017-09-21 12:08:39 +0200 | [diff] [blame] | 7402 | LOGVRB("Module \"%s%s%s\" successfully parsed as %s.", module->name, (module->rev_size ? "@" : ""), |
| 7403 | (module->rev_size ? module->rev[0].date : ""), (module->implemented ? "implemented" : "imported")); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7404 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7405 | |
| 7406 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7407 | /* cleanup */ |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 7408 | unres_schema_free(module, &unres, 1); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7409 | |
| 7410 | if (!module) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7411 | if (ly_vecode(ctx) != LYVE_SUBMODULE) { |
| 7412 | LOGERR(ctx, ly_errno, "Module parsing failed."); |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7413 | } |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7414 | return NULL; |
| 7415 | } |
| 7416 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7417 | LOGERR(ctx, ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7418 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7419 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7420 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 7421 | lyp_del_includedup(module, 1); |
| 7422 | lys_free(module, NULL, 0, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7423 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7424 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7425 | |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7426 | /* logs directly */ |
| 7427 | struct lys_module * |
| 7428 | yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement) |
| 7429 | { |
| 7430 | struct lyxml_elem *yin; |
| 7431 | struct lys_module *result; |
| 7432 | |
Radek Krejci | e1bacd7 | 2017-03-01 13:18:46 +0100 | [diff] [blame] | 7433 | yin = lyxml_parse_mem(ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7434 | if (!yin) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7435 | LOGERR(ctx, ly_errno, "Module parsing failed."); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7436 | return NULL; |
| 7437 | } |
| 7438 | |
| 7439 | result = yin_read_module_(ctx, yin, revision, implement); |
| 7440 | |
| 7441 | lyxml_free(ctx, yin); |
| 7442 | |
| 7443 | return result; |
| 7444 | } |
| 7445 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7446 | static int |
| 7447 | yin_parse_extcomplex_bool(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7448 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7449 | const char *true_val, const char *false_val, struct unres_schema *unres) |
| 7450 | { |
| 7451 | uint8_t *val; |
| 7452 | const char *str; |
| 7453 | struct lyext_substmt *info; |
| 7454 | |
| 7455 | val = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7456 | if (!val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7457 | LOGVAL(mod->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7458 | return EXIT_FAILURE; |
| 7459 | } |
| 7460 | if (*val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7461 | LOGVAL(mod->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7462 | return EXIT_FAILURE; |
| 7463 | } |
| 7464 | |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7465 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7466 | return EXIT_FAILURE; |
| 7467 | } |
| 7468 | |
| 7469 | str = lyxml_get_attr(node, "value", NULL); |
| 7470 | if (!str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7471 | LOGVAL(mod->ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7472 | } else if (true_val && !strcmp(true_val, str)) { |
| 7473 | /* true value */ |
| 7474 | *val = 1; |
| 7475 | } else if (false_val && !strcmp(false_val, str)) { |
| 7476 | /* false value */ |
| 7477 | *val = 2; |
| 7478 | } else { |
| 7479 | /* unknown value */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7480 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7481 | return EXIT_FAILURE; |
| 7482 | } |
| 7483 | |
| 7484 | return EXIT_SUCCESS; |
| 7485 | } |
| 7486 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7487 | /* |
| 7488 | * argelem - 1 if the value is stored in a standalone YIN element, 0 if stored as attribute |
| 7489 | * argname - name of the element/attribute where the value is stored |
| 7490 | */ |
| 7491 | static int |
| 7492 | yin_parse_extcomplex_str(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7493 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7494 | int argelem, const char *argname, struct unres_schema *unres) |
| 7495 | { |
| 7496 | int c; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7497 | const char **str, ***p = NULL, *value; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7498 | void *reallocated; |
| 7499 | struct lyext_substmt *info; |
| 7500 | |
| 7501 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7502 | if (!str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7503 | LOGVAL(mod->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7504 | return EXIT_FAILURE; |
| 7505 | } |
| 7506 | if (info->cardinality < LY_STMT_CARD_SOME && *str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7507 | LOGVAL(mod->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7508 | return EXIT_FAILURE; |
| 7509 | } |
| 7510 | |
| 7511 | c = 0; |
| 7512 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7513 | /* there can be multiple instances, str is actually const char *** */ |
| 7514 | p = (const char ***)str; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7515 | if (!p[0]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7516 | /* allocate initial array */ |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7517 | p[0] = malloc(2 * sizeof(const char *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7518 | LY_CHECK_ERR_RETURN(!p[0], LOGMEM(mod->ctx), EXIT_FAILURE); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7519 | if (stmt == LY_STMT_BELONGSTO) { |
| 7520 | /* allocate another array for the belongs-to's prefixes */ |
| 7521 | p[1] = malloc(2 * sizeof(const char *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7522 | LY_CHECK_ERR_RETURN(!p[1], LOGMEM(mod->ctx), EXIT_FAILURE); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7523 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7524 | /* allocate another array for the yin element */ |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 7525 | ((uint8_t **)p)[1] = malloc(2 * sizeof(uint8_t)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7526 | LY_CHECK_ERR_RETURN(!p[1], LOGMEM(mod->ctx), EXIT_FAILURE); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7527 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7528 | } else { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7529 | /* get the index in the array to add new item */ |
| 7530 | for (c = 0; p[0][c]; c++); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7531 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7532 | str = p[0]; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7533 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7534 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, c, unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7535 | return EXIT_FAILURE; |
| 7536 | } |
| 7537 | |
| 7538 | if (argelem) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7539 | str[c] = read_yin_subnode(mod->ctx, node, argname); |
| 7540 | if (!str[c]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7541 | return EXIT_FAILURE; |
| 7542 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7543 | } else { |
| 7544 | str[c] = lyxml_get_attr(node, argname, NULL); |
| 7545 | if (!str[c]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7546 | LOGVAL(mod->ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, argname, node->name); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7547 | return EXIT_FAILURE; |
| 7548 | } else { |
| 7549 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7550 | } |
| 7551 | |
| 7552 | if (stmt == LY_STMT_BELONGSTO) { |
| 7553 | /* get the belongs-to's mandatory prefix substatement */ |
| 7554 | if (!node->child) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7555 | LOGVAL(mod->ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", node->name); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7556 | return EXIT_FAILURE; |
| 7557 | } else if (strcmp(node->child->name, "prefix")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7558 | LOGVAL(mod->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7559 | return EXIT_FAILURE; |
| 7560 | } else if (node->child->next) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7561 | LOGVAL(mod->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7562 | return EXIT_FAILURE; |
| 7563 | } |
| 7564 | /* and now finally get the value */ |
| 7565 | if (p) { |
| 7566 | str = p[1]; |
| 7567 | } else { |
| 7568 | str++; |
| 7569 | } |
| 7570 | str[c] = lyxml_get_attr(node->child, "value", ((void *)0)); |
| 7571 | if (!str[c]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7572 | LOGVAL(mod->ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7573 | return EXIT_FAILURE; |
| 7574 | } |
| 7575 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7576 | |
PavolVican | 6d40087 | 2017-03-01 15:19:18 +0100 | [diff] [blame] | 7577 | if (!str[c] || lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_PREFIX, c, unres)) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7578 | return EXIT_FAILURE; |
| 7579 | } |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7580 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7581 | str = (p) ? p[1] : str + 1; |
| 7582 | if (!node->child) { |
| 7583 | /* default value of yin element */ |
| 7584 | ((uint8_t *)str)[c] = 2; |
| 7585 | } else { |
| 7586 | /* get optional yin-element substatement */ |
| 7587 | if (strcmp(node->child->name, "yin-element")) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7588 | LOGVAL(mod->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7589 | return EXIT_FAILURE; |
| 7590 | } else if (node->child->next) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7591 | LOGVAL(mod->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7592 | return EXIT_FAILURE; |
| 7593 | } else { |
| 7594 | /* and now finally get the value */ |
| 7595 | value = lyxml_get_attr(node->child, "value", NULL); |
| 7596 | if (!value) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7597 | LOGVAL(mod->ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7598 | return EXIT_FAILURE; |
| 7599 | } |
| 7600 | if (ly_strequal(value, "true", 0)) { |
| 7601 | ((uint8_t *)str)[c] = 1; |
| 7602 | } else if (ly_strequal(value, "false", 0)) { |
| 7603 | ((uint8_t *)str)[c] = 2; |
| 7604 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7605 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7606 | return EXIT_FAILURE; |
| 7607 | } |
| 7608 | |
| 7609 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_YINELEM, c, unres)) { |
| 7610 | return EXIT_FAILURE; |
| 7611 | } |
| 7612 | } |
| 7613 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7614 | } |
| 7615 | } |
| 7616 | if (p) { |
| 7617 | /* enlarge the array(s) */ |
| 7618 | reallocated = realloc(p[0], (c + 2) * sizeof(const char *)); |
| 7619 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7620 | LOGMEM(mod->ctx); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7621 | lydict_remove(mod->ctx, p[0][c]); |
| 7622 | p[0][c] = NULL; |
| 7623 | return EXIT_FAILURE; |
| 7624 | } |
| 7625 | p[0] = reallocated; |
| 7626 | p[0][c + 1] = NULL; |
| 7627 | |
| 7628 | if (stmt == LY_STMT_BELONGSTO) { |
| 7629 | /* enlarge the second belongs-to's array with prefixes */ |
| 7630 | reallocated = realloc(p[1], (c + 2) * sizeof(const char *)); |
| 7631 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7632 | LOGMEM(mod->ctx); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7633 | lydict_remove(mod->ctx, p[1][c]); |
| 7634 | p[1][c] = NULL; |
| 7635 | return EXIT_FAILURE; |
| 7636 | } |
| 7637 | p[1] = reallocated; |
| 7638 | p[1][c + 1] = NULL; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7639 | } else if (stmt == LY_STMT_ARGUMENT){ |
| 7640 | /* enlarge the second argument's array with yin element */ |
| 7641 | reallocated = realloc(p[1], (c + 2) * sizeof(uint8_t)); |
| 7642 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7643 | LOGMEM(mod->ctx); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7644 | ((uint8_t *)p[1])[c] = 0; |
| 7645 | return EXIT_FAILURE; |
| 7646 | } |
| 7647 | p[1] = reallocated; |
| 7648 | ((uint8_t *)p[1])[c + 1] = 0; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7649 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7650 | } |
| 7651 | |
| 7652 | return EXIT_SUCCESS; |
| 7653 | } |
| 7654 | |
| 7655 | static void * |
| 7656 | yin_getplace_for_extcomplex_flags(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt, |
| 7657 | uint16_t mask) |
| 7658 | { |
| 7659 | void *data; |
| 7660 | struct lyext_substmt *info; |
| 7661 | |
| 7662 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7663 | if (!data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7664 | LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7665 | return NULL; |
| 7666 | } |
| 7667 | if (info->cardinality < LY_STMT_CARD_SOME && ((*(uint16_t *)data) & mask)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7668 | LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7669 | return NULL; |
| 7670 | } |
| 7671 | |
| 7672 | return data; |
| 7673 | } |
| 7674 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7675 | static int |
| 7676 | yin_parse_extcomplex_flag(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7677 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7678 | const char *val1_str, const char *val2_str, uint16_t mask, |
| 7679 | uint16_t val1, uint16_t val2, struct unres_schema *unres) |
| 7680 | { |
| 7681 | uint16_t *val; |
| 7682 | const char *str; |
| 7683 | |
| 7684 | val = yin_getplace_for_extcomplex_flags(node, ext, stmt, mask); |
| 7685 | if (!val) { |
| 7686 | return EXIT_FAILURE; |
| 7687 | } |
| 7688 | |
| 7689 | str = lyxml_get_attr(node, "value", NULL); |
| 7690 | if (!str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7691 | LOGVAL(mod->ctx, LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7692 | } else if (!strcmp(val1_str, str)) { |
| 7693 | *val = *val | val1; |
| 7694 | } else if (!strcmp(val2_str, str)) { |
| 7695 | *val = *val | val2; |
| 7696 | } else { |
| 7697 | /* unknown value */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7698 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7699 | return EXIT_FAILURE; |
| 7700 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7701 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7702 | return EXIT_FAILURE; |
| 7703 | } |
| 7704 | return EXIT_SUCCESS; |
| 7705 | } |
| 7706 | |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7707 | static struct lys_node ** |
| 7708 | yin_getplace_for_extcomplex_node(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7709 | { |
| 7710 | struct lyext_substmt *info; |
| 7711 | struct lys_node **snode, *siter; |
| 7712 | |
| 7713 | snode = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7714 | if (!snode) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7715 | LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7716 | return NULL; |
| 7717 | } |
| 7718 | if (info->cardinality < LY_STMT_CARD_SOME) { |
| 7719 | LY_TREE_FOR(*snode, siter) { |
| 7720 | if (stmt == lys_snode2stmt(siter->nodetype)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7721 | LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7722 | return NULL; |
| 7723 | } |
| 7724 | } |
| 7725 | } |
| 7726 | |
| 7727 | return snode; |
| 7728 | } |
| 7729 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7730 | static void ** |
| 7731 | yin_getplace_for_extcomplex_struct(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7732 | { |
| 7733 | int c; |
| 7734 | void **data, ***p = NULL; |
| 7735 | void *reallocated; |
| 7736 | struct lyext_substmt *info; |
| 7737 | |
| 7738 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7739 | if (!data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7740 | LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7741 | return NULL; |
| 7742 | } |
| 7743 | if (info->cardinality < LY_STMT_CARD_SOME && *data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7744 | LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7745 | return NULL; |
| 7746 | } |
| 7747 | |
| 7748 | c = 0; |
| 7749 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7750 | /* there can be multiple instances, so instead of pointer to array, |
| 7751 | * we have in data pointer to pointer to array */ |
| 7752 | p = (void ***)data; |
| 7753 | data = *p; |
| 7754 | if (!data) { |
| 7755 | /* allocate initial array */ |
| 7756 | *p = data = malloc(2 * sizeof(void *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7757 | LY_CHECK_ERR_RETURN(!data, LOGMEM(ext->module->ctx), NULL); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7758 | } else { |
| 7759 | for (c = 0; *data; data++, c++); |
| 7760 | } |
| 7761 | } |
| 7762 | |
| 7763 | if (p) { |
| 7764 | /* enlarge the array */ |
| 7765 | reallocated = realloc(*p, (c + 2) * sizeof(void *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7766 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ext->module->ctx), NULL); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7767 | *p = reallocated; |
| 7768 | data = *p; |
| 7769 | data[c + 1] = NULL; |
| 7770 | } |
| 7771 | |
| 7772 | return &data[c]; |
| 7773 | } |
| 7774 | |
| 7775 | int |
| 7776 | lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, struct lyxml_elem *yin, |
| 7777 | struct unres_schema *unres) |
| 7778 | { |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7779 | struct lyxml_elem *next, *node, *child; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7780 | struct lys_type **type; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7781 | void **pp, *p, *reallocated; |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7782 | const char *value, *name; |
| 7783 | char *endptr, modifier; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7784 | struct lyext_substmt *info; |
| 7785 | long int v; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7786 | long long int ll; |
| 7787 | unsigned long u; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7788 | int i, j; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7789 | |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7790 | #define YIN_STORE_VALUE(TYPE, FROM, TO) \ |
| 7791 | *(TYPE **)TO = malloc(sizeof(TYPE)); \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7792 | if (!*(TYPE **)TO) { LOGMEM(mod->ctx); goto error; } \ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7793 | (**(TYPE **)TO) = (TYPE)FROM; |
| 7794 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7795 | #define YIN_EXTCOMPLEX_GETPLACE(STMT, TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7796 | p = lys_ext_complex_get_substmt(STMT, ext, &info); \ |
| 7797 | if (!p) { \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7798 | LOGVAL(mod->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7799 | goto error; \ |
| 7800 | } \ |
| 7801 | if (info->cardinality < LY_STMT_CARD_SOME && (*(TYPE*)p)) { \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7802 | LOGVAL(mod->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7803 | goto error; \ |
| 7804 | } \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7805 | pp = NULL; i = 0; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7806 | if (info->cardinality >= LY_STMT_CARD_SOME) { \ |
| 7807 | /* there can be multiple instances */ \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7808 | pp = p; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7809 | if (!(*pp)) { \ |
| 7810 | *pp = malloc(2 * sizeof(TYPE)); /* allocate initial array */ \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7811 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM(mod->ctx), error); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7812 | } else { \ |
| 7813 | for (i = 0; (*(TYPE**)pp)[i]; i++); \ |
| 7814 | } \ |
| 7815 | p = &(*(TYPE**)pp)[i]; \ |
| 7816 | } |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7817 | #define YIN_EXTCOMPLEX_ENLARGE(TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7818 | if (pp) { \ |
| 7819 | /* enlarge the array */ \ |
| 7820 | reallocated = realloc(*pp, (i + 2) * sizeof(TYPE*)); \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7821 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM(mod->ctx), error); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7822 | *pp = reallocated; \ |
| 7823 | (*(TYPE**)pp)[i + 1] = 0; \ |
| 7824 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7825 | #define YIN_EXTCOMPLEX_PARSE_SNODE(STMT, FUNC, ARGS...) \ |
| 7826 | pp = (void**)yin_getplace_for_extcomplex_node(node, ext, STMT); \ |
| 7827 | if (!pp) { goto error; } \ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7828 | if (!FUNC(mod, (struct lys_node*)ext, node, ##ARGS, LYS_PARSE_OPT_CFG_NOINHERIT, unres)) { goto error; } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7829 | #define YIN_EXTCOMPLEX_PARSE_RESTR(STMT) \ |
| 7830 | YIN_EXTCOMPLEX_GETPLACE(STMT, struct lys_restr*); \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7831 | GETVAL(mod->ctx, value, node, "value"); \ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7832 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); \ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7833 | LY_CHECK_ERR_GOTO(!*(struct lys_restr **)p, LOGMEM(mod->ctx), error); \ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7834 | (*(struct lys_restr **)p)->expr = lydict_insert(mod->ctx, value, 0); \ |
| 7835 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { \ |
| 7836 | goto error; \ |
| 7837 | } \ |
| 7838 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7839 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7840 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 7841 | if (!node->ns) { |
| 7842 | /* garbage */ |
| 7843 | } else if (node->ns == yin->ns && (ext->flags & LYS_YINELEM) && ly_strequal(node->name, ext->def->argument, 1)) { |
| 7844 | /* we have the extension's argument */ |
| 7845 | if (ext->arg_value) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7846 | LOGVAL(mod->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7847 | goto error; |
| 7848 | } |
| 7849 | ext->arg_value = node->content; |
| 7850 | node->content = NULL; |
| 7851 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 7852 | /* extension */ |
| 7853 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 7854 | goto error; |
| 7855 | } |
| 7856 | } else if (!strcmp(node->name, "description")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7857 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_DESCRIPTION, 1, "text", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7858 | goto error; |
| 7859 | } |
| 7860 | } else if (!strcmp(node->name, "reference")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7861 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_REFERENCE, 1, "text", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7862 | goto error; |
| 7863 | } |
| 7864 | } else if (!strcmp(node->name, "units")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7865 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_UNITS, 0, "name", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7866 | goto error; |
| 7867 | } |
| 7868 | } else if (!strcmp(node->name, "type")) { |
| 7869 | type = (struct lys_type **)yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPE); |
| 7870 | if (!type) { |
| 7871 | goto error; |
| 7872 | } |
| 7873 | /* allocate type structure */ |
| 7874 | (*type) = calloc(1, sizeof **type); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7875 | LY_CHECK_ERR_GOTO(!*type, LOGMEM(mod->ctx), error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7876 | |
| 7877 | /* HACK for unres */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7878 | lyxml_unlink(mod->ctx, node); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7879 | (*type)->der = (struct lys_tpdf *)node; |
| 7880 | (*type)->parent = (struct lys_tpdf *)ext; |
| 7881 | |
| 7882 | if (unres_schema_add_node(mod, unres, *type, UNRES_TYPE_DER_EXT, NULL) == -1) { |
| 7883 | (*type)->der = NULL; |
| 7884 | goto error; |
| 7885 | } |
| 7886 | continue; /* skip lyxml_free() */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7887 | } else if (!strcmp(node->name, "typedef")) { |
| 7888 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPEDEF); |
| 7889 | if (!pp) { |
| 7890 | goto error; |
| 7891 | } |
| 7892 | /* allocate typedef structure */ |
| 7893 | (*pp) = calloc(1, sizeof(struct lys_tpdf)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7894 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM(mod->ctx), error); |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7895 | |
| 7896 | if (fill_yin_typedef(mod, (struct lys_node *)ext, node, *((struct lys_tpdf **)pp), unres)) { |
| 7897 | goto error; |
| 7898 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7899 | } else if (!strcmp(node->name, "if-feature")) { |
| 7900 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_IFFEATURE); |
| 7901 | if (!pp) { |
| 7902 | goto error; |
| 7903 | } |
| 7904 | /* allocate iffeature structure */ |
| 7905 | (*pp) = calloc(1, sizeof(struct lys_iffeature)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7906 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM(mod->ctx), error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7907 | |
| 7908 | if (fill_yin_iffeature((struct lys_node *)ext, 0, node, *((struct lys_iffeature **)pp), unres)) { |
| 7909 | goto error; |
| 7910 | } |
| 7911 | } else if (!strcmp(node->name, "status")) { |
| 7912 | p = yin_getplace_for_extcomplex_flags(node, ext, LY_STMT_STATUS, LYS_STATUS_MASK); |
| 7913 | if (!p) { |
| 7914 | goto error; |
| 7915 | } |
| 7916 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7917 | GETVAL(mod->ctx, value, node, "value"); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7918 | if (!strcmp(value, "current")) { |
| 7919 | *(uint16_t*)p |= LYS_STATUS_CURR; |
| 7920 | } else if (!strcmp(value, "deprecated")) { |
| 7921 | *(uint16_t*)p |= LYS_STATUS_DEPRC; |
| 7922 | } else if (!strcmp(value, "obsolete")) { |
| 7923 | *(uint16_t*)p |= LYS_STATUS_OBSLT; |
| 7924 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7925 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7926 | goto error; |
| 7927 | } |
| 7928 | |
| 7929 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
| 7930 | goto error; |
| 7931 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7932 | } else if (!strcmp(node->name, "config")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7933 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, "true", "false", LYS_CONFIG_MASK, |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 7934 | LYS_CONFIG_W | LYS_CONFIG_SET, LYS_CONFIG_R | LYS_CONFIG_SET, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7935 | goto error; |
| 7936 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7937 | } else if (!strcmp(node->name, "argument")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7938 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ARGUMENT, 0, "name", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7939 | goto error; |
| 7940 | } |
| 7941 | } else if (!strcmp(node->name, "default")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7942 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_DEFAULT, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7943 | goto error; |
| 7944 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7945 | } else if (!strcmp(node->name, "mandatory")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7946 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7947 | "true", "false", LYS_MAND_MASK, LYS_MAND_TRUE, LYS_MAND_FALSE, unres)) { |
| 7948 | goto error; |
| 7949 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7950 | } else if (!strcmp(node->name, "error-app-tag")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7951 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ERRTAG, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7952 | goto error; |
| 7953 | } |
| 7954 | } else if (!strcmp(node->name, "error-message")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7955 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ERRMSG, 1, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7956 | goto error; |
| 7957 | } |
| 7958 | } else if (!strcmp(node->name, "prefix")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7959 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PREFIX, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7960 | goto error; |
| 7961 | } |
| 7962 | } else if (!strcmp(node->name, "namespace")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7963 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_NAMESPACE, 0, "uri", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7964 | goto error; |
| 7965 | } |
| 7966 | } else if (!strcmp(node->name, "presence")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7967 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PRESENCE, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7968 | goto error; |
| 7969 | } |
| 7970 | } else if (!strcmp(node->name, "revision-date")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7971 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_REVISIONDATE, 0, "date", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7972 | goto error; |
| 7973 | } |
| 7974 | } else if (!strcmp(node->name, "key")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7975 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_KEY, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7976 | goto error; |
| 7977 | } |
| 7978 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7979 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_BASE, 0, "name", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7980 | goto error; |
| 7981 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7982 | } else if (!strcmp(node->name, "ordered-by")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7983 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_ORDEREDBY, |
| 7984 | "user", "system", LYS_USERORDERED, LYS_USERORDERED, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7985 | goto error; |
| 7986 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7987 | } else if (!strcmp(node->name, "belongs-to")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7988 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_BELONGSTO, 0, "module", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7989 | goto error; |
| 7990 | } |
| 7991 | } else if (!strcmp(node->name, "contact")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7992 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_CONTACT, 1, "text", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7993 | goto error; |
| 7994 | } |
| 7995 | } else if (!strcmp(node->name, "organization")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7996 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ORGANIZATION, 1, "text", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7997 | goto error; |
| 7998 | } |
| 7999 | } else if (!strcmp(node->name, "path")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 8000 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PATH, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 8001 | goto error; |
| 8002 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 8003 | } else if (!strcmp(node->name, "require-instance")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 8004 | if (yin_parse_extcomplex_bool(mod, node, ext, LY_STMT_REQINSTANCE, "true", "false", unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 8005 | goto error; |
| 8006 | } |
| 8007 | } else if (!strcmp(node->name, "modifier")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 8008 | if (yin_parse_extcomplex_bool(mod, node, ext, LY_STMT_MODIFIER, "invert-match", NULL, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 8009 | goto error; |
| 8010 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8011 | } else if (!strcmp(node->name, "fraction-digits")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8012 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_DIGITS, uint8_t); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8013 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8014 | GETVAL(mod->ctx, value, node, "value"); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8015 | v = strtol(value, NULL, 10); |
| 8016 | |
| 8017 | /* range check */ |
| 8018 | if (v < 1 || v > 18) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8019 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8020 | goto error; |
| 8021 | } |
| 8022 | |
| 8023 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, i, unres)) { |
| 8024 | goto error; |
| 8025 | } |
| 8026 | |
| 8027 | /* store the value */ |
| 8028 | (*(uint8_t *)p) = (uint8_t)v; |
| 8029 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8030 | YIN_EXTCOMPLEX_ENLARGE(uint8_t); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8031 | } else if (!strcmp(node->name, "max-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8032 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MAX, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8033 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8034 | GETVAL(mod->ctx, value, node, "value"); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8035 | while (isspace(value[0])) { |
| 8036 | value++; |
| 8037 | } |
| 8038 | |
| 8039 | if (!strcmp(value, "unbounded")) { |
| 8040 | u = 0; |
| 8041 | } else { |
| 8042 | /* convert it to uint32_t */ |
| 8043 | errno = 0; endptr = NULL; |
| 8044 | u = strtoul(value, &endptr, 10); |
| 8045 | if (*endptr || value[0] == '-' || errno || u == 0 || u > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8046 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8047 | goto error; |
| 8048 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 8049 | } |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8050 | |
| 8051 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 8052 | goto error; |
| 8053 | } |
| 8054 | |
| 8055 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 8056 | YIN_STORE_VALUE(uint32_t, u, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8057 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8058 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8059 | } else if (!strcmp(node->name, "min-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8060 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MIN, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8061 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8062 | GETVAL(mod->ctx, value, node, "value"); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8063 | while (isspace(value[0])) { |
| 8064 | value++; |
| 8065 | } |
| 8066 | |
| 8067 | /* convert it to uint32_t */ |
| 8068 | errno = 0; |
| 8069 | endptr = NULL; |
| 8070 | u = strtoul(value, &endptr, 10); |
| 8071 | if (*endptr || value[0] == '-' || errno || u > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8072 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8073 | goto error; |
| 8074 | } |
| 8075 | |
| 8076 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 8077 | goto error; |
| 8078 | } |
| 8079 | |
| 8080 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 8081 | YIN_STORE_VALUE(uint32_t, u, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8082 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8083 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 8084 | } else if (!strcmp(node->name, "value")) { |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8085 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_VALUE, int32_t*); |
| 8086 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8087 | GETVAL(mod->ctx, value, node, "value"); |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8088 | while (isspace(value[0])) { |
| 8089 | value++; |
| 8090 | } |
| 8091 | |
| 8092 | /* convert it to int32_t */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 8093 | ll = strtoll(value, NULL, 10); |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8094 | |
| 8095 | /* range check */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 8096 | if (ll < INT32_MIN || ll > INT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8097 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8098 | goto error; |
| 8099 | } |
| 8100 | |
| 8101 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_VALUE, i, unres)) { |
| 8102 | goto error; |
| 8103 | } |
| 8104 | |
| 8105 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 8106 | YIN_STORE_VALUE(int32_t, ll, p) |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8107 | |
| 8108 | YIN_EXTCOMPLEX_ENLARGE(int32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8109 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8110 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_POSITION, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8111 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8112 | GETVAL(mod->ctx, value, node, "value"); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8113 | ll = strtoll(value, NULL, 10); |
| 8114 | |
| 8115 | /* range check */ |
| 8116 | if (ll < 0 || ll > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8117 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8118 | goto error; |
| 8119 | } |
| 8120 | |
| 8121 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_POSITION, i, unres)) { |
| 8122 | goto error; |
| 8123 | } |
| 8124 | |
| 8125 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 8126 | YIN_STORE_VALUE(uint32_t, ll, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8127 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8128 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 8129 | } else if (!strcmp(node->name, "module")) { |
| 8130 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MODULE); |
| 8131 | if (!pp) { |
| 8132 | goto error; |
| 8133 | } |
| 8134 | |
| 8135 | *(struct lys_module **)pp = yin_read_module_(mod->ctx, node, NULL, mod->implemented); |
| 8136 | if (!(*pp)) { |
| 8137 | goto error; |
| 8138 | } |
Radek Krejci | c5cc530 | 2017-02-16 10:07:46 +0100 | [diff] [blame] | 8139 | } else if (!strcmp(node->name, "when")) { |
| 8140 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_WHEN, struct lys_when*); |
| 8141 | |
| 8142 | *(struct lys_when**)p = read_yin_when(mod, node, unres); |
| 8143 | if (!*(struct lys_when**)p) { |
| 8144 | goto error; |
| 8145 | } |
| 8146 | |
| 8147 | YIN_EXTCOMPLEX_ENLARGE(struct lys_when*); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 8148 | } else if (!strcmp(node->name, "revision")) { |
| 8149 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_REVISION, struct lys_revision*); |
| 8150 | |
| 8151 | *(struct lys_revision**)p = calloc(1, sizeof(struct lys_revision)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8152 | LY_CHECK_ERR_GOTO(!*(struct lys_revision**)p, LOGMEM(mod->ctx), error); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 8153 | if (fill_yin_revision(mod, node, *(struct lys_revision**)p, unres)) { |
| 8154 | goto error; |
| 8155 | } |
| 8156 | |
| 8157 | /* check uniqueness of the revision dates - not required by RFC */ |
| 8158 | if (pp) { |
| 8159 | for (j = 0; j < i; j++) { |
| 8160 | if (!strcmp((*(struct lys_revision***)pp)[j]->date, (*(struct lys_revision**)p)->date)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8161 | LOGWRN(mod->ctx, "Module's revisions are not unique (%s).", (*(struct lys_revision**)p)->date); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 8162 | } |
| 8163 | } |
| 8164 | } |
| 8165 | |
| 8166 | YIN_EXTCOMPLEX_ENLARGE(struct lys_revision*); |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8167 | } else if (!strcmp(node->name, "unique")) { |
| 8168 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_UNIQUE, struct lys_unique*); |
| 8169 | |
| 8170 | *(struct lys_unique**)p = calloc(1, sizeof(struct lys_unique)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8171 | LY_CHECK_ERR_GOTO(!*(struct lys_unique**)p, LOGMEM(mod->ctx), error); |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8172 | if (fill_yin_unique(mod, (struct lys_node*)ext, node, *(struct lys_unique**)p, unres)) { |
| 8173 | goto error; |
| 8174 | } |
| 8175 | |
| 8176 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_UNIQUE, i, unres)) { |
| 8177 | goto error; |
| 8178 | } |
| 8179 | YIN_EXTCOMPLEX_ENLARGE(struct lys_unique*); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8180 | } else if (!strcmp(node->name, "action")) { |
| 8181 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ACTION, read_yin_rpc_action); |
| 8182 | } else if (!strcmp(node->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8183 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYDATA, read_yin_anydata, LYS_ANYDATA); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8184 | } else if (!strcmp(node->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8185 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYXML, read_yin_anydata, LYS_ANYXML); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8186 | } else if (!strcmp(node->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8187 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CASE, read_yin_case); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8188 | } else if (!strcmp(node->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8189 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CHOICE, read_yin_choice); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8190 | } else if (!strcmp(node->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8191 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CONTAINER, read_yin_container); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8192 | } else if (!strcmp(node->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8193 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_GROUPING, read_yin_grouping); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8194 | } else if (!strcmp(node->name, "output")) { |
| 8195 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_OUTPUT, read_yin_input_output); |
| 8196 | } else if (!strcmp(node->name, "input")) { |
| 8197 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_INPUT, read_yin_input_output); |
| 8198 | } else if (!strcmp(node->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8199 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAF, read_yin_leaf); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8200 | } else if (!strcmp(node->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8201 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAFLIST, read_yin_leaflist); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8202 | } else if (!strcmp(node->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8203 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LIST, read_yin_list); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8204 | } else if (!strcmp(node->name, "notification")) { |
| 8205 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_NOTIFICATION, read_yin_notif); |
| 8206 | } else if (!strcmp(node->name, "uses")) { |
| 8207 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_USES, read_yin_uses); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8208 | } else if (!strcmp(node->name, "length")) { |
| 8209 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_LENGTH); |
| 8210 | } else if (!strcmp(node->name, "must")) { |
| 8211 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MUST); |
| 8212 | if (!pp) { |
| 8213 | goto error; |
| 8214 | } |
| 8215 | /* allocate structure for must */ |
| 8216 | (*pp) = calloc(1, sizeof(struct lys_restr)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8217 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM(mod->ctx), error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8218 | |
| 8219 | if (fill_yin_must(mod, node, *((struct lys_restr **)pp), unres)) { |
| 8220 | goto error; |
| 8221 | } |
| 8222 | } else if (!strcmp(node->name, "pattern")) { |
| 8223 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_PATTERN, struct lys_restr*); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8224 | GETVAL(mod->ctx, value, node, "value"); |
| 8225 | if (lyp_check_pattern(mod->ctx, value, NULL)) { |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8226 | goto error; |
| 8227 | } |
| 8228 | |
| 8229 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8230 | LY_CHECK_ERR_GOTO(!*(struct lys_restr **)p, LOGMEM(mod->ctx), error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8231 | |
| 8232 | modifier = 0x06; /* ACK */ |
| 8233 | if (mod->version >= 2) { |
| 8234 | name = NULL; |
| 8235 | LY_TREE_FOR(node->child, child) { |
| 8236 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 8237 | if (name) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8238 | LOGVAL(mod->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8239 | goto error; |
| 8240 | } |
| 8241 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8242 | GETVAL(mod->ctx, name, child, "value"); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8243 | if (!strcmp(name, "invert-match")) { |
| 8244 | modifier = 0x15; /* NACK */ |
| 8245 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8246 | LOGVAL(mod->ctx, LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8247 | goto error; |
| 8248 | } |
| 8249 | /* get extensions of the modifier */ |
| 8250 | if (lyp_yin_parse_subnode_ext(mod, *(struct lys_restr **)p, LYEXT_PAR_RESTR, child, |
| 8251 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 8252 | goto error; |
| 8253 | } |
| 8254 | } |
| 8255 | } |
| 8256 | } |
| 8257 | |
| 8258 | /* store the value: modifier byte + value + terminating NULL byte */ |
| 8259 | (*(struct lys_restr **)p)->expr = malloc((strlen(value) + 2) * sizeof(char)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8260 | LY_CHECK_ERR_GOTO(!(*(struct lys_restr **)p)->expr, LOGMEM(mod->ctx), error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8261 | ((char *)(*(struct lys_restr **)p)->expr)[0] = modifier; |
| 8262 | strcpy(&((char *)(*(struct lys_restr **)p)->expr)[1], value); |
| 8263 | lydict_insert_zc(mod->ctx, (char *)(*(struct lys_restr **)p)->expr); |
| 8264 | |
| 8265 | /* get possible sub-statements */ |
| 8266 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { |
| 8267 | goto error; |
| 8268 | } |
| 8269 | |
| 8270 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
| 8271 | } else if (!strcmp(node->name, "range")) { |
| 8272 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_RANGE); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8273 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 8274 | LOGERR(mod->ctx, ly_errno, "Extension's substatement \"%s\" not supported.", node->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8275 | } |
| 8276 | lyxml_free(mod->ctx, node); |
| 8277 | } |
| 8278 | |
PavolVican | c4b798e | 2017-02-20 23:15:27 +0100 | [diff] [blame] | 8279 | if (ext->substmt && lyp_mand_check_ext(ext, yin->name)) { |
| 8280 | return EXIT_FAILURE; |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 8281 | } |
| 8282 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8283 | return EXIT_SUCCESS; |
| 8284 | |
| 8285 | error: |
| 8286 | return EXIT_FAILURE; |
| 8287 | } |