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 | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 122 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 123 | read_yin_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; |
| 177 | case LYEXT_PAR_FEATURE: |
| 178 | ext_size = &((struct lys_feature *)elem)->ext_size; |
| 179 | ext = &((struct lys_feature *)elem)->ext; |
| 180 | break; |
| 181 | case LYEXT_PAR_REFINE: |
| 182 | ext_size = &((struct lys_refine *)elem)->ext_size; |
| 183 | ext = &((struct lys_refine *)elem)->ext; |
| 184 | break; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 185 | case LYEXT_PAR_RESTR: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 186 | ext_size = &((struct lys_restr *)elem)->ext_size; |
| 187 | ext = &((struct lys_restr *)elem)->ext; |
| 188 | break; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 189 | case LYEXT_PAR_WHEN: |
| 190 | ext_size = &((struct lys_when *)elem)->ext_size; |
| 191 | ext = &((struct lys_when *)elem)->ext; |
| 192 | break; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 193 | case LYEXT_PAR_DEVIATE: |
| 194 | ext_size = &((struct lys_deviate *)elem)->ext_size; |
| 195 | ext = &((struct lys_deviate *)elem)->ext; |
| 196 | break; |
| 197 | case LYEXT_PAR_DEVIATION: |
| 198 | ext_size = &((struct lys_deviation *)elem)->ext_size; |
| 199 | ext = &((struct lys_deviation *)elem)->ext; |
| 200 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 201 | default: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 202 | LOGERR(LY_EINT, "parent type %d", elem_type); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 203 | return EXIT_FAILURE; |
| 204 | } |
| 205 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 206 | if (type == LYEXT_SUBSTMT_SELF) { |
| 207 | /* parse for the statement self, not for the substatement */ |
| 208 | child = yin; |
| 209 | next = NULL; |
| 210 | goto parseext; |
| 211 | } |
| 212 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 213 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 214 | if (!strcmp(child->ns->value, LY_NSYIN)) { |
| 215 | /* skip the regular YIN nodes */ |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | /* parse it as extension */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 220 | parseext: |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 221 | |
| 222 | /* first, allocate a space for the extension instance in the parent elem */ |
| 223 | reallocated = realloc(*ext, (1 + (*ext_size)) * sizeof **ext); |
| 224 | if (!reallocated) { |
| 225 | LOGMEM; |
| 226 | return EXIT_FAILURE; |
| 227 | } |
| 228 | (*ext) = reallocated; |
| 229 | |
| 230 | /* init memory */ |
| 231 | (*ext)[(*ext_size)] = NULL; |
| 232 | |
| 233 | /* parse YIN data */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 234 | 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] | 235 | (*ext_size)++; |
| 236 | if (r) { |
| 237 | return EXIT_FAILURE; |
| 238 | } |
| 239 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 240 | /* 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] | 241 | } |
| 242 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 243 | return EXIT_SUCCESS; |
| 244 | } |
| 245 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 246 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 247 | static int |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 248 | fill_yin_iffeature(struct lys_node *parent, int parent_is_feature, struct lyxml_elem *yin, struct lys_iffeature *iffeat, |
| 249 | struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 250 | { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 251 | int r, c_ext = 0; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 252 | const char *value; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 253 | struct lyxml_elem *node, *next; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 254 | |
| 255 | GETVAL(value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 256 | |
| 257 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
| 258 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 259 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 260 | return EXIT_FAILURE; |
| 261 | } |
| 262 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 263 | if (!(value = transform_iffeat_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 264 | return EXIT_FAILURE; |
| 265 | } |
| 266 | |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 267 | r = resolve_iffeature_compile(iffeat, value, parent, parent_is_feature, unres); |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 268 | lydict_remove(parent->module->ctx, value); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 269 | if (r) { |
| 270 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 273 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 274 | if (!node->ns) { |
| 275 | /* garbage */ |
| 276 | lyxml_free(parent->module->ctx, node); |
| 277 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 278 | /* extension */ |
| 279 | c_ext++; |
| 280 | } else { |
| 281 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "if-feature"); |
| 282 | return EXIT_FAILURE; |
| 283 | } |
| 284 | } |
| 285 | if (c_ext) { |
| 286 | iffeat->ext = calloc(c_ext, sizeof *iffeat->ext); |
| 287 | if (!iffeat->ext) { |
| 288 | LOGMEM; |
| 289 | return EXIT_FAILURE; |
| 290 | } |
| 291 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 292 | /* extensions */ |
| 293 | 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] | 294 | &iffeat->ext, iffeat->ext_size, unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 295 | iffeat->ext_size++; |
| 296 | if (r) { |
| 297 | return EXIT_FAILURE; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 302 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* logs directly */ |
| 306 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 307 | 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] | 308 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 309 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 310 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 311 | int rc; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 312 | int c_ftrs = 0, c_base = 0, c_ext = 0; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 313 | void *reallocated; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 314 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 315 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 316 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 317 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 318 | 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] | 319 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 320 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 321 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 322 | if (dup_identities_check(ident->name, module)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 323 | goto error; |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 326 | LY_TREE_FOR(yin->child, node) { |
| 327 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 328 | /* extension */ |
| 329 | c_ext++; |
| 330 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 331 | if (c_base && (module->version < 2)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 332 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 333 | goto error; |
| 334 | } |
| 335 | if (read_yin_subnode_ext(module, ident, LYEXT_PAR_IDENT, node, LYEXT_SUBSTMT_BASE, c_base, unres)) { |
| 336 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 337 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 338 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 339 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 340 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 341 | c_ftrs++; |
| 342 | |
| 343 | } else { |
| 344 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 345 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | if (c_base) { |
| 350 | ident->base_size = 0; |
| 351 | ident->base = calloc(c_base, sizeof *ident->base); |
| 352 | if (!ident->base) { |
| 353 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 354 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 355 | } |
| 356 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 357 | if (c_ftrs) { |
| 358 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
| 359 | if (!ident->iffeature) { |
| 360 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 361 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 362 | } |
| 363 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 364 | if (c_ext) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 365 | /* some extensions may be already present from the substatements */ |
| 366 | reallocated = realloc(ident->ext, (c_ext + ident->ext_size) * sizeof *ident->ext); |
| 367 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 368 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 369 | goto error; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 370 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 371 | ident->ext = reallocated; |
| 372 | |
| 373 | /* init memory */ |
| 374 | memset(&ident->ext[ident->ext_size], 0, c_ext * sizeof *ident->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 375 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 376 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 377 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 378 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 379 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 380 | 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] | 381 | ident->ext_size++; |
| 382 | if (rc) { |
| 383 | goto error; |
| 384 | } |
| 385 | } else if (!strcmp(node->name, "base")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 386 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 387 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 388 | if (!value) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 389 | goto error; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 390 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 391 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 392 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 393 | lydict_remove(module->ctx, value); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 394 | goto error; |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 395 | } |
| 396 | lydict_remove(module->ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 397 | } else if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 398 | 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] | 399 | ident->iffeature_size++; |
| 400 | if (rc) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 401 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 402 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 403 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 404 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 405 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 406 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 407 | |
| 408 | error: |
| 409 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 412 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 413 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 414 | read_restr_substmt(struct lys_module *module, LYEXT_PAR restr_type, struct lys_restr *restr, struct lyxml_elem *yin, |
| 415 | struct unres_schema *unres) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 416 | { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 417 | struct lyxml_elem *child, *next; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 418 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 419 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 420 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 421 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 422 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 423 | continue; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 424 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 425 | /* extension */ |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 426 | if (read_yin_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 427 | return EXIT_FAILURE; |
| 428 | } |
| 429 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 430 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 431 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 432 | return EXIT_FAILURE; |
| 433 | } |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 434 | if (read_yin_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 435 | return EXIT_FAILURE; |
| 436 | } |
| 437 | restr->dsc = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 438 | if (!restr->dsc) { |
| 439 | return EXIT_FAILURE; |
| 440 | } |
| 441 | } else if (!strcmp(child->name, "reference")) { |
| 442 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 443 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 444 | return EXIT_FAILURE; |
| 445 | } |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 446 | if (read_yin_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 447 | return EXIT_FAILURE; |
| 448 | } |
| 449 | restr->ref = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 450 | if (!restr->ref) { |
| 451 | return EXIT_FAILURE; |
| 452 | } |
| 453 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 454 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 455 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 456 | return EXIT_FAILURE; |
| 457 | } |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 458 | if (read_yin_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_ERRTAG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 459 | return EXIT_FAILURE; |
| 460 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 461 | GETVAL(value, child, "value"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 462 | restr->eapptag = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 463 | } else if (!strcmp(child->name, "error-message")) { |
| 464 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 465 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 466 | return EXIT_FAILURE; |
| 467 | } |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 468 | if (read_yin_subnode_ext(module, restr, restr_type, child, LYEXT_SUBSTMT_ERRMSG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 469 | return EXIT_FAILURE; |
| 470 | } |
| 471 | restr->emsg = read_yin_subnode(module->ctx, child, "value"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 472 | if (!restr->emsg) { |
| 473 | return EXIT_FAILURE; |
| 474 | } |
| 475 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 476 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 477 | return EXIT_FAILURE; |
| 478 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 482 | |
| 483 | error: |
| 484 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 487 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 488 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 489 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 490 | int tpdftype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 491 | { |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 492 | const char *value, *name; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 493 | struct lys_node *siter; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 494 | struct lyxml_elem *next, *next2, *node, *child, exts; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 495 | struct lys_restr **restrs, *restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 496 | struct lys_type_bit bit, *bits_sc = NULL; |
| 497 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 498 | struct lys_type *dertype; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 499 | int i, j, rc, val_set, c_ftrs, c_ext = 0; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 500 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 501 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 502 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 503 | size_t len; |
| 504 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 505 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 506 | /* init */ |
| 507 | memset(&exts, 0, sizeof exts); |
| 508 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 509 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 510 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 511 | if (!value) { |
| 512 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 513 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 514 | |
| 515 | i = parse_identifier(value); |
| 516 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 517 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 518 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 519 | goto error; |
| 520 | } |
| 521 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 522 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 523 | if (value[i]) { |
| 524 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 525 | name += i; |
| 526 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 527 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 528 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 529 | goto error; |
| 530 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 531 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 532 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 533 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 534 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 535 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 536 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 537 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 538 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 539 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 540 | |
| 541 | /* 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] | 542 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 543 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 544 | lydict_remove(module->ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 545 | ret = EXIT_FAILURE; |
| 546 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 547 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 548 | lydict_remove(module->ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 549 | |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 550 | if (type->base == LY_TYPE_ERR) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 551 | /* 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] | 552 | * 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] | 553 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 554 | if (siter) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 555 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 556 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 557 | LOGINT; |
| 558 | goto error; |
| 559 | } |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 560 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]--; |
| 561 | #else |
| 562 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]) { |
| 563 | LOGINT; |
| 564 | goto error; |
| 565 | } |
| 566 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]--; |
| 567 | #endif |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 568 | } else { |
| 569 | LOGINT; |
| 570 | goto error; |
| 571 | } |
| 572 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 573 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 574 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 575 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 576 | 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] | 577 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 578 | return -1; |
| 579 | } |
| 580 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 581 | /* parse extension instances */ |
| 582 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 583 | if (!node->ns) { |
| 584 | /* garbage */ |
| 585 | lyxml_free(module->ctx, node); |
| 586 | continue; |
| 587 | } else if (!strcmp(node->ns->value, LY_NSYIN)) { |
| 588 | /* YANG (YIN) statements - process later */ |
| 589 | continue; |
| 590 | } |
| 591 | |
| 592 | lyxml_unlink_elem(module->ctx, node, 2); |
| 593 | lyxml_add_child(module->ctx, &exts, node); |
| 594 | c_ext++; |
| 595 | } |
| 596 | if (c_ext) { |
| 597 | type->ext = calloc(c_ext, sizeof *type->ext); |
| 598 | if (!type->ext) { |
| 599 | LOGMEM; |
| 600 | goto error; |
| 601 | } |
| 602 | LY_TREE_FOR_SAFE(exts.child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 603 | 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] | 604 | type->ext_size++; |
| 605 | if (rc) { |
| 606 | goto error; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 611 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 612 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 613 | /* RFC 6020 9.7.4 - bit */ |
| 614 | |
| 615 | /* get bit specifications, at least one must be present */ |
| 616 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 617 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 618 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 619 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 620 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 621 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 622 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 623 | } |
| 624 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 625 | dertype = &type->der->type; |
| 626 | if (!dertype->der) { |
| 627 | if (!type->info.bits.count) { |
| 628 | /* type is derived directly from buit-in bits type and bit statement is required */ |
| 629 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
| 630 | goto error; |
| 631 | } |
| 632 | } else { |
| 633 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 634 | if (module->version < 2 && type->info.bits.count) { |
| 635 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 636 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
| 637 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 638 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 639 | goto error; |
| 640 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 641 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 642 | |
| 643 | 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] | 644 | if (!type->info.bits.bit) { |
| 645 | LOGMEM; |
| 646 | goto error; |
| 647 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 648 | p = 0; |
| 649 | i = -1; |
| 650 | LY_TREE_FOR(yin->child, next) { |
| 651 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 652 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 653 | |
| 654 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 655 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 656 | goto error; |
| 657 | } |
| 658 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 659 | 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] | 660 | 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] | 661 | type->info.bits.count = i + 1; |
| 662 | goto error; |
| 663 | } |
| 664 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 665 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 666 | /* check the name uniqueness */ |
| 667 | for (j = 0; j < i; j++) { |
| 668 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
| 669 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
| 670 | type->info.bits.count = i + 1; |
| 671 | goto error; |
| 672 | } |
| 673 | } |
| 674 | } else { |
| 675 | /* restricted bits type - the name MUST be used in the base type */ |
| 676 | bits_sc = dertype->info.bits.bit; |
| 677 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 678 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 679 | break; |
| 680 | } |
| 681 | } |
| 682 | if (j == dertype->info.bits.count) { |
| 683 | LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 684 | type->info.bits.count = i + 1; |
| 685 | goto error; |
| 686 | } |
| 687 | } |
| 688 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 689 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 690 | p_ = -1; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 691 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 692 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 693 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 694 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 695 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 696 | /* extension */ |
| 697 | if (read_yin_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
| 698 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 699 | goto error; |
| 700 | } |
| 701 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 702 | if (p_ != -1) { |
| 703 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 704 | type->info.bits.count = i + 1; |
| 705 | goto error; |
| 706 | } |
| 707 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 708 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 709 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 710 | |
| 711 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 712 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 713 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 714 | type->info.bits.count = i + 1; |
| 715 | goto error; |
| 716 | } |
| 717 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 718 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 719 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 720 | /* keep the highest enum value for automatic increment */ |
| 721 | if (type->info.bits.bit[i].pos >= p) { |
| 722 | p = type->info.bits.bit[i].pos; |
| 723 | p++; |
| 724 | } else { |
| 725 | /* check that the value is unique */ |
| 726 | for (j = 0; j < i; j++) { |
| 727 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
| 728 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
| 729 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 730 | type->info.bits.bit[j].name); |
| 731 | type->info.bits.count = i + 1; |
| 732 | goto error; |
| 733 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 734 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 735 | } |
| 736 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 737 | |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 738 | if (read_yin_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
| 739 | LYEXT_SUBSTMT_POSITION, 0, unres)) { |
| 740 | goto error; |
| 741 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 742 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 743 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 744 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 745 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 746 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 747 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 748 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 749 | |
| 750 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 751 | if (p_ == -1) { |
| 752 | /* assign value automatically */ |
| 753 | if (p > UINT32_MAX) { |
| 754 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
| 755 | type->info.bits.count = i + 1; |
| 756 | goto error; |
| 757 | } |
| 758 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 759 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 760 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 761 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 762 | } else { /* restricted bits type */ |
| 763 | if (p_ == -1) { |
| 764 | /* automatically assign position from base type */ |
| 765 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 766 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 767 | } else { |
| 768 | /* check that the assigned position corresponds to the original |
| 769 | * position of the bit in the base type */ |
| 770 | if (p_ != bits_sc[j].pos) { |
| 771 | /* p_ - assigned position in restricted bits |
| 772 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
| 773 | 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] | 774 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 775 | type->info.bits.count = i + 1; |
| 776 | goto error; |
| 777 | } |
| 778 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 779 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 780 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 781 | /* if-features */ |
| 782 | if (c_ftrs) { |
| 783 | bits_sc = &type->info.bits.bit[i]; |
| 784 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 785 | if (!bits_sc->iffeature) { |
| 786 | LOGMEM; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 787 | type->info.bits.count = i + 1; |
| 788 | goto error; |
| 789 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 790 | |
| 791 | LY_TREE_FOR(next->child, node) { |
| 792 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 793 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 794 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 795 | bits_sc->iffeature_size++; |
| 796 | if (rc) { |
| 797 | type->info.bits.count = i + 1; |
| 798 | goto error; |
| 799 | } |
| 800 | } |
| 801 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 802 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 803 | |
| 804 | /* keep them ordered by position */ |
| 805 | j = i; |
| 806 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 807 | /* switch them */ |
| 808 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 809 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 810 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 811 | j--; |
| 812 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 813 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 814 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 815 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 816 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 817 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 818 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 819 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 820 | if (!strcmp(node->name, "range")) { |
| 821 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 822 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 823 | goto error; |
| 824 | } |
| 825 | |
| 826 | GETVAL(value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 827 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 828 | if (!type->info.dec64.range) { |
| 829 | LOGMEM; |
| 830 | goto error; |
| 831 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 832 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 833 | |
| 834 | /* get possible substatements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 835 | 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] | 836 | goto error; |
| 837 | } |
| 838 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 839 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 840 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 841 | goto error; |
| 842 | } |
| 843 | GETVAL(value, node, "value"); |
| 844 | v = strtol(value, NULL, 10); |
| 845 | |
| 846 | /* range check */ |
| 847 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 848 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 849 | goto error; |
| 850 | } |
| 851 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 852 | type->info.dec64.div = 10; |
| 853 | for (i = 1; i < v; i++) { |
| 854 | type->info.dec64.div *= 10; |
| 855 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 856 | |
| 857 | /* extensions */ |
| 858 | if (read_yin_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_DIGITS, 0, unres)) { |
| 859 | goto error; |
| 860 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 861 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 862 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 863 | goto error; |
| 864 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /* mandatory sub-statement(s) check */ |
| 868 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 869 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 870 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 871 | goto error; |
| 872 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 873 | if (type->info.dec64.dig && type->der->type.der) { |
| 874 | /* 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] | 875 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 876 | goto error; |
| 877 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 878 | |
| 879 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 880 | if (type->der->type.der) { |
| 881 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 882 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 883 | } |
| 884 | |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 885 | if (type->info.dec64.range && lyp_check_length_range(type->info.dec64.range->expr, type)) { |
| 886 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
| 887 | goto error; |
| 888 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 889 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 891 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 892 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 893 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 894 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 895 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 896 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 897 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 898 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 899 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 900 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 901 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 902 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 903 | } |
| 904 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 905 | dertype = &type->der->type; |
| 906 | if (!dertype->der) { |
| 907 | if (!type->info.enums.count) { |
| 908 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
| 909 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
| 910 | goto error; |
| 911 | } |
| 912 | } else { |
| 913 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 914 | if (module->version < 2 && type->info.enums.count) { |
| 915 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 916 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
| 917 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 918 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 919 | goto error; |
| 920 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 921 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 922 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 923 | 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] | 924 | if (!type->info.enums.enm) { |
| 925 | LOGMEM; |
| 926 | goto error; |
| 927 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 928 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 929 | v = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 930 | i = -1; |
| 931 | LY_TREE_FOR(yin->child, next) { |
| 932 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 933 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 934 | |
| 935 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 936 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 937 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 938 | 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] | 939 | goto error; |
| 940 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 941 | 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] | 942 | 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] | 943 | type->info.enums.count = i + 1; |
| 944 | goto error; |
| 945 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 946 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 947 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 948 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 949 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 950 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 951 | type->info.enums.count = i + 1; |
| 952 | goto error; |
| 953 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 954 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 955 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 956 | /* check the name uniqueness */ |
| 957 | for (j = 0; j < i; j++) { |
| 958 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
| 959 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
| 960 | type->info.enums.count = i + 1; |
| 961 | goto error; |
| 962 | } |
| 963 | } |
| 964 | } else { |
| 965 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 966 | enms_sc = dertype->info.enums.enm; |
| 967 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 968 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | if (j == dertype->info.enums.count) { |
| 973 | LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 974 | type->info.enums.count = i + 1; |
| 975 | goto error; |
| 976 | } |
| 977 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 978 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 979 | val_set = 0; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 980 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 981 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 982 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 983 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 984 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 985 | /* extensions */ |
| 986 | if (read_yin_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
| 987 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 988 | goto error; |
| 989 | } |
| 990 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 991 | if (val_set) { |
| 992 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 993 | type->info.enums.count = i + 1; |
| 994 | goto error; |
| 995 | } |
| 996 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 997 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 998 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 999 | |
| 1000 | /* range check */ |
| 1001 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1002 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1003 | type->info.enums.count = i + 1; |
| 1004 | goto error; |
| 1005 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1006 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1007 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1008 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1009 | if (!i) { |
| 1010 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1011 | v = type->info.enums.enm[i].value; |
| 1012 | v++; |
| 1013 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1014 | /* keep the highest enum value for automatic increment */ |
| 1015 | if (type->info.enums.enm[i].value >= v) { |
| 1016 | v = type->info.enums.enm[i].value; |
| 1017 | v++; |
| 1018 | } else { |
| 1019 | /* check that the value is unique */ |
| 1020 | for (j = 0; j < i; j++) { |
| 1021 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
| 1022 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
| 1023 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 1024 | type->info.enums.enm[j].name); |
| 1025 | type->info.enums.count = i + 1; |
| 1026 | goto error; |
| 1027 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1028 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1029 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1030 | } |
| 1031 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 1032 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1033 | |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1034 | if (read_yin_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
| 1035 | LYEXT_SUBSTMT_VALUE, 0, unres)) { |
| 1036 | goto error; |
| 1037 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1038 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 1039 | c_ftrs++; |
| 1040 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1041 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1042 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1043 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1044 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1045 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1046 | |
| 1047 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 1048 | if (!val_set) { |
| 1049 | /* assign value automatically */ |
| 1050 | if (v > INT32_MAX) { |
| 1051 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
| 1052 | type->info.enums.count = i + 1; |
| 1053 | goto error; |
| 1054 | } |
| 1055 | type->info.enums.enm[i].value = v; |
| 1056 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1057 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1058 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1059 | } else { /* restricted enum type */ |
| 1060 | if (!val_set) { |
| 1061 | /* automatically assign value from base type */ |
| 1062 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 1063 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1064 | } else { |
| 1065 | /* check that the assigned value corresponds to the original |
| 1066 | * value of the enum in the base type */ |
| 1067 | if (v_ != enms_sc[j].value) { |
| 1068 | /* v_ - assigned value in restricted enum |
| 1069 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
| 1070 | LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 1071 | 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] | 1072 | type->info.enums.count = i + 1; |
| 1073 | goto error; |
| 1074 | } |
| 1075 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1076 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1077 | |
| 1078 | /* if-features */ |
| 1079 | if (c_ftrs) { |
| 1080 | enms_sc = &type->info.enums.enm[i]; |
| 1081 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 1082 | if (!enms_sc->iffeature) { |
| 1083 | LOGMEM; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1084 | type->info.enums.count = i + 1; |
| 1085 | goto error; |
| 1086 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1087 | |
| 1088 | LY_TREE_FOR(next->child, node) { |
| 1089 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 1090 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1091 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 1092 | enms_sc->iffeature_size++; |
| 1093 | if (rc) { |
| 1094 | type->info.enums.count = i + 1; |
| 1095 | goto error; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1099 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1100 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1101 | } |
| 1102 | break; |
| 1103 | |
| 1104 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 1105 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1106 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1107 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1108 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1109 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 1110 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1111 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1112 | goto error; |
| 1113 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1114 | |
| 1115 | GETVAL(value, yin->child, "name"); |
| 1116 | /* store in the JSON format */ |
| 1117 | value = transform_schema2json(module, value); |
| 1118 | if (!value) { |
| 1119 | goto error; |
| 1120 | } |
| 1121 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 1122 | lydict_remove(module->ctx, value); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1123 | if (rc == -1) { |
| 1124 | goto error; |
| 1125 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1126 | |
| 1127 | if (read_yin_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_BASE, 0, unres)) { |
| 1128 | goto error; |
| 1129 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1132 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1133 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1134 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1135 | break; |
| 1136 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1137 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1138 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1139 | } else { |
| 1140 | if (type->der->type.der) { |
| 1141 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
| 1142 | goto error; |
| 1143 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1144 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1145 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1146 | 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] | 1147 | goto error; |
| 1148 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1149 | break; |
| 1150 | |
| 1151 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1152 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1153 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1154 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1155 | if (!strcmp(node->name, "require-instance")) { |
| 1156 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1157 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1158 | goto error; |
| 1159 | } |
| 1160 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1161 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1162 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1163 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1164 | type->info.inst.req = -1; |
| 1165 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1166 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1167 | goto error; |
| 1168 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1169 | |
| 1170 | /* extensions */ |
| 1171 | if (read_yin_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINST, 0, unres)) { |
| 1172 | goto error; |
| 1173 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1174 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1175 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1176 | goto error; |
| 1177 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1178 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1180 | break; |
| 1181 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1182 | case LY_TYPE_BINARY: |
| 1183 | /* 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] | 1184 | case LY_TYPE_INT8: |
| 1185 | case LY_TYPE_INT16: |
| 1186 | case LY_TYPE_INT32: |
| 1187 | case LY_TYPE_INT64: |
| 1188 | case LY_TYPE_UINT8: |
| 1189 | case LY_TYPE_UINT16: |
| 1190 | case LY_TYPE_UINT32: |
| 1191 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1192 | /* RFC 6020 9.2.4 - range */ |
| 1193 | |
| 1194 | /* length and range are actually the same restriction, so process |
| 1195 | * them by this common code, we just need to differ the name and |
| 1196 | * structure where the information will be stored |
| 1197 | */ |
| 1198 | if (type->base == LY_TYPE_BINARY) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1199 | restrs = &type->info.binary.length; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1200 | name = "length"; |
| 1201 | } else { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1202 | restrs = &type->info.num.range; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1203 | name = "range"; |
| 1204 | } |
| 1205 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1206 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1207 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1208 | if (!strcmp(node->name, name)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1209 | if (*restrs) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1210 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1211 | goto error; |
| 1212 | } |
| 1213 | |
| 1214 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1215 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1216 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1217 | goto error; |
| 1218 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1219 | *restrs = calloc(1, sizeof **restrs); |
| 1220 | if (!(*restrs)) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1221 | LOGMEM; |
| 1222 | goto error; |
| 1223 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1224 | (*restrs)->expr = lydict_insert(module->ctx, value, 0); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1225 | |
| 1226 | /* get possible substatements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1227 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, *restrs, node, unres)) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1228 | goto error; |
| 1229 | } |
| 1230 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1231 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1232 | goto error; |
| 1233 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1234 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1235 | break; |
| 1236 | |
| 1237 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1238 | /* flag resolving for later use */ |
| 1239 | if (!tpdftype) { |
| 1240 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 1241 | if (siter) { |
| 1242 | /* just a flag - do not resolve */ |
| 1243 | tpdftype = 1; |
| 1244 | } |
| 1245 | } |
| 1246 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1247 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1248 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1249 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1250 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1251 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1252 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1253 | goto error; |
| 1254 | } |
| 1255 | |
| 1256 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1257 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1258 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1259 | if (!type->info.lref.path) { |
| 1260 | goto error; |
| 1261 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1262 | |
| 1263 | /* try to resolve leafref path only when this is instantiated |
| 1264 | * leaf, so it is not: |
| 1265 | * - typedef's type, |
| 1266 | * - in grouping definition, |
| 1267 | * - just instantiated in a grouping definition, |
| 1268 | * because in those cases the nodes referenced in path might not be present |
| 1269 | * and it is not a bug. */ |
| 1270 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1271 | goto error; |
| 1272 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1273 | |
| 1274 | /* extensions */ |
| 1275 | if (read_yin_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_PATH, 0, unres)) { |
| 1276 | goto error; |
| 1277 | } |
Radek Krejci | d6353ed | 2016-09-15 13:30:45 +0200 | [diff] [blame] | 1278 | } else if (module->version >= 2 && !strcmp(node->name, "require-instance")) { |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1279 | if (type->info.lref.req) { |
| 1280 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 1281 | goto error; |
| 1282 | } |
| 1283 | GETVAL(value, node, "value"); |
| 1284 | if (!strcmp(value, "true")) { |
| 1285 | type->info.lref.req = 1; |
| 1286 | } else if (!strcmp(value, "false")) { |
| 1287 | type->info.lref.req = -1; |
| 1288 | } else { |
| 1289 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 1290 | goto error; |
| 1291 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1292 | |
| 1293 | /* extensions */ |
| 1294 | if (read_yin_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINST, 0, unres)) { |
| 1295 | goto error; |
| 1296 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1297 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1298 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1299 | goto error; |
| 1300 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1301 | } |
| 1302 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1303 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1304 | if (!type->der->type.der) { |
| 1305 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
| 1306 | goto error; |
| 1307 | } else { |
| 1308 | /* copy leafref definition into the derived type */ |
| 1309 | type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0); |
| 1310 | /* and resolve the path at the place we are (if not in grouping/typedef) */ |
| 1311 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
| 1312 | goto error; |
| 1313 | } |
| 1314 | |
| 1315 | /* add pointer to leafref target, only on leaves (not in typedefs) */ |
| 1316 | if (type->info.lref.target && lys_leaf_add_leafref_target(type->info.lref.target, (struct lys_node *)type->parent)) { |
| 1317 | goto error; |
| 1318 | } |
| 1319 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1320 | } |
| 1321 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1322 | break; |
| 1323 | |
| 1324 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1325 | /* RFC 6020 9.4.4 - length */ |
| 1326 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1327 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1328 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1329 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1330 | if (!strcmp(node->name, "length")) { |
| 1331 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1332 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1333 | goto error; |
| 1334 | } |
| 1335 | |
| 1336 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1337 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1338 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1339 | goto error; |
| 1340 | } |
| 1341 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1342 | if (!type->info.str.length) { |
| 1343 | LOGMEM; |
| 1344 | goto error; |
| 1345 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1346 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1347 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1348 | /* get possible sub-statements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1349 | 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] | 1350 | goto error; |
| 1351 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1352 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1353 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1354 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1355 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1356 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1357 | goto error; |
| 1358 | } |
| 1359 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1360 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1361 | if (i) { |
| 1362 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1363 | if (!type->info.str.patterns) { |
| 1364 | LOGMEM; |
| 1365 | goto error; |
| 1366 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1367 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1368 | GETVAL(value, node, "value"); |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 1369 | if (lyp_check_pattern(value, NULL)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1370 | free(type->info.str.patterns); |
Radek Krejci | 9f1e853 | 2016-06-16 11:18:21 +0200 | [diff] [blame] | 1371 | type->info.str.patterns = NULL; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1372 | goto error; |
| 1373 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1374 | restr = &type->info.str.patterns[type->info.str.pat_count]; /* shortcut */ |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1375 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1376 | modifier = 0x06; /* ACK */ |
| 1377 | name = NULL; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1378 | if (module->version >= 2) { |
| 1379 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1380 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 1381 | if (name) { |
| 1382 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 1383 | goto error; |
| 1384 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1385 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1386 | GETVAL(name, child, "value"); |
| 1387 | if (!strcmp(name, "invert-match")) { |
| 1388 | modifier = 0x15; /* NACK */ |
| 1389 | } else { |
| 1390 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 1391 | goto error; |
| 1392 | } |
| 1393 | /* get extensions of the modifier */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1394 | if (read_yin_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 1395 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1396 | return EXIT_FAILURE; |
| 1397 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1398 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1399 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1400 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | len = strlen(value); |
| 1405 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
| 1406 | buf[0] = modifier; |
| 1407 | strcpy(&buf[1], value); |
| 1408 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1409 | restr->expr = lydict_insert_zc(module->ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1410 | |
| 1411 | /* get possible sub-statements */ |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1412 | if (read_restr_substmt(module, LYEXT_PAR_RESTR, restr, node, unres)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1413 | free(type->info.str.patterns); |
Pavol Vican | 9fc5d64 | 2016-08-30 15:23:19 +0200 | [diff] [blame] | 1414 | type->info.str.patterns = NULL; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1415 | goto error; |
| 1416 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1417 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1418 | } |
| 1419 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1420 | break; |
| 1421 | |
| 1422 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1423 | /* RFC 6020 7.4 - type */ |
| 1424 | /* count number of types in union */ |
| 1425 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1426 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1427 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1428 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1429 | if (type->der->type.der) { |
| 1430 | /* type can be a substatement only in "union" type, not in derived types */ |
| 1431 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
| 1432 | goto error; |
| 1433 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1434 | i++; |
| 1435 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1436 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1437 | goto error; |
| 1438 | } |
| 1439 | } |
| 1440 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1441 | if (!i && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1442 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1443 | goto error; |
| 1444 | } |
| 1445 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1446 | /* inherit instid presence information */ |
| 1447 | if ((type->der->type.base == LY_TYPE_UNION) && type->der->type.info.uni.has_ptr_type) { |
| 1448 | type->info.uni.has_ptr_type = 1; |
| 1449 | } |
| 1450 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1451 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1452 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1453 | if (!type->info.uni.types) { |
| 1454 | LOGMEM; |
| 1455 | goto error; |
| 1456 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1457 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1458 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1459 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1460 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], tpdftype, unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1461 | if (!rc) { |
| 1462 | type->info.uni.count++; |
| 1463 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1464 | if (module->version < 2) { |
| 1465 | /* union's type cannot be empty or leafref */ |
| 1466 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 1467 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
| 1468 | rc = -1; |
| 1469 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 1470 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
| 1471 | rc = -1; |
| 1472 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1473 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1474 | |
| 1475 | if ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_INST) |
| 1476 | || (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF)) { |
| 1477 | type->info.uni.has_ptr_type = 1; |
| 1478 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1479 | } |
| 1480 | if (rc) { |
| 1481 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1482 | for (i = 0; i < type->info.uni.count; ++i) { |
| 1483 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 1484 | } |
| 1485 | free(type->info.uni.types); |
| 1486 | type->info.uni.types = NULL; |
| 1487 | type->info.uni.count = 0; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1488 | type->info.uni.has_ptr_type = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1489 | type->der = NULL; |
| 1490 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1491 | |
| 1492 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1493 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1494 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1495 | goto error; |
| 1496 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1497 | } |
| 1498 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1499 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1500 | case LY_TYPE_BOOL: |
| 1501 | case LY_TYPE_EMPTY: |
| 1502 | /* no sub-statement allowed */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1503 | if (yin->child) { |
| 1504 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->child->name); |
| 1505 | goto error; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1506 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1507 | break; |
| 1508 | |
| 1509 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1510 | LOGINT; |
| 1511 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1515 | |
| 1516 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1517 | if (type->module_name) { |
| 1518 | lydict_remove(module->ctx, type->module_name); |
| 1519 | type->module_name = NULL; |
| 1520 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1521 | lyxml_free_withsiblings(module->ctx, exts.child); |
| 1522 | |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1523 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1526 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1527 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1528 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, |
| 1529 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1530 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1531 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1532 | struct lyxml_elem *node, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1533 | int rc, has_type = 0, c_ext = 0; |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1534 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1535 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1536 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1537 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1538 | goto error; |
| 1539 | } |
| 1540 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1541 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1542 | /* generic part - status, description, reference */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1543 | 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] | 1544 | goto error; |
| 1545 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1546 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1547 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1548 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1549 | /* extension */ |
| 1550 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1551 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1552 | } else if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1553 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1554 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1555 | goto error; |
| 1556 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1557 | /* HACK for unres */ |
| 1558 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1559 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1560 | 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] | 1561 | goto error; |
| 1562 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1563 | has_type = 1; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1564 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1565 | /* 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] | 1566 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1567 | } else if (!strcmp(node->name, "default")) { |
| 1568 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1569 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1570 | goto error; |
| 1571 | } |
| 1572 | GETVAL(value, node, "value"); |
| 1573 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1574 | |
| 1575 | if (read_yin_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
| 1576 | goto error; |
| 1577 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1578 | } else if (!strcmp(node->name, "units")) { |
| 1579 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1580 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1581 | goto error; |
| 1582 | } |
| 1583 | GETVAL(value, node, "name"); |
| 1584 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1585 | |
| 1586 | if (read_yin_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
| 1587 | goto error; |
| 1588 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1589 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1590 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1591 | goto error; |
| 1592 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1593 | |
| 1594 | lyxml_free(module->ctx, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1595 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1596 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1597 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1598 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1599 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1600 | goto error; |
| 1601 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1602 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1603 | /* check default value (if not defined, there still could be some restrictions |
| 1604 | * 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] | 1605 | 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] | 1606 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1607 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1608 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1609 | /* finish extensions parsing */ |
| 1610 | if (c_ext) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1611 | /* some extensions may be already present from the substatements */ |
| 1612 | reallocated = realloc(tpdf->ext, (c_ext + tpdf->ext_size) * sizeof *tpdf->ext); |
| 1613 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1614 | LOGMEM; |
| 1615 | goto error; |
| 1616 | } |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1617 | tpdf->ext = reallocated; |
| 1618 | |
| 1619 | /* init memory */ |
| 1620 | memset(&tpdf->ext[tpdf->ext_size], 0, c_ext * sizeof *tpdf->ext); |
| 1621 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1622 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1623 | 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] | 1624 | tpdf->ext_size++; |
| 1625 | if (rc) { |
| 1626 | goto error; |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1631 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1632 | |
| 1633 | error: |
| 1634 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1635 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1638 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1639 | 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] | 1640 | { |
| 1641 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1642 | struct lyxml_elem *child, *node, *next, *next2; |
| 1643 | int c_ext = 0, rc; |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1644 | void *reallocated; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1645 | |
| 1646 | GETVAL(value, yin, "name"); |
| 1647 | |
| 1648 | if (lyp_check_identifier(value, LY_IDENT_EXTENSION, module, NULL)) { |
| 1649 | goto error; |
| 1650 | } |
| 1651 | ext->name = lydict_insert(module->ctx, value, strlen(value)); |
| 1652 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1653 | 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] | 1654 | goto error; |
| 1655 | } |
| 1656 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1657 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1658 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1659 | /* possible extension instance */ |
| 1660 | c_ext++; |
| 1661 | } else if (!strcmp(node->name, "argument")) { |
| 1662 | /* argument */ |
| 1663 | GETVAL(value, node, "name"); |
| 1664 | ext->argument = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1665 | if (read_yin_subnode_ext(module, ext, LYEXT_PAR_EXT, node, LYEXT_SUBSTMT_ARGUMENT, 0, unres)) { |
| 1666 | goto error; |
| 1667 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1668 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1669 | /* yin-element */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1670 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1671 | if (child->ns == node->ns && !strcmp(child->name, "yin-element")) { |
| 1672 | GETVAL(value, child, "value"); |
| 1673 | if (ly_strequal(value, "true", 0)) { |
| 1674 | ext->flags |= LYS_YINELEM; |
| 1675 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1676 | |
| 1677 | if (read_yin_subnode_ext(module, ext, LYEXT_PAR_EXT, child, LYEXT_SUBSTMT_YINELEM, 0, unres)) { |
| 1678 | goto error; |
| 1679 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1680 | } else if (child->ns) { |
| 1681 | /* unexpected YANG statement */ |
| 1682 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name); |
| 1683 | goto error; |
| 1684 | } /* else garbage, but save resource needed for unlinking */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1685 | } |
| 1686 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1687 | lyxml_free(module->ctx, node); |
| 1688 | } else { |
| 1689 | /* unexpected YANG statement */ |
| 1690 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->name); |
| 1691 | goto error; |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | if (c_ext) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1696 | /* some extensions may be already present from the substatements */ |
| 1697 | reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext); |
| 1698 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1699 | LOGMEM; |
| 1700 | goto error; |
| 1701 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1702 | ext->ext = reallocated; |
| 1703 | |
| 1704 | /* init memory */ |
| 1705 | memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext); |
| 1706 | |
| 1707 | /* process the extension instances of the extension itself */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1708 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1709 | 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] | 1710 | ext->ext_size++; |
| 1711 | if (rc) { |
| 1712 | goto error; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 1717 | /* search for plugin */ |
| 1718 | 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] | 1719 | |
| 1720 | return EXIT_SUCCESS; |
| 1721 | |
| 1722 | error: |
| 1723 | return EXIT_FAILURE; |
| 1724 | } |
| 1725 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1726 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1727 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1728 | 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] | 1729 | { |
| 1730 | const char *value; |
| 1731 | struct lyxml_elem *child, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1732 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1733 | void *reallocated; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1734 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1735 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1736 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1737 | goto error; |
| 1738 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1739 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1740 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1741 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1742 | 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] | 1743 | goto error; |
| 1744 | } |
| 1745 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1746 | LY_TREE_FOR(yin->child, child) { |
| 1747 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1748 | /* extension */ |
| 1749 | c_ext++; |
| 1750 | } else if (!strcmp(child->name, "if-feature")) { |
| 1751 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1752 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1753 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1754 | goto error; |
| 1755 | } |
| 1756 | } |
| 1757 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1758 | if (c_ftrs) { |
| 1759 | f->iffeature = calloc(c_ftrs, sizeof *f->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1760 | if (!f->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1761 | LOGMEM; |
| 1762 | goto error; |
| 1763 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1764 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1765 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1766 | /* some extensions may be already present from the substatements */ |
| 1767 | reallocated = realloc(f->ext, (c_ext + f->ext_size) * sizeof *f->ext); |
| 1768 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1769 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1770 | goto error; |
| 1771 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1772 | f->ext = reallocated; |
| 1773 | |
| 1774 | /* init memory */ |
| 1775 | memset(&f->ext[f->ext_size], 0, c_ext * sizeof *f->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1778 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1779 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1780 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1781 | 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] | 1782 | f->ext_size++; |
| 1783 | if (ret) { |
| 1784 | goto error; |
| 1785 | } |
| 1786 | } else { /* if-feature */ |
| 1787 | ret = fill_yin_iffeature((struct lys_node *)f, 1, child, &f->iffeature[f->iffeature_size], unres); |
| 1788 | f->iffeature_size++; |
| 1789 | if (ret) { |
| 1790 | goto error; |
| 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1795 | /* check for circular dependencies */ |
| 1796 | if (f->iffeature_size) { |
| 1797 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1798 | goto error; |
| 1799 | } |
| 1800 | } |
| 1801 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1802 | return EXIT_SUCCESS; |
| 1803 | |
| 1804 | error: |
| 1805 | |
| 1806 | return EXIT_FAILURE; |
| 1807 | } |
| 1808 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1809 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1810 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1811 | 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] | 1812 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1813 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1814 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1815 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1816 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1817 | if (!must->expr) { |
| 1818 | goto error; |
| 1819 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1820 | |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 1821 | return read_restr_substmt(module, LYEXT_PAR_RESTR, must, yin, unres); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1822 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1823 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1824 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1825 | } |
| 1826 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1827 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1828 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1829 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1830 | { |
| 1831 | int i, j; |
| 1832 | const char *value, *vaux; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1833 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1834 | |
| 1835 | /* get unique value (list of leafs supposed to be unique */ |
| 1836 | GETVAL(value, yin, "tag"); |
| 1837 | |
| 1838 | /* count the number of unique leafs in the value */ |
| 1839 | vaux = value; |
| 1840 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1841 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1842 | while (isspace(*vaux)) { |
| 1843 | vaux++; |
| 1844 | } |
| 1845 | } |
| 1846 | unique->expr_size++; |
| 1847 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1848 | if (!unique->expr) { |
| 1849 | LOGMEM; |
| 1850 | goto error; |
| 1851 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1852 | |
| 1853 | for (i = 0; i < unique->expr_size; i++) { |
| 1854 | vaux = strpbrk(value, " \t\n"); |
| 1855 | if (!vaux) { |
| 1856 | /* the last token, lydict_insert() will count its size on its own */ |
| 1857 | vaux = value; |
| 1858 | } |
| 1859 | |
| 1860 | /* store token into unique structure */ |
| 1861 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1862 | |
| 1863 | /* check that the expression does not repeat */ |
| 1864 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1865 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1866 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1867 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1868 | goto error; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /* try to resolve leaf */ |
| 1873 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1874 | unique_info = malloc(sizeof *unique_info); |
| 1875 | unique_info->list = parent; |
| 1876 | unique_info->expr = unique->expr[i]; |
| 1877 | unique_info->trg_type = &unique->trg_type; |
| 1878 | 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] | 1879 | goto error; |
| 1880 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1881 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1882 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1883 | goto error; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | /* move to next token */ |
| 1888 | value = vaux; |
| 1889 | while(isspace(*value)) { |
| 1890 | value++; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | return EXIT_SUCCESS; |
| 1895 | |
| 1896 | error: |
| 1897 | return EXIT_FAILURE; |
| 1898 | } |
| 1899 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1900 | /* logs directly |
| 1901 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1902 | * type: 0 - min, 1 - max |
| 1903 | */ |
| 1904 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1905 | 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] | 1906 | { |
| 1907 | const char *value; |
| 1908 | char *endptr; |
| 1909 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1910 | uint32_t *ui32val, *min, *max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1911 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1912 | /* del min/max is forbidden */ |
| 1913 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1914 | 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] | 1915 | goto error; |
| 1916 | } |
| 1917 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1918 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1919 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1920 | max = &((struct lys_node_leaflist *)target)->max; |
| 1921 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1922 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1923 | max = &((struct lys_node_list *)target)->max; |
| 1924 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1925 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1926 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1927 | 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] | 1928 | goto error; |
| 1929 | } |
| 1930 | |
| 1931 | GETVAL(value, node, "value"); |
| 1932 | while (isspace(value[0])) { |
| 1933 | value++; |
| 1934 | } |
| 1935 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1936 | if (type && !strcmp(value, "unbounded")) { |
| 1937 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1938 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1939 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1940 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1941 | /* convert it to uint32_t */ |
| 1942 | errno = 0; |
| 1943 | endptr = NULL; |
| 1944 | val = strtoul(value, &endptr, 10); |
| 1945 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1946 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1947 | goto error; |
| 1948 | } |
| 1949 | if (type) { |
| 1950 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1951 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1952 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1953 | } else { |
| 1954 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1955 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1956 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1957 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | if (d->mod == LY_DEVIATE_ADD) { |
| 1961 | /* check that there is no current value */ |
| 1962 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1963 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1964 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1965 | goto error; |
| 1966 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1967 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1968 | /* unfortunately, there is no way to check reliably that there |
| 1969 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1972 | /* add (already checked) and replace */ |
| 1973 | /* set new value specified in deviation */ |
| 1974 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1975 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1976 | /* check min-elements is smaller than max-elements */ |
| 1977 | if (*max && *min > *max) { |
| 1978 | if (type) { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 1979 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "max-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1980 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
| 1981 | } else { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 1982 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "min-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1983 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 1984 | } |
| 1985 | goto error; |
| 1986 | } |
| 1987 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1988 | return EXIT_SUCCESS; |
| 1989 | |
| 1990 | error: |
| 1991 | |
| 1992 | return EXIT_FAILURE; |
| 1993 | } |
| 1994 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1995 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1996 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1997 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1998 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1999 | { |
| 2000 | const char *value, **stritem; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2001 | struct lyxml_elem *next, *next2, *child, *develem; |
| 2002 | 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] | 2003 | int f_min = 0, f_max = 0; /* flags */ |
Michal Vasko | b40b451 | 2016-02-11 11:35:37 +0100 | [diff] [blame] | 2004 | int i, j, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2005 | unsigned int u; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2006 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2007 | struct lys_deviate *d = NULL; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2008 | struct lys_node *node = NULL, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2009 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2010 | struct lys_node_leaf *leaf = NULL; |
| 2011 | struct ly_set *dflt_check = ly_set_new(); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2012 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2013 | struct lys_node_leaflist *llist = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2014 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2015 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2016 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2017 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2018 | struct lys_module *mod; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2019 | void *reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2020 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2021 | ctx = module->ctx; |
| 2022 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2023 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2024 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2025 | if (!dev->target_name) { |
| 2026 | goto error; |
| 2027 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2028 | |
| 2029 | /* resolve target node */ |
Radek Krejci | df46e22 | 2016-11-08 11:57:37 +0100 | [diff] [blame] | 2030 | 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] | 2031 | if (rc || !dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2032 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2033 | goto error; |
| 2034 | } |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2035 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2036 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 2037 | 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] | 2038 | goto error; |
| 2039 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2040 | |
| 2041 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2042 | if (!child->ns ) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2043 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2044 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2045 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2046 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2047 | /* extension */ |
| 2048 | c_ext++; |
| 2049 | continue; |
| 2050 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2051 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2052 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2053 | goto error; |
| 2054 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2055 | if (read_yin_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 2056 | goto error; |
| 2057 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2058 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2059 | if (!dev->dsc) { |
| 2060 | goto error; |
| 2061 | } |
| 2062 | } else if (!strcmp(child->name, "reference")) { |
| 2063 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2064 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2065 | goto error; |
| 2066 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2067 | if (read_yin_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 2068 | goto error; |
| 2069 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2070 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2071 | if (!dev->ref) { |
| 2072 | goto error; |
| 2073 | } |
| 2074 | } else if (!strcmp(child->name, "deviate")) { |
| 2075 | c_dev++; |
| 2076 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2077 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2078 | * further processed later |
| 2079 | */ |
| 2080 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2081 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2082 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2083 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2084 | goto error; |
| 2085 | } |
| 2086 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2087 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | if (c_dev) { |
| 2091 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2092 | if (!dev->deviate) { |
| 2093 | LOGMEM; |
| 2094 | goto error; |
| 2095 | } |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2096 | } else { |
| 2097 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
| 2098 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2099 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2100 | if (c_ext) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2101 | /* some extensions may be already present from the substatements */ |
| 2102 | reallocated = realloc(dev->ext, (c_ext + dev->ext_size) * sizeof *dev->ext); |
| 2103 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2104 | LOGMEM; |
| 2105 | goto error; |
| 2106 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2107 | dev->ext = reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2108 | |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2109 | /* init memory */ |
| 2110 | memset(&dev->ext[dev->ext_size], 0, c_ext * sizeof *dev->ext); |
| 2111 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2112 | |
| 2113 | LY_TREE_FOR_SAFE(yin->child, next, develem) { |
| 2114 | if (strcmp(develem->ns->value, LY_NSYIN)) { |
| 2115 | /* deviation's extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 2116 | 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] | 2117 | dev->ext_size++; |
| 2118 | if (rc) { |
| 2119 | goto error; |
| 2120 | } |
| 2121 | continue; |
| 2122 | } |
| 2123 | |
| 2124 | /* deviate */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2125 | /* init */ |
| 2126 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2127 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2128 | c_must = 0; |
| 2129 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2130 | c_dflt = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2131 | c_ext = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2132 | |
| 2133 | /* get deviation type */ |
| 2134 | GETVAL(value, develem, "value"); |
| 2135 | if (!strcmp(value, "not-supported")) { |
| 2136 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2137 | /* no other deviate statement is expected, |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2138 | * not-supported deviation must be the only deviation of the target |
| 2139 | */ |
| 2140 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2141 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2142 | 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] | 2143 | goto error; |
| 2144 | } |
| 2145 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2146 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 2147 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 2148 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 2149 | 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] | 2150 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2151 | 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] | 2152 | goto error; |
| 2153 | } |
| 2154 | } |
| 2155 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2156 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2157 | /* unlink and store the original node */ |
| 2158 | lys_node_unlink(dev_target); |
| 2159 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2160 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2161 | } else if (!strcmp(value, "add")) { |
| 2162 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 2163 | } else if (!strcmp(value, "replace")) { |
| 2164 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 2165 | } else if (!strcmp(value, "delete")) { |
| 2166 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 2167 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2168 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2169 | goto error; |
| 2170 | } |
| 2171 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 2172 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2173 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2174 | /* store a shallow copy of the original node */ |
| 2175 | if (!dev->orig_node) { |
| 2176 | memset(&tmp_unres, 0, sizeof tmp_unres); |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 2177 | 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] | 2178 | /* just to be safe */ |
| 2179 | if (tmp_unres.count) { |
| 2180 | LOGINT; |
| 2181 | goto error; |
| 2182 | } |
| 2183 | } |
| 2184 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2185 | /* process deviation properties */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2186 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2187 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2188 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2189 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2190 | continue; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2191 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2192 | /* extensions */ |
| 2193 | c_ext++; |
| 2194 | } else if (d->mod == LY_DEVIATE_NO) { |
| 2195 | /* no YIN substatement expected in this case */ |
| 2196 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2197 | goto error; |
| 2198 | } else if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2199 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2200 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2201 | goto error; |
| 2202 | } |
| 2203 | |
| 2204 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 2205 | * specified in the target explicitly since config property inherits. So we expect |
| 2206 | * that config is specified in every node. But for delete, we check that the value |
| 2207 | * is the same as here in deviation |
| 2208 | */ |
| 2209 | GETVAL(value, child, "value"); |
| 2210 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2211 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2212 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2213 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2214 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2215 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2216 | goto error; |
| 2217 | } |
| 2218 | |
| 2219 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2220 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2221 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2222 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2223 | } else { /* add and replace are the same in this case */ |
| 2224 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2225 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2226 | |
| 2227 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2228 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2229 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2230 | |
| 2231 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
| 2232 | goto error; |
| 2233 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2234 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2235 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
| 2236 | goto error; |
| 2237 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2238 | c_dflt++; |
| 2239 | |
| 2240 | /* check target node type */ |
| 2241 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
| 2242 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2243 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
| 2244 | goto error; |
| 2245 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
| 2246 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2247 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
| 2248 | goto error; |
| 2249 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
| 2250 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2251 | 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] | 2252 | goto error; |
| 2253 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2254 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2255 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 2256 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2257 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2258 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2259 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2260 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2261 | goto error; |
| 2262 | } |
| 2263 | |
| 2264 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2265 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2266 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2267 | 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] | 2268 | goto error; |
| 2269 | } |
| 2270 | |
| 2271 | GETVAL(value, child, "value"); |
| 2272 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2273 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2274 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2275 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2276 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2277 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2278 | goto error; |
| 2279 | } |
| 2280 | |
| 2281 | if (d->mod == LY_DEVIATE_ADD) { |
| 2282 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2283 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2284 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2285 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2286 | goto error; |
| 2287 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2288 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2289 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2290 | if (d->flags & LYS_MAND_TRUE) { |
| 2291 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2292 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
| 2293 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2294 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2295 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 2296 | goto error; |
| 2297 | } |
| 2298 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2299 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
| 2300 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2301 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2302 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 2303 | goto error; |
| 2304 | } |
| 2305 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2306 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2307 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2308 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 2309 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2310 | /* check that there was a value before */ |
| 2311 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2312 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2313 | 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] | 2314 | goto error; |
| 2315 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2316 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2317 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2318 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2319 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2320 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2321 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2322 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2323 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2324 | |
| 2325 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 2326 | for (parent = dev_target->parent; |
| 2327 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 2328 | parent = parent->parent) { |
| 2329 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 2330 | /* stop also on presence containers */ |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 2335 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 2336 | if (lyp_check_mandatory_choice(parent)) { |
| 2337 | goto error; |
| 2338 | } |
| 2339 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2340 | |
| 2341 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
| 2342 | goto error; |
| 2343 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2344 | } else if (!strcmp(child->name, "min-elements")) { |
| 2345 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2346 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2347 | goto error; |
| 2348 | } |
| 2349 | f_min = 1; |
| 2350 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2351 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2352 | goto error; |
| 2353 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2354 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MIN, 0, unres)) { |
| 2355 | goto error; |
| 2356 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2357 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2358 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2359 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2360 | goto error; |
| 2361 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2362 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2363 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2364 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2365 | goto error; |
| 2366 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2367 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MAX, 0, unres)) { |
| 2368 | goto error; |
| 2369 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2370 | } else if (!strcmp(child->name, "must")) { |
| 2371 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2372 | /* 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] | 2373 | continue; |
| 2374 | } else if (!strcmp(child->name, "type")) { |
| 2375 | if (d->type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2376 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2377 | goto error; |
| 2378 | } |
| 2379 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2380 | /* add, del type is forbidden */ |
| 2381 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2382 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2383 | goto error; |
| 2384 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2385 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2386 | goto error; |
| 2387 | } |
| 2388 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2389 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2390 | if (dev_target->nodetype == LYS_LEAF) { |
| 2391 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2392 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 2393 | ly_set_add(dflt_check, dev_target, 0); |
| 2394 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2395 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2396 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2397 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 2398 | ly_set_add(dflt_check, dev_target, 0); |
| 2399 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2400 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2401 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2402 | 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] | 2403 | goto error; |
| 2404 | } |
| 2405 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2406 | /* replace */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2407 | lys_type_free(ctx, t); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2408 | /* HACK for unres */ |
| 2409 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 2410 | 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] | 2411 | goto error; |
| 2412 | } |
| 2413 | d->type = t; |
| 2414 | } else if (!strcmp(child->name, "unique")) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2415 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNIQUE, c_uniq, unres)) { |
| 2416 | goto error; |
| 2417 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2418 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2419 | /* 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] | 2420 | continue; |
| 2421 | } else if (!strcmp(child->name, "units")) { |
| 2422 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2423 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2424 | goto error; |
| 2425 | } |
| 2426 | |
| 2427 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2428 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2429 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 2430 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2431 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2432 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2433 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2434 | 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] | 2435 | goto error; |
| 2436 | } |
| 2437 | |
| 2438 | /* get units value */ |
| 2439 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2440 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2441 | |
| 2442 | /* apply to target */ |
| 2443 | if (d->mod == LY_DEVIATE_ADD) { |
| 2444 | /* check that there is no current value */ |
| 2445 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2446 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2447 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2448 | goto error; |
| 2449 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2450 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2451 | *stritem = lydict_insert(ctx, value, 0); |
| 2452 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2453 | /* check that there was a value before */ |
| 2454 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2455 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2456 | 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] | 2457 | goto error; |
| 2458 | } |
| 2459 | |
| 2460 | lydict_remove(ctx, *stritem); |
| 2461 | *stritem = lydict_insert(ctx, value, 0); |
| 2462 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2463 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2464 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2465 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2466 | 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] | 2467 | goto error; |
| 2468 | } |
| 2469 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2470 | lydict_remove(ctx, *stritem); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2471 | (*stritem) = NULL; |
| 2472 | } |
| 2473 | |
| 2474 | if (read_yin_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
| 2475 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2476 | } |
| 2477 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2478 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2479 | goto error; |
| 2480 | } |
| 2481 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2482 | /* 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] | 2483 | } |
| 2484 | |
| 2485 | if (c_must) { |
| 2486 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2487 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2488 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2489 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2490 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2491 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2492 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2493 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2494 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2495 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2496 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2497 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2498 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2499 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2500 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2501 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2502 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2503 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2504 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2505 | case LYS_ANYDATA: |
| 2506 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2507 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2508 | break; |
| 2509 | default: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2510 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2511 | 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] | 2512 | goto error; |
| 2513 | } |
| 2514 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 2515 | dev_target->flags &= ~LYS_XPATH_DEP; |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2516 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2517 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2518 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2519 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2520 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2521 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2522 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2523 | 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] | 2524 | if (!d->must) { |
| 2525 | LOGMEM; |
| 2526 | goto error; |
| 2527 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2528 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 2529 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2530 | d->must_size = c_must; |
| 2531 | } else { /* LY_DEVIATE_DEL */ |
| 2532 | d->must = calloc(c_must, sizeof *d->must); |
| 2533 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2534 | if (!d->must) { |
| 2535 | LOGMEM; |
| 2536 | goto error; |
| 2537 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2538 | } |
| 2539 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2540 | /* replace unique is forbidden */ |
| 2541 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2542 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2543 | goto error; |
| 2544 | } |
| 2545 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2546 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2547 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2548 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2549 | 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] | 2550 | goto error; |
| 2551 | } |
| 2552 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2553 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2554 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2555 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2556 | 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] | 2557 | list->unique = d->unique; |
| 2558 | d->unique = &list->unique[list->unique_size]; |
| 2559 | d->unique_size = c_uniq; |
| 2560 | } else { /* LY_DEVIATE_DEL */ |
| 2561 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 2562 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2563 | if (!d->unique) { |
| 2564 | LOGMEM; |
| 2565 | goto error; |
| 2566 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2567 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2568 | if (c_dflt) { |
| 2569 | if (d->mod == LY_DEVIATE_ADD) { |
| 2570 | /* check that there is no current value */ |
| 2571 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2572 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
| 2573 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2574 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
| 2575 | goto error; |
| 2576 | } |
| 2577 | |
| 2578 | /* check collision with mandatory/min-elements */ |
| 2579 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2580 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
| 2581 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2582 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2583 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2584 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2585 | goto error; |
| 2586 | } |
| 2587 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2588 | /* check that there was a value before */ |
| 2589 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2590 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
| 2591 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2592 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
| 2593 | goto error; |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2598 | /* reallocate default list in the target */ |
| 2599 | llist = (struct lys_node_leaflist *)dev_target; |
| 2600 | if (d->mod == LY_DEVIATE_ADD) { |
| 2601 | /* reallocate (enlarge) the unique array of the target */ |
| 2602 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
| 2603 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2604 | /* reallocate (replace) the unique array of the target */ |
| 2605 | for (i = 0; i < llist->dflt_size; i++) { |
| 2606 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2607 | } |
| 2608 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2609 | llist->dflt_size = 0; |
| 2610 | } |
| 2611 | } |
| 2612 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
| 2613 | if (!d->dflt) { |
| 2614 | LOGMEM; |
| 2615 | goto error; |
| 2616 | } |
| 2617 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2618 | if (c_ext) { |
| 2619 | /* some extensions may be already present from the substatements */ |
| 2620 | reallocated = realloc(d->ext, (c_ext + d->ext_size) * sizeof *d->ext); |
| 2621 | if (!reallocated) { |
| 2622 | LOGMEM; |
| 2623 | goto error; |
| 2624 | } |
| 2625 | d->ext = reallocated; |
| 2626 | |
| 2627 | /* init memory */ |
| 2628 | memset(&d->ext[d->ext_size], 0, c_ext * sizeof *d->ext); |
| 2629 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2630 | |
| 2631 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2632 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
| 2633 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2634 | /* extension */ |
| 2635 | if (lyp_yin_fill_ext(d, LYEXT_PAR_DEVIATE, 0, 0, module, child, &d->ext, d->ext_size, unres)) { |
| 2636 | goto error; |
| 2637 | } |
| 2638 | d->ext_size++; |
| 2639 | } else if (!strcmp(child->name, "must")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2640 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2641 | if (fill_yin_must(module, child, &d->must[d->must_size], unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2642 | goto error; |
| 2643 | } |
| 2644 | |
| 2645 | /* find must to delete, we are ok with just matching conditions */ |
| 2646 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2647 | 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] | 2648 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2649 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2650 | /* ... and maintain the array */ |
| 2651 | (*trg_must_size)--; |
| 2652 | if (i != *trg_must_size) { |
| 2653 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2654 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2655 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2656 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2657 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2658 | } |
| 2659 | if (!(*trg_must_size)) { |
| 2660 | free(*trg_must); |
| 2661 | *trg_must = NULL; |
| 2662 | } else { |
| 2663 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2664 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2665 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2666 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2667 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2668 | } |
| 2669 | |
| 2670 | i = -1; /* set match flag */ |
| 2671 | break; |
| 2672 | } |
| 2673 | } |
| 2674 | d->must_size++; |
| 2675 | if (i != -1) { |
| 2676 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2677 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2678 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2679 | 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] | 2680 | goto error; |
| 2681 | } |
| 2682 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2683 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2684 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]), unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2685 | goto error; |
| 2686 | } |
| 2687 | (*trg_must_size)++; |
| 2688 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2689 | |
| 2690 | /* check XPath dependencies again */ |
Michal Vasko | e873426 | 2016-09-29 14:12:06 +0200 | [diff] [blame] | 2691 | 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] | 2692 | goto error; |
| 2693 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2694 | } else if (!strcmp(child->name, "unique")) { |
| 2695 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2696 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2697 | 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] | 2698 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2699 | goto error; |
| 2700 | } |
| 2701 | |
| 2702 | /* find unique structures to delete */ |
| 2703 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2704 | 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] | 2705 | continue; |
| 2706 | } |
| 2707 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2708 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2709 | 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] | 2710 | break; |
| 2711 | } |
| 2712 | } |
| 2713 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2714 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2715 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2716 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2717 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2718 | } |
| 2719 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2720 | /* ... and maintain the array */ |
| 2721 | list->unique_size--; |
| 2722 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2723 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2724 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | if (!list->unique_size) { |
| 2728 | free(list->unique); |
| 2729 | list->unique = NULL; |
| 2730 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2731 | list->unique[list->unique_size].expr_size = 0; |
| 2732 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | i = -1; /* set match flag */ |
| 2736 | break; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | d->unique_size++; |
| 2741 | if (i != -1) { |
| 2742 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2743 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2744 | 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] | 2745 | goto error; |
| 2746 | } |
| 2747 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2748 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2749 | 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] | 2750 | list->unique_size++; |
| 2751 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2752 | goto error; |
| 2753 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2754 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2755 | } else if (!strcmp(child->name, "default")) { |
| 2756 | GETVAL(value, child, "value"); |
| 2757 | u = strlen(value); |
| 2758 | d->dflt[d->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2759 | |
| 2760 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2761 | choice = (struct lys_node_choice *)dev_target; |
| 2762 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2763 | if (rc || !node) { |
| 2764 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2765 | goto error; |
| 2766 | } |
| 2767 | if (d->mod == LY_DEVIATE_DEL) { |
| 2768 | if (!choice->dflt || (choice->dflt != node)) { |
| 2769 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2770 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2771 | goto error; |
| 2772 | } |
| 2773 | } else { /* add or replace */ |
| 2774 | choice->dflt = node; |
| 2775 | if (!choice->dflt) { |
| 2776 | /* default branch not found */ |
| 2777 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2778 | goto error; |
| 2779 | } |
| 2780 | } |
| 2781 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2782 | leaf = (struct lys_node_leaf *)dev_target; |
| 2783 | if (d->mod == LY_DEVIATE_DEL) { |
| 2784 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
| 2785 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2786 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2787 | goto error; |
| 2788 | } |
| 2789 | /* remove value */ |
| 2790 | lydict_remove(ctx, leaf->dflt); |
| 2791 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2792 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2793 | } else { /* add (already checked) and replace */ |
| 2794 | /* remove value */ |
| 2795 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2796 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2797 | |
| 2798 | /* set new value */ |
| 2799 | leaf->dflt = lydict_insert(ctx, value, u); |
| 2800 | |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2801 | /* 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] | 2802 | ly_set_add(dflt_check, dev_target, 0); |
| 2803 | } |
| 2804 | } else { /* LYS_LEAFLIST */ |
| 2805 | llist = (struct lys_node_leaflist *)dev_target; |
| 2806 | if (d->mod == LY_DEVIATE_DEL) { |
| 2807 | /* find and remove the value in target list */ |
| 2808 | for (i = 0; i < llist->dflt_size; i++) { |
| 2809 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 2810 | /* match, remove the value */ |
| 2811 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2812 | llist->dflt[i] = NULL; |
| 2813 | break; |
| 2814 | } |
| 2815 | } |
| 2816 | if (i == llist->dflt_size) { |
| 2817 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2818 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
| 2819 | goto error; |
| 2820 | } |
| 2821 | } else { |
| 2822 | /* add or replace, anyway we place items into the deviate's list |
| 2823 | which propagates to the target */ |
| 2824 | /* we just want to check that the value isn't already in the list */ |
| 2825 | for (i = 0; i < llist->dflt_size; i++) { |
| 2826 | if (ly_strequal(llist->dflt[i], value, 1)) { |
| 2827 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2828 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2829 | goto error; |
| 2830 | } |
| 2831 | } |
| 2832 | /* store it in target node */ |
| 2833 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2834 | |
| 2835 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2836 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2837 | llist->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2838 | } |
| 2839 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2840 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2841 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2842 | |
| 2843 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 2844 | /* consolidate the final list in the target after removing items from it */ |
| 2845 | llist = (struct lys_node_leaflist *)dev_target; |
| 2846 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 2847 | llist->dflt[i] = llist->dflt[j]; |
| 2848 | if (llist->dflt[i]) { |
| 2849 | i++; |
| 2850 | } |
| 2851 | } |
| 2852 | llist->dflt_size = i + 1; |
| 2853 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2854 | } |
| 2855 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2856 | /* now check whether default value, if any, matches the type */ |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 2857 | for (u = 0; u < dflt_check->number; ++u) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2858 | value = NULL; |
| 2859 | rc = EXIT_SUCCESS; |
| 2860 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 2861 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2862 | value = leaf->dflt; |
| 2863 | 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] | 2864 | } else { /* LYS_LEAFLIST */ |
| 2865 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 2866 | for (j = 0; j < llist->dflt_size; j++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2867 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 2868 | (struct lys_node *)(&llist->dflt[j])); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2869 | if (rc == -1) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2870 | value = llist->dflt[j]; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2871 | break; |
| 2872 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2873 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2874 | |
| 2875 | } |
| 2876 | if (rc == -1) { |
| 2877 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2878 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2879 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 2880 | dev->target_name); |
| 2881 | goto error; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2882 | } |
| 2883 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2884 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2885 | /* mark all the affected modules as deviated and implemented */ |
| 2886 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 2887 | mod = lys_node_module(parent); |
| 2888 | if (module != mod) { |
| 2889 | mod->deviated = 1; |
| 2890 | lys_set_implemented(mod); |
| 2891 | } |
| 2892 | } |
| 2893 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2894 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2895 | return EXIT_SUCCESS; |
| 2896 | |
| 2897 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2898 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2899 | return EXIT_FAILURE; |
| 2900 | } |
| 2901 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2902 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2903 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2904 | 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] | 2905 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2906 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2907 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2908 | struct lyxml_elem *sub, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2909 | struct lys_node *node; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2910 | int ret, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2911 | void *reallocated; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2912 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 2913 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2914 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2915 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 2916 | if (!aug->target_name) { |
| 2917 | goto error; |
| 2918 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2919 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2920 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 2921 | 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] | 2922 | goto error; |
| 2923 | } |
| 2924 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2925 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 2926 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2927 | /* extension */ |
| 2928 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2929 | continue; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2930 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2931 | c_ftrs++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2932 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2933 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2934 | if (aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2935 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2936 | goto error; |
| 2937 | } |
| 2938 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 2939 | aug->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2940 | if (!aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2941 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2942 | goto error; |
| 2943 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2944 | lyxml_free(module->ctx, sub); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2945 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2946 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2947 | /* check allowed data sub-statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2948 | } else if (!strcmp(sub->name, "container")) { |
| 2949 | node = read_yin_container(module, (struct lys_node *)aug, sub, 1, unres); |
| 2950 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2951 | node = read_yin_leaflist(module, (struct lys_node *)aug, sub, 1, unres); |
| 2952 | } else if (!strcmp(sub->name, "leaf")) { |
| 2953 | node = read_yin_leaf(module, (struct lys_node *)aug, sub, 1, unres); |
| 2954 | } else if (!strcmp(sub->name, "list")) { |
| 2955 | node = read_yin_list(module, (struct lys_node *)aug, sub, 1, unres); |
| 2956 | } else if (!strcmp(sub->name, "uses")) { |
| 2957 | node = read_yin_uses(module, (struct lys_node *)aug, sub, unres); |
| 2958 | } else if (!strcmp(sub->name, "choice")) { |
| 2959 | node = read_yin_choice(module, (struct lys_node *)aug, sub, 1, unres); |
| 2960 | } else if (!strcmp(sub->name, "case")) { |
| 2961 | node = read_yin_case(module, (struct lys_node *)aug, sub, 1, unres); |
| 2962 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2963 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYXML, 1, unres); |
| 2964 | } else if (!strcmp(sub->name, "anydata")) { |
| 2965 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYDATA, 1, unres); |
| 2966 | } else if (!strcmp(sub->name, "action")) { |
| 2967 | node = read_yin_rpc_action(module, (struct lys_node *)aug, sub, unres); |
| 2968 | } else if (!strcmp(sub->name, "notification")) { |
| 2969 | node = read_yin_notif(module, (struct lys_node *)aug, sub, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2970 | } else { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2971 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2972 | goto error; |
| 2973 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2974 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2975 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2976 | goto error; |
| 2977 | } |
| 2978 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2979 | node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2980 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2981 | } |
| 2982 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2983 | if (c_ftrs) { |
| 2984 | aug->iffeature = calloc(c_ftrs, sizeof *aug->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 2985 | if (!aug->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2986 | LOGMEM; |
| 2987 | goto error; |
| 2988 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2989 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2990 | if (c_ext) { |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2991 | /* some extensions may be already present from the substatements */ |
| 2992 | reallocated = realloc(aug->ext, (c_ext + aug->ext_size) * sizeof *aug->ext); |
| 2993 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2994 | LOGMEM; |
| 2995 | goto error; |
| 2996 | } |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2997 | aug->ext = reallocated; |
| 2998 | |
| 2999 | /* init memory */ |
| 3000 | memset(&aug->ext[aug->ext_size], 0, c_ext * sizeof *aug->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3001 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3002 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3003 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3004 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3005 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3006 | 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] | 3007 | aug->ext_size++; |
| 3008 | if (ret) { |
| 3009 | goto error; |
| 3010 | } |
| 3011 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3012 | 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] | 3013 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3014 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3015 | goto error; |
| 3016 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3017 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3018 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3019 | } |
| 3020 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3021 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3022 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3023 | * 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] | 3024 | * when the uses does and cannot be resolved now for sure |
| 3025 | * (the grouping was not yet copied into uses). |
| 3026 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3027 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3028 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 3029 | goto error; |
| 3030 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3031 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3032 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3033 | /* check XPath dependencies */ |
| 3034 | if (aug->when && (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1)) { |
| 3035 | goto error; |
| 3036 | } |
| 3037 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3038 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3039 | |
| 3040 | error: |
| 3041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3042 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3045 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3046 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3047 | 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] | 3048 | { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3049 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3050 | struct lyxml_elem *sub, *next; |
| 3051 | const char *value; |
| 3052 | char *endptr; |
| 3053 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3054 | 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] | 3055 | int r; |
| 3056 | unsigned long int val; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3057 | void *reallocated; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3058 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3059 | assert(uses); |
| 3060 | module = uses->module; /* shorthand */ |
| 3061 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3062 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3063 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 3064 | if (!rfn->target_name) { |
| 3065 | goto error; |
| 3066 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3067 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3068 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3069 | if (!sub->ns) { |
| 3070 | /* garbage */ |
| 3071 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3072 | /* extension */ |
| 3073 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3074 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3075 | |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3076 | } else if (!strcmp(sub->name, "description")) { |
| 3077 | if (rfn->dsc) { |
| 3078 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3079 | goto error; |
| 3080 | } |
| 3081 | |
| 3082 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 3083 | goto error; |
| 3084 | } |
| 3085 | |
| 3086 | rfn->dsc = read_yin_subnode(module->ctx, sub, "text"); |
| 3087 | if (!rfn->dsc) { |
| 3088 | goto error; |
| 3089 | } |
| 3090 | } else if (!strcmp(sub->name, "reference")) { |
| 3091 | if (rfn->ref) { |
| 3092 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3093 | goto error; |
| 3094 | } |
| 3095 | |
| 3096 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 3097 | goto error; |
| 3098 | } |
| 3099 | |
| 3100 | rfn->ref = read_yin_subnode(module->ctx, sub, "text"); |
| 3101 | if (!rfn->ref) { |
| 3102 | goto error; |
| 3103 | } |
| 3104 | } else if (!strcmp(sub->name, "config")) { |
| 3105 | if (rfn->flags & LYS_CONFIG_MASK) { |
| 3106 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3107 | goto error; |
| 3108 | } |
| 3109 | GETVAL(value, sub, "value"); |
| 3110 | if (!strcmp(value, "false")) { |
| 3111 | rfn->flags |= LYS_CONFIG_R; |
| 3112 | } else if (!strcmp(value, "true")) { |
| 3113 | rfn->flags |= LYS_CONFIG_W; |
| 3114 | } else { |
| 3115 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3116 | goto error; |
| 3117 | } |
| 3118 | rfn->flags |= LYS_CONFIG_SET; |
| 3119 | |
| 3120 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
| 3121 | goto error; |
| 3122 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3123 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3124 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3125 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3126 | /* check possibility of statements combination */ |
| 3127 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3128 | if (c_dflt) { |
| 3129 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3130 | if (module->version < 2) { |
| 3131 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3132 | goto error; |
| 3133 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3134 | rfn->target_type &= LYS_LEAFLIST; |
| 3135 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3136 | if (module->version < 2) { |
| 3137 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 3138 | } else { |
| 3139 | /* YANG 1.1 */ |
| 3140 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 3141 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3142 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3143 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3144 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3145 | 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] | 3146 | goto error; |
| 3147 | } |
| 3148 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3149 | if (module->version < 2) { |
| 3150 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 3151 | } else { |
| 3152 | /* YANG 1.1 */ |
| 3153 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 3154 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3155 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3156 | |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3157 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
| 3158 | goto error; |
| 3159 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3160 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3161 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3162 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3163 | /* leaf, choice or anyxml */ |
| 3164 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3165 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3166 | goto error; |
| 3167 | } |
| 3168 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3169 | * multiple mandatory statements with the "false" value |
| 3170 | */ |
| 3171 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3172 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3173 | /* check possibility of statements combination */ |
| 3174 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3175 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3176 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3177 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3178 | 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] | 3179 | goto error; |
| 3180 | } |
| 3181 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3182 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3183 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3184 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3185 | GETVAL(value, sub, "value"); |
| 3186 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3187 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3188 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3189 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3190 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3191 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3192 | goto error; |
| 3193 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3194 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
| 3195 | goto error; |
| 3196 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3197 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3198 | /* list or leaf-list */ |
| 3199 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3200 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3201 | goto error; |
| 3202 | } |
| 3203 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3204 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3205 | /* check possibility of statements combination */ |
| 3206 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3207 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3208 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3209 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3210 | 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] | 3211 | goto error; |
| 3212 | } |
| 3213 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3214 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3215 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3217 | GETVAL(value, sub, "value"); |
| 3218 | while (isspace(value[0])) { |
| 3219 | value++; |
| 3220 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3221 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3222 | /* convert it to uint32_t */ |
| 3223 | errno = 0; |
| 3224 | endptr = NULL; |
| 3225 | val = strtoul(value, &endptr, 10); |
| 3226 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3227 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3228 | goto error; |
| 3229 | } |
| 3230 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3231 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3232 | |
| 3233 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
| 3234 | goto error; |
| 3235 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3236 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3237 | /* list or leaf-list */ |
| 3238 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3239 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3240 | goto error; |
| 3241 | } |
| 3242 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3243 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3244 | /* check possibility of statements combination */ |
| 3245 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3246 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3247 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3248 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3249 | 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] | 3250 | goto error; |
| 3251 | } |
| 3252 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3253 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3254 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3255 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3256 | GETVAL(value, sub, "value"); |
| 3257 | while (isspace(value[0])) { |
| 3258 | value++; |
| 3259 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3260 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3261 | if (!strcmp(value, "unbounded")) { |
| 3262 | rfn->mod.list.max = 0; |
| 3263 | } else { |
| 3264 | /* convert it to uint32_t */ |
| 3265 | errno = 0; |
| 3266 | endptr = NULL; |
| 3267 | val = strtoul(value, &endptr, 10); |
| 3268 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3269 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3270 | goto error; |
| 3271 | } |
| 3272 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3273 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3274 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3275 | |
| 3276 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
| 3277 | goto error; |
| 3278 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3279 | } else if (!strcmp(sub->name, "presence")) { |
| 3280 | /* container */ |
| 3281 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3282 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3283 | goto error; |
| 3284 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3285 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3286 | /* check possibility of statements combination */ |
| 3287 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3288 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3289 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3290 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3291 | 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] | 3292 | goto error; |
| 3293 | } |
| 3294 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3295 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3296 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3297 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3298 | GETVAL(value, sub, "value"); |
| 3299 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3300 | |
| 3301 | if (read_yin_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_PRESENCE, 0, unres)) { |
| 3302 | goto error; |
| 3303 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3304 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3305 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3306 | /* check possibility of statements combination */ |
| 3307 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3308 | 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] | 3309 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3310 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3311 | 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] | 3312 | goto error; |
| 3313 | } |
| 3314 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3315 | 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] | 3316 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3317 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3318 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3319 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3320 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3321 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 3322 | /* leaf, leaf-list, list, container or anyxml */ |
| 3323 | /* check possibility of statements combination */ |
| 3324 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3325 | 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] | 3326 | if (!rfn->target_type) { |
| 3327 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3328 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
| 3329 | goto error; |
| 3330 | } |
| 3331 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3332 | 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] | 3333 | } |
| 3334 | |
| 3335 | c_ftrs++; |
| 3336 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3337 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3338 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3339 | goto error; |
| 3340 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3341 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3342 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3343 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3344 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3345 | /* process nodes with cardinality of 0..n */ |
| 3346 | if (c_must) { |
| 3347 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3348 | if (!rfn->must) { |
| 3349 | LOGMEM; |
| 3350 | goto error; |
| 3351 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3352 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3353 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 3354 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3355 | if (!rfn->iffeature) { |
| 3356 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3357 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3358 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3359 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3360 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3361 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3362 | if (!rfn->dflt) { |
| 3363 | LOGMEM; |
| 3364 | goto error; |
| 3365 | } |
| 3366 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3367 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3368 | /* some extensions may be already present from the substatements */ |
| 3369 | reallocated = realloc(rfn->ext, (c_ext + rfn->ext_size) * sizeof *rfn->ext); |
| 3370 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3371 | LOGMEM; |
| 3372 | goto error; |
| 3373 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3374 | rfn->ext = reallocated; |
| 3375 | |
| 3376 | /* init memory */ |
| 3377 | memset(&rfn->ext[rfn->ext_size], 0, c_ext * sizeof *rfn->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3378 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3379 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3380 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3381 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3382 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3383 | 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] | 3384 | rfn->ext_size++; |
| 3385 | if (r) { |
| 3386 | goto error; |
| 3387 | } |
| 3388 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 3389 | 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] | 3390 | rfn->iffeature_size++; |
| 3391 | if (r) { |
| 3392 | goto error; |
| 3393 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3394 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 3395 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3396 | rfn->must_size++; |
| 3397 | if (r) { |
| 3398 | goto error; |
| 3399 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3400 | } else { /* default */ |
| 3401 | GETVAL(value, sub, "value"); |
| 3402 | |
| 3403 | /* check for duplicity */ |
| 3404 | for (r = 0; r < rfn->dflt_size; r++) { |
| 3405 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
| 3406 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3407 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 3408 | goto error; |
| 3409 | } |
| 3410 | } |
| 3411 | rfn->dflt[rfn->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3412 | } |
| 3413 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3414 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3415 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3416 | |
| 3417 | error: |
| 3418 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3419 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3420 | } |
| 3421 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3422 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3423 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3424 | 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] | 3425 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3426 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3427 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3428 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3429 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3430 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3431 | /* init */ |
| 3432 | memset(&exts, 0, sizeof exts); |
| 3433 | |
| 3434 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3435 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3436 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3437 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3438 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3439 | /* extension */ |
| 3440 | c_ext++; |
| 3441 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3442 | lyxml_add_child(module->ctx, &exts, child); |
| 3443 | } else if (!strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3444 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3445 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3446 | goto error; |
| 3447 | } |
| 3448 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3449 | |
| 3450 | if (read_yin_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
| 3451 | goto error; |
| 3452 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3453 | } else if (!strcmp(child->name, "revision-date")) { |
| 3454 | if (imp->rev[0]) { |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 3455 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3456 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3457 | } |
| 3458 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3459 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3460 | goto error; |
| 3461 | } |
| 3462 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3463 | |
| 3464 | if (read_yin_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
| 3465 | goto error; |
| 3466 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3467 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3468 | if (imp->dsc) { |
| 3469 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3470 | goto error; |
| 3471 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3472 | if (read_yin_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 3473 | goto error; |
| 3474 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3475 | imp->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3476 | if (!imp->dsc) { |
| 3477 | goto error; |
| 3478 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3479 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3480 | if (imp->ref) { |
| 3481 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3482 | goto error; |
| 3483 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3484 | if (read_yin_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 3485 | goto error; |
| 3486 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3487 | imp->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3488 | if (!imp->ref) { |
| 3489 | goto error; |
| 3490 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3491 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3492 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3493 | goto error; |
| 3494 | } |
| 3495 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3496 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3497 | /* check mandatory information */ |
| 3498 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3499 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3500 | goto error; |
| 3501 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3502 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3503 | /* process extensions */ |
| 3504 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3505 | /* some extensions may be already present from the substatements */ |
| 3506 | reallocated = realloc(imp->ext, (c_ext + imp->ext_size) * sizeof *imp->ext); |
| 3507 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3508 | LOGMEM; |
| 3509 | goto error; |
| 3510 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3511 | imp->ext = reallocated; |
| 3512 | |
| 3513 | /* init memory */ |
| 3514 | memset(&imp->ext[imp->ext_size], 0, c_ext * sizeof *imp->ext); |
| 3515 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3516 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3517 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3518 | 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] | 3519 | imp->ext_size++; |
| 3520 | if (r) { |
| 3521 | goto error; |
| 3522 | } |
| 3523 | } |
| 3524 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3525 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3526 | GETVAL(value, yin, "module"); |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 3527 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3528 | |
| 3529 | error: |
| 3530 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3531 | while (exts.child) { |
| 3532 | lyxml_free(module->ctx, exts.child); |
| 3533 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3534 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3535 | } |
| 3536 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3537 | /* logs directly |
| 3538 | * returns: |
| 3539 | * 0 - inc successfully filled |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3540 | * -1 - error |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3541 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3542 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 3543 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 3544 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3545 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3546 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3547 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3548 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3549 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3550 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3551 | /* init */ |
| 3552 | memset(&exts, 0, sizeof exts); |
| 3553 | |
| 3554 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3555 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3556 | /* garbage */ |
| 3557 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3558 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3559 | /* extension */ |
| 3560 | c_ext++; |
| 3561 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3562 | lyxml_add_child(module->ctx, &exts, child); |
| 3563 | } else if (!strcmp(child->name, "revision-date")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3565 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3566 | goto error; |
| 3567 | } |
| 3568 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3569 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3570 | goto error; |
| 3571 | } |
| 3572 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3573 | |
| 3574 | if (read_yin_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
| 3575 | goto error; |
| 3576 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3577 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3578 | if (inc->dsc) { |
| 3579 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3580 | goto error; |
| 3581 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3582 | if (read_yin_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 3583 | goto error; |
| 3584 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3585 | inc->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3586 | if (!inc->dsc) { |
| 3587 | goto error; |
| 3588 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3589 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3590 | if (inc->ref) { |
| 3591 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3592 | goto error; |
| 3593 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3594 | if (read_yin_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 3595 | goto error; |
| 3596 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3597 | inc->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3598 | if (!inc->ref) { |
| 3599 | goto error; |
| 3600 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3601 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3602 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3603 | goto error; |
| 3604 | } |
| 3605 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3606 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3607 | /* process extensions */ |
| 3608 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3609 | /* some extensions may be already present from the substatements */ |
| 3610 | reallocated = realloc(inc->ext, (c_ext + inc->ext_size) * sizeof *inc->ext); |
| 3611 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3612 | LOGMEM; |
| 3613 | goto error; |
| 3614 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3615 | inc->ext = reallocated; |
| 3616 | |
| 3617 | /* init memory */ |
| 3618 | memset(&inc->ext[inc->ext_size], 0, c_ext * sizeof *inc->ext); |
| 3619 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3620 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3621 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3622 | 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] | 3623 | inc->ext_size++; |
| 3624 | if (r) { |
| 3625 | goto error; |
| 3626 | } |
| 3627 | } |
| 3628 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3629 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3630 | GETVAL(value, yin, "module"); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3631 | 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] | 3632 | |
| 3633 | error: |
| 3634 | |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 3635 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3636 | } |
| 3637 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3638 | /* logs directly |
| 3639 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3640 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3641 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3642 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3643 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3644 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3645 | read_yin_common(struct lys_module *module, struct lys_node *parent, void *stmt, LYEXT_PAR stmt_type, |
| 3646 | struct lyxml_elem *xmlnode, int opt, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3647 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3648 | struct lys_node *node = stmt; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3649 | const char *value; |
| 3650 | struct lyxml_elem *sub, *next; |
| 3651 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3652 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3653 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3654 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3655 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3657 | if (opt & OPT_IDENT) { |
| 3658 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3659 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3660 | goto error; |
| 3661 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3662 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3663 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3664 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3665 | /* process local parameters */ |
| 3666 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3667 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3668 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3669 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3670 | continue; |
| 3671 | } |
| 3672 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 3673 | /* 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] | 3674 | continue; |
| 3675 | } |
| 3676 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3677 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3678 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3679 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3680 | goto error; |
| 3681 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3682 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3683 | if (read_yin_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3684 | goto error; |
| 3685 | } |
| 3686 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3687 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3688 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3689 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3690 | } |
| 3691 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3692 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3693 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3694 | goto error; |
| 3695 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3696 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3697 | if (read_yin_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3698 | goto error; |
| 3699 | } |
| 3700 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3701 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3702 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3703 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3704 | } |
| 3705 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3706 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3707 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3708 | goto error; |
| 3709 | } |
| 3710 | GETVAL(value, sub, "value"); |
| 3711 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3712 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3713 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3714 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3715 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3716 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3717 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3718 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3719 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3720 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3721 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3722 | if (read_yin_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3723 | goto error; |
| 3724 | } |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3725 | } else if ((opt & (OPT_CFG_PARSE | OPT_CFG_IGNORE)) && !strcmp(sub->name, "config")) { |
| 3726 | if (opt & OPT_CFG_PARSE) { |
| 3727 | if (node->flags & LYS_CONFIG_MASK) { |
| 3728 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
| 3729 | goto error; |
| 3730 | } |
| 3731 | GETVAL(value, sub, "value"); |
| 3732 | if (!strcmp(value, "false")) { |
| 3733 | node->flags |= LYS_CONFIG_R; |
| 3734 | } else if (!strcmp(value, "true")) { |
| 3735 | node->flags |= LYS_CONFIG_W; |
| 3736 | } else { |
| 3737 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3738 | goto error; |
| 3739 | } |
| 3740 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3741 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3742 | if (read_yin_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3743 | goto error; |
| 3744 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3745 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3746 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3747 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3748 | continue; |
| 3749 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3750 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3751 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3752 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3753 | if ((opt & OPT_CFG_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3754 | /* get config flag from parent */ |
Radek Krejci | f71f48f | 2016-10-25 16:37:24 +0200 | [diff] [blame] | 3755 | if (parent) { |
| 3756 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
| 3757 | } else if (!parent) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3758 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3759 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3760 | } |
| 3761 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3762 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3763 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 3764 | |
| 3765 | error: |
| 3766 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3767 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3768 | } |
| 3769 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3770 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3771 | static struct lys_when * |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3772 | 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] | 3773 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3774 | struct lys_when *retval = NULL; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3775 | struct lyxml_elem *child, *next; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3776 | const char *value; |
| 3777 | |
| 3778 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3779 | if (!retval) { |
| 3780 | LOGMEM; |
| 3781 | return NULL; |
| 3782 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3783 | |
| 3784 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3785 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 3786 | if (!retval->cond) { |
| 3787 | goto error; |
| 3788 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3789 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3790 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3791 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3792 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3793 | continue; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3794 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3795 | /* extensions */ |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3796 | if (read_yin_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] | 3797 | goto error; |
| 3798 | } |
| 3799 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3800 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3801 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3802 | goto error; |
| 3803 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3804 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3805 | if (read_yin_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] | 3806 | goto error; |
| 3807 | } |
| 3808 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3809 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3810 | if (!retval->dsc) { |
| 3811 | goto error; |
| 3812 | } |
| 3813 | } else if (!strcmp(child->name, "reference")) { |
| 3814 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3815 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3816 | goto error; |
| 3817 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3818 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 3819 | if (read_yin_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] | 3820 | goto error; |
| 3821 | } |
| 3822 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3823 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3824 | if (!retval->ref) { |
| 3825 | goto error; |
| 3826 | } |
| 3827 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3828 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3829 | goto error; |
| 3830 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | return retval; |
| 3834 | |
| 3835 | error: |
| 3836 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 3837 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3838 | return NULL; |
| 3839 | } |
| 3840 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3841 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3842 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3843 | 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] | 3844 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3845 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3846 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3847 | struct lys_node_case *cs; |
| 3848 | struct lys_node *retval, *node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3849 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3850 | void *reallocated; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3851 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 3852 | /* init */ |
| 3853 | memset(&root, 0, sizeof root); |
| 3854 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3855 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3856 | if (!cs) { |
| 3857 | LOGMEM; |
| 3858 | return NULL; |
| 3859 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3860 | cs->nodetype = LYS_CASE; |
| 3861 | cs->prev = (struct lys_node *)cs; |
| 3862 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3863 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3864 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 3865 | OPT_IDENT | OPT_MODULE | (valid_config ? OPT_CFG_INHERIT : 0), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3866 | goto error; |
| 3867 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3868 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3869 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3870 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3871 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3872 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3873 | goto error; |
| 3874 | } |
| 3875 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3876 | /* process choice's specific children */ |
| 3877 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3878 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3879 | /* extension */ |
| 3880 | c_ext++; |
| 3881 | } else if (!strcmp(sub->name, "container") || |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3882 | !strcmp(sub->name, "leaf-list") || |
| 3883 | !strcmp(sub->name, "leaf") || |
| 3884 | !strcmp(sub->name, "list") || |
| 3885 | !strcmp(sub->name, "uses") || |
| 3886 | !strcmp(sub->name, "choice") || |
| 3887 | !strcmp(sub->name, "anyxml")) { |
| 3888 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3889 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3890 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3891 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3892 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3893 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3894 | if (cs->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3895 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3896 | goto error; |
| 3897 | } |
| 3898 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3899 | cs->when = read_yin_when(module, sub, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3900 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3901 | goto error; |
| 3902 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3903 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3904 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3905 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3906 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3907 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3908 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3909 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3910 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3911 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3912 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
| 3913 | if (!cs->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3914 | LOGMEM; |
| 3915 | goto error; |
| 3916 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3917 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3918 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3919 | /* some extensions may be already present from the substatements */ |
| 3920 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 3921 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3922 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3923 | goto error; |
| 3924 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3925 | retval->ext = reallocated; |
| 3926 | |
| 3927 | /* init memory */ |
| 3928 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3929 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3930 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3931 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3932 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3933 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3934 | 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] | 3935 | retval->ext_size++; |
| 3936 | if (ret) { |
| 3937 | goto error; |
| 3938 | } |
| 3939 | } else { |
| 3940 | /* if-feature */ |
| 3941 | ret = fill_yin_iffeature(retval, 0, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 3942 | cs->iffeature_size++; |
| 3943 | if (ret) { |
| 3944 | goto error; |
| 3945 | } |
| 3946 | } |
| 3947 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3948 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3949 | /* last part - process data nodes */ |
| 3950 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3951 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3952 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3953 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3954 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3955 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3956 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3957 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3958 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3959 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3960 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3961 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 3962 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3963 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3964 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3965 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3966 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3967 | } |
| 3968 | if (!node) { |
| 3969 | goto error; |
| 3970 | } |
| 3971 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3972 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3973 | } |
| 3974 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3975 | /* check XPath dependencies */ |
| 3976 | if (cs->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 3977 | goto error; |
| 3978 | } |
| 3979 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3980 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3981 | |
| 3982 | error: |
| 3983 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3984 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3985 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3986 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3987 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3988 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3989 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3990 | } |
| 3991 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3992 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3993 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3994 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int valid_config, |
| 3995 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3996 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3997 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3998 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3999 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4000 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4001 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4002 | int f_mand = 0, c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4003 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4004 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4005 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4006 | if (!choice) { |
| 4007 | LOGMEM; |
| 4008 | return NULL; |
| 4009 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4010 | choice->nodetype = LYS_CHOICE; |
| 4011 | choice->prev = (struct lys_node *)choice; |
| 4012 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4013 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4014 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4015 | 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] | 4016 | goto error; |
| 4017 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4018 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4019 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4020 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4021 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4022 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4023 | goto error; |
| 4024 | } |
| 4025 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4026 | /* process choice's specific children */ |
| 4027 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4028 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4029 | /* extension */ |
| 4030 | c_ext++; |
| 4031 | /* keep it for later processing, skip lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4032 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4033 | } else if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4034 | if (!(node = read_yin_container(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4035 | goto error; |
| 4036 | } |
| 4037 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4038 | if (!(node = read_yin_leaflist(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4039 | goto error; |
| 4040 | } |
| 4041 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4042 | if (!(node = read_yin_leaf(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4043 | goto error; |
| 4044 | } |
| 4045 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4046 | if (!(node = read_yin_list(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4047 | goto error; |
| 4048 | } |
| 4049 | } else if (!strcmp(sub->name, "case")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4050 | if (!(node = read_yin_case(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4051 | goto error; |
| 4052 | } |
| 4053 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4054 | 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] | 4055 | goto error; |
| 4056 | } |
| 4057 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4058 | 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] | 4059 | goto error; |
| 4060 | } |
| 4061 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4062 | if (dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4063 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4064 | goto error; |
| 4065 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4066 | |
| 4067 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
| 4068 | goto error; |
| 4069 | } |
| 4070 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4071 | dflt = sub; |
| 4072 | lyxml_unlink_elem(ctx, dflt, 0); |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 4073 | continue; |
| 4074 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 4075 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4076 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4077 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4078 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4079 | goto error; |
| 4080 | } |
| 4081 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4082 | * multiple mandatory statements with the "false" value |
| 4083 | */ |
| 4084 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4085 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4086 | GETVAL(value, sub, "value"); |
| 4087 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4088 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4089 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4090 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4091 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4092 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4093 | goto error; |
| 4094 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4095 | |
| 4096 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
| 4097 | goto error; |
| 4098 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4099 | } else if (!strcmp(sub->name, "when")) { |
| 4100 | if (choice->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4101 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4102 | goto error; |
| 4103 | } |
| 4104 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4105 | choice->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4106 | if (!choice->when) { |
| 4107 | goto error; |
| 4108 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4109 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4110 | c_ftrs++; |
| 4111 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4112 | /* 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] | 4113 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4114 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4115 | if (!(node = read_yin_choice(module, retval, sub, valid_config, unres))) { |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4116 | goto error; |
| 4117 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4118 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4119 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4120 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4121 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4122 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4123 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4124 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4125 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4126 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4127 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4128 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
| 4129 | if (!choice->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4130 | LOGMEM; |
| 4131 | goto error; |
| 4132 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4133 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4134 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4135 | /* some extensions may be already present from the substatements */ |
| 4136 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4137 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4138 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4139 | goto error; |
| 4140 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4141 | retval->ext = reallocated; |
| 4142 | |
| 4143 | /* init memory */ |
| 4144 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4145 | } |
| 4146 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4147 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4148 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4149 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4150 | 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] | 4151 | retval->ext_size++; |
| 4152 | if (ret) { |
| 4153 | goto error; |
| 4154 | } |
| 4155 | } else { |
| 4156 | ret = fill_yin_iffeature(retval, 0, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 4157 | choice->iffeature_size++; |
| 4158 | if (ret) { |
| 4159 | goto error; |
| 4160 | } |
| 4161 | } |
| 4162 | } |
| 4163 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4164 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4165 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4166 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4167 | 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] | 4168 | goto error; |
| 4169 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4170 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4171 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4172 | if (dflt) { |
| 4173 | GETVAL(value, dflt, "value"); |
| 4174 | 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] | 4175 | goto error; |
| 4176 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4177 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4178 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4179 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4180 | /* check XPath dependencies */ |
| 4181 | if (choice->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4182 | goto error; |
| 4183 | } |
| 4184 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4185 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4186 | |
| 4187 | error: |
| 4188 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4189 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4190 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4191 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4192 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4193 | } |
| 4194 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4195 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4196 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4197 | read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, LYS_NODE type, |
| 4198 | int valid_config, struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4199 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4200 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4201 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4202 | struct lyxml_elem *sub, *next; |
| 4203 | const char *value; |
| 4204 | int r; |
| 4205 | int f_mand = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4206 | int c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4207 | void *reallocated; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4208 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4209 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4210 | if (!anyxml) { |
| 4211 | LOGMEM; |
| 4212 | return NULL; |
| 4213 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4214 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4215 | anyxml->prev = (struct lys_node *)anyxml; |
| 4216 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4217 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4218 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4219 | 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] | 4220 | goto error; |
| 4221 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4222 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4223 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4224 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4225 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4226 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4227 | goto error; |
| 4228 | } |
| 4229 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4230 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4231 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4232 | /* extension */ |
| 4233 | c_ext++; |
| 4234 | } else if (!strcmp(sub->name, "mandatory")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4235 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4236 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4237 | goto error; |
| 4238 | } |
| 4239 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4240 | * multiple mandatory statements with the "false" value |
| 4241 | */ |
| 4242 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4243 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4244 | GETVAL(value, sub, "value"); |
| 4245 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4246 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4247 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4248 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4249 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4250 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4251 | goto error; |
| 4252 | } |
| 4253 | /* else false is the default value, so we can ignore it */ |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4254 | |
| 4255 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
| 4256 | goto error; |
| 4257 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4258 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4259 | } else if (!strcmp(sub->name, "when")) { |
| 4260 | if (anyxml->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4261 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4262 | goto error; |
| 4263 | } |
| 4264 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4265 | anyxml->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4266 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4267 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4268 | goto error; |
| 4269 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4270 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4271 | } else if (!strcmp(sub->name, "must")) { |
| 4272 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4273 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4274 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4275 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4276 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4277 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4278 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4279 | } |
| 4280 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4282 | /* middle part - process nodes with cardinality of 0..n */ |
| 4283 | if (c_must) { |
| 4284 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4285 | if (!anyxml->must) { |
| 4286 | LOGMEM; |
| 4287 | goto error; |
| 4288 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4289 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4290 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4291 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
| 4292 | if (!anyxml->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4293 | LOGMEM; |
| 4294 | goto error; |
| 4295 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4296 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4297 | if (c_ext) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4298 | /* some extensions may be already present from the substatements */ |
| 4299 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4300 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4301 | LOGMEM; |
| 4302 | goto error; |
| 4303 | } |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4304 | retval->ext = reallocated; |
| 4305 | |
| 4306 | /* init memory */ |
| 4307 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4308 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4309 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4310 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4311 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4312 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4313 | 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] | 4314 | retval->ext_size++; |
| 4315 | if (r) { |
| 4316 | goto error; |
| 4317 | } |
| 4318 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4319 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4320 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4321 | if (r) { |
| 4322 | goto error; |
| 4323 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4324 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4325 | 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] | 4326 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4327 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4328 | goto error; |
| 4329 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4330 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4331 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4332 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4333 | /* check XPath dependencies */ |
| 4334 | if ((anyxml->when || anyxml->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4335 | goto error; |
| 4336 | } |
| 4337 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4338 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4339 | |
| 4340 | error: |
| 4341 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4342 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4343 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4344 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4345 | } |
| 4346 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4347 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4348 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4349 | 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] | 4350 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4351 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4352 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4353 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4354 | struct lyxml_elem *sub, *next; |
| 4355 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4356 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4357 | 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] | 4358 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4359 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4360 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4361 | if (!leaf) { |
| 4362 | LOGMEM; |
| 4363 | return NULL; |
| 4364 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4365 | leaf->nodetype = LYS_LEAF; |
| 4366 | leaf->prev = (struct lys_node *)leaf; |
| 4367 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4368 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4369 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4370 | 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] | 4371 | goto error; |
| 4372 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4373 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4374 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4375 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4376 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4377 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4378 | goto error; |
| 4379 | } |
| 4380 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4381 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4382 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4383 | /* extension */ |
| 4384 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4385 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4386 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4387 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4388 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4389 | goto error; |
| 4390 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4391 | /* HACK for unres */ |
| 4392 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4393 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4394 | /* postpone type resolution when if-feature parsing is done since we need |
| 4395 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4396 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4397 | } else if (!strcmp(sub->name, "default")) { |
| 4398 | if (leaf->dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4399 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4400 | goto error; |
| 4401 | } |
| 4402 | GETVAL(value, sub, "value"); |
| 4403 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4404 | |
| 4405 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
| 4406 | goto error; |
| 4407 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4408 | } else if (!strcmp(sub->name, "units")) { |
| 4409 | if (leaf->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4410 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4411 | goto error; |
| 4412 | } |
| 4413 | GETVAL(value, sub, "name"); |
| 4414 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4415 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4416 | if (read_yin_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] | 4417 | goto error; |
| 4418 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4419 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4420 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4421 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4422 | goto error; |
| 4423 | } |
| 4424 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4425 | * multiple mandatory statements with the "false" value |
| 4426 | */ |
| 4427 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4428 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4429 | GETVAL(value, sub, "value"); |
| 4430 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4431 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4432 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4433 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4434 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4435 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4436 | goto error; |
| 4437 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4438 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4439 | if (read_yin_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] | 4440 | goto error; |
| 4441 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4442 | } else if (!strcmp(sub->name, "when")) { |
| 4443 | if (leaf->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4444 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4445 | goto error; |
| 4446 | } |
| 4447 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4448 | leaf->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4449 | if (!leaf->when) { |
| 4450 | goto error; |
| 4451 | } |
| 4452 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4453 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4454 | c_must++; |
| 4455 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4456 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4457 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4458 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4459 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4460 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4461 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4462 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4463 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4464 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4465 | /* 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] | 4466 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4467 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4468 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4469 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4470 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4471 | goto error; |
| 4472 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4473 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4474 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4475 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4476 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 4477 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4478 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4480 | /* middle part - process nodes with cardinality of 0..n */ |
| 4481 | if (c_must) { |
| 4482 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4483 | if (!leaf->must) { |
| 4484 | LOGMEM; |
| 4485 | goto error; |
| 4486 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4487 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4488 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4489 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
| 4490 | if (!leaf->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4491 | LOGMEM; |
| 4492 | goto error; |
| 4493 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4494 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4495 | if (c_ext) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4496 | /* some extensions may be already present from the substatements */ |
| 4497 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4498 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4499 | LOGMEM; |
| 4500 | goto error; |
| 4501 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4502 | retval->ext = reallocated; |
| 4503 | |
| 4504 | /* init memory */ |
| 4505 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4506 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4507 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4508 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4509 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4510 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4511 | 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] | 4512 | retval->ext_size++; |
| 4513 | if (r) { |
| 4514 | goto error; |
| 4515 | } |
| 4516 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4517 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4518 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4519 | if (r) { |
| 4520 | goto error; |
| 4521 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4522 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4523 | 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] | 4524 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4525 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4526 | goto error; |
| 4527 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4528 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4529 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4530 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4531 | /* finalize type parsing */ |
| 4532 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
| 4533 | leaf->type.der = NULL; |
| 4534 | goto error; |
| 4535 | } |
| 4536 | |
| 4537 | /* check default value (if not defined, there still could be some restrictions |
| 4538 | * 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] | 4539 | 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] | 4540 | goto error; |
| 4541 | } |
| 4542 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4543 | /* check XPath dependencies */ |
| 4544 | if ((leaf->when || leaf->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4545 | goto error; |
| 4546 | } |
| 4547 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4548 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4549 | |
| 4550 | error: |
| 4551 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4552 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4553 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4554 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4555 | } |
| 4556 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4557 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4558 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4559 | 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] | 4560 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4561 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4562 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4563 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4564 | struct lyxml_elem *sub, *next; |
| 4565 | const char *value; |
| 4566 | char *endptr; |
| 4567 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4568 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4569 | 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] | 4570 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4571 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4572 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4573 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4574 | if (!llist) { |
| 4575 | LOGMEM; |
| 4576 | return NULL; |
| 4577 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4578 | llist->nodetype = LYS_LEAFLIST; |
| 4579 | llist->prev = (struct lys_node *)llist; |
| 4580 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4581 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4582 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4583 | 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] | 4584 | goto error; |
| 4585 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4586 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4587 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4588 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4589 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4590 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4591 | goto error; |
| 4592 | } |
| 4593 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4594 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4595 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4596 | /* extension */ |
| 4597 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4598 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4599 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4600 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4601 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4602 | goto error; |
| 4603 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4604 | /* HACK for unres */ |
| 4605 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4606 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4607 | /* postpone type resolution when if-feature parsing is done since we need |
| 4608 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4609 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4610 | } else if (!strcmp(sub->name, "units")) { |
| 4611 | if (llist->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4612 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4613 | goto error; |
| 4614 | } |
| 4615 | GETVAL(value, sub, "name"); |
| 4616 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4617 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4618 | if (read_yin_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] | 4619 | goto error; |
| 4620 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4621 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4622 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4623 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4624 | goto error; |
| 4625 | } |
| 4626 | /* just checking the flags in llist is not sufficient, we would |
| 4627 | * allow multiple ordered-by statements with the "system" value |
| 4628 | */ |
| 4629 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4630 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4631 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4632 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4633 | * state data |
| 4634 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4635 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4636 | continue; |
| 4637 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4638 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4639 | GETVAL(value, sub, "value"); |
| 4640 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4641 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4643 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4644 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4645 | } /* else system is the default value, so we can ignore it */ |
| 4646 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4647 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
| 4648 | goto error; |
| 4649 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4650 | } else if (!strcmp(sub->name, "must")) { |
| 4651 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4652 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4653 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4654 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4655 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4656 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4657 | /* read the default's extension instances */ |
| 4658 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
| 4659 | goto error; |
| 4660 | } |
| 4661 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4662 | c_dflt++; |
| 4663 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4664 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4665 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4666 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4667 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4668 | goto error; |
| 4669 | } |
| 4670 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4671 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4672 | GETVAL(value, sub, "value"); |
| 4673 | while (isspace(value[0])) { |
| 4674 | value++; |
| 4675 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4676 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4677 | /* convert it to uint32_t */ |
| 4678 | errno = 0; |
| 4679 | endptr = NULL; |
| 4680 | val = strtoul(value, &endptr, 10); |
| 4681 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4682 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4683 | goto error; |
| 4684 | } |
| 4685 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4686 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4687 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4688 | 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] | 4689 | goto error; |
| 4690 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4691 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4692 | if (read_yin_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] | 4693 | goto error; |
| 4694 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4695 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4696 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4697 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4698 | goto error; |
| 4699 | } |
| 4700 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4702 | GETVAL(value, sub, "value"); |
| 4703 | while (isspace(value[0])) { |
| 4704 | value++; |
| 4705 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4706 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4707 | if (!strcmp(value, "unbounded")) { |
| 4708 | llist->max = 0; |
| 4709 | } else { |
| 4710 | /* convert it to uint32_t */ |
| 4711 | errno = 0; |
| 4712 | endptr = NULL; |
| 4713 | val = strtoul(value, &endptr, 10); |
| 4714 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4715 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4716 | goto error; |
| 4717 | } |
| 4718 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4719 | if (llist->min > llist->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4720 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4721 | 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] | 4722 | goto error; |
| 4723 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4724 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4725 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4726 | if (read_yin_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] | 4727 | goto error; |
| 4728 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4729 | } else if (!strcmp(sub->name, "when")) { |
| 4730 | if (llist->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4731 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4732 | goto error; |
| 4733 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4734 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4735 | llist->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4736 | if (!llist->when) { |
| 4737 | goto error; |
| 4738 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4739 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4740 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4741 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4742 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4743 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4744 | /* 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] | 4745 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4746 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4747 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4748 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4749 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4750 | goto error; |
| 4751 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4752 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4753 | /* middle part - process nodes with cardinality of 0..n */ |
| 4754 | if (c_must) { |
| 4755 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4756 | if (!llist->must) { |
| 4757 | LOGMEM; |
| 4758 | goto error; |
| 4759 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4760 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4761 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4762 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
| 4763 | if (!llist->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4764 | LOGMEM; |
| 4765 | goto error; |
| 4766 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4767 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4768 | if (c_dflt) { |
| 4769 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
| 4770 | if (!llist->dflt) { |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4771 | LOGMEM; |
| 4772 | goto error; |
| 4773 | } |
| 4774 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4775 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4776 | /* some extensions may be already present from the substatements */ |
| 4777 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4778 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4779 | LOGMEM; |
| 4780 | goto error; |
| 4781 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4782 | retval->ext = reallocated; |
| 4783 | |
| 4784 | /* init memory */ |
| 4785 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4786 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4787 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4788 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4789 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4790 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4791 | 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] | 4792 | retval->ext_size++; |
| 4793 | if (r) { |
| 4794 | goto error; |
| 4795 | } |
| 4796 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4797 | r = fill_yin_must(module, sub, &llist->must[llist->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4798 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4799 | if (r) { |
| 4800 | goto error; |
| 4801 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4802 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4803 | 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] | 4804 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4805 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4806 | goto error; |
| 4807 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4808 | } else if (!strcmp(sub->name, "default")) { |
| 4809 | GETVAL(value, sub, "value"); |
| 4810 | |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4811 | /* check for duplicity in case of configuration data, |
| 4812 | * in case of status data duplicities are allowed */ |
| 4813 | if (llist->flags & LYS_CONFIG_W) { |
| 4814 | for (r = 0; r < llist->dflt_size; r++) { |
| 4815 | if (ly_strequal(llist->dflt[r], value, 1)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4816 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, "default"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4817 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4818 | goto error; |
| 4819 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4820 | } |
| 4821 | } |
| 4822 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4823 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4824 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4825 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4826 | /* finalize type parsing */ |
| 4827 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
| 4828 | llist->type.der = NULL; |
| 4829 | goto error; |
| 4830 | } |
| 4831 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4832 | if (llist->dflt_size && llist->min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4833 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4834 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4835 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 4836 | goto error; |
| 4837 | } |
| 4838 | |
| 4839 | /* check default value (if not defined, there still could be some restrictions |
| 4840 | * that need to be checked against a default value from a derived type) */ |
| 4841 | for (r = 0; r < llist->dflt_size; r++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 4842 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 4843 | (struct lys_node *)(&llist->dflt[r])) == -1) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4844 | goto error; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4845 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4846 | } |
| 4847 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4848 | /* check XPath dependencies */ |
| 4849 | if ((llist->when || llist->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4850 | goto error; |
| 4851 | } |
| 4852 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4853 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4854 | |
| 4855 | error: |
| 4856 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4857 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4858 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4859 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4860 | } |
| 4861 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4862 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4863 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4864 | 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] | 4865 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4866 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4867 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4868 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4869 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4870 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4871 | 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] | 4872 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4873 | const char *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4874 | char *auxs; |
| 4875 | unsigned long val; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4876 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4877 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4878 | /* init */ |
| 4879 | memset(&root, 0, sizeof root); |
| 4880 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4881 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4882 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4883 | if (!list) { |
| 4884 | LOGMEM; |
| 4885 | return NULL; |
| 4886 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4887 | list->nodetype = LYS_LIST; |
| 4888 | list->prev = (struct lys_node *)list; |
| 4889 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4890 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4891 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 4892 | 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] | 4893 | goto error; |
| 4894 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4895 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4896 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4897 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4898 | /* insert the node into the schema tree */ |
| 4899 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4900 | goto error; |
| 4901 | } |
| 4902 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4903 | /* process list's specific children */ |
| 4904 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4905 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4906 | /* extension */ |
| 4907 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4908 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4909 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4910 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4911 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4912 | !strcmp(sub->name, "leaf-list") || |
| 4913 | !strcmp(sub->name, "leaf") || |
| 4914 | !strcmp(sub->name, "list") || |
| 4915 | !strcmp(sub->name, "choice") || |
| 4916 | !strcmp(sub->name, "uses") || |
| 4917 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4918 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4919 | !strcmp(sub->name, "action") || |
| 4920 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4921 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4922 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4923 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4924 | /* array counters */ |
| 4925 | } else if (!strcmp(sub->name, "key")) { |
| 4926 | /* check cardinality 0..1 */ |
| 4927 | if (list->keys_size) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4928 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4929 | goto error; |
| 4930 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4931 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4932 | /* count the number of keys */ |
| 4933 | GETVAL(value, sub, "value"); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4934 | list->keys_str = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4935 | while ((value = strpbrk(value, " \t\n"))) { |
| 4936 | list->keys_size++; |
| 4937 | while (isspace(*value)) { |
| 4938 | value++; |
| 4939 | } |
| 4940 | } |
| 4941 | list->keys_size++; |
| 4942 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4943 | if (!list->keys) { |
| 4944 | LOGMEM; |
| 4945 | goto error; |
| 4946 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4947 | |
| 4948 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_KEY, 0, unres)) { |
| 4949 | goto error; |
| 4950 | } |
| 4951 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4952 | } else if (!strcmp(sub->name, "unique")) { |
| 4953 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4954 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4955 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4956 | } else if (!strcmp(sub->name, "typedef")) { |
| 4957 | c_tpdf++; |
| 4958 | } else if (!strcmp(sub->name, "must")) { |
| 4959 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4960 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4961 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4963 | /* optional stetments */ |
| 4964 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4965 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4966 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4967 | goto error; |
| 4968 | } |
| 4969 | /* just checking the flags in llist is not sufficient, we would |
| 4970 | * allow multiple ordered-by statements with the "system" value |
| 4971 | */ |
| 4972 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4973 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4974 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4975 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4976 | * state data |
| 4977 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4978 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4979 | continue; |
| 4980 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4981 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4982 | GETVAL(value, sub, "value"); |
| 4983 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4984 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4985 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4986 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4987 | goto error; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4988 | } /* else system is the default value, so we can ignore it */ |
| 4989 | |
| 4990 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
| 4991 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4992 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4993 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4994 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4995 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4996 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4997 | goto error; |
| 4998 | } |
| 4999 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5000 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5001 | GETVAL(value, sub, "value"); |
| 5002 | while (isspace(value[0])) { |
| 5003 | value++; |
| 5004 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5005 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5006 | /* convert it to uint32_t */ |
| 5007 | errno = 0; |
| 5008 | auxs = NULL; |
| 5009 | val = strtoul(value, &auxs, 10); |
| 5010 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5011 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5012 | goto error; |
| 5013 | } |
| 5014 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5015 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5016 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5017 | 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] | 5018 | lyxml_free(module->ctx, sub); |
| 5019 | goto error; |
| 5020 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5021 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
| 5022 | goto error; |
| 5023 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5024 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5025 | } else if (!strcmp(sub->name, "max-elements")) { |
| 5026 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5027 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5028 | goto error; |
| 5029 | } |
| 5030 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5031 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5032 | GETVAL(value, sub, "value"); |
| 5033 | while (isspace(value[0])) { |
| 5034 | value++; |
| 5035 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5036 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5037 | if (!strcmp(value, "unbounded")) { |
| 5038 | list->max = 0;; |
| 5039 | } else { |
| 5040 | /* convert it to uint32_t */ |
| 5041 | errno = 0; |
| 5042 | auxs = NULL; |
| 5043 | val = strtoul(value, &auxs, 10); |
| 5044 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5045 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5046 | goto error; |
| 5047 | } |
| 5048 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5049 | if (list->min > list->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5050 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5051 | 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] | 5052 | goto error; |
| 5053 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5054 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5055 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
| 5056 | goto error; |
| 5057 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5058 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5059 | } else if (!strcmp(sub->name, "when")) { |
| 5060 | if (list->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5061 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5062 | goto error; |
| 5063 | } |
| 5064 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5065 | list->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5066 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5067 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5068 | goto error; |
| 5069 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5070 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5071 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5072 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5073 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5074 | } |
| 5075 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5076 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5077 | /* check - if list is configuration, key statement is mandatory |
| 5078 | * (but only if we are not in a grouping or augment, then the check is deferred) */ |
| 5079 | 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] | 5080 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys_str) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5081 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5082 | goto error; |
| 5083 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5084 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5085 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5086 | if (c_tpdf) { |
| 5087 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5088 | if (!list->tpdf) { |
| 5089 | LOGMEM; |
| 5090 | goto error; |
| 5091 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5092 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5093 | if (c_must) { |
| 5094 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5095 | if (!list->must) { |
| 5096 | LOGMEM; |
| 5097 | goto error; |
| 5098 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5099 | } |
| 5100 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5101 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
| 5102 | if (!list->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5103 | LOGMEM; |
| 5104 | goto error; |
| 5105 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5106 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5107 | if (c_ext) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5108 | /* some extensions may be already present from the substatements */ |
| 5109 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5110 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5111 | LOGMEM; |
| 5112 | goto error; |
| 5113 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5114 | retval->ext = reallocated; |
| 5115 | |
| 5116 | /* init memory */ |
| 5117 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5118 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5119 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5120 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5121 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5122 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5123 | 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] | 5124 | retval->ext_size++; |
| 5125 | if (r) { |
| 5126 | goto error; |
| 5127 | } |
| 5128 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5129 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 5130 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5131 | if (r) { |
| 5132 | goto error; |
| 5133 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5134 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5135 | 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] | 5136 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5137 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5138 | goto error; |
| 5139 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5140 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5141 | r = fill_yin_must(module, sub, &list->must[list->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5142 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5143 | if (r) { |
| 5144 | goto error; |
| 5145 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5146 | } |
| 5147 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5148 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5149 | /* last part - process data nodes */ |
| 5150 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5151 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5152 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5153 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5154 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5155 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5156 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5157 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5158 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5159 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5160 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5161 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5162 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5163 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5164 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5165 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5166 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5167 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5168 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5169 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5170 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5171 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5172 | node = read_yin_notif(module, retval, sub, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5173 | } else { |
| 5174 | LOGINT; |
| 5175 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5176 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5177 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5178 | goto error; |
| 5179 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5180 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5181 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5182 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5183 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5184 | if (list->keys_str) { |
| 5185 | /* check that we are not in grouping */ |
| 5186 | for (node = parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node)); |
| 5187 | 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] | 5188 | goto error; |
| 5189 | } |
| 5190 | } /* 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] | 5191 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5192 | /* process unique statements */ |
| 5193 | if (c_uniq) { |
| 5194 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5195 | if (!list->unique) { |
| 5196 | LOGMEM; |
| 5197 | goto error; |
| 5198 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5199 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5200 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 5201 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 5202 | list->unique_size++; |
| 5203 | if (r) { |
| 5204 | goto error; |
| 5205 | } |
| 5206 | |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5207 | if (read_yin_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, |
| 5208 | LYEXT_SUBSTMT_UNIQUE, list->unique_size - 1, unres)) { |
| 5209 | goto error; |
| 5210 | } |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5211 | lyxml_free(module->ctx, sub); |
| 5212 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5213 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5214 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5215 | /* check XPath dependencies */ |
| 5216 | if ((list->when || list->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5217 | goto error; |
| 5218 | } |
| 5219 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5220 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5221 | |
| 5222 | error: |
| 5223 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5224 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5225 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5226 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5227 | } |
| 5228 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5229 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5230 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5231 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5232 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5233 | } |
| 5234 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5235 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5236 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5237 | 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] | 5238 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5239 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5240 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5241 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5242 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5243 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5244 | const char *value; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5245 | void *reallocated; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5246 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5247 | 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] | 5248 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5249 | /* init */ |
| 5250 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5251 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5252 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5253 | if (!cont) { |
| 5254 | LOGMEM; |
| 5255 | return NULL; |
| 5256 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5257 | cont->nodetype = LYS_CONTAINER; |
| 5258 | cont->prev = (struct lys_node *)cont; |
| 5259 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5260 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5261 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
| 5262 | 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] | 5263 | goto error; |
| 5264 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5265 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5266 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5267 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5268 | /* insert the node into the schema tree */ |
| 5269 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5270 | goto error; |
| 5271 | } |
| 5272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5273 | /* process container's specific children */ |
| 5274 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5275 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5276 | /* extension */ |
| 5277 | c_ext++; |
| 5278 | } else if (!strcmp(sub->name, "presence")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5279 | if (cont->presence) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5280 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5281 | goto error; |
| 5282 | } |
| 5283 | GETVAL(value, sub, "value"); |
| 5284 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5285 | |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 5286 | if (read_yin_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] | 5287 | goto error; |
| 5288 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5289 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5290 | } else if (!strcmp(sub->name, "when")) { |
| 5291 | if (cont->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5292 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5293 | goto error; |
| 5294 | } |
| 5295 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5296 | cont->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5297 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5298 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5299 | goto error; |
| 5300 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5301 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 5302 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5303 | /* data statements */ |
| 5304 | } else if (!strcmp(sub->name, "container") || |
| 5305 | !strcmp(sub->name, "leaf-list") || |
| 5306 | !strcmp(sub->name, "leaf") || |
| 5307 | !strcmp(sub->name, "list") || |
| 5308 | !strcmp(sub->name, "choice") || |
| 5309 | !strcmp(sub->name, "uses") || |
| 5310 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5311 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5312 | !strcmp(sub->name, "action") || |
| 5313 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5314 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5315 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5316 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5317 | /* array counters */ |
| 5318 | } else if (!strcmp(sub->name, "typedef")) { |
| 5319 | c_tpdf++; |
| 5320 | } else if (!strcmp(sub->name, "must")) { |
| 5321 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5322 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5323 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5324 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5325 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5326 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5327 | } |
| 5328 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5329 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5330 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5331 | if (c_tpdf) { |
| 5332 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5333 | if (!cont->tpdf) { |
| 5334 | LOGMEM; |
| 5335 | goto error; |
| 5336 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5337 | } |
| 5338 | if (c_must) { |
| 5339 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5340 | if (!cont->must) { |
| 5341 | LOGMEM; |
| 5342 | goto error; |
| 5343 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5344 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5345 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5346 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
| 5347 | if (!cont->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5348 | LOGMEM; |
| 5349 | goto error; |
| 5350 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5351 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5352 | if (c_ext) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5353 | /* some extensions may be already present from the substatements */ |
| 5354 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5355 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5356 | LOGMEM; |
| 5357 | goto error; |
| 5358 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5359 | retval->ext = reallocated; |
| 5360 | |
| 5361 | /* init memory */ |
| 5362 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5363 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5364 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5365 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5366 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5367 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5368 | 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] | 5369 | retval->ext_size++; |
| 5370 | if (r) { |
| 5371 | goto error; |
| 5372 | } |
| 5373 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5374 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 5375 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5376 | if (r) { |
| 5377 | goto error; |
| 5378 | } |
| 5379 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5380 | r = fill_yin_must(module, sub, &cont->must[cont->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5381 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5382 | if (r) { |
| 5383 | goto error; |
| 5384 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5385 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5386 | 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] | 5387 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5388 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5389 | goto error; |
| 5390 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5391 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5392 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5393 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5394 | /* last part - process data nodes */ |
| 5395 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5396 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5397 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5398 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5399 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5400 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5401 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5402 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5403 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5404 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5405 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5406 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5407 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5408 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5409 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5410 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5411 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5412 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5413 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5414 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5415 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5416 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5417 | node = read_yin_notif(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5418 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5419 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5420 | goto error; |
| 5421 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5422 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5423 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5424 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5425 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5426 | /* check XPath dependencies */ |
| 5427 | if ((cont->when || cont->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5428 | goto error; |
| 5429 | } |
| 5430 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5431 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5432 | |
| 5433 | error: |
| 5434 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5435 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5436 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5437 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5438 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5439 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5440 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5441 | } |
| 5442 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5443 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5444 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5445 | 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] | 5446 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5447 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5448 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5449 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5450 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5451 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5452 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5453 | int c_tpdf = 0, c_ext = 0; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5454 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5455 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5456 | /* init */ |
| 5457 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5458 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5459 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5460 | if (!grp) { |
| 5461 | LOGMEM; |
| 5462 | return NULL; |
| 5463 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5464 | grp->nodetype = LYS_GROUPING; |
| 5465 | grp->prev = (struct lys_node *)grp; |
| 5466 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5467 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5468 | 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] | 5469 | goto error; |
| 5470 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5471 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5472 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5473 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5474 | /* insert the node into the schema tree */ |
| 5475 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5476 | goto error; |
| 5477 | } |
| 5478 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5479 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5480 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5481 | /* extension */ |
| 5482 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5484 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5485 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5486 | !strcmp(sub->name, "leaf-list") || |
| 5487 | !strcmp(sub->name, "leaf") || |
| 5488 | !strcmp(sub->name, "list") || |
| 5489 | !strcmp(sub->name, "choice") || |
| 5490 | !strcmp(sub->name, "uses") || |
| 5491 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5492 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5493 | !strcmp(sub->name, "action") || |
| 5494 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5495 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5496 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5497 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5498 | /* array counters */ |
| 5499 | } else if (!strcmp(sub->name, "typedef")) { |
| 5500 | c_tpdf++; |
| 5501 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5502 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5503 | goto error; |
| 5504 | } |
| 5505 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5506 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5507 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5508 | if (c_tpdf) { |
| 5509 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5510 | if (!grp->tpdf) { |
| 5511 | LOGMEM; |
| 5512 | goto error; |
| 5513 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5514 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5515 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5516 | /* some extensions may be already present from the substatements */ |
| 5517 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5518 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5519 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5520 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5521 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5522 | retval->ext = reallocated; |
| 5523 | |
| 5524 | /* init memory */ |
| 5525 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5526 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5527 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5528 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5529 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5530 | 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] | 5531 | retval->ext_size++; |
| 5532 | if (r) { |
| 5533 | goto error; |
| 5534 | } |
| 5535 | } else { |
| 5536 | /* typedef */ |
| 5537 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 5538 | grp->tpdf_size++; |
| 5539 | if (r) { |
| 5540 | goto error; |
| 5541 | } |
| 5542 | } |
| 5543 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5544 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5545 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5546 | if (!root.child) { |
| 5547 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 5548 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5549 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5550 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5551 | node = read_yin_container(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5552 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5553 | node = read_yin_leaflist(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5554 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5555 | node = read_yin_leaf(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5556 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5557 | node = read_yin_list(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5558 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5559 | node = read_yin_choice(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5560 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5561 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5562 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5563 | node = read_yin_grouping(module, retval, sub, valid_config, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5564 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5565 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, valid_config, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5566 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5567 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, valid_config, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5568 | } else if (!strcmp(sub->name, "action")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5569 | node = read_yin_rpc_action(module, retval, sub, unres); |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5570 | } else if (!strcmp(sub->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5571 | node = read_yin_notif(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5572 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5573 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5574 | goto error; |
| 5575 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5576 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5577 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5578 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5579 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5580 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5581 | |
| 5582 | error: |
| 5583 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5584 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5585 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5586 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5587 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5588 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5589 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5590 | } |
| 5591 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5592 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5593 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5594 | 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] | 5595 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5596 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5597 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5598 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 5599 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5600 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5601 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5602 | int c_tpdf = 0, c_must = 0, c_ext = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5603 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5604 | /* init */ |
| 5605 | memset(&root, 0, sizeof root); |
| 5606 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5607 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5608 | if (!inout) { |
| 5609 | LOGMEM; |
| 5610 | return NULL; |
| 5611 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5612 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5613 | |
| 5614 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5615 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5616 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5617 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5618 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5619 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5620 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5621 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5622 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5623 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5624 | } |
| 5625 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5626 | retval = (struct lys_node *)inout; |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5627 | retval->module = module; |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 5628 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5629 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5630 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5631 | /* insert the node into the schema tree */ |
| 5632 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5633 | goto error; |
| 5634 | } |
| 5635 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5636 | /* data statements */ |
| 5637 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5638 | if (!sub->ns) { |
| 5639 | /* garbage */ |
| 5640 | lyxml_free(module->ctx, sub); |
| 5641 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5642 | /* extension */ |
| 5643 | c_ext++; |
| 5644 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5645 | !strcmp(sub->name, "leaf-list") || |
| 5646 | !strcmp(sub->name, "leaf") || |
| 5647 | !strcmp(sub->name, "list") || |
| 5648 | !strcmp(sub->name, "choice") || |
| 5649 | !strcmp(sub->name, "uses") || |
| 5650 | !strcmp(sub->name, "grouping") || |
| 5651 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5652 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5653 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5654 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5655 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5656 | } else if (!strcmp(sub->name, "typedef")) { |
| 5657 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 5658 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5659 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5660 | c_must++; |
| 5661 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5662 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5663 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5664 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5665 | } |
| 5666 | } |
| 5667 | |
| 5668 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5669 | if (c_tpdf) { |
| 5670 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5671 | if (!inout->tpdf) { |
| 5672 | LOGMEM; |
| 5673 | goto error; |
| 5674 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5675 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5676 | if (c_must) { |
| 5677 | inout->must = calloc(c_must, sizeof *inout->must); |
| 5678 | if (!inout->must) { |
| 5679 | LOGMEM; |
| 5680 | goto error; |
| 5681 | } |
| 5682 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5683 | if (c_ext) { |
| 5684 | inout->ext = calloc(c_ext, sizeof *inout->ext); |
| 5685 | if (!inout->ext) { |
| 5686 | LOGMEM; |
| 5687 | goto error; |
| 5688 | } |
| 5689 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5690 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5691 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5692 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5693 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5694 | 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] | 5695 | retval->ext_size++; |
| 5696 | if (r) { |
| 5697 | goto error; |
| 5698 | } |
| 5699 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5700 | r = fill_yin_must(module, sub, &inout->must[inout->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5701 | inout->must_size++; |
| 5702 | if (r) { |
| 5703 | goto error; |
| 5704 | } |
| 5705 | } else { /* typedef */ |
| 5706 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 5707 | inout->tpdf_size++; |
| 5708 | if (r) { |
| 5709 | goto error; |
| 5710 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5711 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | /* last part - process data nodes */ |
| 5715 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5716 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5717 | node = read_yin_container(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5718 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5719 | node = read_yin_leaflist(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5720 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5721 | node = read_yin_leaf(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5722 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5723 | node = read_yin_list(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5724 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5725 | node = read_yin_choice(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5726 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5727 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5728 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5729 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5730 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5731 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5732 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5733 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, 0, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5734 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5735 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5736 | goto error; |
| 5737 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5738 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5739 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5740 | } |
| 5741 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5742 | /* check XPath dependencies */ |
| 5743 | if (inout->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5744 | goto error; |
| 5745 | } |
| 5746 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5747 | return retval; |
| 5748 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5749 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5750 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5751 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 5752 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5753 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | return NULL; |
| 5757 | } |
| 5758 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5759 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5760 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5761 | 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] | 5762 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5763 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5764 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5765 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5766 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5767 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5768 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5769 | 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] | 5770 | void *reallocated; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5771 | |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5772 | if (parent && (module->version < 2)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5773 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "notification"); |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5774 | return NULL; |
| 5775 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5776 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5777 | memset(&root, 0, sizeof root); |
| 5778 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5779 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5780 | if (!notif) { |
| 5781 | LOGMEM; |
| 5782 | return NULL; |
| 5783 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5784 | notif->nodetype = LYS_NOTIF; |
| 5785 | notif->prev = (struct lys_node *)notif; |
| 5786 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5787 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5788 | 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] | 5789 | goto error; |
| 5790 | } |
| 5791 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5792 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5793 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5794 | /* insert the node into the schema tree */ |
| 5795 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5796 | goto error; |
| 5797 | } |
| 5798 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5799 | /* process rpc's specific children */ |
| 5800 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5801 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5802 | /* extension */ |
| 5803 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5804 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5805 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5806 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5807 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5808 | !strcmp(sub->name, "leaf-list") || |
| 5809 | !strcmp(sub->name, "leaf") || |
| 5810 | !strcmp(sub->name, "list") || |
| 5811 | !strcmp(sub->name, "choice") || |
| 5812 | !strcmp(sub->name, "uses") || |
| 5813 | !strcmp(sub->name, "grouping") || |
| 5814 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5815 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5816 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5817 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5818 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5819 | } else if (!strcmp(sub->name, "typedef")) { |
| 5820 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5821 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5822 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5823 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5824 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5825 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5826 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5827 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5832 | if (c_tpdf) { |
| 5833 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5834 | if (!notif->tpdf) { |
| 5835 | LOGMEM; |
| 5836 | goto error; |
| 5837 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5838 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5839 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5840 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
| 5841 | if (!notif->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5842 | LOGMEM; |
| 5843 | goto error; |
| 5844 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5845 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5846 | if (c_must) { |
| 5847 | notif->must = calloc(c_must, sizeof *notif->must); |
| 5848 | if (!notif->must) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5849 | LOGMEM; |
| 5850 | goto error; |
| 5851 | } |
| 5852 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5853 | if (c_ext) { |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5854 | /* some extensions may be already present from the substatements */ |
| 5855 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5856 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5857 | LOGMEM; |
| 5858 | goto error; |
| 5859 | } |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5860 | retval->ext = reallocated; |
| 5861 | |
| 5862 | /* init memory */ |
| 5863 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5864 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5865 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5866 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5867 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5868 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5869 | 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] | 5870 | retval->ext_size++; |
| 5871 | if (r) { |
| 5872 | goto error; |
| 5873 | } |
| 5874 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5875 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 5876 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5877 | if (r) { |
| 5878 | goto error; |
| 5879 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 5880 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5881 | 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] | 5882 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5883 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5884 | goto error; |
| 5885 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5886 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5887 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5888 | notif->must_size++; |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 5889 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5890 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5891 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5892 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | /* last part - process data nodes */ |
| 5896 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5897 | if (!strcmp(sub->name, "container")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5898 | node = read_yin_container(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5899 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5900 | node = read_yin_leaflist(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5901 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5902 | node = read_yin_leaf(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5903 | } else if (!strcmp(sub->name, "list")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5904 | node = read_yin_list(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5905 | } else if (!strcmp(sub->name, "choice")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5906 | node = read_yin_choice(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5907 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5908 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5909 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5910 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5911 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5912 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5913 | } else if (!strcmp(sub->name, "anydata")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5914 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, 0, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5915 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5916 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5917 | goto error; |
| 5918 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5919 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5920 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5921 | } |
| 5922 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5923 | /* check XPath dependencies */ |
| 5924 | if (notif->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5925 | goto error; |
| 5926 | } |
| 5927 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5928 | return retval; |
| 5929 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5930 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5931 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5932 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5933 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5934 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | return NULL; |
| 5938 | } |
| 5939 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5940 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5941 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5942 | 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] | 5943 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5944 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5945 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5946 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5947 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5948 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5949 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5950 | 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] | 5951 | void *reallocated; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5952 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5953 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5954 | if (module->version < 2) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5955 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "action"); |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 5956 | return NULL; |
| 5957 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5958 | for (node = parent; node; node = lys_parent(node)) { |
Radek Krejci | a3b19f7 | 2016-09-30 13:02:45 +0200 | [diff] [blame] | 5959 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5960 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5961 | LOGVAL(LYE_INPAR, LY_VLOG_LYS, parent, strnodetype(node->nodetype), "action"); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5962 | return NULL; |
| 5963 | } |
| 5964 | } |
| 5965 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5966 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5967 | /* init */ |
| 5968 | memset(&root, 0, sizeof root); |
| 5969 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5970 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5971 | if (!rpc) { |
| 5972 | LOGMEM; |
| 5973 | return NULL; |
| 5974 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5975 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5976 | rpc->prev = (struct lys_node *)rpc; |
| 5977 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5978 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5979 | 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] | 5980 | goto error; |
| 5981 | } |
| 5982 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5983 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5984 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5985 | /* insert the node into the schema tree */ |
| 5986 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5987 | goto error; |
| 5988 | } |
| 5989 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5990 | /* process rpc's specific children */ |
| 5991 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5992 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5993 | /* extension */ |
| 5994 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5995 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5996 | } else if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 5997 | if (c_input) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5998 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5999 | goto error; |
| 6000 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6001 | c_input++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6002 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6003 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6004 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6005 | if (c_output) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6006 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6007 | goto error; |
| 6008 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6009 | c_output++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6010 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6011 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6012 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6013 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6014 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6015 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6016 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6017 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6018 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6019 | } else if (!strcmp(sub->name, "typedef")) { |
| 6020 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6021 | } else if (!strcmp(sub->name, "if-feature")) { |
| 6022 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6023 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6024 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6025 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6026 | } |
| 6027 | } |
| 6028 | |
| 6029 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6030 | if (c_tpdf) { |
| 6031 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6032 | if (!rpc->tpdf) { |
| 6033 | LOGMEM; |
| 6034 | goto error; |
| 6035 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6036 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6037 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6038 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
| 6039 | if (!rpc->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6040 | LOGMEM; |
| 6041 | goto error; |
| 6042 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6043 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6044 | if (c_ext) { |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6045 | /* some extensions may be already present from the substatements */ |
| 6046 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6047 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6048 | LOGMEM; |
| 6049 | goto error; |
| 6050 | } |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6051 | retval->ext = reallocated; |
| 6052 | |
| 6053 | /* init memory */ |
| 6054 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6055 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6056 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6057 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6058 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6059 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6060 | 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] | 6061 | retval->ext_size++; |
| 6062 | if (r) { |
| 6063 | goto error; |
| 6064 | } |
| 6065 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6066 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 6067 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6068 | if (r) { |
| 6069 | goto error; |
| 6070 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6071 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6072 | 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] | 6073 | rpc->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6074 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6075 | goto error; |
| 6076 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6077 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | /* last part - process data nodes */ |
| 6081 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6082 | if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6083 | node = read_yin_grouping(module, retval, sub, 0, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6084 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6085 | node = read_yin_input_output(module, retval, sub, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6086 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6087 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6088 | goto error; |
| 6089 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6090 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6091 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6092 | } |
| 6093 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6094 | return retval; |
| 6095 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6096 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6097 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6098 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6099 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6100 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | return NULL; |
| 6104 | } |
| 6105 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6106 | /* logs directly |
| 6107 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6108 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 6109 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 6110 | * we just get information but we do not apply augment or refine to it. |
| 6111 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6112 | static struct lys_node * |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 6113 | 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] | 6114 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6115 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6116 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6117 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6118 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6119 | 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] | 6120 | int r; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6121 | void *reallocated; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6122 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6123 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6124 | if (!uses) { |
| 6125 | LOGMEM; |
| 6126 | return NULL; |
| 6127 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6128 | uses->nodetype = LYS_USES; |
| 6129 | uses->prev = (struct lys_node *)uses; |
| 6130 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6131 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6132 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6133 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 6134 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6135 | 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] | 6136 | goto error; |
| 6137 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6138 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6139 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 6140 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6141 | /* insert the node into the schema tree */ |
| 6142 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6143 | goto error; |
| 6144 | } |
| 6145 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6146 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6147 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6148 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6149 | /* extension */ |
| 6150 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6151 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6152 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6153 | c_ref++; |
| 6154 | } else if (!strcmp(sub->name, "augment")) { |
| 6155 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6156 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 6157 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6158 | } else if (!strcmp(sub->name, "when")) { |
| 6159 | if (uses->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6160 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6161 | goto error; |
| 6162 | } |
| 6163 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 6164 | uses->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6165 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6166 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6167 | goto error; |
| 6168 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6169 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6170 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6171 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6172 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6173 | } |
| 6174 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6175 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6176 | /* process properties with cardinality 0..n */ |
| 6177 | if (c_ref) { |
| 6178 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6179 | if (!uses->refine) { |
| 6180 | LOGMEM; |
| 6181 | goto error; |
| 6182 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6183 | } |
| 6184 | if (c_aug) { |
| 6185 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6186 | if (!uses->augment) { |
| 6187 | LOGMEM; |
| 6188 | goto error; |
| 6189 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6190 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6191 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6192 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
| 6193 | if (!uses->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6194 | LOGMEM; |
| 6195 | goto error; |
| 6196 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6197 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6198 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6199 | /* some extensions may be already present from the substatements */ |
| 6200 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6201 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6202 | LOGMEM; |
| 6203 | goto error; |
| 6204 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6205 | retval->ext = reallocated; |
| 6206 | |
| 6207 | /* init memory */ |
| 6208 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6209 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6210 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6211 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6212 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6213 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6214 | 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] | 6215 | retval->ext_size++; |
| 6216 | if (r) { |
| 6217 | goto error; |
| 6218 | } |
| 6219 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 6220 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6221 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6222 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6223 | goto error; |
| 6224 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6225 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6226 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 6227 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6228 | if (r) { |
| 6229 | goto error; |
| 6230 | } |
| 6231 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6232 | 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] | 6233 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6234 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6235 | goto error; |
| 6236 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6237 | } |
| 6238 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6239 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6240 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6241 | goto error; |
| 6242 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6243 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6244 | /* check XPath dependencies */ |
| 6245 | if (uses->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 6246 | goto error; |
| 6247 | } |
| 6248 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6249 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6250 | |
| 6251 | error: |
| 6252 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6253 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6254 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6255 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6256 | } |
| 6257 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6258 | /* logs directly |
| 6259 | * |
| 6260 | * common code for yin_read_module() and yin_read_submodule() |
| 6261 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6262 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6263 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 6264 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6265 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6266 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6267 | struct lyxml_elem *next, *child, *next2, *child2, root, grps, augs, exts; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6268 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6269 | struct lys_module *trg; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6270 | const char *value; |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 6271 | int i, r; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6272 | int version_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6273 | /* counters */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6274 | 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; |
| 6275 | int c_ext = 0, c_extinst = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6276 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6277 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6278 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 6279 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6280 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6281 | /* init */ |
| 6282 | memset(&root, 0, sizeof root); |
| 6283 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6284 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6285 | memset(&exts, 0, sizeof exts); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6286 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6287 | /* |
| 6288 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 6289 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 6290 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 6291 | * need have all top-level and groupings already prepared at that time. In |
| 6292 | * the middle loop, we process other elements with carinality of 0..n since |
| 6293 | * we need to allocate arrays to store them. |
| 6294 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6295 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6296 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6297 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6298 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6299 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6300 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 6301 | /* possible extension instance */ |
| 6302 | lyxml_unlink_elem(module->ctx, child, 2); |
| 6303 | lyxml_add_child(module->ctx, &exts, child); |
| 6304 | c_extinst++; |
| 6305 | } else if (!submodule && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6306 | if (module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6307 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6308 | goto error; |
| 6309 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6310 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6311 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6312 | |
| 6313 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_NAMESPACE, 0, unres)) { |
| 6314 | goto error; |
| 6315 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6316 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6317 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6318 | if (module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6319 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6320 | goto error; |
| 6321 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6322 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6323 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6324 | goto error; |
| 6325 | } |
| 6326 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6327 | |
| 6328 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
| 6329 | goto error; |
| 6330 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6331 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6332 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
| 6333 | if (submodule->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6334 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6335 | goto error; |
| 6336 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6337 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 6338 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6339 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6340 | goto error; |
| 6341 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 6342 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6343 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_BELONGSTO, 0, unres)) { |
| 6344 | goto error; |
| 6345 | } |
| 6346 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6347 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6348 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6349 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6350 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6351 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6352 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6353 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6354 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6355 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6356 | goto error; |
| 6357 | } |
| 6358 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6359 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6360 | /* check here differs from a generic prefix check, since this prefix |
| 6361 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6362 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6363 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6364 | goto error; |
| 6365 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6366 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 6367 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6368 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child->child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
| 6369 | goto error; |
| 6370 | } |
| 6371 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6372 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6373 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6374 | |
| 6375 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6376 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6377 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6378 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6379 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6380 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6381 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6382 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6383 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6384 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6385 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6386 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6387 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6388 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6389 | lyxml_unlink_elem(ctx, child, 2); |
| 6390 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6391 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6392 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6393 | c_ftrs++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6395 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6396 | } else if (!strcmp(child->name, "container") || |
| 6397 | !strcmp(child->name, "leaf-list") || |
| 6398 | !strcmp(child->name, "leaf") || |
| 6399 | !strcmp(child->name, "list") || |
| 6400 | !strcmp(child->name, "choice") || |
| 6401 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6402 | !strcmp(child->name, "anyxml") || |
| 6403 | !strcmp(child->name, "rpc") || |
| 6404 | !strcmp(child->name, "notification")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6405 | lyxml_unlink_elem(ctx, child, 2); |
| 6406 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6407 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6408 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6409 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6410 | lyxml_unlink_elem(ctx, child, 2); |
| 6411 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6412 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6413 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6414 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6415 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6416 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6417 | goto error; |
| 6418 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6419 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 6420 | goto error; |
| 6421 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6422 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6423 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6424 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6425 | goto error; |
| 6426 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6427 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6428 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6429 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6430 | goto error; |
| 6431 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6432 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 6433 | goto error; |
| 6434 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6435 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6436 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6437 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6438 | goto error; |
| 6439 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6440 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6441 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6442 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6443 | goto error; |
| 6444 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6445 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_ORGANIZATION, 0, unres)) { |
| 6446 | goto error; |
| 6447 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6448 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6449 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6450 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6451 | goto error; |
| 6452 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6453 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6454 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6455 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6456 | goto error; |
| 6457 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6458 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_CONTACT, 0, unres)) { |
| 6459 | goto error; |
| 6460 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6461 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6462 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6463 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6464 | goto error; |
| 6465 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6466 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6467 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6468 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6469 | goto error; |
| 6470 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6471 | GETVAL(value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6472 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6473 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6474 | goto error; |
| 6475 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6476 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6477 | if (!strcmp(value, "1")) { |
| 6478 | if (submodule) { |
| 6479 | if (module->version > 1) { |
| 6480 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6481 | goto error; |
| 6482 | } |
| 6483 | } else { |
| 6484 | module->version = 1; |
| 6485 | } |
| 6486 | } else { |
| 6487 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6488 | if (module->version < 2) { |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6489 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6490 | goto error; |
| 6491 | } |
| 6492 | } else { |
| 6493 | module->version = 2; |
| 6494 | } |
| 6495 | } |
| 6496 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6497 | if (read_yin_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_VERSION, 0, unres)) { |
| 6498 | goto error; |
| 6499 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6500 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6501 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6502 | } else if (!strcmp(child->name, "extension")) { |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6503 | c_ext++; |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 6504 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6505 | } else if (!strcmp(child->name, "deviation")) { |
| 6506 | c_dev++; |
| 6507 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6508 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6509 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6510 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6511 | } |
| 6512 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6513 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6514 | /* check for mandatory statements */ |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6515 | if (submodule) { |
| 6516 | if (!submodule->prefix) { |
| 6517 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
| 6518 | goto error; |
| 6519 | } |
| 6520 | if (!version_flag) { |
| 6521 | /* check version compatibility with the main module */ |
| 6522 | if (module->version > 1) { |
| 6523 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6524 | goto error; |
| 6525 | } |
| 6526 | } |
| 6527 | } else { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6528 | if (!module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6529 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6530 | goto error; |
| 6531 | } |
| 6532 | if (!module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6533 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6534 | goto error; |
| 6535 | } |
| 6536 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 6537 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6538 | /* allocate arrays for elements with cardinality of 0..n */ |
| 6539 | if (c_imp) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6540 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6541 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6542 | LOGMEM; |
| 6543 | goto error; |
| 6544 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6545 | } |
| 6546 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6547 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 6548 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6549 | LOGMEM; |
| 6550 | goto error; |
| 6551 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6552 | } |
| 6553 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6554 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 6555 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6556 | LOGMEM; |
| 6557 | goto error; |
| 6558 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6559 | } |
| 6560 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6561 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 6562 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6563 | LOGMEM; |
| 6564 | goto error; |
| 6565 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6566 | } |
| 6567 | if (c_inc) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6568 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6569 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6570 | LOGMEM; |
| 6571 | goto error; |
| 6572 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6573 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6574 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6575 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 6576 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6577 | LOGMEM; |
| 6578 | goto error; |
| 6579 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6580 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6581 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6582 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 6583 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6584 | LOGMEM; |
| 6585 | goto error; |
| 6586 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6587 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6588 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6589 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 6590 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6591 | LOGMEM; |
| 6592 | goto error; |
| 6593 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6594 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6595 | if (c_ext) { |
| 6596 | trg->extensions = calloc(c_ext, sizeof *trg->extensions); |
| 6597 | if (!trg->extensions) { |
| 6598 | LOGMEM; |
| 6599 | goto error; |
| 6600 | } |
| 6601 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6602 | if (c_extinst) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6603 | /* some extensions may be already present from the substatements */ |
| 6604 | reallocated = realloc(trg->ext, (c_extinst + trg->ext_size) * sizeof *trg->ext); |
| 6605 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6606 | LOGMEM; |
| 6607 | goto error; |
| 6608 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6609 | trg->ext = reallocated; |
| 6610 | |
| 6611 | /* init memory */ |
| 6612 | memset(&trg->ext[trg->ext_size], 0, c_extinst * sizeof *trg->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6613 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6614 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6615 | /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */ |
| 6616 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6617 | if (!strcmp(child->name, "import")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6618 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size], unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6619 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6620 | if (r) { |
| 6621 | goto error; |
| 6622 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6623 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6624 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6625 | r = fill_yin_include(trg, submodule, child, &trg->inc[trg->inc_size], unres); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6626 | trg->inc_size++; |
| 6627 | if (r) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6628 | goto error; |
| 6629 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6630 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6631 | } else if (!strcmp(child->name, "revision")) { |
| 6632 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6633 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6634 | goto error; |
| 6635 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6636 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6637 | /* check uniqueness of the revision date - not required by RFC */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6638 | for (i = 0; i < trg->rev_size; i++) { |
| 6639 | if (!strcmp(value, trg->rev[i].date)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6640 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 6641 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6642 | } |
| 6643 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6644 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6645 | LY_TREE_FOR_SAFE(child->child, next2, child2) { |
| 6646 | if (!child2->ns) { |
| 6647 | /* garbage */ |
| 6648 | continue; |
| 6649 | } else if (strcmp(child2->ns->value, LY_NSYIN)) { |
| 6650 | /* possible extension instance */ |
| 6651 | if (read_yin_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6652 | child2, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 6653 | goto error; |
| 6654 | } |
| 6655 | } else if (!strcmp(child2->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6656 | if (trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6657 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6658 | goto error; |
| 6659 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6660 | if (read_yin_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6661 | child2, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 6662 | goto error; |
| 6663 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6664 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 6665 | if (!trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6666 | goto error; |
| 6667 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6668 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6669 | if (trg->rev[trg->rev_size].ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6670 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6671 | goto error; |
| 6672 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6673 | if (read_yin_subnode_ext(trg, &trg->rev[trg->rev_size], LYEXT_PAR_REVISION, |
| 6674 | child2, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 6675 | goto error; |
| 6676 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6677 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 6678 | if (!trg->rev[trg->rev_size].ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6679 | goto error; |
| 6680 | } |
| 6681 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6682 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6683 | goto error; |
| 6684 | } |
| 6685 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6686 | trg->rev_size++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6687 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6688 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6689 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 6690 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6691 | if (r) { |
| 6692 | goto error; |
| 6693 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6694 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6695 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6696 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 6697 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6698 | if (r) { |
| 6699 | goto error; |
| 6700 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6701 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6702 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6703 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 6704 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6705 | if (r) { |
| 6706 | goto error; |
| 6707 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6708 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6709 | } else if (!strcmp(child->name, "extension")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6710 | r = fill_yin_extension(trg, child, &trg->extensions[trg->extensions_size], unres); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6711 | trg->extensions_size++; |
| 6712 | if (r) { |
| 6713 | goto error; |
| 6714 | } |
| 6715 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6716 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6717 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 6718 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6719 | if (r) { |
| 6720 | goto error; |
| 6721 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6722 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6723 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6724 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6725 | /* process extension instances */ |
| 6726 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6727 | 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] | 6728 | trg->ext_size++; |
| 6729 | if (r) { |
| 6730 | goto error; |
| 6731 | } |
| 6732 | } |
| 6733 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6734 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6735 | * refer to them. Submodule's data nodes are stored in the |
| 6736 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6737 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6738 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6739 | node = read_yin_grouping(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6740 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6741 | goto error; |
| 6742 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6743 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6744 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6745 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6746 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6747 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6748 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6749 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6750 | if (!strcmp(child->name, "container")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6751 | node = read_yin_container(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6752 | } else if (!strcmp(child->name, "leaf-list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6753 | node = read_yin_leaflist(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6754 | } else if (!strcmp(child->name, "leaf")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6755 | node = read_yin_leaf(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6756 | } else if (!strcmp(child->name, "list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6757 | node = read_yin_list(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6758 | } else if (!strcmp(child->name, "choice")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 6759 | node = read_yin_choice(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6760 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 6761 | node = read_yin_uses(trg, NULL, child, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6762 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6763 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 1, unres); |
| 6764 | } else if (!strcmp(child->name, "anydata")) { |
| 6765 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6766 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6767 | node = read_yin_rpc_action(trg, NULL, child, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6768 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6769 | node = read_yin_notif(trg, NULL, child, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6770 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6771 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6772 | goto error; |
| 6773 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 6774 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6775 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6776 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6777 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6778 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 6779 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6780 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 6781 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6782 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6783 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6784 | goto error; |
| 6785 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6786 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6787 | } |
| 6788 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6789 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6790 | |
| 6791 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6792 | /* cleanup */ |
| 6793 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6794 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6795 | } |
| 6796 | while (grps.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6797 | lyxml_free(module->ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6798 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6799 | while (augs.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6800 | lyxml_free(module->ctx, augs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6801 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6802 | while (exts.child) { |
| 6803 | lyxml_free(module->ctx, exts.child); |
| 6804 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6805 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6806 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6807 | } |
| 6808 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6809 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6810 | struct lys_submodule * |
| 6811 | 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] | 6812 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6813 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6814 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6815 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6816 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6817 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6818 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 6819 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6820 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6821 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6822 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6823 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6824 | /* check root element */ |
| 6825 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6826 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6827 | goto error; |
| 6828 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6829 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6830 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6831 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6832 | goto error; |
| 6833 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6834 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6835 | submodule = calloc(1, sizeof *submodule); |
| 6836 | if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6837 | LOGMEM; |
| 6838 | goto error; |
| 6839 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6840 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6841 | submodule->ctx = module->ctx; |
| 6842 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 6843 | submodule->type = 1; |
| 6844 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6845 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6846 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
| 6847 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6848 | goto error; |
| 6849 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6850 | |
Radek Krejci | 33fc477 | 2017-01-26 16:00:35 +0100 | [diff] [blame] | 6851 | lyp_sort_revisions((struct lys_module *)submodule); |
| 6852 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6853 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6854 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6855 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6856 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6857 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6858 | |
| 6859 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6860 | /* cleanup */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6861 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6862 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 6863 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6864 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6865 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6866 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6867 | } |
| 6868 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6869 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6870 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 6871 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 6872 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6873 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6874 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6875 | } |
| 6876 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6877 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6878 | struct lys_module * |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 6879 | 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] | 6880 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6881 | struct lyxml_elem *yin; |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 6882 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6883 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6884 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6885 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6886 | unres = calloc(1, sizeof *unres); |
| 6887 | if (!unres) { |
| 6888 | LOGMEM; |
| 6889 | return NULL; |
| 6890 | } |
| 6891 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 6892 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6893 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6894 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6895 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6896 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6897 | /* check root element */ |
| 6898 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 6899 | if (ly_strequal("submodule", yin->name, 0)) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 6900 | LOGVAL(LYE_SUBMODULE, LY_VLOG_NONE, NULL); |
| 6901 | } else { |
| 6902 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 6903 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6904 | goto error; |
| 6905 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6906 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6907 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6908 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6909 | goto error; |
| 6910 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6911 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6912 | module = calloc(1, sizeof *module); |
| 6913 | if (!module) { |
| 6914 | LOGMEM; |
| 6915 | goto error; |
| 6916 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6917 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6918 | module->ctx = ctx; |
| 6919 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 6920 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 6921 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6922 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 6923 | LOGVRB("Reading module \"%s\".", module->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6924 | if (read_sub_module(module, NULL, yin, unres)) { |
| 6925 | goto error; |
| 6926 | } |
| 6927 | |
| 6928 | /* resolve rest of unres items */ |
| 6929 | if (unres->count && resolve_unres_schema(module, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6930 | goto error; |
| 6931 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6932 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6933 | lyp_sort_revisions(module); |
Radek Krejci | bf28583 | 2017-01-26 16:05:41 +0100 | [diff] [blame^] | 6934 | lyp_rfn_apply_ext(module); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6935 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 6936 | if (revision) { |
| 6937 | /* check revision of the parsed model */ |
| 6938 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 6939 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 6940 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 6941 | goto error; |
| 6942 | } |
| 6943 | } |
| 6944 | |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6945 | /* check correctness of includes */ |
| 6946 | if (lyp_check_include_missing(module)) { |
| 6947 | goto error; |
| 6948 | } |
| 6949 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 6950 | if (lyp_ctx_add_module(&module)) { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 6951 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6952 | } |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 6953 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 6954 | if (module->deviation_size && !module->implemented) { |
| 6955 | LOGVRB("Module \"%s\" includes deviations, changing its conformance to \"implement\".", module->name); |
| 6956 | /* deviations always causes target to be made implemented, |
| 6957 | * but augents and leafrefs not, so we have to apply them now */ |
| 6958 | if (lys_set_implemented(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 6959 | goto error; |
| 6960 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 6961 | } |
| 6962 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6963 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6964 | unres_schema_free(NULL, &unres); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 6965 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6966 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6967 | |
| 6968 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6969 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6970 | lyxml_free(ctx, yin); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 6971 | unres_schema_free(module, &unres); |
| 6972 | |
| 6973 | if (!module) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 6974 | if (ly_vecode != LYVE_SUBMODULE) { |
| 6975 | LOGERR(ly_errno, "Module parsing failed."); |
| 6976 | } |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 6977 | return NULL; |
| 6978 | } |
| 6979 | |
| 6980 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6981 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 6982 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 6983 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6984 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6985 | } |