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 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 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" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 28 | #include "dict_private.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 | |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 35 | #define GETVAL(value, node, arg) \ |
| 36 | value = lyxml_get_attr(node, arg, NULL); \ |
| 37 | if (!value) { \ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 38 | LOGVAL(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 | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 42 | #define OPT_IDENT 0x01 |
| 43 | #define OPT_CFG_PARSE 0x02 |
| 44 | #define OPT_CFG_INHERIT 0x04 |
| 45 | #define OPT_CFG_IGNORE 0x08 |
| 46 | #define OPT_MODULE 0x10 |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 47 | static int read_yin_common(struct lys_module *, struct lys_node *, void *, LYEXT_PAR, struct lyxml_elem *, int, |
| 48 | struct unres_schema *); |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 49 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 50 | static struct lys_node *read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 51 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 52 | static struct lys_node *read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 53 | int valid_config, struct unres_schema *unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 54 | 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] | 55 | LYS_NODE type, int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 56 | static struct lys_node *read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 57 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 58 | 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] | 59 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 60 | 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] | 61 | int valid_config, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 62 | static struct lys_node *read_yin_list(struct lys_module *module,struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 63 | int valid_config, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 64 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 65 | struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 66 | static struct lys_node *read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 67 | int valid_config, struct unres_schema *unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 68 | static struct lys_node *read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 69 | struct unres_schema *unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 70 | static struct lys_node *read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 71 | struct unres_schema *unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 72 | 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] | 73 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 74 | /* |
| 75 | * yin - the provided XML subtree is unlinked |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 76 | * 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] | 77 | */ |
| 78 | int |
| 79 | 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] | 80 | struct lys_module *module, struct lyxml_elem *yin, struct lys_ext_instance ***ext, |
| 81 | uint8_t ext_index, struct unres_schema *unres) |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 82 | { |
| 83 | struct unres_ext *info; |
| 84 | |
| 85 | info = malloc(sizeof *info); |
| 86 | lyxml_unlink(module->ctx, yin); |
| 87 | info->data.yin = yin; |
| 88 | info->datatype = LYS_IN_YIN; |
| 89 | info->parent = parent; |
Radek Krejci | a7db970 | 2017-01-20 12:55:14 +0100 | [diff] [blame] | 90 | info->mod = module; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 91 | info->parent_type = parent_type; |
| 92 | info->substmt = substmt; |
| 93 | info->substmt_index = substmt_index; |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 94 | info->ext_index = ext_index; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 95 | |
| 96 | if (unres_schema_add_node(module, unres, ext, UNRES_EXT, (struct lys_node *)info) == -1) { |
| 97 | return EXIT_FAILURE; |
| 98 | } |
| 99 | |
| 100 | return EXIT_SUCCESS; |
| 101 | } |
| 102 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 103 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 104 | static const char * |
| 105 | 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] | 106 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 107 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 109 | /* there should be <text> child */ |
| 110 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 111 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 112 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 113 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 114 | } else if (node->child->content) { |
| 115 | len = strlen(node->child->content); |
| 116 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 117 | } else { |
| 118 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 119 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 122 | int |
| 123 | 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] | 124 | 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] | 125 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 126 | void *reallocated; |
| 127 | struct lyxml_elem *next, *child; |
| 128 | int r; |
| 129 | struct lys_ext_instance ***ext; |
| 130 | uint8_t *ext_size; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 131 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 132 | switch (elem_type) { |
| 133 | case LYEXT_PAR_MODULE: |
| 134 | ext_size = &((struct lys_module *)elem)->ext_size; |
| 135 | ext = &((struct lys_module *)elem)->ext; |
| 136 | break; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 137 | case LYEXT_PAR_IMPORT: |
| 138 | ext_size = &((struct lys_import *)elem)->ext_size; |
| 139 | ext = &((struct lys_import *)elem)->ext; |
| 140 | break; |
| 141 | case LYEXT_PAR_INCLUDE: |
| 142 | ext_size = &((struct lys_include *)elem)->ext_size; |
| 143 | ext = &((struct lys_include *)elem)->ext; |
| 144 | break; |
| 145 | case LYEXT_PAR_REVISION: |
| 146 | ext_size = &((struct lys_revision *)elem)->ext_size; |
| 147 | ext = &((struct lys_revision *)elem)->ext; |
| 148 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 149 | case LYEXT_PAR_NODE: |
| 150 | ext_size = &((struct lys_node *)elem)->ext_size; |
| 151 | ext = &((struct lys_node *)elem)->ext; |
| 152 | break; |
| 153 | case LYEXT_PAR_IDENT: |
| 154 | ext_size = &((struct lys_ident *)elem)->ext_size; |
| 155 | ext = &((struct lys_ident *)elem)->ext; |
| 156 | break; |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 157 | case LYEXT_PAR_TYPE: |
| 158 | ext_size = &((struct lys_type *)elem)->ext_size; |
| 159 | ext = &((struct lys_type *)elem)->ext; |
| 160 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 161 | case LYEXT_PAR_TYPE_BIT: |
| 162 | ext_size = &((struct lys_type_bit *)elem)->ext_size; |
| 163 | ext = &((struct lys_type_bit *)elem)->ext; |
| 164 | break; |
| 165 | case LYEXT_PAR_TYPE_ENUM: |
| 166 | ext_size = &((struct lys_type_enum *)elem)->ext_size; |
| 167 | ext = &((struct lys_type_enum *)elem)->ext; |
| 168 | break; |
| 169 | case LYEXT_PAR_TPDF: |
| 170 | ext_size = &((struct lys_tpdf *)elem)->ext_size; |
| 171 | ext = &((struct lys_tpdf *)elem)->ext; |
| 172 | break; |
| 173 | case LYEXT_PAR_EXT: |
| 174 | ext_size = &((struct lys_ext *)elem)->ext_size; |
| 175 | ext = &((struct lys_ext *)elem)->ext; |
| 176 | break; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 177 | case LYEXT_PAR_EXTINST: |
| 178 | ext_size = &((struct lys_ext_instance *)elem)->ext_size; |
| 179 | ext = &((struct lys_ext_instance *)elem)->ext; |
| 180 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 181 | case LYEXT_PAR_FEATURE: |
| 182 | ext_size = &((struct lys_feature *)elem)->ext_size; |
| 183 | ext = &((struct lys_feature *)elem)->ext; |
| 184 | break; |
| 185 | case LYEXT_PAR_REFINE: |
| 186 | ext_size = &((struct lys_refine *)elem)->ext_size; |
| 187 | ext = &((struct lys_refine *)elem)->ext; |
| 188 | break; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 189 | case LYEXT_PAR_RESTR: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 190 | ext_size = &((struct lys_restr *)elem)->ext_size; |
| 191 | ext = &((struct lys_restr *)elem)->ext; |
| 192 | break; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 193 | case LYEXT_PAR_WHEN: |
| 194 | ext_size = &((struct lys_when *)elem)->ext_size; |
| 195 | ext = &((struct lys_when *)elem)->ext; |
| 196 | break; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 197 | case LYEXT_PAR_DEVIATE: |
| 198 | ext_size = &((struct lys_deviate *)elem)->ext_size; |
| 199 | ext = &((struct lys_deviate *)elem)->ext; |
| 200 | break; |
| 201 | case LYEXT_PAR_DEVIATION: |
| 202 | ext_size = &((struct lys_deviation *)elem)->ext_size; |
| 203 | ext = &((struct lys_deviation *)elem)->ext; |
| 204 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 205 | default: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 206 | LOGERR(LY_EINT, "parent type %d", elem_type); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 207 | return EXIT_FAILURE; |
| 208 | } |
| 209 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 210 | if (type == LYEXT_SUBSTMT_SELF) { |
| 211 | /* parse for the statement self, not for the substatement */ |
| 212 | child = yin; |
| 213 | next = NULL; |
| 214 | goto parseext; |
| 215 | } |
| 216 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 217 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 218 | if (!strcmp(child->ns->value, LY_NSYIN)) { |
| 219 | /* skip the regular YIN nodes */ |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | /* parse it as extension */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 224 | parseext: |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 225 | |
| 226 | /* first, allocate a space for the extension instance in the parent elem */ |
| 227 | reallocated = realloc(*ext, (1 + (*ext_size)) * sizeof **ext); |
| 228 | if (!reallocated) { |
| 229 | LOGMEM; |
| 230 | return EXIT_FAILURE; |
| 231 | } |
| 232 | (*ext) = reallocated; |
| 233 | |
| 234 | /* init memory */ |
| 235 | (*ext)[(*ext_size)] = NULL; |
| 236 | |
| 237 | /* parse YIN data */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 238 | 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] | 239 | (*ext_size)++; |
| 240 | if (r) { |
| 241 | return EXIT_FAILURE; |
| 242 | } |
| 243 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 244 | /* 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] | 245 | } |
| 246 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 247 | return EXIT_SUCCESS; |
| 248 | } |
| 249 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 250 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 251 | static int |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 252 | fill_yin_iffeature(struct lys_node *parent, int parent_is_feature, struct lyxml_elem *yin, struct lys_iffeature *iffeat, |
| 253 | struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 254 | { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 255 | int r, c_ext = 0; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 256 | const char *value; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 257 | struct lyxml_elem *node, *next; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 258 | |
| 259 | GETVAL(value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 260 | |
| 261 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
| 262 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 263 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 264 | return EXIT_FAILURE; |
| 265 | } |
| 266 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 267 | if (!(value = transform_iffeat_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 268 | return EXIT_FAILURE; |
| 269 | } |
| 270 | |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 271 | r = resolve_iffeature_compile(iffeat, value, parent, parent_is_feature, unres); |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 272 | lydict_remove(parent->module->ctx, value); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 273 | if (r) { |
| 274 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 277 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 278 | if (!node->ns) { |
| 279 | /* garbage */ |
| 280 | lyxml_free(parent->module->ctx, node); |
| 281 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 282 | /* extension */ |
| 283 | c_ext++; |
| 284 | } else { |
| 285 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "if-feature"); |
| 286 | return EXIT_FAILURE; |
| 287 | } |
| 288 | } |
| 289 | if (c_ext) { |
| 290 | iffeat->ext = calloc(c_ext, sizeof *iffeat->ext); |
| 291 | if (!iffeat->ext) { |
| 292 | LOGMEM; |
| 293 | return EXIT_FAILURE; |
| 294 | } |
| 295 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 296 | /* extensions */ |
| 297 | 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] | 298 | &iffeat->ext, iffeat->ext_size, unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 299 | iffeat->ext_size++; |
| 300 | if (r) { |
| 301 | return EXIT_FAILURE; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 306 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* logs directly */ |
| 310 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 311 | 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] | 312 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 313 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 314 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 315 | int rc; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 316 | int c_ftrs = 0, c_base = 0, c_ext = 0; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 317 | void *reallocated; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 318 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 319 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 320 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 321 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 322 | 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] | 323 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 324 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 325 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 326 | if (dup_identities_check(ident->name, module)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 327 | goto error; |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 330 | LY_TREE_FOR(yin->child, node) { |
| 331 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 332 | /* extension */ |
| 333 | c_ext++; |
| 334 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 335 | if (c_base && (module->version < 2)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 336 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 337 | goto error; |
| 338 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 339 | 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] | 340 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 341 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 342 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 343 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 344 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 345 | c_ftrs++; |
| 346 | |
| 347 | } else { |
| 348 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 349 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | if (c_base) { |
| 354 | ident->base_size = 0; |
| 355 | ident->base = calloc(c_base, sizeof *ident->base); |
| 356 | if (!ident->base) { |
| 357 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 358 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 359 | } |
| 360 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 361 | if (c_ftrs) { |
| 362 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
| 363 | if (!ident->iffeature) { |
| 364 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 365 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 366 | } |
| 367 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 368 | if (c_ext) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 369 | /* some extensions may be already present from the substatements */ |
| 370 | reallocated = realloc(ident->ext, (c_ext + ident->ext_size) * sizeof *ident->ext); |
| 371 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 372 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 373 | goto error; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 374 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 375 | ident->ext = reallocated; |
| 376 | |
| 377 | /* init memory */ |
| 378 | memset(&ident->ext[ident->ext_size], 0, c_ext * sizeof *ident->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 379 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 380 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 381 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 382 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 383 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 384 | 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] | 385 | ident->ext_size++; |
| 386 | if (rc) { |
| 387 | goto error; |
| 388 | } |
| 389 | } else if (!strcmp(node->name, "base")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 390 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 391 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 392 | if (!value) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 393 | goto error; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 394 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 395 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 396 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 397 | lydict_remove(module->ctx, value); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 398 | goto error; |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 399 | } |
| 400 | lydict_remove(module->ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 401 | } else if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 402 | 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] | 403 | ident->iffeature_size++; |
| 404 | if (rc) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 405 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 406 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 407 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 408 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 409 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 410 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 411 | |
| 412 | error: |
| 413 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 416 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 417 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 418 | read_restr_substmt(struct lys_module *module, LYEXT_PAR restr_type, struct lys_restr *restr, struct lyxml_elem *yin, |
| 419 | struct unres_schema *unres) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 420 | { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 421 | struct lyxml_elem *child, *next; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 422 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 423 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 424 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 425 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 426 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 427 | continue; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 428 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 429 | /* extension */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 430 | if (lyp_yin_parse_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 431 | return EXIT_FAILURE; |
| 432 | } |
| 433 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 434 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 435 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 436 | return EXIT_FAILURE; |
| 437 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 438 | if (lyp_yin_parse_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 439 | return EXIT_FAILURE; |
| 440 | } |
| 441 | restr->dsc = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 442 | if (!restr->dsc) { |
| 443 | return EXIT_FAILURE; |
| 444 | } |
| 445 | } else if (!strcmp(child->name, "reference")) { |
| 446 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 447 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 448 | return EXIT_FAILURE; |
| 449 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 450 | if (lyp_yin_parse_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 451 | return EXIT_FAILURE; |
| 452 | } |
| 453 | restr->ref = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 454 | if (!restr->ref) { |
| 455 | return EXIT_FAILURE; |
| 456 | } |
| 457 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 458 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 459 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 460 | return EXIT_FAILURE; |
| 461 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 462 | if (lyp_yin_parse_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_ERRTAG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 463 | return EXIT_FAILURE; |
| 464 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 465 | GETVAL(value, child, "value"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 466 | restr->eapptag = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 467 | } else if (!strcmp(child->name, "error-message")) { |
| 468 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 469 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 470 | return EXIT_FAILURE; |
| 471 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 472 | if (lyp_yin_parse_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_ERRMSG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 473 | return EXIT_FAILURE; |
| 474 | } |
| 475 | restr->emsg = read_yin_subnode(module->ctx, child, "value"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 476 | if (!restr->emsg) { |
| 477 | return EXIT_FAILURE; |
| 478 | } |
| 479 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 480 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 481 | return EXIT_FAILURE; |
| 482 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 486 | |
| 487 | error: |
| 488 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 489 | } |
| 490 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 491 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 492 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 493 | 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] | 494 | int parenttype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 495 | { |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 496 | const char *value, *name; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 497 | struct lys_node *siter; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 498 | struct lyxml_elem *next, *next2, *node, *child, exts; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 499 | struct lys_restr **restrs, *restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 500 | struct lys_type_bit bit, *bits_sc = NULL; |
| 501 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 502 | struct lys_type *dertype; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 503 | int i, j, rc, val_set, c_ftrs, c_ext = 0; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 504 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 505 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 506 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 507 | size_t len; |
| 508 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 509 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 510 | /* init */ |
| 511 | memset(&exts, 0, sizeof exts); |
| 512 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 513 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 514 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 515 | if (!value) { |
| 516 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 517 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 518 | |
| 519 | i = parse_identifier(value); |
| 520 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 521 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 522 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 523 | goto error; |
| 524 | } |
| 525 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 526 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 527 | if (value[i]) { |
| 528 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 529 | name += i; |
| 530 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 531 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 532 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 533 | goto error; |
| 534 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 535 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 536 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 537 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 538 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 539 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 540 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 541 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 542 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 543 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 544 | |
| 545 | /* 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] | 546 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 547 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 548 | lydict_remove(module->ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 549 | ret = EXIT_FAILURE; |
| 550 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 551 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 552 | lydict_remove(module->ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 553 | |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 554 | if (type->base == LY_TYPE_ERR) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 555 | /* resolved type in grouping, decrease the grouping's nacm number to indicate that one less |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 556 | * unresolved item left inside the grouping, LY_TYPE_ERR used as a flag for types inside a grouping. */ |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 557 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 558 | if (siter) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 559 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 560 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 561 | LOGINT; |
| 562 | goto error; |
| 563 | } |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 564 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]--; |
| 565 | #else |
| 566 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]) { |
| 567 | LOGINT; |
| 568 | goto error; |
| 569 | } |
| 570 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]--; |
| 571 | #endif |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 572 | } else { |
| 573 | LOGINT; |
| 574 | goto error; |
| 575 | } |
| 576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 577 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 578 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 579 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 580 | if (lyp_check_status(type->parent->flags, type->parent->module, type->parent->name, |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 581 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 582 | return -1; |
| 583 | } |
| 584 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 585 | /* parse extension instances */ |
| 586 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 587 | if (!node->ns) { |
| 588 | /* garbage */ |
| 589 | lyxml_free(module->ctx, node); |
| 590 | continue; |
| 591 | } else if (!strcmp(node->ns->value, LY_NSYIN)) { |
| 592 | /* YANG (YIN) statements - process later */ |
| 593 | continue; |
| 594 | } |
| 595 | |
| 596 | lyxml_unlink_elem(module->ctx, node, 2); |
| 597 | lyxml_add_child(module->ctx, &exts, node); |
| 598 | c_ext++; |
| 599 | } |
| 600 | if (c_ext) { |
| 601 | type->ext = calloc(c_ext, sizeof *type->ext); |
| 602 | if (!type->ext) { |
| 603 | LOGMEM; |
| 604 | goto error; |
| 605 | } |
| 606 | LY_TREE_FOR_SAFE(exts.child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 607 | 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] | 608 | type->ext_size++; |
| 609 | if (rc) { |
| 610 | goto error; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 615 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 616 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 617 | /* RFC 6020 9.7.4 - bit */ |
| 618 | |
| 619 | /* get bit specifications, at least one must be present */ |
| 620 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 621 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 622 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 623 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 624 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 625 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 626 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 627 | } |
| 628 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 629 | dertype = &type->der->type; |
| 630 | if (!dertype->der) { |
| 631 | if (!type->info.bits.count) { |
| 632 | /* type is derived directly from buit-in bits type and bit statement is required */ |
| 633 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
| 634 | goto error; |
| 635 | } |
| 636 | } else { |
| 637 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 638 | if (module->version < 2 && type->info.bits.count) { |
| 639 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 640 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
| 641 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 642 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 643 | goto error; |
| 644 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 645 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 646 | |
| 647 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 648 | if (!type->info.bits.bit) { |
| 649 | LOGMEM; |
| 650 | goto error; |
| 651 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 652 | p = 0; |
| 653 | i = -1; |
| 654 | LY_TREE_FOR(yin->child, next) { |
| 655 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 656 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 657 | |
| 658 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 659 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 660 | goto error; |
| 661 | } |
| 662 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 663 | type->info.bits.bit[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 664 | 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] | 665 | type->info.bits.count = i + 1; |
| 666 | goto error; |
| 667 | } |
| 668 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 669 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 670 | /* check the name uniqueness */ |
| 671 | for (j = 0; j < i; j++) { |
| 672 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
| 673 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
| 674 | type->info.bits.count = i + 1; |
| 675 | goto error; |
| 676 | } |
| 677 | } |
| 678 | } else { |
| 679 | /* restricted bits type - the name MUST be used in the base type */ |
| 680 | bits_sc = dertype->info.bits.bit; |
| 681 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 682 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | if (j == dertype->info.bits.count) { |
| 687 | LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 688 | type->info.bits.count = i + 1; |
| 689 | goto error; |
| 690 | } |
| 691 | } |
| 692 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 693 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 694 | p_ = -1; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 695 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 696 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 697 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 698 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 699 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 700 | /* extension */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 701 | 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] | 702 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 703 | goto error; |
| 704 | } |
| 705 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 706 | if (p_ != -1) { |
| 707 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 708 | type->info.bits.count = i + 1; |
| 709 | goto error; |
| 710 | } |
| 711 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 712 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 713 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 714 | |
| 715 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 716 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 717 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 718 | type->info.bits.count = i + 1; |
| 719 | goto error; |
| 720 | } |
| 721 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 722 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 723 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 724 | /* keep the highest enum value for automatic increment */ |
| 725 | if (type->info.bits.bit[i].pos >= p) { |
| 726 | p = type->info.bits.bit[i].pos; |
| 727 | p++; |
| 728 | } else { |
| 729 | /* check that the value is unique */ |
| 730 | for (j = 0; j < i; j++) { |
| 731 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
| 732 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
| 733 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 734 | type->info.bits.bit[j].name); |
| 735 | type->info.bits.count = i + 1; |
| 736 | goto error; |
| 737 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 738 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 739 | } |
| 740 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 741 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 742 | 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] | 743 | LYEXT_SUBSTMT_POSITION, 0, unres)) { |
| 744 | goto error; |
| 745 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 746 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 747 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 748 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 749 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 750 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 751 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 752 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 753 | |
| 754 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 755 | if (p_ == -1) { |
| 756 | /* assign value automatically */ |
| 757 | if (p > UINT32_MAX) { |
| 758 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
| 759 | type->info.bits.count = i + 1; |
| 760 | goto error; |
| 761 | } |
| 762 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 763 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 764 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 765 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 766 | } else { /* restricted bits type */ |
| 767 | if (p_ == -1) { |
| 768 | /* automatically assign position from base type */ |
| 769 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 770 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 771 | } else { |
| 772 | /* check that the assigned position corresponds to the original |
| 773 | * position of the bit in the base type */ |
| 774 | if (p_ != bits_sc[j].pos) { |
| 775 | /* p_ - assigned position in restricted bits |
| 776 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
| 777 | LOGVAL(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] | 778 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 779 | type->info.bits.count = i + 1; |
| 780 | goto error; |
| 781 | } |
| 782 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 783 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 784 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 785 | /* if-features */ |
| 786 | if (c_ftrs) { |
| 787 | bits_sc = &type->info.bits.bit[i]; |
| 788 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 789 | if (!bits_sc->iffeature) { |
| 790 | LOGMEM; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 791 | type->info.bits.count = i + 1; |
| 792 | goto error; |
| 793 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 794 | |
| 795 | LY_TREE_FOR(next->child, node) { |
| 796 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 797 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 798 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 799 | bits_sc->iffeature_size++; |
| 800 | if (rc) { |
| 801 | type->info.bits.count = i + 1; |
| 802 | goto error; |
| 803 | } |
| 804 | } |
| 805 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 806 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 807 | |
| 808 | /* keep them ordered by position */ |
| 809 | j = i; |
| 810 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 811 | /* switch them */ |
| 812 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 813 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 814 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 815 | j--; |
| 816 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 817 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 818 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 819 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 820 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 821 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 822 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 823 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 824 | if (!strcmp(node->name, "range")) { |
| 825 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 826 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 827 | goto error; |
| 828 | } |
| 829 | |
| 830 | GETVAL(value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 831 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 832 | if (!type->info.dec64.range) { |
| 833 | LOGMEM; |
| 834 | goto error; |
| 835 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 836 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 837 | |
| 838 | /* get possible substatements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 839 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, type->info.dec64.range, node, unres)) { |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 840 | goto error; |
| 841 | } |
| 842 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 843 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 844 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 845 | goto error; |
| 846 | } |
| 847 | GETVAL(value, node, "value"); |
| 848 | v = strtol(value, NULL, 10); |
| 849 | |
| 850 | /* range check */ |
| 851 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 852 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 853 | goto error; |
| 854 | } |
| 855 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 856 | type->info.dec64.div = 10; |
| 857 | for (i = 1; i < v; i++) { |
| 858 | type->info.dec64.div *= 10; |
| 859 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 860 | |
| 861 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 862 | 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] | 863 | goto error; |
| 864 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 865 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 866 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 867 | goto error; |
| 868 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* mandatory sub-statement(s) check */ |
| 872 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 873 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 874 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 875 | goto error; |
| 876 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 877 | if (type->info.dec64.dig && type->der->type.der) { |
| 878 | /* type is not directly derived from buit-in type and fraction-digits statement is prohibited */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 879 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 880 | goto error; |
| 881 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 882 | |
| 883 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 884 | if (type->der->type.der) { |
| 885 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 886 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 887 | } |
| 888 | |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 889 | if (type->info.dec64.range && lyp_check_length_range(type->info.dec64.range->expr, type)) { |
| 890 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
| 891 | goto error; |
| 892 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 893 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 894 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 895 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 896 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 897 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 898 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 899 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 900 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 901 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 902 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 903 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 904 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 905 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 906 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 907 | } |
| 908 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 909 | dertype = &type->der->type; |
| 910 | if (!dertype->der) { |
| 911 | if (!type->info.enums.count) { |
| 912 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
| 913 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
| 914 | goto error; |
| 915 | } |
| 916 | } else { |
| 917 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 918 | if (module->version < 2 && type->info.enums.count) { |
| 919 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 920 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
| 921 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 922 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 923 | goto error; |
| 924 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 925 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 926 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 927 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 928 | if (!type->info.enums.enm) { |
| 929 | LOGMEM; |
| 930 | goto error; |
| 931 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 932 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 933 | v = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 934 | i = -1; |
| 935 | LY_TREE_FOR(yin->child, next) { |
| 936 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 937 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 938 | |
| 939 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 940 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 941 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 942 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty."); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 943 | goto error; |
| 944 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 945 | type->info.enums.enm[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 946 | 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] | 947 | type->info.enums.count = i + 1; |
| 948 | goto error; |
| 949 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 950 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 951 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 952 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 953 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 954 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 955 | type->info.enums.count = i + 1; |
| 956 | goto error; |
| 957 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 958 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 959 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 960 | /* check the name uniqueness */ |
| 961 | for (j = 0; j < i; j++) { |
| 962 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
| 963 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
| 964 | type->info.enums.count = i + 1; |
| 965 | goto error; |
| 966 | } |
| 967 | } |
| 968 | } else { |
| 969 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 970 | enms_sc = dertype->info.enums.enm; |
| 971 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 972 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | if (j == dertype->info.enums.count) { |
| 977 | LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 978 | type->info.enums.count = i + 1; |
| 979 | goto error; |
| 980 | } |
| 981 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 982 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 983 | val_set = 0; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 984 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 985 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 986 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 987 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 988 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 989 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 990 | 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] | 991 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 992 | goto error; |
| 993 | } |
| 994 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 995 | if (val_set) { |
| 996 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 997 | type->info.enums.count = i + 1; |
| 998 | goto error; |
| 999 | } |
| 1000 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1001 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 1002 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1003 | |
| 1004 | /* range check */ |
| 1005 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1006 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1007 | type->info.enums.count = i + 1; |
| 1008 | goto error; |
| 1009 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1010 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1011 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1012 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1013 | if (!i) { |
| 1014 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1015 | v = type->info.enums.enm[i].value; |
| 1016 | v++; |
| 1017 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1018 | /* keep the highest enum value for automatic increment */ |
| 1019 | if (type->info.enums.enm[i].value >= v) { |
| 1020 | v = type->info.enums.enm[i].value; |
| 1021 | v++; |
| 1022 | } else { |
| 1023 | /* check that the value is unique */ |
| 1024 | for (j = 0; j < i; j++) { |
| 1025 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
| 1026 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
| 1027 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 1028 | type->info.enums.enm[j].name); |
| 1029 | type->info.enums.count = i + 1; |
| 1030 | goto error; |
| 1031 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1032 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1033 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1034 | } |
| 1035 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 1036 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1037 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1038 | 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] | 1039 | LYEXT_SUBSTMT_VALUE, 0, unres)) { |
| 1040 | goto error; |
| 1041 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1042 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 1043 | c_ftrs++; |
| 1044 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1045 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1046 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1047 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1048 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1049 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1050 | |
| 1051 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 1052 | if (!val_set) { |
| 1053 | /* assign value automatically */ |
| 1054 | if (v > INT32_MAX) { |
| 1055 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
| 1056 | type->info.enums.count = i + 1; |
| 1057 | goto error; |
| 1058 | } |
| 1059 | type->info.enums.enm[i].value = v; |
| 1060 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1061 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1062 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1063 | } else { /* restricted enum type */ |
| 1064 | if (!val_set) { |
| 1065 | /* automatically assign value from base type */ |
| 1066 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 1067 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1068 | } else { |
| 1069 | /* check that the assigned value corresponds to the original |
| 1070 | * value of the enum in the base type */ |
| 1071 | if (v_ != enms_sc[j].value) { |
| 1072 | /* v_ - assigned value in restricted enum |
| 1073 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
| 1074 | LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 1075 | 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] | 1076 | type->info.enums.count = i + 1; |
| 1077 | goto error; |
| 1078 | } |
| 1079 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1080 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1081 | |
| 1082 | /* if-features */ |
| 1083 | if (c_ftrs) { |
| 1084 | enms_sc = &type->info.enums.enm[i]; |
| 1085 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 1086 | if (!enms_sc->iffeature) { |
| 1087 | LOGMEM; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1088 | type->info.enums.count = i + 1; |
| 1089 | goto error; |
| 1090 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1091 | |
| 1092 | LY_TREE_FOR(next->child, node) { |
| 1093 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 1094 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1095 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 1096 | enms_sc->iffeature_size++; |
| 1097 | if (rc) { |
| 1098 | type->info.enums.count = i + 1; |
| 1099 | goto error; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1103 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1104 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1105 | } |
| 1106 | break; |
| 1107 | |
| 1108 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 1109 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1110 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1111 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1112 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1113 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 1114 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1115 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1116 | goto error; |
| 1117 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1118 | |
| 1119 | GETVAL(value, yin->child, "name"); |
| 1120 | /* store in the JSON format */ |
| 1121 | value = transform_schema2json(module, value); |
| 1122 | if (!value) { |
| 1123 | goto error; |
| 1124 | } |
| 1125 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 1126 | lydict_remove(module->ctx, value); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1127 | if (rc == -1) { |
| 1128 | goto error; |
| 1129 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1130 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1131 | 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] | 1132 | goto error; |
| 1133 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1136 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1137 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1138 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1139 | break; |
| 1140 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1141 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1142 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1143 | } else { |
| 1144 | if (type->der->type.der) { |
| 1145 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
| 1146 | goto error; |
| 1147 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1148 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1149 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1150 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, yin->child->next->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1151 | goto error; |
| 1152 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1153 | break; |
| 1154 | |
| 1155 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1156 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1157 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1158 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1159 | if (!strcmp(node->name, "require-instance")) { |
| 1160 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1161 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1162 | goto error; |
| 1163 | } |
| 1164 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1165 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1166 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1167 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1168 | type->info.inst.req = -1; |
| 1169 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1170 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1171 | goto error; |
| 1172 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1173 | |
| 1174 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1175 | 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] | 1176 | goto error; |
| 1177 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1178 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1179 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1180 | goto error; |
| 1181 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1182 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1183 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1184 | break; |
| 1185 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1186 | case LY_TYPE_BINARY: |
| 1187 | /* 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] | 1188 | case LY_TYPE_INT8: |
| 1189 | case LY_TYPE_INT16: |
| 1190 | case LY_TYPE_INT32: |
| 1191 | case LY_TYPE_INT64: |
| 1192 | case LY_TYPE_UINT8: |
| 1193 | case LY_TYPE_UINT16: |
| 1194 | case LY_TYPE_UINT32: |
| 1195 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1196 | /* RFC 6020 9.2.4 - range */ |
| 1197 | |
| 1198 | /* length and range are actually the same restriction, so process |
| 1199 | * them by this common code, we just need to differ the name and |
| 1200 | * structure where the information will be stored |
| 1201 | */ |
| 1202 | if (type->base == LY_TYPE_BINARY) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1203 | restrs = &type->info.binary.length; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1204 | name = "length"; |
| 1205 | } else { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1206 | restrs = &type->info.num.range; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1207 | name = "range"; |
| 1208 | } |
| 1209 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1210 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1211 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1212 | if (!strcmp(node->name, name)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1213 | if (*restrs) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1214 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1215 | goto error; |
| 1216 | } |
| 1217 | |
| 1218 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1219 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1220 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1221 | goto error; |
| 1222 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1223 | *restrs = calloc(1, sizeof **restrs); |
| 1224 | if (!(*restrs)) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1225 | LOGMEM; |
| 1226 | goto error; |
| 1227 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1228 | (*restrs)->expr = lydict_insert(module->ctx, value, 0); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1229 | |
| 1230 | /* get possible substatements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1231 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, *restrs, node, unres)) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1232 | goto error; |
| 1233 | } |
| 1234 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1235 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1236 | goto error; |
| 1237 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1238 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1242 | /* flag resolving for later use */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1243 | if (!parenttype) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1244 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 1245 | if (siter) { |
| 1246 | /* just a flag - do not resolve */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1247 | parenttype = 1; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1248 | } |
| 1249 | } |
| 1250 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1251 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1252 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1253 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1254 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1255 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1256 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1257 | goto error; |
| 1258 | } |
| 1259 | |
| 1260 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1261 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1262 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1263 | if (!type->info.lref.path) { |
| 1264 | goto error; |
| 1265 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1266 | |
| 1267 | /* try to resolve leafref path only when this is instantiated |
| 1268 | * leaf, so it is not: |
| 1269 | * - typedef's type, |
| 1270 | * - in grouping definition, |
| 1271 | * - just instantiated in a grouping definition, |
| 1272 | * because in those cases the nodes referenced in path might not be present |
| 1273 | * and it is not a bug. */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1274 | 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] | 1275 | goto error; |
| 1276 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1277 | |
| 1278 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1279 | 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] | 1280 | goto error; |
| 1281 | } |
Radek Krejci | d6353ed | 2016-09-15 13:30:45 +0200 | [diff] [blame] | 1282 | } else if (module->version >= 2 && !strcmp(node->name, "require-instance")) { |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1283 | if (type->info.lref.req) { |
| 1284 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 1285 | goto error; |
| 1286 | } |
| 1287 | GETVAL(value, node, "value"); |
| 1288 | if (!strcmp(value, "true")) { |
| 1289 | type->info.lref.req = 1; |
| 1290 | } else if (!strcmp(value, "false")) { |
| 1291 | type->info.lref.req = -1; |
| 1292 | } else { |
| 1293 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 1294 | goto error; |
| 1295 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1296 | |
| 1297 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1298 | 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] | 1299 | goto error; |
| 1300 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1301 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1302 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1303 | goto error; |
| 1304 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1307 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1308 | if (!type->der->type.der) { |
| 1309 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
| 1310 | goto error; |
| 1311 | } else { |
| 1312 | /* copy leafref definition into the derived type */ |
| 1313 | type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0); |
| 1314 | /* 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] | 1315 | 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] | 1316 | goto error; |
| 1317 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1318 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1324 | /* RFC 6020 9.4.4 - length */ |
| 1325 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1326 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1327 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1328 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1329 | if (!strcmp(node->name, "length")) { |
| 1330 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1331 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1332 | goto error; |
| 1333 | } |
| 1334 | |
| 1335 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1336 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1337 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1338 | goto error; |
| 1339 | } |
| 1340 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1341 | if (!type->info.str.length) { |
| 1342 | LOGMEM; |
| 1343 | goto error; |
| 1344 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1345 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1346 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1347 | /* get possible sub-statements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1348 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, type->info.str.length, node, unres)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1349 | goto error; |
| 1350 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1351 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1352 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1353 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1354 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1355 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1356 | goto error; |
| 1357 | } |
| 1358 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1359 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1360 | if (i) { |
| 1361 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1362 | if (!type->info.str.patterns) { |
| 1363 | LOGMEM; |
| 1364 | goto error; |
| 1365 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1366 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1367 | GETVAL(value, node, "value"); |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 1368 | if (lyp_check_pattern(value, NULL)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1369 | free(type->info.str.patterns); |
Radek Krejci | 9f1e853 | 2016-06-16 11:18:21 +0200 | [diff] [blame] | 1370 | type->info.str.patterns = NULL; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1371 | goto error; |
| 1372 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1373 | restr = &type->info.str.patterns[type->info.str.pat_count]; /* shortcut */ |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1374 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1375 | modifier = 0x06; /* ACK */ |
| 1376 | name = NULL; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1377 | if (module->version >= 2) { |
| 1378 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1379 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 1380 | if (name) { |
| 1381 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 1382 | goto error; |
| 1383 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1384 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1385 | GETVAL(name, child, "value"); |
| 1386 | if (!strcmp(name, "invert-match")) { |
| 1387 | modifier = 0x15; /* NACK */ |
| 1388 | } else { |
| 1389 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 1390 | goto error; |
| 1391 | } |
| 1392 | /* get extensions of the modifier */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1393 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 1394 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1395 | return EXIT_FAILURE; |
| 1396 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1397 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1398 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1399 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | len = strlen(value); |
| 1404 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
| 1405 | buf[0] = modifier; |
| 1406 | strcpy(&buf[1], value); |
| 1407 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1408 | restr->expr = lydict_insert_zc(module->ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1409 | |
| 1410 | /* get possible sub-statements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1411 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, restr, node, unres)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1412 | free(type->info.str.patterns); |
Pavol Vican | 9fc5d64 | 2016-08-30 15:23:19 +0200 | [diff] [blame] | 1413 | type->info.str.patterns = NULL; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1414 | goto error; |
| 1415 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1416 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1417 | } |
| 1418 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1422 | /* RFC 6020 7.4 - type */ |
| 1423 | /* count number of types in union */ |
| 1424 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1425 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1426 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1427 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1428 | if (type->der->type.der) { |
| 1429 | /* type can be a substatement only in "union" type, not in derived types */ |
| 1430 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
| 1431 | goto error; |
| 1432 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1433 | i++; |
| 1434 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1435 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1436 | goto error; |
| 1437 | } |
| 1438 | } |
| 1439 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1440 | if (!i && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1441 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1442 | goto error; |
| 1443 | } |
| 1444 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1445 | /* inherit instid presence information */ |
| 1446 | if ((type->der->type.base == LY_TYPE_UNION) && type->der->type.info.uni.has_ptr_type) { |
| 1447 | type->info.uni.has_ptr_type = 1; |
| 1448 | } |
| 1449 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1450 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1451 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1452 | if (!type->info.uni.types) { |
| 1453 | LOGMEM; |
| 1454 | goto error; |
| 1455 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1456 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1457 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1458 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1459 | 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] | 1460 | if (!rc) { |
| 1461 | type->info.uni.count++; |
| 1462 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1463 | if (module->version < 2) { |
| 1464 | /* union's type cannot be empty or leafref */ |
| 1465 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 1466 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
| 1467 | rc = -1; |
| 1468 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 1469 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
| 1470 | rc = -1; |
| 1471 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1472 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1473 | |
| 1474 | if ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_INST) |
| 1475 | || (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF)) { |
| 1476 | type->info.uni.has_ptr_type = 1; |
| 1477 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1478 | } |
| 1479 | if (rc) { |
| 1480 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1481 | for (i = 0; i < type->info.uni.count; ++i) { |
| 1482 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 1483 | } |
| 1484 | free(type->info.uni.types); |
| 1485 | type->info.uni.types = NULL; |
| 1486 | type->info.uni.count = 0; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1487 | type->info.uni.has_ptr_type = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1488 | type->der = NULL; |
| 1489 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1490 | |
| 1491 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1492 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1493 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1494 | goto error; |
| 1495 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1496 | } |
| 1497 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1498 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1499 | case LY_TYPE_BOOL: |
| 1500 | case LY_TYPE_EMPTY: |
| 1501 | /* no sub-statement allowed */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1502 | if (yin->child) { |
| 1503 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->child->name); |
| 1504 | goto error; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1505 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1506 | break; |
| 1507 | |
| 1508 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1509 | LOGINT; |
| 1510 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1514 | |
| 1515 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1516 | if (type->module_name) { |
| 1517 | lydict_remove(module->ctx, type->module_name); |
| 1518 | type->module_name = NULL; |
| 1519 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1520 | lyxml_free_withsiblings(module->ctx, exts.child); |
| 1521 | |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1522 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1525 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1526 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1527 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, |
| 1528 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1529 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1530 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1531 | struct lyxml_elem *node, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1532 | int rc, has_type = 0, c_ext = 0; |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1533 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1535 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1536 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1537 | goto error; |
| 1538 | } |
| 1539 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1540 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1541 | /* generic part - status, description, reference */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1542 | 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] | 1543 | goto error; |
| 1544 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1545 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1546 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1547 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1548 | /* extension */ |
| 1549 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1550 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1551 | } else if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1552 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1553 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1554 | goto error; |
| 1555 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1556 | /* HACK for unres */ |
| 1557 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1558 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1559 | 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] | 1560 | goto error; |
| 1561 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1562 | has_type = 1; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1563 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1564 | /* 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] | 1565 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1566 | } else if (!strcmp(node->name, "default")) { |
| 1567 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1568 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1569 | goto error; |
| 1570 | } |
| 1571 | GETVAL(value, node, "value"); |
| 1572 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1573 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1574 | 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] | 1575 | goto error; |
| 1576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1577 | } else if (!strcmp(node->name, "units")) { |
| 1578 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1579 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1580 | goto error; |
| 1581 | } |
| 1582 | GETVAL(value, node, "name"); |
| 1583 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1584 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1585 | 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] | 1586 | goto error; |
| 1587 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1588 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1589 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1590 | goto error; |
| 1591 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1592 | |
| 1593 | lyxml_free(module->ctx, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1594 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1595 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1596 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1597 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1598 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1599 | goto error; |
| 1600 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1601 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1602 | /* check default value (if not defined, there still could be some restrictions |
| 1603 | * that need to be checked against a default value from a derived type) */ |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 1604 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&tpdf->dflt)) == -1) { |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1605 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1606 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1607 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1608 | /* finish extensions parsing */ |
| 1609 | if (c_ext) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1610 | /* some extensions may be already present from the substatements */ |
| 1611 | reallocated = realloc(tpdf->ext, (c_ext + tpdf->ext_size) * sizeof *tpdf->ext); |
| 1612 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1613 | LOGMEM; |
| 1614 | goto error; |
| 1615 | } |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1616 | tpdf->ext = reallocated; |
| 1617 | |
| 1618 | /* init memory */ |
| 1619 | memset(&tpdf->ext[tpdf->ext_size], 0, c_ext * sizeof *tpdf->ext); |
| 1620 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1621 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1622 | 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] | 1623 | tpdf->ext_size++; |
| 1624 | if (rc) { |
| 1625 | goto error; |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1630 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1631 | |
| 1632 | error: |
| 1633 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1634 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1637 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1638 | 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] | 1639 | { |
| 1640 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1641 | struct lyxml_elem *child, *node, *next, *next2; |
| 1642 | int c_ext = 0, rc; |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1643 | void *reallocated; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1644 | |
| 1645 | GETVAL(value, yin, "name"); |
| 1646 | |
| 1647 | if (lyp_check_identifier(value, LY_IDENT_EXTENSION, module, NULL)) { |
| 1648 | goto error; |
| 1649 | } |
| 1650 | ext->name = lydict_insert(module->ctx, value, strlen(value)); |
| 1651 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1652 | 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] | 1653 | goto error; |
| 1654 | } |
| 1655 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1656 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1657 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1658 | /* possible extension instance */ |
| 1659 | c_ext++; |
| 1660 | } else if (!strcmp(node->name, "argument")) { |
| 1661 | /* argument */ |
| 1662 | GETVAL(value, node, "name"); |
| 1663 | ext->argument = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1664 | 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] | 1665 | goto error; |
| 1666 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1667 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1668 | /* yin-element */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1669 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1670 | if (child->ns == node->ns && !strcmp(child->name, "yin-element")) { |
| 1671 | GETVAL(value, child, "value"); |
| 1672 | if (ly_strequal(value, "true", 0)) { |
| 1673 | ext->flags |= LYS_YINELEM; |
| 1674 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1675 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1676 | 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] | 1677 | goto error; |
| 1678 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1679 | } else if (child->ns) { |
| 1680 | /* unexpected YANG statement */ |
| 1681 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name); |
| 1682 | goto error; |
| 1683 | } /* else garbage, but save resource needed for unlinking */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1684 | } |
| 1685 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1686 | lyxml_free(module->ctx, node); |
| 1687 | } else { |
| 1688 | /* unexpected YANG statement */ |
| 1689 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->name); |
| 1690 | goto error; |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | if (c_ext) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1695 | /* some extensions may be already present from the substatements */ |
| 1696 | reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext); |
| 1697 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1698 | LOGMEM; |
| 1699 | goto error; |
| 1700 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1701 | ext->ext = reallocated; |
| 1702 | |
| 1703 | /* init memory */ |
| 1704 | memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext); |
| 1705 | |
| 1706 | /* process the extension instances of the extension itself */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1707 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1708 | 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] | 1709 | ext->ext_size++; |
| 1710 | if (rc) { |
| 1711 | goto error; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 1716 | /* search for plugin */ |
| 1717 | 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] | 1718 | |
| 1719 | return EXIT_SUCCESS; |
| 1720 | |
| 1721 | error: |
| 1722 | return EXIT_FAILURE; |
| 1723 | } |
| 1724 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1725 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1726 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1727 | 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] | 1728 | { |
| 1729 | const char *value; |
| 1730 | struct lyxml_elem *child, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1731 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1732 | void *reallocated; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1733 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1734 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1735 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1736 | goto error; |
| 1737 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1738 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1739 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1740 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1741 | 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] | 1742 | goto error; |
| 1743 | } |
| 1744 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1745 | LY_TREE_FOR(yin->child, child) { |
| 1746 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1747 | /* extension */ |
| 1748 | c_ext++; |
| 1749 | } else if (!strcmp(child->name, "if-feature")) { |
| 1750 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1751 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1752 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1753 | goto error; |
| 1754 | } |
| 1755 | } |
| 1756 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1757 | if (c_ftrs) { |
| 1758 | f->iffeature = calloc(c_ftrs, sizeof *f->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1759 | if (!f->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1760 | LOGMEM; |
| 1761 | goto error; |
| 1762 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1763 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1764 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1765 | /* some extensions may be already present from the substatements */ |
| 1766 | reallocated = realloc(f->ext, (c_ext + f->ext_size) * sizeof *f->ext); |
| 1767 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1768 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1769 | goto error; |
| 1770 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1771 | f->ext = reallocated; |
| 1772 | |
| 1773 | /* init memory */ |
| 1774 | memset(&f->ext[f->ext_size], 0, c_ext * sizeof *f->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1777 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1778 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1779 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1780 | 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] | 1781 | f->ext_size++; |
| 1782 | if (ret) { |
| 1783 | goto error; |
| 1784 | } |
| 1785 | } else { /* if-feature */ |
| 1786 | ret = fill_yin_iffeature((struct lys_node *)f, 1, child, &f->iffeature[f->iffeature_size], unres); |
| 1787 | f->iffeature_size++; |
| 1788 | if (ret) { |
| 1789 | goto error; |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1794 | /* check for circular dependencies */ |
| 1795 | if (f->iffeature_size) { |
| 1796 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1797 | goto error; |
| 1798 | } |
| 1799 | } |
| 1800 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1801 | return EXIT_SUCCESS; |
| 1802 | |
| 1803 | error: |
| 1804 | |
| 1805 | return EXIT_FAILURE; |
| 1806 | } |
| 1807 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1808 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1809 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1810 | 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] | 1811 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1812 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1813 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1814 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1815 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1816 | if (!must->expr) { |
| 1817 | goto error; |
| 1818 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1819 | |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1820 | return read_restr_substmt(module, LYEXT_PAR_RESTR, must, yin, unres); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1821 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1822 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1823 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1824 | } |
| 1825 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1826 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1827 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1828 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1829 | { |
| 1830 | int i, j; |
| 1831 | const char *value, *vaux; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1832 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1833 | |
| 1834 | /* get unique value (list of leafs supposed to be unique */ |
| 1835 | GETVAL(value, yin, "tag"); |
| 1836 | |
| 1837 | /* count the number of unique leafs in the value */ |
| 1838 | vaux = value; |
| 1839 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1840 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1841 | while (isspace(*vaux)) { |
| 1842 | vaux++; |
| 1843 | } |
| 1844 | } |
| 1845 | unique->expr_size++; |
| 1846 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1847 | if (!unique->expr) { |
| 1848 | LOGMEM; |
| 1849 | goto error; |
| 1850 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1851 | |
| 1852 | for (i = 0; i < unique->expr_size; i++) { |
| 1853 | vaux = strpbrk(value, " \t\n"); |
| 1854 | if (!vaux) { |
| 1855 | /* the last token, lydict_insert() will count its size on its own */ |
| 1856 | vaux = value; |
| 1857 | } |
| 1858 | |
| 1859 | /* store token into unique structure */ |
| 1860 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1861 | |
| 1862 | /* check that the expression does not repeat */ |
| 1863 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1864 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1865 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1866 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1867 | goto error; |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | /* try to resolve leaf */ |
| 1872 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1873 | unique_info = malloc(sizeof *unique_info); |
| 1874 | unique_info->list = parent; |
| 1875 | unique_info->expr = unique->expr[i]; |
| 1876 | unique_info->trg_type = &unique->trg_type; |
| 1877 | 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] | 1878 | goto error; |
| 1879 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1880 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1881 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1882 | goto error; |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | /* move to next token */ |
| 1887 | value = vaux; |
| 1888 | while(isspace(*value)) { |
| 1889 | value++; |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | return EXIT_SUCCESS; |
| 1894 | |
| 1895 | error: |
| 1896 | return EXIT_FAILURE; |
| 1897 | } |
| 1898 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1899 | /* logs directly |
| 1900 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1901 | * type: 0 - min, 1 - max |
| 1902 | */ |
| 1903 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1904 | 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] | 1905 | { |
| 1906 | const char *value; |
| 1907 | char *endptr; |
| 1908 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1909 | uint32_t *ui32val, *min, *max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1910 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1911 | /* del min/max is forbidden */ |
| 1912 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1913 | LOGVAL(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] | 1914 | goto error; |
| 1915 | } |
| 1916 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1917 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1918 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1919 | max = &((struct lys_node_leaflist *)target)->max; |
| 1920 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1921 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1922 | max = &((struct lys_node_list *)target)->max; |
| 1923 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1924 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1925 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1926 | LOGVAL(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] | 1927 | goto error; |
| 1928 | } |
| 1929 | |
| 1930 | GETVAL(value, node, "value"); |
| 1931 | while (isspace(value[0])) { |
| 1932 | value++; |
| 1933 | } |
| 1934 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1935 | if (type && !strcmp(value, "unbounded")) { |
| 1936 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1937 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1938 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1939 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1940 | /* convert it to uint32_t */ |
| 1941 | errno = 0; |
| 1942 | endptr = NULL; |
| 1943 | val = strtoul(value, &endptr, 10); |
| 1944 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1945 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1946 | goto error; |
| 1947 | } |
| 1948 | if (type) { |
| 1949 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1950 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1951 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1952 | } else { |
| 1953 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1954 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1955 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1956 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | if (d->mod == LY_DEVIATE_ADD) { |
| 1960 | /* check that there is no current value */ |
| 1961 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1962 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1963 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1964 | goto error; |
| 1965 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1966 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1967 | /* unfortunately, there is no way to check reliably that there |
| 1968 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1969 | } |
| 1970 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1971 | /* add (already checked) and replace */ |
| 1972 | /* set new value specified in deviation */ |
| 1973 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1974 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1975 | /* check min-elements is smaller than max-elements */ |
| 1976 | if (*max && *min > *max) { |
| 1977 | if (type) { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 1978 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "max-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1979 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
| 1980 | } else { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 1981 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "min-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1982 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 1983 | } |
| 1984 | goto error; |
| 1985 | } |
| 1986 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1987 | return EXIT_SUCCESS; |
| 1988 | |
| 1989 | error: |
| 1990 | |
| 1991 | return EXIT_FAILURE; |
| 1992 | } |
| 1993 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1994 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1995 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1996 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1997 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1998 | { |
| 1999 | const char *value, **stritem; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2000 | struct lyxml_elem *next, *next2, *child, *develem; |
| 2001 | 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] | 2002 | int f_min = 0, f_max = 0; /* flags */ |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2003 | int i, j, k, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2004 | unsigned int u; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2005 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2006 | struct lys_deviate *d = NULL; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2007 | struct lys_node *node = NULL, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2008 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2009 | struct lys_node_leaf *leaf = NULL; |
| 2010 | struct ly_set *dflt_check = ly_set_new(); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2011 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2012 | struct lys_node_leaflist *llist = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2013 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2014 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2015 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2016 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2017 | struct lys_module *mod; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2018 | void *reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2019 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2020 | ctx = module->ctx; |
| 2021 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2022 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2023 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2024 | if (!dev->target_name) { |
| 2025 | goto error; |
| 2026 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2027 | |
| 2028 | /* resolve target node */ |
Radek Krejci | df46e22 | 2016-11-08 11:57:37 +0100 | [diff] [blame] | 2029 | rc = resolve_augment_schema_nodeid(dev->target_name, NULL, module, 1, (const struct lys_node **)&dev_target); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2030 | if (rc || !dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2031 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2032 | goto error; |
| 2033 | } |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2034 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2035 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 2036 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2037 | goto error; |
| 2038 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2039 | |
| 2040 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2041 | if (!child->ns ) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2042 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2043 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2044 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2045 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2046 | /* extension */ |
| 2047 | c_ext++; |
| 2048 | continue; |
| 2049 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2050 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2051 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2052 | goto error; |
| 2053 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2054 | 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] | 2055 | goto error; |
| 2056 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2057 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2058 | if (!dev->dsc) { |
| 2059 | goto error; |
| 2060 | } |
| 2061 | } else if (!strcmp(child->name, "reference")) { |
| 2062 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2063 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2064 | goto error; |
| 2065 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2066 | 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] | 2067 | goto error; |
| 2068 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2069 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2070 | if (!dev->ref) { |
| 2071 | goto error; |
| 2072 | } |
| 2073 | } else if (!strcmp(child->name, "deviate")) { |
| 2074 | c_dev++; |
| 2075 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2076 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2077 | * further processed later |
| 2078 | */ |
| 2079 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2080 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2081 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2082 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2083 | goto error; |
| 2084 | } |
| 2085 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2086 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | if (c_dev) { |
| 2090 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2091 | if (!dev->deviate) { |
| 2092 | LOGMEM; |
| 2093 | goto error; |
| 2094 | } |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2095 | } else { |
| 2096 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
| 2097 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2098 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2099 | if (c_ext) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2100 | /* some extensions may be already present from the substatements */ |
| 2101 | reallocated = realloc(dev->ext, (c_ext + dev->ext_size) * sizeof *dev->ext); |
| 2102 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2103 | LOGMEM; |
| 2104 | goto error; |
| 2105 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2106 | dev->ext = reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2107 | |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2108 | /* init memory */ |
| 2109 | memset(&dev->ext[dev->ext_size], 0, c_ext * sizeof *dev->ext); |
| 2110 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2111 | |
| 2112 | LY_TREE_FOR_SAFE(yin->child, next, develem) { |
| 2113 | if (strcmp(develem->ns->value, LY_NSYIN)) { |
| 2114 | /* deviation's extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 2115 | 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] | 2116 | dev->ext_size++; |
| 2117 | if (rc) { |
| 2118 | goto error; |
| 2119 | } |
| 2120 | continue; |
| 2121 | } |
| 2122 | |
| 2123 | /* deviate */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2124 | /* init */ |
| 2125 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2126 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2127 | c_must = 0; |
| 2128 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2129 | c_dflt = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2130 | c_ext = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2131 | |
| 2132 | /* get deviation type */ |
| 2133 | GETVAL(value, develem, "value"); |
| 2134 | if (!strcmp(value, "not-supported")) { |
| 2135 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2136 | /* no other deviate statement is expected, |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2137 | * not-supported deviation must be the only deviation of the target |
| 2138 | */ |
| 2139 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2140 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2141 | LOGVAL(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] | 2142 | goto error; |
| 2143 | } |
| 2144 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2145 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 2146 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 2147 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 2148 | if (((struct lys_node_list *)lys_parent(dev_target))->keys[i] == (struct lys_node_leaf *)dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2149 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2150 | LOGVAL(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] | 2151 | goto error; |
| 2152 | } |
| 2153 | } |
| 2154 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2155 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2156 | /* unlink and store the original node */ |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2157 | parent = dev_target->parent; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2158 | lys_node_unlink(dev_target); |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2159 | if (parent && parent->nodetype == LYS_AUGMENT) { |
| 2160 | /* hack for augment, because when the original will be sometime reconnected back, we actually need |
| 2161 | * to reconnect it to both - the augment and its target (which is deduced from the deviations target |
| 2162 | * path), so we need to remember the augment as an addition */ |
| 2163 | dev_target->parent = parent; |
| 2164 | } |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2165 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2166 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2167 | } else if (!strcmp(value, "add")) { |
| 2168 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 2169 | } else if (!strcmp(value, "replace")) { |
| 2170 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 2171 | } else if (!strcmp(value, "delete")) { |
| 2172 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 2173 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2174 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2175 | goto error; |
| 2176 | } |
| 2177 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 2178 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2179 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2180 | /* store a shallow copy of the original node */ |
| 2181 | if (!dev->orig_node) { |
| 2182 | memset(&tmp_unres, 0, sizeof tmp_unres); |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 2183 | 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] | 2184 | /* just to be safe */ |
| 2185 | if (tmp_unres.count) { |
| 2186 | LOGINT; |
| 2187 | goto error; |
| 2188 | } |
| 2189 | } |
| 2190 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2191 | /* process deviation properties */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2192 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2193 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2194 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2195 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2196 | continue; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2197 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2198 | /* extensions */ |
| 2199 | c_ext++; |
| 2200 | } else if (d->mod == LY_DEVIATE_NO) { |
| 2201 | /* no YIN substatement expected in this case */ |
| 2202 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2203 | goto error; |
| 2204 | } else if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2205 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2206 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2207 | goto error; |
| 2208 | } |
| 2209 | |
| 2210 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 2211 | * specified in the target explicitly since config property inherits. So we expect |
| 2212 | * that config is specified in every node. But for delete, we check that the value |
| 2213 | * is the same as here in deviation |
| 2214 | */ |
| 2215 | GETVAL(value, child, "value"); |
| 2216 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2217 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2218 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2219 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2220 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2221 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2222 | goto error; |
| 2223 | } |
| 2224 | |
| 2225 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2226 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2227 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2228 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2229 | } else { /* add and replace are the same in this case */ |
| 2230 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2231 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2232 | |
| 2233 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2234 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2235 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2236 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2237 | 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] | 2238 | goto error; |
| 2239 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2240 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2241 | 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] | 2242 | goto error; |
| 2243 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2244 | c_dflt++; |
| 2245 | |
| 2246 | /* check target node type */ |
| 2247 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
| 2248 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2249 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
| 2250 | goto error; |
| 2251 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
| 2252 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2253 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
| 2254 | goto error; |
| 2255 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
| 2256 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2257 | LOGVAL(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] | 2258 | goto error; |
| 2259 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2260 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2261 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 2262 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2263 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2264 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2265 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2266 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2267 | goto error; |
| 2268 | } |
| 2269 | |
| 2270 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2271 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2272 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2273 | LOGVAL(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] | 2274 | goto error; |
| 2275 | } |
| 2276 | |
| 2277 | GETVAL(value, child, "value"); |
| 2278 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2279 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2280 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2281 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2282 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2283 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2284 | goto error; |
| 2285 | } |
| 2286 | |
| 2287 | if (d->mod == LY_DEVIATE_ADD) { |
| 2288 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2289 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2290 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2291 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2292 | goto error; |
| 2293 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2294 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2295 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2296 | if (d->flags & LYS_MAND_TRUE) { |
| 2297 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2298 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
| 2299 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2300 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2301 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 2302 | goto error; |
| 2303 | } |
| 2304 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2305 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
| 2306 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2307 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2308 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 2309 | goto error; |
| 2310 | } |
| 2311 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2312 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2313 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2314 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 2315 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2316 | /* check that there was a value before */ |
| 2317 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2318 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2319 | LOGVAL(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] | 2320 | goto error; |
| 2321 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2322 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2323 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2324 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2325 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2326 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2327 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2328 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2329 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2330 | |
| 2331 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 2332 | for (parent = dev_target->parent; |
| 2333 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 2334 | parent = parent->parent) { |
| 2335 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 2336 | /* stop also on presence containers */ |
| 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 2341 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 2342 | if (lyp_check_mandatory_choice(parent)) { |
| 2343 | goto error; |
| 2344 | } |
| 2345 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2346 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2347 | 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] | 2348 | goto error; |
| 2349 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2350 | } else if (!strcmp(child->name, "min-elements")) { |
| 2351 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2352 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2353 | goto error; |
| 2354 | } |
| 2355 | f_min = 1; |
| 2356 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2357 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2358 | goto error; |
| 2359 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2360 | 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] | 2361 | goto error; |
| 2362 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2363 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2364 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2365 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2366 | goto error; |
| 2367 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2368 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2369 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2370 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2371 | goto error; |
| 2372 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2373 | 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] | 2374 | goto error; |
| 2375 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2376 | } else if (!strcmp(child->name, "must")) { |
| 2377 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2378 | /* 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] | 2379 | continue; |
| 2380 | } else if (!strcmp(child->name, "type")) { |
| 2381 | if (d->type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2382 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2383 | goto error; |
| 2384 | } |
| 2385 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2386 | /* add, del type is forbidden */ |
| 2387 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2388 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2389 | goto error; |
| 2390 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2391 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2392 | goto error; |
| 2393 | } |
| 2394 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2395 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2396 | if (dev_target->nodetype == LYS_LEAF) { |
| 2397 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2398 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 2399 | ly_set_add(dflt_check, dev_target, 0); |
| 2400 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2401 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2402 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2403 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 2404 | ly_set_add(dflt_check, dev_target, 0); |
| 2405 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2406 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2407 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2408 | LOGVAL(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] | 2409 | goto error; |
| 2410 | } |
| 2411 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2412 | /* replace */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2413 | lys_type_free(ctx, t); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2414 | /* HACK for unres */ |
| 2415 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 2416 | 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] | 2417 | goto error; |
| 2418 | } |
| 2419 | d->type = t; |
| 2420 | } else if (!strcmp(child->name, "unique")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2421 | 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] | 2422 | goto error; |
| 2423 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2424 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2425 | /* 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] | 2426 | continue; |
| 2427 | } else if (!strcmp(child->name, "units")) { |
| 2428 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2429 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2430 | goto error; |
| 2431 | } |
| 2432 | |
| 2433 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2434 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2435 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 2436 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2437 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2438 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2439 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2440 | LOGVAL(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] | 2441 | goto error; |
| 2442 | } |
| 2443 | |
| 2444 | /* get units value */ |
| 2445 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2446 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2447 | |
| 2448 | /* apply to target */ |
| 2449 | if (d->mod == LY_DEVIATE_ADD) { |
| 2450 | /* check that there is no current value */ |
| 2451 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2452 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2453 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2454 | goto error; |
| 2455 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2456 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2457 | *stritem = lydict_insert(ctx, value, 0); |
| 2458 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2459 | /* check that there was a value before */ |
| 2460 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2461 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2462 | LOGVAL(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] | 2463 | goto error; |
| 2464 | } |
| 2465 | |
| 2466 | lydict_remove(ctx, *stritem); |
| 2467 | *stritem = lydict_insert(ctx, value, 0); |
| 2468 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2469 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2470 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2471 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2472 | LOGVAL(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] | 2473 | goto error; |
| 2474 | } |
| 2475 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2476 | lydict_remove(ctx, *stritem); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2477 | (*stritem) = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2478 | |
| 2479 | /* remove its extensions */ |
| 2480 | j = -1; |
| 2481 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNITS)) != -1) { |
| 2482 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2483 | --j; |
| 2484 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2485 | } |
| 2486 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2487 | 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] | 2488 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2489 | } |
| 2490 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2491 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2492 | goto error; |
| 2493 | } |
| 2494 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2495 | /* 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] | 2496 | } |
| 2497 | |
| 2498 | if (c_must) { |
| 2499 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2500 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2501 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2502 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2503 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2504 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2505 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2506 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2507 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2508 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2509 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2510 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2511 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2512 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2513 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2514 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2515 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2516 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2517 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2518 | case LYS_ANYDATA: |
| 2519 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2520 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2521 | break; |
| 2522 | default: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2523 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2524 | LOGVAL(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] | 2525 | goto error; |
| 2526 | } |
| 2527 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 2528 | dev_target->flags &= ~LYS_XPATH_DEP; |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2529 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2530 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2531 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2532 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2533 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2534 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2535 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2536 | d->must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2537 | if (!d->must) { |
| 2538 | LOGMEM; |
| 2539 | goto error; |
| 2540 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2541 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 2542 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2543 | d->must_size = c_must; |
| 2544 | } else { /* LY_DEVIATE_DEL */ |
| 2545 | d->must = calloc(c_must, sizeof *d->must); |
| 2546 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2547 | if (!d->must) { |
| 2548 | LOGMEM; |
| 2549 | goto error; |
| 2550 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2551 | } |
| 2552 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2553 | /* replace unique is forbidden */ |
| 2554 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2555 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2556 | goto error; |
| 2557 | } |
| 2558 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2559 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2560 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2561 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2562 | LOGVAL(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] | 2563 | goto error; |
| 2564 | } |
| 2565 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2566 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2567 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2568 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2569 | d->unique = ly_realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2570 | list->unique = d->unique; |
| 2571 | d->unique = &list->unique[list->unique_size]; |
| 2572 | d->unique_size = c_uniq; |
| 2573 | } else { /* LY_DEVIATE_DEL */ |
| 2574 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 2575 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2576 | if (!d->unique) { |
| 2577 | LOGMEM; |
| 2578 | goto error; |
| 2579 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2580 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2581 | if (c_dflt) { |
| 2582 | if (d->mod == LY_DEVIATE_ADD) { |
| 2583 | /* check that there is no current value */ |
| 2584 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2585 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
| 2586 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2587 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
| 2588 | goto error; |
| 2589 | } |
| 2590 | |
| 2591 | /* check collision with mandatory/min-elements */ |
| 2592 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2593 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
| 2594 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2595 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2596 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2597 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2598 | goto error; |
| 2599 | } |
| 2600 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2601 | /* check that there was a value before */ |
| 2602 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2603 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
| 2604 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2605 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
| 2606 | goto error; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2611 | /* reallocate default list in the target */ |
| 2612 | llist = (struct lys_node_leaflist *)dev_target; |
| 2613 | if (d->mod == LY_DEVIATE_ADD) { |
| 2614 | /* reallocate (enlarge) the unique array of the target */ |
| 2615 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
| 2616 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2617 | /* reallocate (replace) the unique array of the target */ |
| 2618 | for (i = 0; i < llist->dflt_size; i++) { |
| 2619 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2620 | } |
| 2621 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2622 | llist->dflt_size = 0; |
| 2623 | } |
| 2624 | } |
| 2625 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
| 2626 | if (!d->dflt) { |
| 2627 | LOGMEM; |
| 2628 | goto error; |
| 2629 | } |
| 2630 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2631 | if (c_ext) { |
| 2632 | /* some extensions may be already present from the substatements */ |
| 2633 | reallocated = realloc(d->ext, (c_ext + d->ext_size) * sizeof *d->ext); |
| 2634 | if (!reallocated) { |
| 2635 | LOGMEM; |
| 2636 | goto error; |
| 2637 | } |
| 2638 | d->ext = reallocated; |
| 2639 | |
| 2640 | /* init memory */ |
| 2641 | memset(&d->ext[d->ext_size], 0, c_ext * sizeof *d->ext); |
| 2642 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2643 | |
| 2644 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2645 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
| 2646 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2647 | /* extension */ |
| 2648 | if (lyp_yin_fill_ext(d, LYEXT_PAR_DEVIATE, 0, 0, module, child, &d->ext, d->ext_size, unres)) { |
| 2649 | goto error; |
| 2650 | } |
| 2651 | d->ext_size++; |
| 2652 | } else if (!strcmp(child->name, "must")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2653 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2654 | if (fill_yin_must(module, child, &d->must[d->must_size], unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2655 | goto error; |
| 2656 | } |
| 2657 | |
| 2658 | /* find must to delete, we are ok with just matching conditions */ |
| 2659 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2660 | 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] | 2661 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2662 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2663 | /* ... and maintain the array */ |
| 2664 | (*trg_must_size)--; |
| 2665 | if (i != *trg_must_size) { |
| 2666 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2667 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2668 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2669 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2670 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2671 | } |
| 2672 | if (!(*trg_must_size)) { |
| 2673 | free(*trg_must); |
| 2674 | *trg_must = NULL; |
| 2675 | } else { |
| 2676 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2677 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2678 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2679 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2680 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2681 | } |
| 2682 | |
| 2683 | i = -1; /* set match flag */ |
| 2684 | break; |
| 2685 | } |
| 2686 | } |
| 2687 | d->must_size++; |
| 2688 | if (i != -1) { |
| 2689 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2690 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2691 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2692 | LOGVAL(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] | 2693 | goto error; |
| 2694 | } |
| 2695 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2696 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2697 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]), unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2698 | goto error; |
| 2699 | } |
| 2700 | (*trg_must_size)++; |
| 2701 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2702 | |
| 2703 | /* check XPath dependencies again */ |
Michal Vasko | e873426 | 2016-09-29 14:12:06 +0200 | [diff] [blame] | 2704 | if (*trg_must_size && unres_schema_add_node(module, unres, dev_target, UNRES_XPATH, NULL)) { |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2705 | goto error; |
| 2706 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2707 | } else if (!strcmp(child->name, "unique")) { |
| 2708 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2709 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2710 | 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] | 2711 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2712 | goto error; |
| 2713 | } |
| 2714 | |
| 2715 | /* find unique structures to delete */ |
| 2716 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2717 | 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] | 2718 | continue; |
| 2719 | } |
| 2720 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2721 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2722 | 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] | 2723 | break; |
| 2724 | } |
| 2725 | } |
| 2726 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2727 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2728 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2729 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2730 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2731 | } |
| 2732 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2733 | /* ... and maintain the array */ |
| 2734 | list->unique_size--; |
| 2735 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2736 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2737 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | if (!list->unique_size) { |
| 2741 | free(list->unique); |
| 2742 | list->unique = NULL; |
| 2743 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2744 | list->unique[list->unique_size].expr_size = 0; |
| 2745 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2746 | } |
| 2747 | |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2748 | k = i; /* remember index for removing extensions */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2749 | i = -1; /* set match flag */ |
| 2750 | break; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | d->unique_size++; |
| 2755 | if (i != -1) { |
| 2756 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2757 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2758 | LOGVAL(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] | 2759 | goto error; |
| 2760 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2761 | |
| 2762 | /* remove extensions of this unique instance from the target node */ |
| 2763 | j = -1; |
| 2764 | 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] | 2765 | if (dev_target->ext[j]->insubstmt_index == k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2766 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2767 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2768 | } else if (dev_target->ext[j]->insubstmt_index > k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2769 | /* 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] | 2770 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2771 | } |
| 2772 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2773 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2774 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2775 | 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] | 2776 | list->unique_size++; |
| 2777 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2778 | goto error; |
| 2779 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2780 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2781 | } else if (!strcmp(child->name, "default")) { |
| 2782 | GETVAL(value, child, "value"); |
| 2783 | u = strlen(value); |
| 2784 | d->dflt[d->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2785 | |
| 2786 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2787 | choice = (struct lys_node_choice *)dev_target; |
| 2788 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2789 | if (rc || !node) { |
| 2790 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2791 | goto error; |
| 2792 | } |
| 2793 | if (d->mod == LY_DEVIATE_DEL) { |
| 2794 | if (!choice->dflt || (choice->dflt != node)) { |
| 2795 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2796 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2797 | goto error; |
| 2798 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2799 | choice->dflt = NULL; |
| 2800 | /* remove extensions of this default instance from the target node */ |
| 2801 | j = -1; |
| 2802 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2803 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2804 | --j; |
| 2805 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2806 | } else { /* add or replace */ |
| 2807 | choice->dflt = node; |
| 2808 | if (!choice->dflt) { |
| 2809 | /* default branch not found */ |
| 2810 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2811 | goto error; |
| 2812 | } |
| 2813 | } |
| 2814 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2815 | leaf = (struct lys_node_leaf *)dev_target; |
| 2816 | if (d->mod == LY_DEVIATE_DEL) { |
| 2817 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
| 2818 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2819 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2820 | goto error; |
| 2821 | } |
| 2822 | /* remove value */ |
| 2823 | lydict_remove(ctx, leaf->dflt); |
| 2824 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2825 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2826 | |
| 2827 | /* remove extensions of this default instance from the target node */ |
| 2828 | j = -1; |
| 2829 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2830 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2831 | --j; |
| 2832 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2833 | } else { /* add (already checked) and replace */ |
| 2834 | /* remove value */ |
| 2835 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2836 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2837 | |
| 2838 | /* set new value */ |
| 2839 | leaf->dflt = lydict_insert(ctx, value, u); |
| 2840 | |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2841 | /* 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] | 2842 | ly_set_add(dflt_check, dev_target, 0); |
| 2843 | } |
| 2844 | } else { /* LYS_LEAFLIST */ |
| 2845 | llist = (struct lys_node_leaflist *)dev_target; |
| 2846 | if (d->mod == LY_DEVIATE_DEL) { |
| 2847 | /* find and remove the value in target list */ |
| 2848 | for (i = 0; i < llist->dflt_size; i++) { |
| 2849 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 2850 | /* match, remove the value */ |
| 2851 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2852 | llist->dflt[i] = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2853 | |
| 2854 | /* remove extensions of this default instance from the target node */ |
| 2855 | j = -1; |
| 2856 | 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] | 2857 | if (dev_target->ext[j]->insubstmt_index == i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2858 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2859 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2860 | } else if (dev_target->ext[j]->insubstmt_index > i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2861 | /* 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] | 2862 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2863 | } |
| 2864 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2865 | break; |
| 2866 | } |
| 2867 | } |
| 2868 | if (i == llist->dflt_size) { |
| 2869 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2870 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
| 2871 | goto error; |
| 2872 | } |
| 2873 | } else { |
| 2874 | /* add or replace, anyway we place items into the deviate's list |
| 2875 | which propagates to the target */ |
| 2876 | /* we just want to check that the value isn't already in the list */ |
| 2877 | for (i = 0; i < llist->dflt_size; i++) { |
| 2878 | if (ly_strequal(llist->dflt[i], value, 1)) { |
| 2879 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2880 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2881 | goto error; |
| 2882 | } |
| 2883 | } |
| 2884 | /* store it in target node */ |
| 2885 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2886 | |
| 2887 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2888 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2889 | llist->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2890 | } |
| 2891 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2892 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2893 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2894 | |
| 2895 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 2896 | /* consolidate the final list in the target after removing items from it */ |
| 2897 | llist = (struct lys_node_leaflist *)dev_target; |
| 2898 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 2899 | llist->dflt[i] = llist->dflt[j]; |
| 2900 | if (llist->dflt[i]) { |
| 2901 | i++; |
| 2902 | } |
| 2903 | } |
| 2904 | llist->dflt_size = i + 1; |
| 2905 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2906 | } |
| 2907 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2908 | /* now check whether default value, if any, matches the type */ |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 2909 | for (u = 0; u < dflt_check->number; ++u) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2910 | value = NULL; |
| 2911 | rc = EXIT_SUCCESS; |
| 2912 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 2913 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2914 | value = leaf->dflt; |
| 2915 | rc = unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt)); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2916 | } else { /* LYS_LEAFLIST */ |
| 2917 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 2918 | for (j = 0; j < llist->dflt_size; j++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2919 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 2920 | (struct lys_node *)(&llist->dflt[j])); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2921 | if (rc == -1) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2922 | value = llist->dflt[j]; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2923 | break; |
| 2924 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2925 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2926 | |
| 2927 | } |
| 2928 | if (rc == -1) { |
| 2929 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2930 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2931 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 2932 | dev->target_name); |
| 2933 | goto error; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2934 | } |
| 2935 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2936 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2937 | /* mark all the affected modules as deviated and implemented */ |
| 2938 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 2939 | mod = lys_node_module(parent); |
| 2940 | if (module != mod) { |
| 2941 | mod->deviated = 1; |
| 2942 | lys_set_implemented(mod); |
| 2943 | } |
| 2944 | } |
| 2945 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2946 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2947 | return EXIT_SUCCESS; |
| 2948 | |
| 2949 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2950 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2951 | return EXIT_FAILURE; |
| 2952 | } |
| 2953 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2954 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2955 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2956 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2957 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2958 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2959 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2960 | struct lyxml_elem *sub, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2961 | struct lys_node *node; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2962 | int ret, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2963 | void *reallocated; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2964 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 2965 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2966 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2967 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 2968 | if (!aug->target_name) { |
| 2969 | goto error; |
| 2970 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2971 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2972 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 2973 | 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] | 2974 | goto error; |
| 2975 | } |
| 2976 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2977 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 2978 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2979 | /* extension */ |
| 2980 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2981 | continue; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2982 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2983 | c_ftrs++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2984 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2985 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2986 | if (aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2987 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2988 | goto error; |
| 2989 | } |
| 2990 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 2991 | aug->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2992 | if (!aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2993 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2994 | goto error; |
| 2995 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2996 | lyxml_free(module->ctx, sub); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2997 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2998 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2999 | /* check allowed data sub-statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3000 | } else if (!strcmp(sub->name, "container")) { |
| 3001 | node = read_yin_container(module, (struct lys_node *)aug, sub, 1, unres); |
| 3002 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 3003 | node = read_yin_leaflist(module, (struct lys_node *)aug, sub, 1, unres); |
| 3004 | } else if (!strcmp(sub->name, "leaf")) { |
| 3005 | node = read_yin_leaf(module, (struct lys_node *)aug, sub, 1, unres); |
| 3006 | } else if (!strcmp(sub->name, "list")) { |
| 3007 | node = read_yin_list(module, (struct lys_node *)aug, sub, 1, unres); |
| 3008 | } else if (!strcmp(sub->name, "uses")) { |
| 3009 | node = read_yin_uses(module, (struct lys_node *)aug, sub, unres); |
| 3010 | } else if (!strcmp(sub->name, "choice")) { |
| 3011 | node = read_yin_choice(module, (struct lys_node *)aug, sub, 1, unres); |
| 3012 | } else if (!strcmp(sub->name, "case")) { |
| 3013 | node = read_yin_case(module, (struct lys_node *)aug, sub, 1, unres); |
| 3014 | } else if (!strcmp(sub->name, "anyxml")) { |
| 3015 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYXML, 1, unres); |
| 3016 | } else if (!strcmp(sub->name, "anydata")) { |
| 3017 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYDATA, 1, unres); |
| 3018 | } else if (!strcmp(sub->name, "action")) { |
| 3019 | node = read_yin_rpc_action(module, (struct lys_node *)aug, sub, unres); |
| 3020 | } else if (!strcmp(sub->name, "notification")) { |
| 3021 | node = read_yin_notif(module, (struct lys_node *)aug, sub, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3022 | } else { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3023 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3024 | goto error; |
| 3025 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3026 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3027 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3028 | goto error; |
| 3029 | } |
| 3030 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3031 | node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3032 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3033 | } |
| 3034 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3035 | if (c_ftrs) { |
| 3036 | aug->iffeature = calloc(c_ftrs, sizeof *aug->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3037 | if (!aug->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3038 | LOGMEM; |
| 3039 | goto error; |
| 3040 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3041 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3042 | if (c_ext) { |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3043 | /* some extensions may be already present from the substatements */ |
| 3044 | reallocated = realloc(aug->ext, (c_ext + aug->ext_size) * sizeof *aug->ext); |
| 3045 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3046 | LOGMEM; |
| 3047 | goto error; |
| 3048 | } |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3049 | aug->ext = reallocated; |
| 3050 | |
| 3051 | /* init memory */ |
| 3052 | memset(&aug->ext[aug->ext_size], 0, c_ext * sizeof *aug->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3053 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3054 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3055 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3056 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3057 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3058 | 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] | 3059 | aug->ext_size++; |
| 3060 | if (ret) { |
| 3061 | goto error; |
| 3062 | } |
| 3063 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3064 | 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] | 3065 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3066 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3067 | goto error; |
| 3068 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3069 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3070 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3071 | } |
| 3072 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3073 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3074 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3075 | * 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] | 3076 | * when the uses does and cannot be resolved now for sure |
| 3077 | * (the grouping was not yet copied into uses). |
| 3078 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3079 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3080 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 3081 | goto error; |
| 3082 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3083 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3084 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3085 | /* check XPath dependencies */ |
| 3086 | if (aug->when && (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1)) { |
| 3087 | goto error; |
| 3088 | } |
| 3089 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3090 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3091 | |
| 3092 | error: |
| 3093 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3094 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3095 | } |
| 3096 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3097 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3098 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3099 | 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] | 3100 | { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3101 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3102 | struct lyxml_elem *sub, *next; |
| 3103 | const char *value; |
| 3104 | char *endptr; |
| 3105 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3106 | 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] | 3107 | int r; |
| 3108 | unsigned long int val; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3109 | void *reallocated; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3110 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3111 | assert(uses); |
| 3112 | module = uses->module; /* shorthand */ |
| 3113 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3114 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3115 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 3116 | if (!rfn->target_name) { |
| 3117 | goto error; |
| 3118 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3119 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3120 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3121 | if (!sub->ns) { |
| 3122 | /* garbage */ |
| 3123 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3124 | /* extension */ |
| 3125 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3126 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3127 | |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3128 | } else if (!strcmp(sub->name, "description")) { |
| 3129 | if (rfn->dsc) { |
| 3130 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3131 | goto error; |
| 3132 | } |
| 3133 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3134 | 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] | 3135 | goto error; |
| 3136 | } |
| 3137 | |
| 3138 | rfn->dsc = read_yin_subnode(module->ctx, sub, "text"); |
| 3139 | if (!rfn->dsc) { |
| 3140 | goto error; |
| 3141 | } |
| 3142 | } else if (!strcmp(sub->name, "reference")) { |
| 3143 | if (rfn->ref) { |
| 3144 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3145 | goto error; |
| 3146 | } |
| 3147 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3148 | 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] | 3149 | goto error; |
| 3150 | } |
| 3151 | |
| 3152 | rfn->ref = read_yin_subnode(module->ctx, sub, "text"); |
| 3153 | if (!rfn->ref) { |
| 3154 | goto error; |
| 3155 | } |
| 3156 | } else if (!strcmp(sub->name, "config")) { |
| 3157 | if (rfn->flags & LYS_CONFIG_MASK) { |
| 3158 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3159 | goto error; |
| 3160 | } |
| 3161 | GETVAL(value, sub, "value"); |
| 3162 | if (!strcmp(value, "false")) { |
| 3163 | rfn->flags |= LYS_CONFIG_R; |
| 3164 | } else if (!strcmp(value, "true")) { |
| 3165 | rfn->flags |= LYS_CONFIG_W; |
| 3166 | } else { |
| 3167 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3168 | goto error; |
| 3169 | } |
| 3170 | rfn->flags |= LYS_CONFIG_SET; |
| 3171 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3172 | 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] | 3173 | goto error; |
| 3174 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3175 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3176 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3177 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3178 | /* check possibility of statements combination */ |
| 3179 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3180 | if (c_dflt) { |
| 3181 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3182 | if (module->version < 2) { |
| 3183 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3184 | goto error; |
| 3185 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3186 | rfn->target_type &= LYS_LEAFLIST; |
| 3187 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3188 | if (module->version < 2) { |
| 3189 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 3190 | } else { |
| 3191 | /* YANG 1.1 */ |
| 3192 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 3193 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3194 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3195 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3196 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3197 | LOGVAL(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] | 3198 | goto error; |
| 3199 | } |
| 3200 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3201 | if (module->version < 2) { |
| 3202 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 3203 | } else { |
| 3204 | /* YANG 1.1 */ |
| 3205 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 3206 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3207 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3208 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3209 | 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] | 3210 | goto error; |
| 3211 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3212 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3213 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3214 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3215 | /* leaf, choice or anyxml */ |
| 3216 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3217 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3218 | goto error; |
| 3219 | } |
| 3220 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3221 | * multiple mandatory statements with the "false" value |
| 3222 | */ |
| 3223 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3224 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3225 | /* check possibility of statements combination */ |
| 3226 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3227 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3228 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3229 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3230 | LOGVAL(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] | 3231 | goto error; |
| 3232 | } |
| 3233 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3234 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3235 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3236 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3237 | GETVAL(value, sub, "value"); |
| 3238 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3239 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3240 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3241 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3242 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3243 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3244 | goto error; |
| 3245 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3246 | 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] | 3247 | goto error; |
| 3248 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3249 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3250 | /* list or leaf-list */ |
| 3251 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3252 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3253 | goto error; |
| 3254 | } |
| 3255 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3256 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3257 | /* check possibility of statements combination */ |
| 3258 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3259 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3260 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3261 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3262 | LOGVAL(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] | 3263 | goto error; |
| 3264 | } |
| 3265 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3266 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3267 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3268 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3269 | GETVAL(value, sub, "value"); |
| 3270 | while (isspace(value[0])) { |
| 3271 | value++; |
| 3272 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3273 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3274 | /* convert it to uint32_t */ |
| 3275 | errno = 0; |
| 3276 | endptr = NULL; |
| 3277 | val = strtoul(value, &endptr, 10); |
| 3278 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3279 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3280 | goto error; |
| 3281 | } |
| 3282 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3283 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3284 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3285 | 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] | 3286 | goto error; |
| 3287 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3288 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3289 | /* list or leaf-list */ |
| 3290 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3291 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3292 | goto error; |
| 3293 | } |
| 3294 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3295 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3296 | /* check possibility of statements combination */ |
| 3297 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3298 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3299 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3300 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3301 | LOGVAL(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] | 3302 | goto error; |
| 3303 | } |
| 3304 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3305 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3306 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3307 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3308 | GETVAL(value, sub, "value"); |
| 3309 | while (isspace(value[0])) { |
| 3310 | value++; |
| 3311 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3312 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3313 | if (!strcmp(value, "unbounded")) { |
| 3314 | rfn->mod.list.max = 0; |
| 3315 | } else { |
| 3316 | /* convert it to uint32_t */ |
| 3317 | errno = 0; |
| 3318 | endptr = NULL; |
| 3319 | val = strtoul(value, &endptr, 10); |
| 3320 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3321 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3322 | goto error; |
| 3323 | } |
| 3324 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3325 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3326 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3327 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3328 | 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] | 3329 | goto error; |
| 3330 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3331 | } else if (!strcmp(sub->name, "presence")) { |
| 3332 | /* container */ |
| 3333 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3334 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3335 | goto error; |
| 3336 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3337 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3338 | /* check possibility of statements combination */ |
| 3339 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3340 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3341 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3342 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3343 | LOGVAL(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] | 3344 | goto error; |
| 3345 | } |
| 3346 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3347 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3348 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3349 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3350 | GETVAL(value, sub, "value"); |
| 3351 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 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_PRESENCE, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3354 | goto error; |
| 3355 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3356 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3357 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3358 | /* check possibility of statements combination */ |
| 3359 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3360 | 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] | 3361 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3362 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3363 | LOGVAL(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] | 3364 | goto error; |
| 3365 | } |
| 3366 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3367 | 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] | 3368 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3369 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3370 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3371 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3372 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3373 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 3374 | /* leaf, leaf-list, list, container or anyxml */ |
| 3375 | /* check possibility of statements combination */ |
| 3376 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3377 | 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] | 3378 | if (!rfn->target_type) { |
| 3379 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3380 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
| 3381 | goto error; |
| 3382 | } |
| 3383 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3384 | 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] | 3385 | } |
| 3386 | |
| 3387 | c_ftrs++; |
| 3388 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3389 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3390 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3391 | goto error; |
| 3392 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3393 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3394 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3395 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3396 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3397 | /* process nodes with cardinality of 0..n */ |
| 3398 | if (c_must) { |
| 3399 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3400 | if (!rfn->must) { |
| 3401 | LOGMEM; |
| 3402 | goto error; |
| 3403 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3404 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3405 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 3406 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3407 | if (!rfn->iffeature) { |
| 3408 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3409 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3410 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3411 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3412 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3413 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3414 | if (!rfn->dflt) { |
| 3415 | LOGMEM; |
| 3416 | goto error; |
| 3417 | } |
| 3418 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3419 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3420 | /* some extensions may be already present from the substatements */ |
| 3421 | reallocated = realloc(rfn->ext, (c_ext + rfn->ext_size) * sizeof *rfn->ext); |
| 3422 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3423 | LOGMEM; |
| 3424 | goto error; |
| 3425 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3426 | rfn->ext = reallocated; |
| 3427 | |
| 3428 | /* init memory */ |
| 3429 | memset(&rfn->ext[rfn->ext_size], 0, c_ext * sizeof *rfn->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3430 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3431 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3432 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3433 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3434 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3435 | 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] | 3436 | rfn->ext_size++; |
| 3437 | if (r) { |
| 3438 | goto error; |
| 3439 | } |
| 3440 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 3441 | 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] | 3442 | rfn->iffeature_size++; |
| 3443 | if (r) { |
| 3444 | goto error; |
| 3445 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3446 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 3447 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3448 | rfn->must_size++; |
| 3449 | if (r) { |
| 3450 | goto error; |
| 3451 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3452 | } else { /* default */ |
| 3453 | GETVAL(value, sub, "value"); |
| 3454 | |
| 3455 | /* check for duplicity */ |
| 3456 | for (r = 0; r < rfn->dflt_size; r++) { |
| 3457 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
| 3458 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3459 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 3460 | goto error; |
| 3461 | } |
| 3462 | } |
| 3463 | rfn->dflt[rfn->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3464 | } |
| 3465 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3466 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3467 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3468 | |
| 3469 | error: |
| 3470 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3471 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3472 | } |
| 3473 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3474 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3475 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3476 | 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] | 3477 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3478 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3479 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3480 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3481 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3482 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3483 | /* init */ |
| 3484 | memset(&exts, 0, sizeof exts); |
| 3485 | |
| 3486 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3487 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3488 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3489 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3490 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3491 | /* extension */ |
| 3492 | c_ext++; |
| 3493 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3494 | lyxml_add_child(module->ctx, &exts, child); |
| 3495 | } else if (!strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3496 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3497 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3498 | goto error; |
| 3499 | } |
| 3500 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3501 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3502 | 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] | 3503 | goto error; |
| 3504 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3505 | } else if (!strcmp(child->name, "revision-date")) { |
| 3506 | if (imp->rev[0]) { |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 3507 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3508 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3509 | } |
| 3510 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3511 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3512 | goto error; |
| 3513 | } |
| 3514 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3515 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3516 | 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] | 3517 | goto error; |
| 3518 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3519 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3520 | if (imp->dsc) { |
| 3521 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3522 | goto error; |
| 3523 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3524 | 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] | 3525 | goto error; |
| 3526 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3527 | imp->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3528 | if (!imp->dsc) { |
| 3529 | goto error; |
| 3530 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3531 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3532 | if (imp->ref) { |
| 3533 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3534 | goto error; |
| 3535 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3536 | 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] | 3537 | goto error; |
| 3538 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3539 | imp->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3540 | if (!imp->ref) { |
| 3541 | goto error; |
| 3542 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3543 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3544 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3545 | goto error; |
| 3546 | } |
| 3547 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3548 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3549 | /* check mandatory information */ |
| 3550 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3551 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3552 | goto error; |
| 3553 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3554 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3555 | /* process extensions */ |
| 3556 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3557 | /* some extensions may be already present from the substatements */ |
| 3558 | reallocated = realloc(imp->ext, (c_ext + imp->ext_size) * sizeof *imp->ext); |
| 3559 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3560 | LOGMEM; |
| 3561 | goto error; |
| 3562 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3563 | imp->ext = reallocated; |
| 3564 | |
| 3565 | /* init memory */ |
| 3566 | memset(&imp->ext[imp->ext_size], 0, c_ext * sizeof *imp->ext); |
| 3567 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3568 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3569 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3570 | 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] | 3571 | imp->ext_size++; |
| 3572 | if (r) { |
| 3573 | goto error; |
| 3574 | } |
| 3575 | } |
| 3576 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3577 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3578 | GETVAL(value, yin, "module"); |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 3579 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3580 | |
| 3581 | error: |
| 3582 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3583 | while (exts.child) { |
| 3584 | lyxml_free(module->ctx, exts.child); |
| 3585 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3586 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3587 | } |
| 3588 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3589 | /* logs directly |
| 3590 | * returns: |
| 3591 | * 0 - inc successfully filled |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3592 | * -1 - error |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3593 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3594 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 3595 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 3596 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3597 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3598 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3599 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3600 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3601 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3602 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3603 | /* init */ |
| 3604 | memset(&exts, 0, sizeof exts); |
| 3605 | |
| 3606 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3607 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3608 | /* garbage */ |
| 3609 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3610 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3611 | /* extension */ |
| 3612 | c_ext++; |
| 3613 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3614 | lyxml_add_child(module->ctx, &exts, child); |
| 3615 | } else if (!strcmp(child->name, "revision-date")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3616 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3617 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3618 | goto error; |
| 3619 | } |
| 3620 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3621 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3622 | goto error; |
| 3623 | } |
| 3624 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3625 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3626 | 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] | 3627 | goto error; |
| 3628 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3629 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3630 | if (inc->dsc) { |
| 3631 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3632 | goto error; |
| 3633 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3634 | 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] | 3635 | goto error; |
| 3636 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3637 | inc->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3638 | if (!inc->dsc) { |
| 3639 | goto error; |
| 3640 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3641 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3642 | if (inc->ref) { |
| 3643 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3644 | goto error; |
| 3645 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3646 | 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] | 3647 | goto error; |
| 3648 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3649 | inc->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3650 | if (!inc->ref) { |
| 3651 | goto error; |
| 3652 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3653 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3654 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3655 | goto error; |
| 3656 | } |
| 3657 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3658 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3659 | /* process extensions */ |
| 3660 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3661 | /* some extensions may be already present from the substatements */ |
| 3662 | reallocated = realloc(inc->ext, (c_ext + inc->ext_size) * sizeof *inc->ext); |
| 3663 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3664 | LOGMEM; |
| 3665 | goto error; |
| 3666 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3667 | inc->ext = reallocated; |
| 3668 | |
| 3669 | /* init memory */ |
| 3670 | memset(&inc->ext[inc->ext_size], 0, c_ext * sizeof *inc->ext); |
| 3671 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3672 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3673 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3674 | 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] | 3675 | inc->ext_size++; |
| 3676 | if (r) { |
| 3677 | goto error; |
| 3678 | } |
| 3679 | } |
| 3680 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3681 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3682 | GETVAL(value, yin, "module"); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3683 | 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] | 3684 | |
| 3685 | error: |
| 3686 | |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 3687 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3688 | } |
| 3689 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3690 | /* logs directly |
| 3691 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3692 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3693 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3694 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3695 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3696 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3697 | read_yin_common(struct lys_module *module, struct lys_node *parent, void *stmt, LYEXT_PAR stmt_type, |
| 3698 | struct lyxml_elem *xmlnode, int opt, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3699 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3700 | struct lys_node *node = stmt; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3701 | const char *value; |
| 3702 | struct lyxml_elem *sub, *next; |
| 3703 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3704 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3705 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3706 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3707 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3708 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3709 | if (opt & OPT_IDENT) { |
| 3710 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3711 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3712 | goto error; |
| 3713 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3714 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3715 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3716 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3717 | /* process local parameters */ |
| 3718 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3719 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3720 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3721 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3722 | continue; |
| 3723 | } |
| 3724 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 3725 | /* 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] | 3726 | continue; |
| 3727 | } |
| 3728 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3729 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3730 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3731 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3732 | goto error; |
| 3733 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3734 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3735 | 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] | 3736 | goto error; |
| 3737 | } |
| 3738 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3739 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3740 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3741 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3742 | } |
| 3743 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3744 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3745 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3746 | goto error; |
| 3747 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3748 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3749 | 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] | 3750 | goto error; |
| 3751 | } |
| 3752 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3753 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3754 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3755 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3756 | } |
| 3757 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3758 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3759 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3760 | goto error; |
| 3761 | } |
| 3762 | GETVAL(value, sub, "value"); |
| 3763 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3764 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3765 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3766 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3767 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3768 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3769 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3770 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3771 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3772 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3773 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3774 | 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] | 3775 | goto error; |
| 3776 | } |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3777 | } else if ((opt & (OPT_CFG_PARSE | OPT_CFG_IGNORE)) && !strcmp(sub->name, "config")) { |
| 3778 | if (opt & OPT_CFG_PARSE) { |
| 3779 | if (node->flags & LYS_CONFIG_MASK) { |
| 3780 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
| 3781 | goto error; |
| 3782 | } |
| 3783 | GETVAL(value, sub, "value"); |
| 3784 | if (!strcmp(value, "false")) { |
| 3785 | node->flags |= LYS_CONFIG_R; |
| 3786 | } else if (!strcmp(value, "true")) { |
| 3787 | node->flags |= LYS_CONFIG_W; |
| 3788 | } else { |
| 3789 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3790 | goto error; |
| 3791 | } |
| 3792 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3793 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3794 | 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] | 3795 | goto error; |
| 3796 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3797 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3798 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3799 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3800 | continue; |
| 3801 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3802 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3803 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3804 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3805 | if ((opt & OPT_CFG_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3806 | /* get config flag from parent */ |
Radek Krejci | f71f48f | 2016-10-25 16:37:24 +0200 | [diff] [blame] | 3807 | if (parent) { |
| 3808 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
| 3809 | } else if (!parent) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3810 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3811 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3812 | } |
| 3813 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3814 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3815 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 3816 | |
| 3817 | error: |
| 3818 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3819 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3820 | } |
| 3821 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3822 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3823 | static struct lys_when * |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3824 | 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] | 3825 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3826 | struct lys_when *retval = NULL; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3827 | struct lyxml_elem *child, *next; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3828 | const char *value; |
| 3829 | |
| 3830 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3831 | if (!retval) { |
| 3832 | LOGMEM; |
| 3833 | return NULL; |
| 3834 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3835 | |
| 3836 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3837 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 3838 | if (!retval->cond) { |
| 3839 | goto error; |
| 3840 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3841 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3842 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3843 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3844 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3845 | continue; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3846 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3847 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3848 | 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] | 3849 | goto error; |
| 3850 | } |
| 3851 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3852 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3853 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3854 | goto error; |
| 3855 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3856 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3857 | 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] | 3858 | goto error; |
| 3859 | } |
| 3860 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3861 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3862 | if (!retval->dsc) { |
| 3863 | goto error; |
| 3864 | } |
| 3865 | } else if (!strcmp(child->name, "reference")) { |
| 3866 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3867 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3868 | goto error; |
| 3869 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3870 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3871 | 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] | 3872 | goto error; |
| 3873 | } |
| 3874 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3875 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3876 | if (!retval->ref) { |
| 3877 | goto error; |
| 3878 | } |
| 3879 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3880 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3881 | goto error; |
| 3882 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | return retval; |
| 3886 | |
| 3887 | error: |
| 3888 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 3889 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3890 | return NULL; |
| 3891 | } |
| 3892 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3893 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3894 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3895 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3896 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3897 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3898 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3899 | struct lys_node_case *cs; |
| 3900 | struct lys_node *retval, *node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3901 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3902 | void *reallocated; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3903 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 3904 | /* init */ |
| 3905 | memset(&root, 0, sizeof root); |
| 3906 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3907 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3908 | if (!cs) { |
| 3909 | LOGMEM; |
| 3910 | return NULL; |
| 3911 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3912 | cs->nodetype = LYS_CASE; |
| 3913 | cs->prev = (struct lys_node *)cs; |
| 3914 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3915 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3916 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 3917 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_INHERIT : 0), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3918 | goto error; |
| 3919 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3920 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3921 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3922 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3923 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3924 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3925 | goto error; |
| 3926 | } |
| 3927 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3928 | /* process choice's specific children */ |
| 3929 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3930 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3931 | /* extension */ |
| 3932 | c_ext++; |
| 3933 | } else if (!strcmp(sub->name, "container") || |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3934 | !strcmp(sub->name, "leaf-list") || |
| 3935 | !strcmp(sub->name, "leaf") || |
| 3936 | !strcmp(sub->name, "list") || |
| 3937 | !strcmp(sub->name, "uses") || |
| 3938 | !strcmp(sub->name, "choice") || |
| 3939 | !strcmp(sub->name, "anyxml")) { |
| 3940 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3941 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3942 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3943 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3944 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3945 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3946 | if (cs->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3947 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3948 | goto error; |
| 3949 | } |
| 3950 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3951 | cs->when = read_yin_when(module, sub, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3952 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3953 | goto error; |
| 3954 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3955 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3956 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3957 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3958 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3959 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3960 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3961 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3962 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3963 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3964 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
| 3965 | if (!cs->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3966 | LOGMEM; |
| 3967 | goto error; |
| 3968 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3969 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3970 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3971 | /* some extensions may be already present from the substatements */ |
| 3972 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 3973 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3974 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3975 | goto error; |
| 3976 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3977 | retval->ext = reallocated; |
| 3978 | |
| 3979 | /* init memory */ |
| 3980 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3981 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3982 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3983 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3984 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3985 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3986 | 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] | 3987 | retval->ext_size++; |
| 3988 | if (ret) { |
| 3989 | goto error; |
| 3990 | } |
| 3991 | } else { |
| 3992 | /* if-feature */ |
| 3993 | ret = fill_yin_iffeature(retval, 0, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 3994 | cs->iffeature_size++; |
| 3995 | if (ret) { |
| 3996 | goto error; |
| 3997 | } |
| 3998 | } |
| 3999 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4000 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4001 | /* last part - process data nodes */ |
| 4002 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4003 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4004 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4005 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4006 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4007 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4008 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4009 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4010 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4011 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4012 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4013 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4014 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4015 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4016 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4017 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4018 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4019 | } |
| 4020 | if (!node) { |
| 4021 | goto error; |
| 4022 | } |
| 4023 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4024 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4025 | } |
| 4026 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4027 | /* check XPath dependencies */ |
| 4028 | if (cs->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4029 | goto error; |
| 4030 | } |
| 4031 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4032 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4033 | |
| 4034 | error: |
| 4035 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4036 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4037 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4038 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4039 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4040 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4041 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4042 | } |
| 4043 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4044 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4045 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4046 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
| 4047 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4048 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4049 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4050 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4051 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4052 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4053 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4054 | int f_mand = 0, c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4055 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4056 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4057 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4058 | if (!choice) { |
| 4059 | LOGMEM; |
| 4060 | return NULL; |
| 4061 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4062 | choice->nodetype = LYS_CHOICE; |
| 4063 | choice->prev = (struct lys_node *)choice; |
| 4064 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4065 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4066 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4067 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4068 | goto error; |
| 4069 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4070 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4071 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4072 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4073 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4074 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4075 | goto error; |
| 4076 | } |
| 4077 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4078 | /* process choice's specific children */ |
| 4079 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4080 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4081 | /* extension */ |
| 4082 | c_ext++; |
| 4083 | /* keep it for later processing, skip lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4084 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4085 | } else if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4086 | if (!(node = read_yin_container(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4087 | goto error; |
| 4088 | } |
| 4089 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4090 | if (!(node = read_yin_leaflist(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4091 | goto error; |
| 4092 | } |
| 4093 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4094 | if (!(node = read_yin_leaf(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4095 | goto error; |
| 4096 | } |
| 4097 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4098 | if (!(node = read_yin_list(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4099 | goto error; |
| 4100 | } |
| 4101 | } else if (!strcmp(sub->name, "case")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4102 | if (!(node = read_yin_case(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4103 | goto error; |
| 4104 | } |
| 4105 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4106 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres))) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4107 | goto error; |
| 4108 | } |
| 4109 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4110 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4111 | goto error; |
| 4112 | } |
| 4113 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4114 | if (dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4115 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4116 | goto error; |
| 4117 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4118 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4119 | 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] | 4120 | goto error; |
| 4121 | } |
| 4122 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4123 | dflt = sub; |
| 4124 | lyxml_unlink_elem(ctx, dflt, 0); |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 4125 | continue; |
| 4126 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 4127 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4128 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4129 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4130 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4131 | goto error; |
| 4132 | } |
| 4133 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4134 | * multiple mandatory statements with the "false" value |
| 4135 | */ |
| 4136 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4137 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4138 | GETVAL(value, sub, "value"); |
| 4139 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4140 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4141 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4142 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4143 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4144 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4145 | goto error; |
| 4146 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4147 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4148 | 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] | 4149 | goto error; |
| 4150 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4151 | } else if (!strcmp(sub->name, "when")) { |
| 4152 | if (choice->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4153 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4154 | goto error; |
| 4155 | } |
| 4156 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4157 | choice->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4158 | if (!choice->when) { |
| 4159 | goto error; |
| 4160 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4161 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4162 | c_ftrs++; |
| 4163 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4164 | /* 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] | 4165 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4166 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4167 | if (!(node = read_yin_choice(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4168 | goto error; |
| 4169 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4170 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4171 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4172 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4173 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4174 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4175 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4176 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4177 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4178 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4179 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4180 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
| 4181 | if (!choice->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4182 | LOGMEM; |
| 4183 | goto error; |
| 4184 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4185 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4186 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4187 | /* some extensions may be already present from the substatements */ |
| 4188 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4189 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4190 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4191 | goto error; |
| 4192 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4193 | retval->ext = reallocated; |
| 4194 | |
| 4195 | /* init memory */ |
| 4196 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4197 | } |
| 4198 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4199 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4200 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4201 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4202 | 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] | 4203 | retval->ext_size++; |
| 4204 | if (ret) { |
| 4205 | goto error; |
| 4206 | } |
| 4207 | } else { |
| 4208 | ret = fill_yin_iffeature(retval, 0, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 4209 | choice->iffeature_size++; |
| 4210 | if (ret) { |
| 4211 | goto error; |
| 4212 | } |
| 4213 | } |
| 4214 | } |
| 4215 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4216 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4217 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4218 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4219 | LOGVAL(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] | 4220 | goto error; |
| 4221 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4222 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4223 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4224 | if (dflt) { |
| 4225 | GETVAL(value, dflt, "value"); |
| 4226 | 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] | 4227 | goto error; |
| 4228 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4229 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4230 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4231 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4232 | /* check XPath dependencies */ |
| 4233 | if (choice->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4234 | goto error; |
| 4235 | } |
| 4236 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4237 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4238 | |
| 4239 | error: |
| 4240 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4241 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4242 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4243 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4244 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4245 | } |
| 4246 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4247 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4248 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4249 | read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, LYS_NODE type, |
| 4250 | int valid_config, struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4251 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4252 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4253 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4254 | struct lyxml_elem *sub, *next; |
| 4255 | const char *value; |
| 4256 | int r; |
| 4257 | int f_mand = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4258 | int c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4259 | void *reallocated; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4261 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4262 | if (!anyxml) { |
| 4263 | LOGMEM; |
| 4264 | return NULL; |
| 4265 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4266 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4267 | anyxml->prev = (struct lys_node *)anyxml; |
| 4268 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4269 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4270 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4271 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4272 | goto error; |
| 4273 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4274 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4275 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4276 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4277 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4278 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4279 | goto error; |
| 4280 | } |
| 4281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4282 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4283 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4284 | /* extension */ |
| 4285 | c_ext++; |
| 4286 | } else if (!strcmp(sub->name, "mandatory")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4287 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4288 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4289 | goto error; |
| 4290 | } |
| 4291 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4292 | * multiple mandatory statements with the "false" value |
| 4293 | */ |
| 4294 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4295 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4296 | GETVAL(value, sub, "value"); |
| 4297 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4298 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4299 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4300 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4301 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4302 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4303 | goto error; |
| 4304 | } |
| 4305 | /* else false is the default value, so we can ignore it */ |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4306 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4307 | 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] | 4308 | goto error; |
| 4309 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4310 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4311 | } else if (!strcmp(sub->name, "when")) { |
| 4312 | if (anyxml->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4313 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4314 | goto error; |
| 4315 | } |
| 4316 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4317 | anyxml->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4318 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4319 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4320 | goto error; |
| 4321 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4322 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4323 | } else if (!strcmp(sub->name, "must")) { |
| 4324 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4325 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4326 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4328 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4329 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4330 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4331 | } |
| 4332 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4333 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4334 | /* middle part - process nodes with cardinality of 0..n */ |
| 4335 | if (c_must) { |
| 4336 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4337 | if (!anyxml->must) { |
| 4338 | LOGMEM; |
| 4339 | goto error; |
| 4340 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4341 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4342 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4343 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
| 4344 | if (!anyxml->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4345 | LOGMEM; |
| 4346 | goto error; |
| 4347 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4348 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4349 | if (c_ext) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4350 | /* some extensions may be already present from the substatements */ |
| 4351 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4352 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4353 | LOGMEM; |
| 4354 | goto error; |
| 4355 | } |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4356 | retval->ext = reallocated; |
| 4357 | |
| 4358 | /* init memory */ |
| 4359 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4360 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4361 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4362 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4363 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4364 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4365 | 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] | 4366 | retval->ext_size++; |
| 4367 | if (r) { |
| 4368 | goto error; |
| 4369 | } |
| 4370 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4371 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4372 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4373 | if (r) { |
| 4374 | goto error; |
| 4375 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4376 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4377 | 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] | 4378 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4379 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4380 | goto error; |
| 4381 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4382 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4383 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4384 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4385 | /* check XPath dependencies */ |
| 4386 | if ((anyxml->when || anyxml->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4387 | goto error; |
| 4388 | } |
| 4389 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4390 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4391 | |
| 4392 | error: |
| 4393 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4394 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4395 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4396 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4397 | } |
| 4398 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4399 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4400 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4401 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4402 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4403 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4404 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4405 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4406 | struct lyxml_elem *sub, *next; |
| 4407 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4408 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4409 | 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] | 4410 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4411 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4412 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4413 | if (!leaf) { |
| 4414 | LOGMEM; |
| 4415 | return NULL; |
| 4416 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4417 | leaf->nodetype = LYS_LEAF; |
| 4418 | leaf->prev = (struct lys_node *)leaf; |
| 4419 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4420 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4421 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4422 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4423 | goto error; |
| 4424 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4425 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4426 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4427 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4428 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4429 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4430 | goto error; |
| 4431 | } |
| 4432 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4433 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4434 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4435 | /* extension */ |
| 4436 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4437 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4438 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4439 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4440 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4441 | goto error; |
| 4442 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4443 | /* HACK for unres */ |
| 4444 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4445 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4446 | /* postpone type resolution when if-feature parsing is done since we need |
| 4447 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4448 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4449 | } else if (!strcmp(sub->name, "default")) { |
| 4450 | if (leaf->dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4451 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4452 | goto error; |
| 4453 | } |
| 4454 | GETVAL(value, sub, "value"); |
| 4455 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4456 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4457 | 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] | 4458 | goto error; |
| 4459 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4460 | } else if (!strcmp(sub->name, "units")) { |
| 4461 | if (leaf->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4462 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4463 | goto error; |
| 4464 | } |
| 4465 | GETVAL(value, sub, "name"); |
| 4466 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4467 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4468 | 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] | 4469 | goto error; |
| 4470 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4471 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4472 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4473 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4474 | goto error; |
| 4475 | } |
| 4476 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4477 | * multiple mandatory statements with the "false" value |
| 4478 | */ |
| 4479 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4480 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4481 | GETVAL(value, sub, "value"); |
| 4482 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4483 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4484 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4485 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4486 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4487 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4488 | goto error; |
| 4489 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4490 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4491 | 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] | 4492 | goto error; |
| 4493 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4494 | } else if (!strcmp(sub->name, "when")) { |
| 4495 | if (leaf->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4496 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4497 | goto error; |
| 4498 | } |
| 4499 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4500 | leaf->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4501 | if (!leaf->when) { |
| 4502 | goto error; |
| 4503 | } |
| 4504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4505 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4506 | c_must++; |
| 4507 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4508 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4509 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4510 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4511 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4512 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4513 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4514 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4515 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4516 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4517 | /* 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] | 4518 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4519 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4520 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4521 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4522 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4523 | goto error; |
| 4524 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4525 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4526 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4527 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4528 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 4529 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4530 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4531 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4532 | /* middle part - process nodes with cardinality of 0..n */ |
| 4533 | if (c_must) { |
| 4534 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4535 | if (!leaf->must) { |
| 4536 | LOGMEM; |
| 4537 | goto error; |
| 4538 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4539 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4540 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4541 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
| 4542 | if (!leaf->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4543 | LOGMEM; |
| 4544 | goto error; |
| 4545 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4546 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4547 | if (c_ext) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4548 | /* some extensions may be already present from the substatements */ |
| 4549 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4550 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4551 | LOGMEM; |
| 4552 | goto error; |
| 4553 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4554 | retval->ext = reallocated; |
| 4555 | |
| 4556 | /* init memory */ |
| 4557 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4558 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4559 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4560 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4561 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4562 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4563 | 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] | 4564 | retval->ext_size++; |
| 4565 | if (r) { |
| 4566 | goto error; |
| 4567 | } |
| 4568 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4569 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4570 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4571 | if (r) { |
| 4572 | goto error; |
| 4573 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4574 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4575 | 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] | 4576 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4577 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4578 | goto error; |
| 4579 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4580 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4581 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4582 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4583 | /* finalize type parsing */ |
| 4584 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
| 4585 | leaf->type.der = NULL; |
| 4586 | goto error; |
| 4587 | } |
| 4588 | |
| 4589 | /* check default value (if not defined, there still could be some restrictions |
| 4590 | * that need to be checked against a default value from a derived type) */ |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 4591 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt)) == -1) { |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4592 | goto error; |
| 4593 | } |
| 4594 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4595 | /* check XPath dependencies */ |
| 4596 | if ((leaf->when || leaf->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4597 | goto error; |
| 4598 | } |
| 4599 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4600 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4601 | |
| 4602 | error: |
| 4603 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4604 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4605 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4606 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4607 | } |
| 4608 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4609 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4610 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4611 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4612 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4613 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4614 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4615 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4616 | struct lyxml_elem *sub, *next; |
| 4617 | const char *value; |
| 4618 | char *endptr; |
| 4619 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4620 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4621 | 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] | 4622 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4623 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4624 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4625 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4626 | if (!llist) { |
| 4627 | LOGMEM; |
| 4628 | return NULL; |
| 4629 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4630 | llist->nodetype = LYS_LEAFLIST; |
| 4631 | llist->prev = (struct lys_node *)llist; |
| 4632 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4633 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4634 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4635 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4636 | goto error; |
| 4637 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4638 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4639 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4640 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4641 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4642 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4643 | goto error; |
| 4644 | } |
| 4645 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4646 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4647 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4648 | /* extension */ |
| 4649 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4650 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4651 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4652 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4653 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4654 | goto error; |
| 4655 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4656 | /* HACK for unres */ |
| 4657 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4658 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4659 | /* postpone type resolution when if-feature parsing is done since we need |
| 4660 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4661 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4662 | } else if (!strcmp(sub->name, "units")) { |
| 4663 | if (llist->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4664 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4665 | goto error; |
| 4666 | } |
| 4667 | GETVAL(value, sub, "name"); |
| 4668 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4669 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4670 | 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] | 4671 | goto error; |
| 4672 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4673 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4674 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4675 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4676 | goto error; |
| 4677 | } |
| 4678 | /* just checking the flags in llist is not sufficient, we would |
| 4679 | * allow multiple ordered-by statements with the "system" value |
| 4680 | */ |
| 4681 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4682 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4683 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4684 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4685 | * state data |
| 4686 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4687 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4688 | continue; |
| 4689 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4691 | GETVAL(value, sub, "value"); |
| 4692 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4693 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4694 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4695 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4696 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4697 | } /* else system is the default value, so we can ignore it */ |
| 4698 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4699 | 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] | 4700 | goto error; |
| 4701 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4702 | } else if (!strcmp(sub->name, "must")) { |
| 4703 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4704 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4705 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4706 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4707 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4708 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4709 | /* read the default's extension instances */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4710 | 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] | 4711 | goto error; |
| 4712 | } |
| 4713 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4714 | c_dflt++; |
| 4715 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4716 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4717 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4718 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4719 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4720 | goto error; |
| 4721 | } |
| 4722 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4723 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4724 | GETVAL(value, sub, "value"); |
| 4725 | while (isspace(value[0])) { |
| 4726 | value++; |
| 4727 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4728 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4729 | /* convert it to uint32_t */ |
| 4730 | errno = 0; |
| 4731 | endptr = NULL; |
| 4732 | val = strtoul(value, &endptr, 10); |
| 4733 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4734 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4735 | goto error; |
| 4736 | } |
| 4737 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4738 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4739 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4740 | LOGVAL(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] | 4741 | goto error; |
| 4742 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4743 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4744 | 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] | 4745 | goto error; |
| 4746 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4747 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4748 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4749 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4750 | goto error; |
| 4751 | } |
| 4752 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4753 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4754 | GETVAL(value, sub, "value"); |
| 4755 | while (isspace(value[0])) { |
| 4756 | value++; |
| 4757 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4758 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4759 | if (!strcmp(value, "unbounded")) { |
| 4760 | llist->max = 0; |
| 4761 | } else { |
| 4762 | /* convert it to uint32_t */ |
| 4763 | errno = 0; |
| 4764 | endptr = NULL; |
| 4765 | val = strtoul(value, &endptr, 10); |
| 4766 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4767 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4768 | goto error; |
| 4769 | } |
| 4770 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4771 | if (llist->min > llist->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4772 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4773 | LOGVAL(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] | 4774 | goto error; |
| 4775 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4776 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4777 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4778 | 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] | 4779 | goto error; |
| 4780 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4781 | } else if (!strcmp(sub->name, "when")) { |
| 4782 | if (llist->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4783 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4784 | goto error; |
| 4785 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4786 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4787 | llist->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4788 | if (!llist->when) { |
| 4789 | goto error; |
| 4790 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4791 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4792 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4793 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4794 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4795 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4796 | /* 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] | 4797 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4798 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4799 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4800 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4801 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4802 | goto error; |
| 4803 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4804 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4805 | /* middle part - process nodes with cardinality of 0..n */ |
| 4806 | if (c_must) { |
| 4807 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4808 | if (!llist->must) { |
| 4809 | LOGMEM; |
| 4810 | goto error; |
| 4811 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4812 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4813 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4814 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
| 4815 | if (!llist->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4816 | LOGMEM; |
| 4817 | goto error; |
| 4818 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4819 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4820 | if (c_dflt) { |
| 4821 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
| 4822 | if (!llist->dflt) { |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4823 | LOGMEM; |
| 4824 | goto error; |
| 4825 | } |
| 4826 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4827 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4828 | /* some extensions may be already present from the substatements */ |
| 4829 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4830 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4831 | LOGMEM; |
| 4832 | goto error; |
| 4833 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4834 | retval->ext = reallocated; |
| 4835 | |
| 4836 | /* init memory */ |
| 4837 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4838 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4839 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4840 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4841 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4842 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4843 | 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] | 4844 | retval->ext_size++; |
| 4845 | if (r) { |
| 4846 | goto error; |
| 4847 | } |
| 4848 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4849 | r = fill_yin_must(module, sub, &llist->must[llist->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4850 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4851 | if (r) { |
| 4852 | goto error; |
| 4853 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4854 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4855 | 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] | 4856 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4857 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4858 | goto error; |
| 4859 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4860 | } else if (!strcmp(sub->name, "default")) { |
| 4861 | GETVAL(value, sub, "value"); |
| 4862 | |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4863 | /* check for duplicity in case of configuration data, |
| 4864 | * in case of status data duplicities are allowed */ |
| 4865 | if (llist->flags & LYS_CONFIG_W) { |
| 4866 | for (r = 0; r < llist->dflt_size; r++) { |
| 4867 | if (ly_strequal(llist->dflt[r], value, 1)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4868 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, "default"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4869 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4870 | goto error; |
| 4871 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4872 | } |
| 4873 | } |
| 4874 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4875 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4876 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4877 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4878 | /* finalize type parsing */ |
| 4879 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
| 4880 | llist->type.der = NULL; |
| 4881 | goto error; |
| 4882 | } |
| 4883 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4884 | if (llist->dflt_size && llist->min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4885 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4886 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4887 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 4888 | goto error; |
| 4889 | } |
| 4890 | |
| 4891 | /* check default value (if not defined, there still could be some restrictions |
| 4892 | * that need to be checked against a default value from a derived type) */ |
| 4893 | for (r = 0; r < llist->dflt_size; r++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 4894 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 4895 | (struct lys_node *)(&llist->dflt[r])) == -1) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4896 | goto error; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4897 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4898 | } |
| 4899 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4900 | /* check XPath dependencies */ |
| 4901 | if ((llist->when || llist->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4902 | goto error; |
| 4903 | } |
| 4904 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4905 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4906 | |
| 4907 | error: |
| 4908 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4909 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4910 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4911 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4912 | } |
| 4913 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4914 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4915 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4916 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4917 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4918 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4919 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4920 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4921 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4922 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4923 | 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] | 4924 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4925 | const char *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4926 | char *auxs; |
| 4927 | unsigned long val; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4928 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4929 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4930 | /* init */ |
| 4931 | memset(&root, 0, sizeof root); |
| 4932 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4933 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4934 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4935 | if (!list) { |
| 4936 | LOGMEM; |
| 4937 | return NULL; |
| 4938 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4939 | list->nodetype = LYS_LIST; |
| 4940 | list->prev = (struct lys_node *)list; |
| 4941 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4942 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4943 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4944 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4945 | goto error; |
| 4946 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4947 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4948 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4949 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4950 | /* insert the node into the schema tree */ |
| 4951 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4952 | goto error; |
| 4953 | } |
| 4954 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4955 | /* process list's specific children */ |
| 4956 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4957 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4958 | /* extension */ |
| 4959 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4960 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4961 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4962 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4963 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4964 | !strcmp(sub->name, "leaf-list") || |
| 4965 | !strcmp(sub->name, "leaf") || |
| 4966 | !strcmp(sub->name, "list") || |
| 4967 | !strcmp(sub->name, "choice") || |
| 4968 | !strcmp(sub->name, "uses") || |
| 4969 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4970 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4971 | !strcmp(sub->name, "action") || |
| 4972 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4973 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4974 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4975 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4976 | /* array counters */ |
| 4977 | } else if (!strcmp(sub->name, "key")) { |
| 4978 | /* check cardinality 0..1 */ |
| 4979 | if (list->keys_size) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4980 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4981 | goto error; |
| 4982 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4983 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4984 | /* count the number of keys */ |
| 4985 | GETVAL(value, sub, "value"); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4986 | list->keys_str = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4987 | while ((value = strpbrk(value, " \t\n"))) { |
| 4988 | list->keys_size++; |
| 4989 | while (isspace(*value)) { |
| 4990 | value++; |
| 4991 | } |
| 4992 | } |
| 4993 | list->keys_size++; |
| 4994 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4995 | if (!list->keys) { |
| 4996 | LOGMEM; |
| 4997 | goto error; |
| 4998 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4999 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5000 | 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] | 5001 | goto error; |
| 5002 | } |
| 5003 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5004 | } else if (!strcmp(sub->name, "unique")) { |
| 5005 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5006 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5007 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5008 | } else if (!strcmp(sub->name, "typedef")) { |
| 5009 | c_tpdf++; |
| 5010 | } else if (!strcmp(sub->name, "must")) { |
| 5011 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5012 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5013 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5014 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5015 | /* optional stetments */ |
| 5016 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 5017 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5018 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5019 | goto error; |
| 5020 | } |
| 5021 | /* just checking the flags in llist is not sufficient, we would |
| 5022 | * allow multiple ordered-by statements with the "system" value |
| 5023 | */ |
| 5024 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5025 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5026 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5027 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 5028 | * state data |
| 5029 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5030 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5031 | continue; |
| 5032 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5033 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5034 | GETVAL(value, sub, "value"); |
| 5035 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5036 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5037 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5038 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5039 | goto error; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5040 | } /* else system is the default value, so we can ignore it */ |
| 5041 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5042 | 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] | 5043 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5044 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5045 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5046 | } else if (!strcmp(sub->name, "min-elements")) { |
| 5047 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5048 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5049 | goto error; |
| 5050 | } |
| 5051 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5052 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5053 | GETVAL(value, sub, "value"); |
| 5054 | while (isspace(value[0])) { |
| 5055 | value++; |
| 5056 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5057 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5058 | /* convert it to uint32_t */ |
| 5059 | errno = 0; |
| 5060 | auxs = NULL; |
| 5061 | val = strtoul(value, &auxs, 10); |
| 5062 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5063 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5064 | goto error; |
| 5065 | } |
| 5066 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5067 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5068 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5069 | LOGVAL(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] | 5070 | lyxml_free(module->ctx, sub); |
| 5071 | goto error; |
| 5072 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5073 | 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] | 5074 | goto error; |
| 5075 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5076 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5077 | } else if (!strcmp(sub->name, "max-elements")) { |
| 5078 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5079 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5080 | goto error; |
| 5081 | } |
| 5082 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5083 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5084 | GETVAL(value, sub, "value"); |
| 5085 | while (isspace(value[0])) { |
| 5086 | value++; |
| 5087 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5088 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5089 | if (!strcmp(value, "unbounded")) { |
| 5090 | list->max = 0;; |
| 5091 | } else { |
| 5092 | /* convert it to uint32_t */ |
| 5093 | errno = 0; |
| 5094 | auxs = NULL; |
| 5095 | val = strtoul(value, &auxs, 10); |
| 5096 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5097 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5098 | goto error; |
| 5099 | } |
| 5100 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5101 | if (list->min > list->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5102 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5103 | LOGVAL(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] | 5104 | goto error; |
| 5105 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5106 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5107 | 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] | 5108 | goto error; |
| 5109 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5110 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5111 | } else if (!strcmp(sub->name, "when")) { |
| 5112 | if (list->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5113 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5114 | goto error; |
| 5115 | } |
| 5116 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5117 | list->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5118 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5119 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5120 | goto error; |
| 5121 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5122 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5123 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5124 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5125 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5126 | } |
| 5127 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5128 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5129 | /* check - if list is configuration, key statement is mandatory |
| 5130 | * (but only if we are not in a grouping or augment, then the check is deferred) */ |
| 5131 | for (node = retval; node && !(node->nodetype & (LYS_GROUPING | LYS_AUGMENT)); node = node->parent); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5132 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys_str) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5133 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5134 | goto error; |
| 5135 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5137 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5138 | if (c_tpdf) { |
| 5139 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5140 | if (!list->tpdf) { |
| 5141 | LOGMEM; |
| 5142 | goto error; |
| 5143 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5144 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5145 | if (c_must) { |
| 5146 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5147 | if (!list->must) { |
| 5148 | LOGMEM; |
| 5149 | goto error; |
| 5150 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5151 | } |
| 5152 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5153 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
| 5154 | if (!list->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5155 | LOGMEM; |
| 5156 | goto error; |
| 5157 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5158 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5159 | if (c_ext) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5160 | /* some extensions may be already present from the substatements */ |
| 5161 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5162 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5163 | LOGMEM; |
| 5164 | goto error; |
| 5165 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5166 | retval->ext = reallocated; |
| 5167 | |
| 5168 | /* init memory */ |
| 5169 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5170 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5171 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5172 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5173 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5174 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5175 | 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] | 5176 | retval->ext_size++; |
| 5177 | if (r) { |
| 5178 | goto error; |
| 5179 | } |
| 5180 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5181 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 5182 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5183 | if (r) { |
| 5184 | goto error; |
| 5185 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5186 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5187 | 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] | 5188 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5189 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5190 | goto error; |
| 5191 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5192 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5193 | r = fill_yin_must(module, sub, &list->must[list->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5194 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5195 | if (r) { |
| 5196 | goto error; |
| 5197 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5198 | } |
| 5199 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5200 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5201 | /* last part - process data nodes */ |
| 5202 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5203 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5204 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5205 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5206 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5207 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5208 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5209 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5210 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5211 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5212 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5213 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5214 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5215 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5216 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5217 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5218 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5219 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5220 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5221 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5222 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5223 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5224 | node = read_yin_notif(module, retval, sub, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5225 | } else { |
| 5226 | LOGINT; |
| 5227 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5228 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5229 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5230 | goto error; |
| 5231 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5232 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5233 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5234 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5235 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5236 | if (list->keys_str) { |
| 5237 | /* check that we are not in grouping */ |
| 5238 | for (node = parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node)); |
| 5239 | if (!node && unres_schema_add_node(module, unres, list, UNRES_LIST_KEYS, NULL) == -1) { |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5240 | goto error; |
| 5241 | } |
| 5242 | } /* 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] | 5243 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5244 | /* process unique statements */ |
| 5245 | if (c_uniq) { |
| 5246 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5247 | if (!list->unique) { |
| 5248 | LOGMEM; |
| 5249 | goto error; |
| 5250 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5251 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5252 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 5253 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 5254 | list->unique_size++; |
| 5255 | if (r) { |
| 5256 | goto error; |
| 5257 | } |
| 5258 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5259 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5260 | LYEXT_SUBSTMT_UNIQUE, list->unique_size - 1, unres)) { |
| 5261 | goto error; |
| 5262 | } |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5263 | lyxml_free(module->ctx, sub); |
| 5264 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5265 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5266 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5267 | /* check XPath dependencies */ |
| 5268 | if ((list->when || list->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5269 | goto error; |
| 5270 | } |
| 5271 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5272 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5273 | |
| 5274 | error: |
| 5275 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5276 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5277 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5278 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5279 | } |
| 5280 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5281 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5282 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5283 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5284 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5285 | } |
| 5286 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5287 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5288 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5289 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5290 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5291 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5292 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5293 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5294 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5295 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5296 | const char *value; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5297 | void *reallocated; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5298 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5299 | 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] | 5300 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5301 | /* init */ |
| 5302 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5303 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5304 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5305 | if (!cont) { |
| 5306 | LOGMEM; |
| 5307 | return NULL; |
| 5308 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5309 | cont->nodetype = LYS_CONTAINER; |
| 5310 | cont->prev = (struct lys_node *)cont; |
| 5311 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5312 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5313 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 5314 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_PARSE | OPT_CFG_INHERIT : OPT_CFG_IGNORE), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5315 | goto error; |
| 5316 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5317 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5318 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5319 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5320 | /* insert the node into the schema tree */ |
| 5321 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5322 | goto error; |
| 5323 | } |
| 5324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5325 | /* process container's specific children */ |
| 5326 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5327 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5328 | /* extension */ |
| 5329 | c_ext++; |
| 5330 | } else if (!strcmp(sub->name, "presence")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5331 | if (cont->presence) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5332 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5333 | goto error; |
| 5334 | } |
| 5335 | GETVAL(value, sub, "value"); |
| 5336 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5337 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5338 | 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] | 5339 | goto error; |
| 5340 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5341 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5342 | } else if (!strcmp(sub->name, "when")) { |
| 5343 | if (cont->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5344 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5345 | goto error; |
| 5346 | } |
| 5347 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5348 | cont->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5349 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5350 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5351 | goto error; |
| 5352 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5353 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 5354 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5355 | /* data statements */ |
| 5356 | } else if (!strcmp(sub->name, "container") || |
| 5357 | !strcmp(sub->name, "leaf-list") || |
| 5358 | !strcmp(sub->name, "leaf") || |
| 5359 | !strcmp(sub->name, "list") || |
| 5360 | !strcmp(sub->name, "choice") || |
| 5361 | !strcmp(sub->name, "uses") || |
| 5362 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5363 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5364 | !strcmp(sub->name, "action") || |
| 5365 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5366 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5367 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5368 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5369 | /* array counters */ |
| 5370 | } else if (!strcmp(sub->name, "typedef")) { |
| 5371 | c_tpdf++; |
| 5372 | } else if (!strcmp(sub->name, "must")) { |
| 5373 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5374 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5375 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5376 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5377 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5378 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5379 | } |
| 5380 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5381 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5382 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5383 | if (c_tpdf) { |
| 5384 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5385 | if (!cont->tpdf) { |
| 5386 | LOGMEM; |
| 5387 | goto error; |
| 5388 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5389 | } |
| 5390 | if (c_must) { |
| 5391 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5392 | if (!cont->must) { |
| 5393 | LOGMEM; |
| 5394 | goto error; |
| 5395 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5396 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5397 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5398 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
| 5399 | if (!cont->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5400 | LOGMEM; |
| 5401 | goto error; |
| 5402 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5403 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5404 | if (c_ext) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5405 | /* some extensions may be already present from the substatements */ |
| 5406 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5407 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5408 | LOGMEM; |
| 5409 | goto error; |
| 5410 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5411 | retval->ext = reallocated; |
| 5412 | |
| 5413 | /* init memory */ |
| 5414 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5415 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5416 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5417 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5418 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5419 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5420 | 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] | 5421 | retval->ext_size++; |
| 5422 | if (r) { |
| 5423 | goto error; |
| 5424 | } |
| 5425 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5426 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 5427 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5428 | if (r) { |
| 5429 | goto error; |
| 5430 | } |
| 5431 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5432 | r = fill_yin_must(module, sub, &cont->must[cont->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5433 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5434 | if (r) { |
| 5435 | goto error; |
| 5436 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5437 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5438 | 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] | 5439 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5440 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5441 | goto error; |
| 5442 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5443 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5444 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5445 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5446 | /* last part - process data nodes */ |
| 5447 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5448 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5449 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5450 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5451 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5452 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5453 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5454 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5455 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5456 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5457 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5458 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5459 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5460 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5461 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5462 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5463 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5464 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5465 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5466 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5467 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5468 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5469 | node = read_yin_notif(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5470 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5471 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5472 | goto error; |
| 5473 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5474 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5475 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5476 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5477 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5478 | /* check XPath dependencies */ |
| 5479 | if ((cont->when || cont->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5480 | goto error; |
| 5481 | } |
| 5482 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5483 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5484 | |
| 5485 | error: |
| 5486 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5487 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5488 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5489 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5490 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5491 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5492 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5493 | } |
| 5494 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5495 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5496 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5497 | read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5498 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5499 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5500 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5501 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5502 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5503 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5504 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5505 | int c_tpdf = 0, c_ext = 0; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5506 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5507 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5508 | /* init */ |
| 5509 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5510 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5511 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5512 | if (!grp) { |
| 5513 | LOGMEM; |
| 5514 | return NULL; |
| 5515 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5516 | grp->nodetype = LYS_GROUPING; |
| 5517 | grp->prev = (struct lys_node *)grp; |
| 5518 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5519 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5520 | 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] | 5521 | goto error; |
| 5522 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5523 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5524 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5525 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5526 | /* insert the node into the schema tree */ |
| 5527 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5528 | goto error; |
| 5529 | } |
| 5530 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5531 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5532 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5533 | /* extension */ |
| 5534 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5535 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5536 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5537 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5538 | !strcmp(sub->name, "leaf-list") || |
| 5539 | !strcmp(sub->name, "leaf") || |
| 5540 | !strcmp(sub->name, "list") || |
| 5541 | !strcmp(sub->name, "choice") || |
| 5542 | !strcmp(sub->name, "uses") || |
| 5543 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5544 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5545 | !strcmp(sub->name, "action") || |
| 5546 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5547 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5548 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5550 | /* array counters */ |
| 5551 | } else if (!strcmp(sub->name, "typedef")) { |
| 5552 | c_tpdf++; |
| 5553 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5554 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5555 | goto error; |
| 5556 | } |
| 5557 | } |
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 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5560 | if (c_tpdf) { |
| 5561 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5562 | if (!grp->tpdf) { |
| 5563 | LOGMEM; |
| 5564 | goto error; |
| 5565 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5566 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5567 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5568 | /* some extensions may be already present from the substatements */ |
| 5569 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5570 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5571 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5572 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5573 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5574 | retval->ext = reallocated; |
| 5575 | |
| 5576 | /* init memory */ |
| 5577 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5578 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5579 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5580 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5581 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5582 | 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] | 5583 | retval->ext_size++; |
| 5584 | if (r) { |
| 5585 | goto error; |
| 5586 | } |
| 5587 | } else { |
| 5588 | /* typedef */ |
| 5589 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 5590 | grp->tpdf_size++; |
| 5591 | if (r) { |
| 5592 | goto error; |
| 5593 | } |
| 5594 | } |
| 5595 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5596 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5597 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5598 | if (!root.child) { |
| 5599 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 5600 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5601 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5602 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5603 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5604 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5605 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5606 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5607 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5608 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5609 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5610 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5611 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5612 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5613 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5614 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5615 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5616 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5617 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5618 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5619 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5620 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5621 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5622 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5623 | node = read_yin_notif(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5624 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5625 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5626 | goto error; |
| 5627 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5628 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5629 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5630 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5631 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5632 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5633 | |
| 5634 | error: |
| 5635 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5636 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5637 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5638 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5639 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5640 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5641 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5642 | } |
| 5643 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5644 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5645 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5646 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5647 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5648 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5649 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5650 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 5651 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5652 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5653 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5654 | int c_tpdf = 0, c_must = 0, c_ext = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5655 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5656 | /* init */ |
| 5657 | memset(&root, 0, sizeof root); |
| 5658 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5659 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5660 | if (!inout) { |
| 5661 | LOGMEM; |
| 5662 | return NULL; |
| 5663 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5664 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5665 | |
| 5666 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5667 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5668 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5669 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5670 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5671 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5672 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5673 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5674 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5675 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5676 | } |
| 5677 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5678 | retval = (struct lys_node *)inout; |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5679 | retval->module = module; |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 5680 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5681 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5682 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5683 | /* insert the node into the schema tree */ |
| 5684 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5685 | goto error; |
| 5686 | } |
| 5687 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5688 | /* data statements */ |
| 5689 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5690 | if (!sub->ns) { |
| 5691 | /* garbage */ |
| 5692 | lyxml_free(module->ctx, sub); |
| 5693 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5694 | /* extension */ |
| 5695 | c_ext++; |
| 5696 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5697 | !strcmp(sub->name, "leaf-list") || |
| 5698 | !strcmp(sub->name, "leaf") || |
| 5699 | !strcmp(sub->name, "list") || |
| 5700 | !strcmp(sub->name, "choice") || |
| 5701 | !strcmp(sub->name, "uses") || |
| 5702 | !strcmp(sub->name, "grouping") || |
| 5703 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5704 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5705 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5706 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5707 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5708 | } else if (!strcmp(sub->name, "typedef")) { |
| 5709 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 5710 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5711 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5712 | c_must++; |
| 5713 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5714 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5715 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5716 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5721 | if (c_tpdf) { |
| 5722 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5723 | if (!inout->tpdf) { |
| 5724 | LOGMEM; |
| 5725 | goto error; |
| 5726 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5727 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5728 | if (c_must) { |
| 5729 | inout->must = calloc(c_must, sizeof *inout->must); |
| 5730 | if (!inout->must) { |
| 5731 | LOGMEM; |
| 5732 | goto error; |
| 5733 | } |
| 5734 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5735 | if (c_ext) { |
| 5736 | inout->ext = calloc(c_ext, sizeof *inout->ext); |
| 5737 | if (!inout->ext) { |
| 5738 | LOGMEM; |
| 5739 | goto error; |
| 5740 | } |
| 5741 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5742 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5743 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5744 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5745 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5746 | 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] | 5747 | retval->ext_size++; |
| 5748 | if (r) { |
| 5749 | goto error; |
| 5750 | } |
| 5751 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5752 | r = fill_yin_must(module, sub, &inout->must[inout->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5753 | inout->must_size++; |
| 5754 | if (r) { |
| 5755 | goto error; |
| 5756 | } |
| 5757 | } else { /* typedef */ |
| 5758 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 5759 | inout->tpdf_size++; |
| 5760 | if (r) { |
| 5761 | goto error; |
| 5762 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5763 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | /* last part - process data nodes */ |
| 5767 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5768 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5769 | node = read_yin_container(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5770 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5771 | node = read_yin_leaflist(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5772 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5773 | node = read_yin_leaf(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5774 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5775 | node = read_yin_list(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5776 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5777 | node = read_yin_choice(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5778 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5779 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5780 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5781 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5782 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5783 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5784 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5785 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5786 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5787 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5788 | goto error; |
| 5789 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5790 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5791 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5792 | } |
| 5793 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5794 | /* check XPath dependencies */ |
| 5795 | if (inout->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5796 | goto error; |
| 5797 | } |
| 5798 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5799 | return retval; |
| 5800 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5801 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5802 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5803 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 5804 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5805 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | return NULL; |
| 5809 | } |
| 5810 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5811 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5812 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5813 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5814 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5815 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5816 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5817 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5818 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5819 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5820 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5821 | 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] | 5822 | void *reallocated; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5823 | |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5824 | if (parent && (module->version < 2)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5825 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "notification"); |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5826 | return NULL; |
| 5827 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5828 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5829 | memset(&root, 0, sizeof root); |
| 5830 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5831 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5832 | if (!notif) { |
| 5833 | LOGMEM; |
| 5834 | return NULL; |
| 5835 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5836 | notif->nodetype = LYS_NOTIF; |
| 5837 | notif->prev = (struct lys_node *)notif; |
| 5838 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5839 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5840 | 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] | 5841 | goto error; |
| 5842 | } |
| 5843 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5844 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5845 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5846 | /* insert the node into the schema tree */ |
| 5847 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5848 | goto error; |
| 5849 | } |
| 5850 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5851 | /* process rpc's specific children */ |
| 5852 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5853 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5854 | /* extension */ |
| 5855 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5856 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5857 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5858 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5859 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5860 | !strcmp(sub->name, "leaf-list") || |
| 5861 | !strcmp(sub->name, "leaf") || |
| 5862 | !strcmp(sub->name, "list") || |
| 5863 | !strcmp(sub->name, "choice") || |
| 5864 | !strcmp(sub->name, "uses") || |
| 5865 | !strcmp(sub->name, "grouping") || |
| 5866 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5867 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5868 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5869 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5870 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5871 | } else if (!strcmp(sub->name, "typedef")) { |
| 5872 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5873 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5874 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5875 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5876 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5877 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5878 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5879 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5884 | if (c_tpdf) { |
| 5885 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5886 | if (!notif->tpdf) { |
| 5887 | LOGMEM; |
| 5888 | goto error; |
| 5889 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5890 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5891 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5892 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
| 5893 | if (!notif->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5894 | LOGMEM; |
| 5895 | goto error; |
| 5896 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5897 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5898 | if (c_must) { |
| 5899 | notif->must = calloc(c_must, sizeof *notif->must); |
| 5900 | if (!notif->must) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5901 | LOGMEM; |
| 5902 | goto error; |
| 5903 | } |
| 5904 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5905 | if (c_ext) { |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5906 | /* some extensions may be already present from the substatements */ |
| 5907 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5908 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5909 | LOGMEM; |
| 5910 | goto error; |
| 5911 | } |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5912 | retval->ext = reallocated; |
| 5913 | |
| 5914 | /* init memory */ |
| 5915 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5916 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5917 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5918 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5919 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5920 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5921 | 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] | 5922 | retval->ext_size++; |
| 5923 | if (r) { |
| 5924 | goto error; |
| 5925 | } |
| 5926 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5927 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 5928 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5929 | if (r) { |
| 5930 | goto error; |
| 5931 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 5932 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5933 | 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] | 5934 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5935 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5936 | goto error; |
| 5937 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5938 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5939 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5940 | notif->must_size++; |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 5941 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5942 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5943 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5944 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | /* last part - process data nodes */ |
| 5948 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5949 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5950 | node = read_yin_container(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5951 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5952 | node = read_yin_leaflist(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5953 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5954 | node = read_yin_leaf(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5955 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5956 | node = read_yin_list(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5957 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5958 | node = read_yin_choice(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5959 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5960 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5961 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5962 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5963 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5964 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5965 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5966 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5967 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5968 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5969 | goto error; |
| 5970 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5971 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5972 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5973 | } |
| 5974 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5975 | /* check XPath dependencies */ |
| 5976 | if (notif->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5977 | goto error; |
| 5978 | } |
| 5979 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5980 | return retval; |
| 5981 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5982 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5983 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5984 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5985 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5986 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | return NULL; |
| 5990 | } |
| 5991 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5992 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5993 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5994 | read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5995 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5996 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5997 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5998 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5999 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 6000 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6001 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6002 | 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] | 6003 | void *reallocated; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6004 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6005 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6006 | if (module->version < 2) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6007 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "action"); |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 6008 | return NULL; |
| 6009 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6010 | for (node = parent; node; node = lys_parent(node)) { |
Radek Krejci | a3b19f7 | 2016-09-30 13:02:45 +0200 | [diff] [blame] | 6011 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6012 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6013 | LOGVAL(LYE_INPAR, LY_VLOG_LYS, parent, strnodetype(node->nodetype), "action"); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6014 | return NULL; |
| 6015 | } |
| 6016 | } |
| 6017 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6018 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6019 | /* init */ |
| 6020 | memset(&root, 0, sizeof root); |
| 6021 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6022 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6023 | if (!rpc) { |
| 6024 | LOGMEM; |
| 6025 | return NULL; |
| 6026 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6027 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6028 | rpc->prev = (struct lys_node *)rpc; |
| 6029 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6030 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6031 | 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] | 6032 | goto error; |
| 6033 | } |
| 6034 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6035 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 6036 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6037 | /* insert the node into the schema tree */ |
| 6038 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6039 | goto error; |
| 6040 | } |
| 6041 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6042 | /* process rpc's specific children */ |
| 6043 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6044 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6045 | /* extension */ |
| 6046 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6047 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6048 | } else if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6049 | if (c_input) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6050 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6051 | goto error; |
| 6052 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6053 | c_input++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6054 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6055 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6056 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6057 | if (c_output) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6058 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6059 | goto error; |
| 6060 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6061 | c_output++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6062 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6063 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6064 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6065 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6066 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6067 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6068 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6069 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6070 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6071 | } else if (!strcmp(sub->name, "typedef")) { |
| 6072 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6073 | } else if (!strcmp(sub->name, "if-feature")) { |
| 6074 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6075 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6076 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6077 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6082 | if (c_tpdf) { |
| 6083 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6084 | if (!rpc->tpdf) { |
| 6085 | LOGMEM; |
| 6086 | goto error; |
| 6087 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6088 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6089 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6090 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
| 6091 | if (!rpc->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6092 | LOGMEM; |
| 6093 | goto error; |
| 6094 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6095 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6096 | if (c_ext) { |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6097 | /* some extensions may be already present from the substatements */ |
| 6098 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6099 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6100 | LOGMEM; |
| 6101 | goto error; |
| 6102 | } |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6103 | retval->ext = reallocated; |
| 6104 | |
| 6105 | /* init memory */ |
| 6106 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6107 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6108 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6109 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6110 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6111 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6112 | 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] | 6113 | retval->ext_size++; |
| 6114 | if (r) { |
| 6115 | goto error; |
| 6116 | } |
| 6117 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6118 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 6119 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6120 | if (r) { |
| 6121 | goto error; |
| 6122 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6123 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6124 | 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] | 6125 | rpc->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6126 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6127 | goto error; |
| 6128 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6129 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | /* last part - process data nodes */ |
| 6133 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6134 | if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6135 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6136 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6137 | node = read_yin_input_output(module, retval, sub, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6138 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6139 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6140 | goto error; |
| 6141 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6142 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6143 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6144 | } |
| 6145 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6146 | return retval; |
| 6147 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6148 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6149 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6150 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6151 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6152 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | return NULL; |
| 6156 | } |
| 6157 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6158 | /* logs directly |
| 6159 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6160 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 6161 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 6162 | * we just get information but we do not apply augment or refine to it. |
| 6163 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6164 | static struct lys_node * |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 6165 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6166 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6167 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6168 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6169 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6170 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6171 | 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] | 6172 | int r; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6173 | void *reallocated; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6174 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6175 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6176 | if (!uses) { |
| 6177 | LOGMEM; |
| 6178 | return NULL; |
| 6179 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6180 | uses->nodetype = LYS_USES; |
| 6181 | uses->prev = (struct lys_node *)uses; |
| 6182 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6183 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6184 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6185 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 6186 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6187 | 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] | 6188 | goto error; |
| 6189 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6190 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6191 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 6192 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6193 | /* insert the node into the schema tree */ |
| 6194 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6195 | goto error; |
| 6196 | } |
| 6197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6198 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6199 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6200 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6201 | /* extension */ |
| 6202 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6203 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6204 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6205 | c_ref++; |
| 6206 | } else if (!strcmp(sub->name, "augment")) { |
| 6207 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6208 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 6209 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6210 | } else if (!strcmp(sub->name, "when")) { |
| 6211 | if (uses->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6212 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6213 | goto error; |
| 6214 | } |
| 6215 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 6216 | uses->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6217 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6218 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6219 | goto error; |
| 6220 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6221 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6222 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6223 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6224 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6225 | } |
| 6226 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6227 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6228 | /* process properties with cardinality 0..n */ |
| 6229 | if (c_ref) { |
| 6230 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6231 | if (!uses->refine) { |
| 6232 | LOGMEM; |
| 6233 | goto error; |
| 6234 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6235 | } |
| 6236 | if (c_aug) { |
| 6237 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6238 | if (!uses->augment) { |
| 6239 | LOGMEM; |
| 6240 | goto error; |
| 6241 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6242 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6243 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6244 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
| 6245 | if (!uses->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6246 | LOGMEM; |
| 6247 | goto error; |
| 6248 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6249 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6250 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6251 | /* some extensions may be already present from the substatements */ |
| 6252 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6253 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6254 | LOGMEM; |
| 6255 | goto error; |
| 6256 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6257 | retval->ext = reallocated; |
| 6258 | |
| 6259 | /* init memory */ |
| 6260 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6261 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6262 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6263 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6264 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6265 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6266 | 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] | 6267 | retval->ext_size++; |
| 6268 | if (r) { |
| 6269 | goto error; |
| 6270 | } |
| 6271 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 6272 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6273 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6274 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6275 | goto error; |
| 6276 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6277 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6278 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 6279 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6280 | if (r) { |
| 6281 | goto error; |
| 6282 | } |
| 6283 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6284 | 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] | 6285 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6286 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6287 | goto error; |
| 6288 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6289 | } |
| 6290 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6291 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6292 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6293 | goto error; |
| 6294 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6295 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6296 | /* check XPath dependencies */ |
| 6297 | if (uses->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 6298 | goto error; |
| 6299 | } |
| 6300 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6301 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6302 | |
| 6303 | error: |
| 6304 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6305 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6306 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6307 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6308 | } |
| 6309 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6310 | /* logs directly |
| 6311 | * |
| 6312 | * common code for yin_read_module() and yin_read_submodule() |
| 6313 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6314 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6315 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 6316 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6317 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6318 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6319 | struct lyxml_elem *next, *child, *child2, root, grps, augs, revs, exts; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6320 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6321 | struct lys_module *trg; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6322 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6323 | int i, r, ret = -1; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6324 | int version_flag = 0; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6325 | /* (sub)module substatements are ordered in groups, increment this value when moving to another group |
| 6326 | * 0 - header-stmts, 1 - linkage-stmts, 2 - meta-stmts, 3 - revision-stmts, 4 - body-stmts */ |
| 6327 | int substmt_group; |
| 6328 | /* just remember last substatement for logging */ |
| 6329 | const char *substmt_prev; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6330 | /* counters */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6331 | 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; |
| 6332 | int c_ext = 0, c_extinst = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6333 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6334 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6335 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 6336 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6337 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6338 | /* init */ |
| 6339 | memset(&root, 0, sizeof root); |
| 6340 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6341 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6342 | memset(&exts, 0, sizeof exts); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6343 | memset(&revs, 0, sizeof revs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6344 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6345 | /* |
| 6346 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 6347 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 6348 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 6349 | * need have all top-level and groupings already prepared at that time. In |
| 6350 | * the middle loop, we process other elements with carinality of 0..n since |
| 6351 | * we need to allocate arrays to store them. |
| 6352 | */ |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6353 | substmt_group = 0; |
| 6354 | substmt_prev = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6355 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6356 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6357 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6358 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6359 | continue; |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6360 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6361 | /* possible extension instance */ |
| 6362 | lyxml_unlink_elem(module->ctx, child, 2); |
| 6363 | lyxml_add_child(module->ctx, &exts, child); |
| 6364 | c_extinst++; |
| 6365 | } else if (!submodule && !strcmp(child->name, "namespace")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6366 | if (substmt_group > 0) { |
| 6367 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6368 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6369 | child->name, substmt_prev); |
| 6370 | goto error; |
| 6371 | } |
| 6372 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6373 | if (trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6374 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6375 | goto error; |
| 6376 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6377 | GETVAL(value, child, "uri"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6378 | trg->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6379 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6380 | 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] | 6381 | goto error; |
| 6382 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6383 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6384 | |
| 6385 | substmt_prev = "namespace"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6386 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6387 | if (substmt_group > 0) { |
| 6388 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6389 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6390 | child->name, substmt_prev); |
| 6391 | goto error; |
| 6392 | } |
| 6393 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6394 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6395 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6396 | goto error; |
| 6397 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6398 | GETVAL(value, child, "value"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6399 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, trg, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6400 | goto error; |
| 6401 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6402 | trg->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6403 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6404 | 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] | 6405 | goto error; |
| 6406 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6407 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6408 | |
| 6409 | substmt_prev = "prefix"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6410 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6411 | if (substmt_group > 0) { |
| 6412 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6413 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6414 | child->name, substmt_prev); |
| 6415 | goto error; |
| 6416 | } |
| 6417 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6418 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6419 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6420 | goto error; |
| 6421 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6422 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 6423 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6424 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6425 | goto error; |
| 6426 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 6427 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6428 | 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] | 6429 | goto error; |
| 6430 | } |
| 6431 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6432 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6433 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6434 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6435 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6436 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6437 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6438 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6439 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6440 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6441 | goto error; |
| 6442 | } |
| 6443 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6444 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6445 | /* check here differs from a generic prefix check, since this prefix |
| 6446 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6447 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6448 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6449 | goto error; |
| 6450 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6451 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 6452 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6453 | 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] | 6454 | goto error; |
| 6455 | } |
| 6456 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6457 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6458 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6459 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6460 | substmt_prev = "belongs-to"; |
| 6461 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6462 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6463 | } else if (!strcmp(child->name, "import")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6464 | if (substmt_group > 1) { |
| 6465 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6466 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6467 | child->name, substmt_prev); |
| 6468 | goto error; |
| 6469 | } |
| 6470 | substmt_group = 1; |
| 6471 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6472 | c_imp++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6473 | |
| 6474 | substmt_prev = "import"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6475 | } else if (!strcmp(child->name, "revision")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6476 | if (substmt_group > 3) { |
| 6477 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6478 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6479 | child->name, substmt_prev); |
| 6480 | goto error; |
| 6481 | } |
| 6482 | substmt_group = 3; |
| 6483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6484 | c_rev++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6485 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6486 | lyxml_unlink_elem(ctx, child, 2); |
| 6487 | lyxml_add_child(ctx, &revs, child); |
| 6488 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6489 | substmt_prev = "revision"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6490 | } else if (!strcmp(child->name, "typedef")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6491 | substmt_group = 4; |
| 6492 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6493 | c_tpdf++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6494 | |
| 6495 | substmt_prev = "typedef"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6496 | } else if (!strcmp(child->name, "identity")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6497 | substmt_group = 4; |
| 6498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6499 | c_ident++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6500 | |
| 6501 | substmt_prev = "identity"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6502 | } else if (!strcmp(child->name, "include")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6503 | if (substmt_group > 1) { |
| 6504 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6505 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6506 | child->name, substmt_prev); |
| 6507 | goto error; |
| 6508 | } |
| 6509 | substmt_group = 1; |
| 6510 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6511 | c_inc++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6512 | |
| 6513 | substmt_prev = "include"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6514 | } else if (!strcmp(child->name, "augment")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6515 | substmt_group = 4; |
| 6516 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6517 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6518 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6519 | lyxml_unlink_elem(ctx, child, 2); |
| 6520 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6521 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6522 | substmt_prev = "augment"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6523 | } else if (!strcmp(child->name, "feature")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6524 | substmt_group = 4; |
| 6525 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6526 | c_ftrs++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6527 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6528 | substmt_prev = "feature"; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6529 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6530 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6531 | } else if (!strcmp(child->name, "container") || |
| 6532 | !strcmp(child->name, "leaf-list") || |
| 6533 | !strcmp(child->name, "leaf") || |
| 6534 | !strcmp(child->name, "list") || |
| 6535 | !strcmp(child->name, "choice") || |
| 6536 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6537 | !strcmp(child->name, "anyxml") || |
| 6538 | !strcmp(child->name, "rpc") || |
| 6539 | !strcmp(child->name, "notification")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6540 | substmt_group = 4; |
| 6541 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6542 | lyxml_unlink_elem(ctx, child, 2); |
| 6543 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6544 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6545 | substmt_prev = "data definition"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6546 | } else if (!strcmp(child->name, "grouping")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6547 | substmt_group = 4; |
| 6548 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6549 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6550 | lyxml_unlink_elem(ctx, child, 2); |
| 6551 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6552 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6553 | substmt_prev = "grouping"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6554 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6555 | } else if (!strcmp(child->name, "description")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6556 | if (substmt_group > 2) { |
| 6557 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6558 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6559 | child->name, substmt_prev); |
| 6560 | goto error; |
| 6561 | } |
| 6562 | substmt_group = 2; |
| 6563 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6564 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6565 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6566 | goto error; |
| 6567 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6568 | 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] | 6569 | goto error; |
| 6570 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6571 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6572 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6573 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6574 | goto error; |
| 6575 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6576 | |
| 6577 | substmt_prev = "description"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6578 | } else if (!strcmp(child->name, "reference")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6579 | if (substmt_group > 2) { |
| 6580 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6581 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6582 | child->name, substmt_prev); |
| 6583 | goto error; |
| 6584 | } |
| 6585 | substmt_group = 2; |
| 6586 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6587 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6588 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6589 | goto error; |
| 6590 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6591 | 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] | 6592 | goto error; |
| 6593 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6594 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6595 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6596 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6597 | goto error; |
| 6598 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6599 | |
| 6600 | substmt_prev = "reference"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6601 | } else if (!strcmp(child->name, "organization")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6602 | if (substmt_group > 2) { |
| 6603 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6604 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6605 | child->name, substmt_prev); |
| 6606 | goto error; |
| 6607 | } |
| 6608 | substmt_group = 2; |
| 6609 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6610 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6611 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6612 | goto error; |
| 6613 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6614 | 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] | 6615 | goto error; |
| 6616 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6617 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6618 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6619 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6620 | goto error; |
| 6621 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6622 | |
| 6623 | substmt_prev = "organization"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6624 | } else if (!strcmp(child->name, "contact")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6625 | if (substmt_group > 2) { |
| 6626 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6627 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6628 | child->name, substmt_prev); |
| 6629 | goto error; |
| 6630 | } |
| 6631 | substmt_group = 2; |
| 6632 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6633 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6634 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6635 | goto error; |
| 6636 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6637 | 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] | 6638 | goto error; |
| 6639 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6640 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6641 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6642 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6643 | goto error; |
| 6644 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6645 | |
| 6646 | substmt_prev = "contact"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6647 | } else if (!strcmp(child->name, "yang-version")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6648 | if (substmt_group > 0) { |
| 6649 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6650 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6651 | child->name, substmt_prev); |
| 6652 | goto error; |
| 6653 | } |
| 6654 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6655 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6656 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6657 | goto error; |
| 6658 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6659 | GETVAL(value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6660 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6661 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6662 | goto error; |
| 6663 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6664 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6665 | if (!strcmp(value, "1")) { |
| 6666 | if (submodule) { |
| 6667 | if (module->version > 1) { |
| 6668 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6669 | goto error; |
| 6670 | } |
| 6671 | } else { |
| 6672 | module->version = 1; |
| 6673 | } |
| 6674 | } else { |
| 6675 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6676 | if (module->version < 2) { |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6677 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6678 | goto error; |
| 6679 | } |
| 6680 | } else { |
| 6681 | module->version = 2; |
| 6682 | } |
| 6683 | } |
| 6684 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6685 | 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] | 6686 | goto error; |
| 6687 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6688 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6689 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6690 | substmt_prev = "yang-version"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6691 | } else if (!strcmp(child->name, "extension")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6692 | substmt_group = 4; |
| 6693 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6694 | c_ext++; |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 6695 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6696 | substmt_prev = "extension"; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6697 | } else if (!strcmp(child->name, "deviation")) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6698 | substmt_group = 4; |
| 6699 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6700 | c_dev++; |
| 6701 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6702 | substmt_prev = "deviation"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6703 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6704 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6705 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6706 | } |
| 6707 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6708 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6709 | /* check for mandatory statements */ |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6710 | if (submodule) { |
| 6711 | if (!submodule->prefix) { |
| 6712 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
| 6713 | goto error; |
| 6714 | } |
| 6715 | if (!version_flag) { |
| 6716 | /* check version compatibility with the main module */ |
| 6717 | if (module->version > 1) { |
| 6718 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6719 | goto error; |
| 6720 | } |
| 6721 | } |
| 6722 | } else { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6723 | if (!trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6724 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6725 | goto error; |
| 6726 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6727 | if (!trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6728 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6729 | goto error; |
| 6730 | } |
| 6731 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 6732 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6733 | /* allocate arrays for elements with cardinality of 0..n */ |
| 6734 | if (c_imp) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6735 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6736 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6737 | LOGMEM; |
| 6738 | goto error; |
| 6739 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6740 | } |
| 6741 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6742 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 6743 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6744 | LOGMEM; |
| 6745 | goto error; |
| 6746 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6747 | } |
| 6748 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6749 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 6750 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6751 | LOGMEM; |
| 6752 | goto error; |
| 6753 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6754 | } |
| 6755 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6756 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 6757 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6758 | LOGMEM; |
| 6759 | goto error; |
| 6760 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6761 | } |
| 6762 | if (c_inc) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6763 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6764 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6765 | LOGMEM; |
| 6766 | goto error; |
| 6767 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6768 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6769 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6770 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 6771 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6772 | LOGMEM; |
| 6773 | goto error; |
| 6774 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6775 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6776 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6777 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 6778 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6779 | LOGMEM; |
| 6780 | goto error; |
| 6781 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6782 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6783 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6784 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 6785 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6786 | LOGMEM; |
| 6787 | goto error; |
| 6788 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6789 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6790 | if (c_ext) { |
| 6791 | trg->extensions = calloc(c_ext, sizeof *trg->extensions); |
| 6792 | if (!trg->extensions) { |
| 6793 | LOGMEM; |
| 6794 | goto error; |
| 6795 | } |
| 6796 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6797 | if (c_extinst) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6798 | /* some extensions may be already present from the substatements */ |
| 6799 | reallocated = realloc(trg->ext, (c_extinst + trg->ext_size) * sizeof *trg->ext); |
| 6800 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6801 | LOGMEM; |
| 6802 | goto error; |
| 6803 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6804 | trg->ext = reallocated; |
| 6805 | |
| 6806 | /* init memory */ |
| 6807 | memset(&trg->ext[trg->ext_size], 0, c_extinst * sizeof *trg->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6808 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6809 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6810 | /* middle part 1 - process revision and then check whether this (sub)module was not already parsed, add it there */ |
| 6811 | LY_TREE_FOR_SAFE(revs.child, next, child) { |
| 6812 | GETVAL(value, child, "date"); |
| 6813 | if (lyp_check_date(value)) { |
| 6814 | goto error; |
| 6815 | } |
| 6816 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
| 6817 | /* check uniqueness of the revision date - not required by RFC */ |
| 6818 | for (i = 0; i < trg->rev_size; i++) { |
| 6819 | if (!strcmp(value, trg->rev[i].date)) { |
| 6820 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 6821 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Revision is not unique."); |
| 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | LY_TREE_FOR(child->child, child2) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6826 | if (!child2->ns) { |
| 6827 | /* garbage */ |
| 6828 | continue; |
| 6829 | } else if (strcmp(child2->ns->value, LY_NSYIN)) { |
| 6830 | /* possible extension instance */ |
| 6831 | if (lyp_yin_parse_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6832 | child2, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 6833 | goto error; |
| 6834 | } |
| 6835 | } else if (!strcmp(child2->name, "description")) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6836 | if (trg->rev[trg->rev_size].dsc) { |
| 6837 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
| 6838 | goto error; |
| 6839 | } |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6840 | if (lyp_yin_parse_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6841 | child2, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 6842 | goto error; |
| 6843 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6844 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 6845 | if (!trg->rev[trg->rev_size].dsc) { |
| 6846 | goto error; |
| 6847 | } |
| 6848 | } else if (!strcmp(child2->name, "reference")) { |
| 6849 | if (trg->rev[trg->rev_size].ref) { |
| 6850 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
| 6851 | goto error; |
| 6852 | } |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame^] | 6853 | if (lyp_yin_parse_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6854 | child2, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 6855 | goto error; |
| 6856 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6857 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 6858 | if (!trg->rev[trg->rev_size].ref) { |
| 6859 | goto error; |
| 6860 | } |
| 6861 | } else { |
| 6862 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child2->name); |
| 6863 | goto error; |
| 6864 | } |
| 6865 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6866 | trg->rev_size++; |
| 6867 | |
| 6868 | lyxml_free(ctx, child); |
| 6869 | } |
| 6870 | |
| 6871 | /* check the module with respect to the context now */ |
| 6872 | if (!submodule) { |
| 6873 | switch (lyp_ctx_check_module(module)) { |
| 6874 | case -1: |
| 6875 | goto error; |
| 6876 | case 0: |
| 6877 | break; |
| 6878 | case 1: |
| 6879 | /* it's already there */ |
| 6880 | ret = 1; |
| 6881 | goto error; |
| 6882 | } |
| 6883 | } |
| 6884 | |
| 6885 | /* 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] | 6886 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6887 | if (!strcmp(child->name, "import")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6888 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size], unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6889 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6890 | if (r) { |
| 6891 | goto error; |
| 6892 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6893 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6894 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6895 | r = fill_yin_include(module, submodule, child, &trg->inc[trg->inc_size], unres); |
| 6896 | trg->inc_size++; |
| 6897 | if (r) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6898 | goto error; |
| 6899 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6900 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6901 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6902 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 6903 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6904 | if (r) { |
| 6905 | goto error; |
| 6906 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6907 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6908 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6909 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 6910 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6911 | if (r) { |
| 6912 | goto error; |
| 6913 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6914 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6915 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6916 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 6917 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6918 | if (r) { |
| 6919 | goto error; |
| 6920 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6921 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6922 | } else if (!strcmp(child->name, "extension")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6923 | r = fill_yin_extension(trg, child, &trg->extensions[trg->extensions_size], unres); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6924 | trg->extensions_size++; |
| 6925 | if (r) { |
| 6926 | goto error; |
| 6927 | } |
| 6928 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6929 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6930 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 6931 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6932 | if (r) { |
| 6933 | goto error; |
| 6934 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6935 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6936 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6937 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6938 | /* process extension instances */ |
| 6939 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6940 | r = lyp_yin_fill_ext(trg, LYEXT_PAR_MODULE, 0, 0, trg, child, &trg->ext, trg->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6941 | trg->ext_size++; |
| 6942 | if (r) { |
| 6943 | goto error; |
| 6944 | } |
| 6945 | } |
| 6946 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6947 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6948 | * refer to them. Submodule's data nodes are stored in the |
| 6949 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6950 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6951 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6952 | node = read_yin_grouping(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6953 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6954 | goto error; |
| 6955 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6956 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6957 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6958 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6959 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6960 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6961 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6962 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6963 | if (!strcmp(child->name, "container")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6964 | node = read_yin_container(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6965 | } else if (!strcmp(child->name, "leaf-list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6966 | node = read_yin_leaflist(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6967 | } else if (!strcmp(child->name, "leaf")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6968 | node = read_yin_leaf(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6969 | } else if (!strcmp(child->name, "list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6970 | node = read_yin_list(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6971 | } else if (!strcmp(child->name, "choice")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6972 | node = read_yin_choice(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6973 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 6974 | node = read_yin_uses(trg, NULL, child, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6975 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6976 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 1, unres); |
| 6977 | } else if (!strcmp(child->name, "anydata")) { |
| 6978 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6979 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6980 | node = read_yin_rpc_action(trg, NULL, child, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6981 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6982 | node = read_yin_notif(trg, NULL, child, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6983 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6984 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6985 | goto error; |
| 6986 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 6987 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6988 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6989 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6990 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6991 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 6992 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6993 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 6994 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6995 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6996 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6997 | goto error; |
| 6998 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6999 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7000 | } |
| 7001 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7002 | return 0; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7003 | |
| 7004 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7005 | while (root.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7006 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7007 | } |
| 7008 | while (grps.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7009 | lyxml_free(ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7010 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7011 | while (augs.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7012 | lyxml_free(ctx, augs.child); |
| 7013 | } |
| 7014 | while (revs.child) { |
| 7015 | lyxml_free(ctx, revs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 7016 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7017 | while (exts.child) { |
| 7018 | lyxml_free(module->ctx, exts.child); |
| 7019 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7020 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7021 | return ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7022 | } |
| 7023 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7024 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7025 | struct lys_submodule * |
| 7026 | 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] | 7027 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7028 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7029 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7030 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7031 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7032 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7033 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 7034 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7035 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7036 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7037 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7038 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7039 | /* check root element */ |
| 7040 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7041 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7042 | goto error; |
| 7043 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7044 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7045 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7046 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7047 | goto error; |
| 7048 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7049 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7050 | submodule = calloc(1, sizeof *submodule); |
| 7051 | if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7052 | LOGMEM; |
| 7053 | goto error; |
| 7054 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7055 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7056 | submodule->ctx = module->ctx; |
| 7057 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 7058 | submodule->type = 1; |
| 7059 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7060 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7061 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7062 | /* module cannot be changed in this case and 1 cannot be returned */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7063 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7064 | goto error; |
| 7065 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7066 | |
Radek Krejci | 33fc477 | 2017-01-26 16:00:35 +0100 | [diff] [blame] | 7067 | lyp_sort_revisions((struct lys_module *)submodule); |
| 7068 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7069 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7070 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7071 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7072 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7073 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7074 | |
| 7075 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7076 | /* cleanup */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7077 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7078 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7079 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7080 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7081 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7082 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7083 | } |
| 7084 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7085 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7086 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7087 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 7088 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7089 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7090 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7091 | } |
| 7092 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7093 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 7094 | struct lys_module * |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7095 | yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7096 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7097 | struct lyxml_elem *yin; |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 7098 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7099 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7100 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7101 | int ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7102 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7103 | unres = calloc(1, sizeof *unres); |
| 7104 | if (!unres) { |
| 7105 | LOGMEM; |
| 7106 | return NULL; |
| 7107 | } |
| 7108 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 7109 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7110 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7111 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7112 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7113 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7114 | /* check root element */ |
| 7115 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7116 | if (ly_strequal("submodule", yin->name, 0)) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7117 | LOGVAL(LYE_SUBMODULE, LY_VLOG_NONE, NULL); |
| 7118 | } else { |
| 7119 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7120 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7121 | goto error; |
| 7122 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7123 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7124 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7125 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7126 | goto error; |
| 7127 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7128 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7129 | module = calloc(1, sizeof *module); |
| 7130 | if (!module) { |
| 7131 | LOGMEM; |
| 7132 | goto error; |
| 7133 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7134 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7135 | module->ctx = ctx; |
| 7136 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 7137 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 7138 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7139 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7140 | LOGVRB("Reading module \"%s\".", module->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7141 | ret = read_sub_module(module, NULL, yin, unres); |
| 7142 | if (ret == -1) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7143 | goto error; |
| 7144 | } |
| 7145 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7146 | if (ret == 1) { |
| 7147 | assert(!unres->count); |
| 7148 | } else { |
| 7149 | /* resolve rest of unres items */ |
| 7150 | if (unres->count && resolve_unres_schema(module, unres)) { |
| 7151 | goto error; |
| 7152 | } |
| 7153 | |
| 7154 | /* check correctness of includes */ |
| 7155 | if (lyp_check_include_missing(module)) { |
| 7156 | goto error; |
| 7157 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7158 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7159 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7160 | lyp_sort_revisions(module); |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 7161 | |
| 7162 | if (lyp_rfn_apply_ext(module) || lyp_deviation_apply_ext(module)) { |
| 7163 | goto error; |
| 7164 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7165 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7166 | if (revision) { |
| 7167 | /* check revision of the parsed model */ |
| 7168 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 7169 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 7170 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7171 | goto error; |
| 7172 | } |
| 7173 | } |
| 7174 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7175 | /* add into context if not already there */ |
| 7176 | if (!ret) { |
| 7177 | if (module->deviation_size && !module->implemented) { |
| 7178 | LOGVRB("Module \"%s\" includes deviations, changing its conformance to \"implement\".", module->name); |
| 7179 | /* deviations always causes target to be made implemented, |
| 7180 | * but augents and leafrefs not, so we have to apply them now */ |
| 7181 | if (lys_set_implemented(module)) { |
| 7182 | goto error; |
| 7183 | } |
| 7184 | } |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7185 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7186 | if (lyp_ctx_add_module(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 7187 | goto error; |
| 7188 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7189 | } else { |
| 7190 | /* free what was parsed */ |
| 7191 | lys_free(module, NULL, 0); |
| 7192 | |
| 7193 | /* get the model from the context */ |
| 7194 | module = (struct lys_module *)ly_ctx_get_module(ctx, value, revision); |
| 7195 | assert(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7196 | } |
| 7197 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7198 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7199 | unres_schema_free(NULL, &unres); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7200 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7201 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7202 | |
| 7203 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7204 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7205 | lyxml_free(ctx, yin); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7206 | unres_schema_free(module, &unres); |
| 7207 | |
| 7208 | if (!module) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7209 | if (ly_vecode != LYVE_SUBMODULE) { |
| 7210 | LOGERR(ly_errno, "Module parsing failed."); |
| 7211 | } |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7212 | return NULL; |
| 7213 | } |
| 7214 | |
| 7215 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7216 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7217 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7218 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7219 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7220 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7221 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7222 | static int |
| 7223 | yin_parse_extcomplex_bool(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7224 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7225 | const char *true_val, const char *false_val, struct unres_schema *unres) |
| 7226 | { |
| 7227 | uint8_t *val; |
| 7228 | const char *str; |
| 7229 | struct lyext_substmt *info; |
| 7230 | |
| 7231 | val = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7232 | if (!val) { |
| 7233 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7234 | return EXIT_FAILURE; |
| 7235 | } |
| 7236 | if (*val) { |
| 7237 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7238 | return EXIT_FAILURE; |
| 7239 | } |
| 7240 | |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7241 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7242 | return EXIT_FAILURE; |
| 7243 | } |
| 7244 | |
| 7245 | str = lyxml_get_attr(node, "value", NULL); |
| 7246 | if (!str) { |
| 7247 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7248 | } else if (true_val && !strcmp(true_val, str)) { |
| 7249 | /* true value */ |
| 7250 | *val = 1; |
| 7251 | } else if (false_val && !strcmp(false_val, str)) { |
| 7252 | /* false value */ |
| 7253 | *val = 2; |
| 7254 | } else { |
| 7255 | /* unknown value */ |
| 7256 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7257 | return EXIT_FAILURE; |
| 7258 | } |
| 7259 | |
| 7260 | return EXIT_SUCCESS; |
| 7261 | } |
| 7262 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7263 | /* |
| 7264 | * argelem - 1 if the value is stored in a standalone YIN element, 0 if stored as attribute |
| 7265 | * argname - name of the element/attribute where the value is stored |
| 7266 | */ |
| 7267 | static int |
| 7268 | yin_parse_extcomplex_str(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7269 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7270 | int argelem, const char *argname, struct unres_schema *unres) |
| 7271 | { |
| 7272 | int c; |
| 7273 | const char **str, ***p = NULL; |
| 7274 | void *reallocated; |
| 7275 | struct lyext_substmt *info; |
| 7276 | |
| 7277 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7278 | if (!str) { |
| 7279 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7280 | return EXIT_FAILURE; |
| 7281 | } |
| 7282 | if (info->cardinality < LY_STMT_CARD_SOME && *str) { |
| 7283 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7284 | return EXIT_FAILURE; |
| 7285 | } |
| 7286 | |
| 7287 | c = 0; |
| 7288 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7289 | /* there can be multiple instances, str is actually const char *** */ |
| 7290 | p = (const char ***)str; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7291 | if (!p[0]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7292 | /* allocate initial array */ |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7293 | p[0] = malloc(2 * sizeof(const char *)); |
| 7294 | if (stmt == LY_STMT_BELONGSTO) { |
| 7295 | /* allocate another array for the belongs-to's prefixes */ |
| 7296 | p[1] = malloc(2 * sizeof(const char *)); |
| 7297 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7298 | } else { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7299 | /* get the index in the array to add new item */ |
| 7300 | for (c = 0; p[0][c]; c++); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7301 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7302 | str = p[0]; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7303 | } |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7304 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, stmt, c, unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7305 | return EXIT_FAILURE; |
| 7306 | } |
| 7307 | |
| 7308 | if (argelem) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7309 | str[c] = read_yin_subnode(mod->ctx, node, argname); |
| 7310 | if (!str[c]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7311 | return EXIT_FAILURE; |
| 7312 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7313 | } else { |
| 7314 | str[c] = lyxml_get_attr(node, argname, NULL); |
| 7315 | if (!str[c]) { |
| 7316 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, argname, node->name); |
| 7317 | return EXIT_FAILURE; |
| 7318 | } else { |
| 7319 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7320 | } |
| 7321 | |
| 7322 | if (stmt == LY_STMT_BELONGSTO) { |
| 7323 | /* get the belongs-to's mandatory prefix substatement */ |
| 7324 | if (!node->child) { |
| 7325 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", node->name); |
| 7326 | return EXIT_FAILURE; |
| 7327 | } else if (strcmp(node->child->name, "prefix")) { |
| 7328 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
| 7329 | return EXIT_FAILURE; |
| 7330 | } else if (node->child->next) { |
| 7331 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
| 7332 | return EXIT_FAILURE; |
| 7333 | } |
| 7334 | /* and now finally get the value */ |
| 7335 | if (p) { |
| 7336 | str = p[1]; |
| 7337 | } else { |
| 7338 | str++; |
| 7339 | } |
| 7340 | str[c] = lyxml_get_attr(node->child, "value", ((void *)0)); |
| 7341 | if (!str[c]) { |
| 7342 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
| 7343 | return EXIT_FAILURE; |
| 7344 | } |
| 7345 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7346 | |
| 7347 | if (!str[c] || lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
| 7348 | return EXIT_FAILURE; |
| 7349 | } |
| 7350 | } |
| 7351 | } |
| 7352 | if (p) { |
| 7353 | /* enlarge the array(s) */ |
| 7354 | reallocated = realloc(p[0], (c + 2) * sizeof(const char *)); |
| 7355 | if (!reallocated) { |
| 7356 | LOGMEM; |
| 7357 | lydict_remove(mod->ctx, p[0][c]); |
| 7358 | p[0][c] = NULL; |
| 7359 | return EXIT_FAILURE; |
| 7360 | } |
| 7361 | p[0] = reallocated; |
| 7362 | p[0][c + 1] = NULL; |
| 7363 | |
| 7364 | if (stmt == LY_STMT_BELONGSTO) { |
| 7365 | /* enlarge the second belongs-to's array with prefixes */ |
| 7366 | reallocated = realloc(p[1], (c + 2) * sizeof(const char *)); |
| 7367 | if (!reallocated) { |
| 7368 | LOGMEM; |
| 7369 | lydict_remove(mod->ctx, p[1][c]); |
| 7370 | p[1][c] = NULL; |
| 7371 | return EXIT_FAILURE; |
| 7372 | } |
| 7373 | p[1] = reallocated; |
| 7374 | p[1][c + 1] = NULL; |
| 7375 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7376 | } |
| 7377 | |
| 7378 | return EXIT_SUCCESS; |
| 7379 | } |
| 7380 | |
| 7381 | static void * |
| 7382 | yin_getplace_for_extcomplex_flags(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt, |
| 7383 | uint16_t mask) |
| 7384 | { |
| 7385 | void *data; |
| 7386 | struct lyext_substmt *info; |
| 7387 | |
| 7388 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7389 | if (!data) { |
| 7390 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7391 | return NULL; |
| 7392 | } |
| 7393 | if (info->cardinality < LY_STMT_CARD_SOME && ((*(uint16_t *)data) & mask)) { |
| 7394 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7395 | return NULL; |
| 7396 | } |
| 7397 | |
| 7398 | return data; |
| 7399 | } |
| 7400 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7401 | static int |
| 7402 | yin_parse_extcomplex_flag(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7403 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7404 | const char *val1_str, const char *val2_str, uint16_t mask, |
| 7405 | uint16_t val1, uint16_t val2, struct unres_schema *unres) |
| 7406 | { |
| 7407 | uint16_t *val; |
| 7408 | const char *str; |
| 7409 | |
| 7410 | val = yin_getplace_for_extcomplex_flags(node, ext, stmt, mask); |
| 7411 | if (!val) { |
| 7412 | return EXIT_FAILURE; |
| 7413 | } |
| 7414 | |
| 7415 | str = lyxml_get_attr(node, "value", NULL); |
| 7416 | if (!str) { |
| 7417 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7418 | } else if (!strcmp(val1_str, str)) { |
| 7419 | *val = *val | val1; |
| 7420 | } else if (!strcmp(val2_str, str)) { |
| 7421 | *val = *val | val2; |
| 7422 | } else { |
| 7423 | /* unknown value */ |
| 7424 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7425 | return EXIT_FAILURE; |
| 7426 | } |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7427 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7428 | return EXIT_FAILURE; |
| 7429 | } |
| 7430 | return EXIT_SUCCESS; |
| 7431 | } |
| 7432 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7433 | static void ** |
| 7434 | yin_getplace_for_extcomplex_struct(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7435 | { |
| 7436 | int c; |
| 7437 | void **data, ***p = NULL; |
| 7438 | void *reallocated; |
| 7439 | struct lyext_substmt *info; |
| 7440 | |
| 7441 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7442 | if (!data) { |
| 7443 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7444 | return NULL; |
| 7445 | } |
| 7446 | if (info->cardinality < LY_STMT_CARD_SOME && *data) { |
| 7447 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7448 | return NULL; |
| 7449 | } |
| 7450 | |
| 7451 | c = 0; |
| 7452 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7453 | /* there can be multiple instances, so instead of pointer to array, |
| 7454 | * we have in data pointer to pointer to array */ |
| 7455 | p = (void ***)data; |
| 7456 | data = *p; |
| 7457 | if (!data) { |
| 7458 | /* allocate initial array */ |
| 7459 | *p = data = malloc(2 * sizeof(void *)); |
| 7460 | } else { |
| 7461 | for (c = 0; *data; data++, c++); |
| 7462 | } |
| 7463 | } |
| 7464 | |
| 7465 | if (p) { |
| 7466 | /* enlarge the array */ |
| 7467 | reallocated = realloc(*p, (c + 2) * sizeof(void *)); |
| 7468 | if (!reallocated) { |
| 7469 | LOGMEM; |
| 7470 | return NULL; |
| 7471 | } |
| 7472 | *p = reallocated; |
| 7473 | data = *p; |
| 7474 | data[c + 1] = NULL; |
| 7475 | } |
| 7476 | |
| 7477 | return &data[c]; |
| 7478 | } |
| 7479 | |
| 7480 | int |
| 7481 | lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, struct lyxml_elem *yin, |
| 7482 | struct unres_schema *unres) |
| 7483 | { |
| 7484 | struct lyxml_elem *next, *node; |
| 7485 | struct lys_type **type; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7486 | void **pp, *p, *reallocated; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7487 | const char *value; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7488 | struct lyext_substmt *info; |
| 7489 | long int v; |
| 7490 | int i; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7491 | |
| 7492 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 7493 | if (!node->ns) { |
| 7494 | /* garbage */ |
| 7495 | } else if (node->ns == yin->ns && (ext->flags & LYS_YINELEM) && ly_strequal(node->name, ext->def->argument, 1)) { |
| 7496 | /* we have the extension's argument */ |
| 7497 | if (ext->arg_value) { |
| 7498 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 7499 | goto error; |
| 7500 | } |
| 7501 | ext->arg_value = node->content; |
| 7502 | node->content = NULL; |
| 7503 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 7504 | /* extension */ |
| 7505 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 7506 | goto error; |
| 7507 | } |
| 7508 | } else if (!strcmp(node->name, "description")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7509 | 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] | 7510 | goto error; |
| 7511 | } |
| 7512 | } else if (!strcmp(node->name, "reference")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7513 | 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] | 7514 | goto error; |
| 7515 | } |
| 7516 | } else if (!strcmp(node->name, "units")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7517 | 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] | 7518 | goto error; |
| 7519 | } |
| 7520 | } else if (!strcmp(node->name, "type")) { |
| 7521 | type = (struct lys_type **)yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPE); |
| 7522 | if (!type) { |
| 7523 | goto error; |
| 7524 | } |
| 7525 | /* allocate type structure */ |
| 7526 | (*type) = calloc(1, sizeof **type); |
| 7527 | |
| 7528 | /* HACK for unres */ |
| 7529 | (*type)->der = (struct lys_tpdf *)node; |
| 7530 | (*type)->parent = (struct lys_tpdf *)ext; |
| 7531 | |
| 7532 | if (unres_schema_add_node(mod, unres, *type, UNRES_TYPE_DER_EXT, NULL) == -1) { |
| 7533 | (*type)->der = NULL; |
| 7534 | goto error; |
| 7535 | } |
| 7536 | continue; /* skip lyxml_free() */ |
| 7537 | } else if (!strcmp(node->name, "if-feature")) { |
| 7538 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_IFFEATURE); |
| 7539 | if (!pp) { |
| 7540 | goto error; |
| 7541 | } |
| 7542 | /* allocate iffeature structure */ |
| 7543 | (*pp) = calloc(1, sizeof(struct lys_iffeature)); |
| 7544 | |
| 7545 | if (fill_yin_iffeature((struct lys_node *)ext, 0, node, *((struct lys_iffeature **)pp), unres)) { |
| 7546 | goto error; |
| 7547 | } |
| 7548 | } else if (!strcmp(node->name, "status")) { |
| 7549 | p = yin_getplace_for_extcomplex_flags(node, ext, LY_STMT_STATUS, LYS_STATUS_MASK); |
| 7550 | if (!p) { |
| 7551 | goto error; |
| 7552 | } |
| 7553 | |
| 7554 | GETVAL(value, node, "value"); |
| 7555 | if (!strcmp(value, "current")) { |
| 7556 | *(uint16_t*)p |= LYS_STATUS_CURR; |
| 7557 | } else if (!strcmp(value, "deprecated")) { |
| 7558 | *(uint16_t*)p |= LYS_STATUS_DEPRC; |
| 7559 | } else if (!strcmp(value, "obsolete")) { |
| 7560 | *(uint16_t*)p |= LYS_STATUS_OBSLT; |
| 7561 | } else { |
| 7562 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7563 | goto error; |
| 7564 | } |
| 7565 | |
| 7566 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
| 7567 | goto error; |
| 7568 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7569 | } else if (!strcmp(node->name, "config")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7570 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, "true", "false", LYS_CONFIG_MASK, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7571 | LYS_CONFIG_W | LYS_CONFIG_SET, LYS_CONFIG_R | LYS_CONFIG_SET, unres)) { |
| 7572 | goto error; |
| 7573 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7574 | } else if (!strcmp(node->name, "argument")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7575 | 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] | 7576 | goto error; |
| 7577 | } |
| 7578 | } else if (!strcmp(node->name, "default")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7579 | 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] | 7580 | goto error; |
| 7581 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7582 | } else if (!strcmp(node->name, "mandatory")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7583 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7584 | "true", "false", LYS_MAND_MASK, LYS_MAND_TRUE, LYS_MAND_FALSE, unres)) { |
| 7585 | goto error; |
| 7586 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7587 | } else if (!strcmp(node->name, "error-app-tag")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7588 | 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] | 7589 | goto error; |
| 7590 | } |
| 7591 | } else if (!strcmp(node->name, "error-message")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7592 | 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] | 7593 | goto error; |
| 7594 | } |
| 7595 | } else if (!strcmp(node->name, "prefix")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7596 | 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] | 7597 | goto error; |
| 7598 | } |
| 7599 | } else if (!strcmp(node->name, "namespace")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7600 | 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] | 7601 | goto error; |
| 7602 | } |
| 7603 | } else if (!strcmp(node->name, "presence")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7604 | 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] | 7605 | goto error; |
| 7606 | } |
| 7607 | } else if (!strcmp(node->name, "revision-date")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7608 | 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] | 7609 | goto error; |
| 7610 | } |
| 7611 | } else if (!strcmp(node->name, "key")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7612 | 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] | 7613 | goto error; |
| 7614 | } |
| 7615 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7616 | 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] | 7617 | goto error; |
| 7618 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7619 | } else if (!strcmp(node->name, "ordered-by")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7620 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_ORDEREDBY, |
| 7621 | "user", "system", LYS_USERORDERED, LYS_USERORDERED, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7622 | goto error; |
| 7623 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7624 | } else if (!strcmp(node->name, "belongs-to")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7625 | 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] | 7626 | goto error; |
| 7627 | } |
| 7628 | } else if (!strcmp(node->name, "contact")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7629 | 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] | 7630 | goto error; |
| 7631 | } |
| 7632 | } else if (!strcmp(node->name, "organization")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7633 | 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] | 7634 | goto error; |
| 7635 | } |
| 7636 | } else if (!strcmp(node->name, "path")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7637 | 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] | 7638 | goto error; |
| 7639 | } |
| 7640 | } else if (!strcmp(node->name, "yang-version")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7641 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_VERSION, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7642 | goto error; |
| 7643 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7644 | } else if (!strcmp(node->name, "require-instance")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7645 | 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] | 7646 | goto error; |
| 7647 | } |
| 7648 | } else if (!strcmp(node->name, "modifier")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7649 | 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] | 7650 | goto error; |
| 7651 | } |
| 7652 | } else if (!strcmp(node->name, "yin-element")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7653 | if (yin_parse_extcomplex_bool(mod, node, ext, LY_STMT_YINELEM, "true", "false", unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7654 | goto error; |
| 7655 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7656 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7657 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_VALUE, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7658 | goto error; |
| 7659 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7660 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 7661 | p = lys_ext_complex_get_substmt(LY_STMT_DIGITS, ext, &info); |
| 7662 | if (!p) { |
| 7663 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7664 | goto error; |
| 7665 | } |
| 7666 | if (info->cardinality < LY_STMT_CARD_SOME && (*(uint8_t *)p)) { |
| 7667 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7668 | goto error; |
| 7669 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7670 | pp = NULL; |
| 7671 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7672 | /* there can be multiple instances */ |
| 7673 | pp = p; |
Radek Krejci | b84686f | 2017-02-09 16:04:55 +0100 | [diff] [blame] | 7674 | i = 0; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7675 | if (!(*pp)) { |
| 7676 | /* allocate initial array */ |
Radek Krejci | b84686f | 2017-02-09 16:04:55 +0100 | [diff] [blame] | 7677 | *pp = malloc(2 * sizeof(uint8_t)); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7678 | } else { |
Radek Krejci | b84686f | 2017-02-09 16:04:55 +0100 | [diff] [blame] | 7679 | for (i = 0; (*(uint8_t**)pp)[i]; i++); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7680 | } |
Radek Krejci | b84686f | 2017-02-09 16:04:55 +0100 | [diff] [blame] | 7681 | p = &(*(uint8_t**)pp)[i]; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7682 | } |
| 7683 | |
| 7684 | GETVAL(value, node, "value"); |
| 7685 | v = strtol(value, NULL, 10); |
| 7686 | |
| 7687 | /* range check */ |
| 7688 | if (v < 1 || v > 18) { |
| 7689 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7690 | goto error; |
| 7691 | } |
| 7692 | |
| 7693 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, i, unres)) { |
| 7694 | goto error; |
| 7695 | } |
| 7696 | |
| 7697 | /* store the value */ |
| 7698 | (*(uint8_t *)p) = (uint8_t)v; |
| 7699 | |
| 7700 | if (pp) { |
| 7701 | /* enlarge the array */ |
| 7702 | reallocated = realloc(*pp, (i + 2) * sizeof(uint8_t*)); |
| 7703 | if (!reallocated) { |
| 7704 | LOGMEM; |
| 7705 | goto error; |
| 7706 | } |
| 7707 | *pp = reallocated; |
Radek Krejci | b84686f | 2017-02-09 16:04:55 +0100 | [diff] [blame] | 7708 | (*(uint8_t**)pp)[i + 1] = 0; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7709 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7710 | } else { |
| 7711 | LOGERR(LY_SUCCESS, "Extension's substatement \"%s\" not yet supported.", node->name); |
| 7712 | //LOGERR(LY_EINT, "Extension's substatement \"%s\" not yet supported.", node->name); |
| 7713 | //return EXIT_FAILURE; |
| 7714 | } |
| 7715 | lyxml_free(mod->ctx, node); |
| 7716 | } |
| 7717 | |
| 7718 | /* TODO check for mandatory substatements */ |
| 7719 | return EXIT_SUCCESS; |
| 7720 | |
| 7721 | error: |
| 7722 | return EXIT_FAILURE; |
| 7723 | } |